Georgios Pinitas | e2c82fe | 2017-10-02 18:51:47 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2017 ARM Limited. |
| 3 | * |
| 4 | * SPDX-License-Identifier: MIT |
| 5 | * |
| 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 7 | * of this software and associated documentation files (the "Software"), to |
| 8 | * deal in the Software without restriction, including without limitation the |
| 9 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or |
| 10 | * sell copies of the Software, and to permit persons to whom the Software is |
| 11 | * furnished to do so, subject to the following conditions: |
| 12 | * |
| 13 | * The above copyright notice and this permission notice shall be included in all |
| 14 | * copies or substantial portions of the Software. |
| 15 | * |
| 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 22 | * SOFTWARE. |
| 23 | */ |
| 24 | #ifndef __ARM_COMPUTE_GRAPH_SUBGRAPH_H__ |
| 25 | #define __ARM_COMPUTE_GRAPH_SUBGRAPH_H__ |
| 26 | |
| 27 | #include "arm_compute/graph/Graph.h" |
| 28 | #include "arm_compute/graph/INode.h" |
| 29 | #include "arm_compute/graph/ITensorObject.h" |
| 30 | #include "arm_compute/graph/SubTensor.h" |
| 31 | #include "arm_compute/graph/Tensor.h" |
| 32 | #include "arm_compute/graph/Types.h" |
| 33 | #include "arm_compute/runtime/IFunction.h" |
| 34 | |
| 35 | #include <memory> |
| 36 | |
| 37 | namespace arm_compute |
| 38 | { |
| 39 | namespace graph |
| 40 | { |
| 41 | /** SubGraph class */ |
| 42 | class SubGraph |
| 43 | { |
| 44 | public: |
| 45 | /** Constructor */ |
| 46 | SubGraph(); |
| 47 | /** Adds a node to the graph |
| 48 | * |
| 49 | * @param[in] node Node to add |
| 50 | */ |
| 51 | void add_node(std::unique_ptr<INode> node); |
| 52 | /** Adds a tensor to the graph |
| 53 | * |
| 54 | * @param[in] tensor Tensor to add |
| 55 | */ |
| 56 | void add_tensor_object(std::unique_ptr<ITensorObject> tensor); |
| 57 | /** Constructs a graph from a subgraph |
| 58 | * |
| 59 | * @param[in] hint Execution target hint |
| 60 | * @param[in] input Input to the graph |
| 61 | * @param[in] output Output to the graph |
| 62 | * |
| 63 | * @return A graph |
| 64 | */ |
| 65 | std::unique_ptr<Graph> construct(TargetHint hint, std::unique_ptr<ITensorObject> input, std::unique_ptr<ITensorObject> output); |
| 66 | /** Checks if the subgraph has an input |
| 67 | * |
| 68 | * @return True if the sub-graph has an input else false |
| 69 | */ |
| 70 | bool has_input() const; |
| 71 | /** Checks if the subgraph has an output |
| 72 | * |
| 73 | * @return True if the sub-graph has an output else false |
| 74 | */ |
| 75 | bool has_output() const; |
| 76 | |
| 77 | private: |
| 78 | std::vector<std::unique_ptr<INode>> _nodes; |
| 79 | std::unique_ptr<ITensorObject> _input; |
| 80 | std::unique_ptr<ITensorObject> _output; |
| 81 | }; |
| 82 | |
| 83 | SubGraph &operator<<(SubGraph &graph, Tensor &&tensor); |
| 84 | SubGraph &operator<<(SubGraph &graph, SubTensor &&sub_tensor); |
| 85 | |
| 86 | template <typename Node> |
| 87 | SubGraph &operator<<(SubGraph &sub_graph, Node node) |
| 88 | { |
| 89 | sub_graph.add_node(arm_compute::support::cpp14::make_unique<Node>(std::move(node))); |
| 90 | return sub_graph; |
| 91 | } |
| 92 | } // namespace graph |
| 93 | } // namespace arm_compute |
| 94 | #endif /* __ARM_COMPUTE_GRAPH_INODE_H__ */ |