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