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