blob: 72130878f8059d31df1d3230c90712fe76046e90 [file] [log] [blame]
Anthony Barbier2a07e182017-08-04 18:20:27 +01001/*
Gian Marco36a0a462018-01-12 10:21:40 +00002 * Copyright (c) 2017-2018 ARM Limited.
Anthony Barbier2a07e182017-08-04 18:20:27 +01003 *
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 Marco36a0a462018-01-12 10:21:40 +000027#include "arm_compute/core/CL/CLTypes.h"
Anthony Barbier2a07e182017-08-04 18:20:27 +010028#include "arm_compute/graph/INode.h"
Georgios Pinitase2c82fe2017-10-02 18:51:47 +010029#include "arm_compute/graph/ITensorObject.h"
30#include "arm_compute/graph/SubTensor.h"
Anthony Barbier2a07e182017-08-04 18:20:27 +010031#include "arm_compute/graph/Tensor.h"
32#include "arm_compute/graph/Types.h"
33#include "support/ToolchainSupport.h"
34
35#include <memory>
36
37namespace arm_compute
38{
39class IFunction;
40
41namespace graph
42{
43/** Graph class */
44class Graph final
45{
46public:
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 Giorgioe3fba0a2018-02-14 14:18:01 +000059 /** 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 Barbier2a07e182017-08-04 18:20:27 +010064 /** 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 Pinitase2c82fe2017-10-02 18:51:47 +010075 void add_tensor_object(std::unique_ptr<ITensorObject> tensor);
Gian Marco36a0a462018-01-12 10:21:40 +000076 /** Check if the OpenCL target is available
Isabella Gottardib28f29d2017-11-09 17:05:07 +000077 */
78 static bool opencl_is_available();
Gian Marco36a0a462018-01-12 10:21:40 +000079 /** Returns the GPU target
80 */
81 static GPUTarget gpu_target();
Anthony Barbier2a07e182017-08-04 18:20:27 +010082 /** 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 Spyroue4720822017-10-02 17:44:52 +010087
Georgios Pinitasff421f22017-10-04 16:53:58 +010088 /** Returns the graph hints that are currently used
89 *
90 * @return Graph hints
91 */
92 GraphHints &hints();
Anthony Barbier2a07e182017-08-04 18:20:27 +010093
94private:
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 */
106Graph &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 */
114Graph &operator<<(Graph &graph, Tensor &&tensor);
Georgios Pinitase2c82fe2017-10-02 18:51:47 +0100115/** 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 */
122Graph &operator<<(Graph &graph, SubTensor &&sub_tensor);
Georgios Pinitasff421f22017-10-04 16:53:58 +0100123/** Overloaded stream operator to provide a target hint to the graph
Anthony Barbier2a07e182017-08-04 18:20:27 +0100124 *
Georgios Pinitasff421f22017-10-04 16:53:58 +0100125 * @param[in, out] graph Graph to provide the hint to
126 * @param[in] target_hint Target hint to be considered
Anthony Barbier2a07e182017-08-04 18:20:27 +0100127 *
128 * @return Updated graph
129 */
Georgios Pinitasff421f22017-10-04 16:53:58 +0100130Graph &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 */
138Graph &operator<<(Graph &graph, ConvolutionMethodHint conv_method_hint);
Anthony Barbier2a07e182017-08-04 18:20:27 +0100139/** 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 */
146template <typename Node>
147Graph &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__ */