Anthony Barbier | 2a07e18 | 2017-08-04 18:20:27 +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_GRAPH_H__ |
| 25 | #define __ARM_COMPUTE_GRAPH_GRAPH_H__ |
| 26 | |
| 27 | #include "arm_compute/graph/INode.h" |
| 28 | #include "arm_compute/graph/Tensor.h" |
| 29 | #include "arm_compute/graph/Types.h" |
| 30 | #include "support/ToolchainSupport.h" |
| 31 | |
| 32 | #include <memory> |
| 33 | |
| 34 | namespace arm_compute |
| 35 | { |
| 36 | class IFunction; |
| 37 | |
| 38 | namespace graph |
| 39 | { |
| 40 | /** Graph class */ |
| 41 | class Graph final |
| 42 | { |
| 43 | public: |
| 44 | /** Constructor */ |
| 45 | Graph(); |
| 46 | /** Destructor */ |
| 47 | ~Graph(); |
| 48 | /** Prevent instances from being copy constructed */ |
| 49 | Graph(const Graph &) = delete; |
| 50 | /** Prevent instances from being copy assigned */ |
| 51 | const Graph &operator=(const Graph &) = delete; |
| 52 | /** Prevent instances from being move constructed */ |
| 53 | Graph(Graph &&) = delete; |
| 54 | /** Prevent instances from being move assigned */ |
| 55 | Graph &operator=(Graph &&) = delete; |
| 56 | /** Executes the graph */ |
| 57 | void run(); |
| 58 | /** Adds a node to the graph |
| 59 | * |
| 60 | * @param[in] node Node to add |
| 61 | */ |
| 62 | void add_node(std::unique_ptr<INode> node); |
| 63 | /** Adds a tensor to the graph |
| 64 | * |
| 65 | * @param[in] tensor Tensor to add |
| 66 | */ |
| 67 | void add_tensor(std::unique_ptr<Tensor> tensor); |
Anthony Barbier | 2a07e18 | 2017-08-04 18:20:27 +0100 | [diff] [blame] | 68 | /** Manually sets the output of the current node |
| 69 | * |
| 70 | * @param[in] tmp Output info to set |
| 71 | */ |
| 72 | void set_temp(TensorInfo &&tmp); |
Anthony Barbier | 2a07e18 | 2017-08-04 18:20:27 +0100 | [diff] [blame] | 73 | /** Sets whether to enable information print out |
| 74 | * |
| 75 | * @param[in] is_enabled Set to true if need info printed out |
| 76 | */ |
| 77 | void set_info_enablement(bool is_enabled); |
Georgios Pinitas | ff421f2 | 2017-10-04 16:53:58 +0100 | [diff] [blame^] | 78 | /** Returns the graph hints that are currently used |
| 79 | * |
| 80 | * @return Graph hints |
| 81 | */ |
| 82 | GraphHints &hints(); |
Anthony Barbier | 2a07e18 | 2017-08-04 18:20:27 +0100 | [diff] [blame] | 83 | |
| 84 | private: |
| 85 | class Private; |
| 86 | std::unique_ptr<Private> _pimpl; /**< Internal implementation class */ |
| 87 | }; |
| 88 | |
| 89 | /** Overloaded stream operator to add a tensor through its tensor info to the graph |
| 90 | * |
| 91 | * @param[in, out] graph Graph to add the tensor |
| 92 | * @param[in] info Tensor information of the tensor to be added |
| 93 | * |
| 94 | * @return Updated graph |
| 95 | */ |
| 96 | Graph &operator<<(Graph &graph, TensorInfo &&info); |
| 97 | /** Overloaded stream operator to add a tensor to the graph |
| 98 | * |
| 99 | * @param[in, out] graph Graph to add the tensor |
| 100 | * @param[in] tensor Tensor to be added |
| 101 | * |
| 102 | * @return Updated graph |
| 103 | */ |
| 104 | Graph &operator<<(Graph &graph, Tensor &&tensor); |
Georgios Pinitas | ff421f2 | 2017-10-04 16:53:58 +0100 | [diff] [blame^] | 105 | /** Overloaded stream operator to provide a target hint to the graph |
Anthony Barbier | 2a07e18 | 2017-08-04 18:20:27 +0100 | [diff] [blame] | 106 | * |
Georgios Pinitas | ff421f2 | 2017-10-04 16:53:58 +0100 | [diff] [blame^] | 107 | * @param[in, out] graph Graph to provide the hint to |
| 108 | * @param[in] target_hint Target hint to be considered |
Anthony Barbier | 2a07e18 | 2017-08-04 18:20:27 +0100 | [diff] [blame] | 109 | * |
| 110 | * @return Updated graph |
| 111 | */ |
Georgios Pinitas | ff421f2 | 2017-10-04 16:53:58 +0100 | [diff] [blame^] | 112 | Graph &operator<<(Graph &graph, TargetHint target_hint); |
| 113 | /** Overloaded stream operator to provide a convolution method hint to the graph |
| 114 | * |
| 115 | * @param[in, out] graph Graph to provide the hint to |
| 116 | * @param[in] conv_method_hint Convolution method hint to be considered |
| 117 | * |
| 118 | * @return Updated graph |
| 119 | */ |
| 120 | Graph &operator<<(Graph &graph, ConvolutionMethodHint conv_method_hint); |
Anthony Barbier | 2a07e18 | 2017-08-04 18:20:27 +0100 | [diff] [blame] | 121 | /** Overloaded stream operator to add a node to the graph |
| 122 | * |
| 123 | * @param[in, out] graph Graph to add the tensor |
| 124 | * @param[in] node Node to be added |
| 125 | * |
| 126 | * @return Updated graph |
| 127 | */ |
| 128 | template <typename Node> |
| 129 | Graph &operator<<(Graph &graph, Node node) |
| 130 | { |
| 131 | graph.add_node(arm_compute::support::cpp14::make_unique<Node>(std::move(node))); |
| 132 | return graph; |
| 133 | } |
| 134 | } // namespace graph |
| 135 | } // namespace arm_compute |
| 136 | #endif /* __ARM_COMPUTE_GRAPH_GRAPH_H__ */ |