blob: 4afe96b40b4bb294aa289cdb428fd7e821750766 [file] [log] [blame]
Anthony Barbier2a07e182017-08-04 18:20:27 +01001/*
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 Pinitase2c82fe2017-10-02 18:51:47 +010028#include "arm_compute/graph/ITensorObject.h"
29#include "arm_compute/graph/SubTensor.h"
Anthony Barbier2a07e182017-08-04 18:20:27 +010030#include "arm_compute/graph/Tensor.h"
31#include "arm_compute/graph/Types.h"
32#include "support/ToolchainSupport.h"
33
34#include <memory>
35
36namespace arm_compute
37{
38class IFunction;
39
40namespace graph
41{
42/** Graph class */
43class Graph final
44{
45public:
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 Pinitase2c82fe2017-10-02 18:51:47 +010069 void add_tensor_object(std::unique_ptr<ITensorObject> tensor);
Anthony Barbier2a07e182017-08-04 18:20:27 +010070 /** Manually sets the output of the current node
71 *
72 * @param[in] tmp Output info to set
73 */
74 void set_temp(TensorInfo &&tmp);
Michalis Spyroue4720822017-10-02 17:44:52 +010075
Georgios Pinitasff421f22017-10-04 16:53:58 +010076 /** Returns the graph hints that are currently used
77 *
78 * @return Graph hints
79 */
80 GraphHints &hints();
Anthony Barbier2a07e182017-08-04 18:20:27 +010081
82private:
83 class Private;
84 std::unique_ptr<Private> _pimpl; /**< Internal implementation class */
85};
86
87/** Overloaded stream operator to add a tensor through its tensor info to the graph
88 *
89 * @param[in, out] graph Graph to add the tensor
90 * @param[in] info Tensor information of the tensor to be added
91 *
92 * @return Updated graph
93 */
94Graph &operator<<(Graph &graph, TensorInfo &&info);
95/** Overloaded stream operator to add a tensor to the graph
96 *
97 * @param[in, out] graph Graph to add the tensor
98 * @param[in] tensor Tensor to be added
99 *
100 * @return Updated graph
101 */
102Graph &operator<<(Graph &graph, Tensor &&tensor);
Georgios Pinitase2c82fe2017-10-02 18:51:47 +0100103/** Overloaded stream operator to add a sub-tensor to the graph
104 *
105 * @param[in, out] graph Graph to add the tensor
106 * @param[in] sub_tensor Sub-tensor to be added
107 *
108 * @return Updated graph
109 */
110Graph &operator<<(Graph &graph, SubTensor &&sub_tensor);
Georgios Pinitasff421f22017-10-04 16:53:58 +0100111/** Overloaded stream operator to provide a target hint to the graph
Anthony Barbier2a07e182017-08-04 18:20:27 +0100112 *
Georgios Pinitasff421f22017-10-04 16:53:58 +0100113 * @param[in, out] graph Graph to provide the hint to
114 * @param[in] target_hint Target hint to be considered
Anthony Barbier2a07e182017-08-04 18:20:27 +0100115 *
116 * @return Updated graph
117 */
Georgios Pinitasff421f22017-10-04 16:53:58 +0100118Graph &operator<<(Graph &graph, TargetHint target_hint);
119/** Overloaded stream operator to provide a convolution method hint to the graph
120 *
121 * @param[in, out] graph Graph to provide the hint to
122 * @param[in] conv_method_hint Convolution method hint to be considered
123 *
124 * @return Updated graph
125 */
126Graph &operator<<(Graph &graph, ConvolutionMethodHint conv_method_hint);
Anthony Barbier2a07e182017-08-04 18:20:27 +0100127/** Overloaded stream operator to add a node to the graph
128 *
129 * @param[in, out] graph Graph to add the tensor
130 * @param[in] node Node to be added
131 *
132 * @return Updated graph
133 */
134template <typename Node>
135Graph &operator<<(Graph &graph, Node node)
136{
137 graph.add_node(arm_compute::support::cpp14::make_unique<Node>(std::move(node)));
138 return graph;
139}
140} // namespace graph
141} // namespace arm_compute
142#endif /* __ARM_COMPUTE_GRAPH_GRAPH_H__ */