blob: 5646ea81d2bb78e1d5e6d644d473911aa20d022f [file] [log] [blame]
Anthony Barbier2a07e182017-08-04 18:20:27 +01001/*
Jakub Sujak0d27b2e2023-08-24 14:01:20 +01002 * Copyright (c) 2018-2019,2021,2023 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 */
Jakub Sujak0d27b2e2023-08-24 14:01:20 +010024#ifndef ACL_ARM_COMPUTE_GRAPH_INODE_H
25#define ACL_ARM_COMPUTE_GRAPH_INODE_H
Anthony Barbier2a07e182017-08-04 18:20:27 +010026
Georgios Pinitasd9eb2752018-04-03 13:44:29 +010027#include "arm_compute/core/Error.h"
Isabella Gottardi0ae5de92019-03-14 10:32:11 +000028#include "arm_compute/graph/LayerDescriptors.h"
Georgios Pinitasd9eb2752018-04-03 13:44:29 +010029#include "arm_compute/graph/TensorDescriptor.h"
Anthony Barbier2a07e182017-08-04 18:20:27 +010030#include "arm_compute/graph/Types.h"
Anthony Barbier2a07e182017-08-04 18:20:27 +010031
Sheri Zhangc65023e2021-11-03 21:24:00 +000032#include <list>
Georgios Pinitasd9eb2752018-04-03 13:44:29 +010033#include <set>
Anthony Barbier2a07e182017-08-04 18:20:27 +010034
35namespace arm_compute
36{
37namespace graph
38{
Georgios Pinitasd9eb2752018-04-03 13:44:29 +010039// Forward declarations
40class Graph;
41class Edge;
42class INodeVisitor;
43class Tensor;
44
Anthony Barbier2a07e182017-08-04 18:20:27 +010045/** Node interface */
46class INode
47{
48public:
Georgios Pinitasd9eb2752018-04-03 13:44:29 +010049 /** Constructor */
50 INode();
51 /** Destructor **/
Anthony Barbier2a07e182017-08-04 18:20:27 +010052 virtual ~INode() = default;
Georgios Pinitasd9eb2752018-04-03 13:44:29 +010053 /** Prevent instances of this class from being copied (As this class contains pointers) */
54 INode(const INode &) = delete;
55 /** Prevent instances of this class from being copy assigned (As this class contains pointers) */
56 INode &operator=(const INode &) = delete;
57 /** Allow instances of this class to be moved */
58 INode(INode &&) = default;
59 /** Allow instances of this class to be move assigned */
60 INode &operator=(INode &&) = default;
61 /** Validate node
Anthony Barbier2a07e182017-08-04 18:20:27 +010062 *
Georgios Pinitasd9eb2752018-04-03 13:44:29 +010063 * @return Status containing any errors
Anthony Barbier2a07e182017-08-04 18:20:27 +010064 */
Georgios Pinitascac13b12018-04-27 19:07:19 +010065 virtual Status validate() const;
Georgios Pinitasd9eb2752018-04-03 13:44:29 +010066 /** Returns node's type
Anthony Barbier2a07e182017-08-04 18:20:27 +010067 *
Georgios Pinitasd9eb2752018-04-03 13:44:29 +010068 * @return Node's type
Anthony Barbier2a07e182017-08-04 18:20:27 +010069 */
Georgios Pinitasd9eb2752018-04-03 13:44:29 +010070 virtual NodeType type() const = 0;
71 /** Accepts a node visitor
Michele Di Giorgiodde9ec92018-02-13 15:24:04 +000072 *
Georgios Pinitasd9eb2752018-04-03 13:44:29 +010073 * @param[in] v Visitor to accept
Michele Di Giorgiodde9ec92018-02-13 15:24:04 +000074 */
Georgios Pinitasd9eb2752018-04-03 13:44:29 +010075 virtual void accept(INodeVisitor &v) = 0;
76 /** Forwards descriptor information to outputs if possible
Michele Di Giorgiodde9ec92018-02-13 15:24:04 +000077 *
Georgios Pinitasd9eb2752018-04-03 13:44:29 +010078 * @return True if descriptor information could be forwarded otherwise false
Michele Di Giorgiodde9ec92018-02-13 15:24:04 +000079 */
Georgios Pinitasd9eb2752018-04-03 13:44:29 +010080 virtual bool forward_descriptors() = 0;
81 /** Calculates output configuration
82 *
83 * @param[in] idx Output index to configure
84 *
85 * @return Output descriptor configuration
86 */
87 virtual TensorDescriptor configure_output(size_t idx) const = 0;
88 /** Returns node's name
89 *
90 * @return Node name
91 */
92 std::string name() const;
93 /** Returns node's ID
94 *
95 * @return Node's ID
96 */
97 NodeID id() const;
98 /** Returns node's Graph
99 *
100 * @return Node's graph
101 */
102 const Graph *graph() const;
103 /** Returns node's Graph
104 *
105 * @return Node's graph
106 */
107 Graph *graph();
108 /** Sets the graph that this node is registered to
109 *
110 * @param[in] g Back reference to graph
111 */
112 void set_graph(Graph *g);
113 /** Sets the node id
114 *
115 * @param[in] id Node id
116 */
117 void set_id(NodeID id);
118 /** Sets common node parameters
119 *
120 * @param[in] common_params Common node parameters to set
121 */
122 void set_common_node_parameters(NodeParams common_params);
123 /** Sets target preference
124 *
125 * @note This is not the target that the graph executor might choose, its just an indication
126 *
127 * @param[in] target Target preference
128 */
129 void set_requested_target(Target target);
130 /** Sets the final execution target
131 *
132 * @note GraphManager might change this target
133 *
134 * @param[in] target Final execution target
135 */
136 void set_assigned_target(Target target);
137 /** Sets the output tensor of at a given index
138 *
139 * @note All edges will get updated
140 *
141 * @param[in] tid Tensor ID
142 * @param[in] idx Output index
143 */
144 void set_output_tensor(TensorID tid, size_t idx);
145 /** Returns inputs of the node
146 *
147 * @return Inputs of the node
148 */
149 const std::vector<TensorID> &inputs() const;
150 /** Returns outputs of the node
151 *
152 * @return Outputs of the node
153 */
154 const std::vector<TensorID> &outputs() const;
155 /** Returns input edge set
156 *
157 * @return Set of input edges
158 */
159 const std::vector<EdgeID> &input_edges() const;
160 /** Returns output edge set
161 *
162 * @return Set of output edges
163 */
164 const std::set<EdgeID> &output_edges() const;
165 /** Returns the tensor ID of a given input of the node
166 *
167 * @note Precondition : idx should be a valid input index
168 *
169 * @param[in] idx Index of the node input
170 *
171 * @return TensorID of the requested input
172 */
173 TensorID input_id(size_t idx) const;
174 /** Returns the tensor ID of a given output of the node
175 *
176 * @note Precondition : idx should be a valid output index
177 *
178 * @param[in] idx Index of the node output
179 *
180 * @return TensorID of the requested output
181 */
182 TensorID output_id(size_t idx) const;
183 /** Returns the tensor of a given input of the node
184 *
185 * @note Precondition : idx should be a valid input index
186 *
187 * @param[in] idx Index of the node input
188 *
189 * @return Tensor of the requested input
190 */
191 Tensor *input(size_t idx) const;
192 /** Returns the tensor of a given output of the node
193 *
194 * @note Precondition : idx should be a valid output index
195 *
196 * @param[in] idx Index of the node output
197 *
198 * @return Tensor of the requested output
199 */
200 Tensor *output(size_t idx) const;
201 /** Returns the edge ID of a given input of the node
202 *
203 * @note Precondition : idx should be a valid input index
204 *
205 * @param[in] idx Index of the node input
206 *
207 * @return EdgeID of the requested input
208 */
209 EdgeID input_edge_id(size_t idx) const;
210 /** Returns the edge of a given input of the node
211 *
212 * @note Precondition : idx should be a valid input index
213 *
214 * @param[in] idx Index of the node input
215 *
216 * @return Edge of the requested input
217 */
218 Edge *input_edge(size_t idx) const;
219 /** Returns number of inputs of the node
220 *
221 * @return Number of inputs
222 */
223 size_t num_inputs() const;
224 /** Returns number of outputs of the node
225 *
226 * @return Number of outputs
227 */
228 size_t num_outputs() const;
Georgios Pinitas2a2db592018-08-15 12:14:46 +0100229 /** Returns common node parameters
230 *
231 * @return Common node parameters
232 */
233 NodeParams common_node_params() const;
Georgios Pinitasd9eb2752018-04-03 13:44:29 +0100234 /** Returns requested target for this node
235 *
236 * @return Requested execution target
237 */
238 Target requested_target() const;
239 /** Returns assigned target for this node
240 *
241 * @return Assigned target of this node
242 */
243 Target assigned_target() const;
Anthony Barbier2a07e182017-08-04 18:20:27 +0100244
Anthony Barbier2a07e182017-08-04 18:20:27 +0100245protected:
Georgios Pinitasd9eb2752018-04-03 13:44:29 +0100246 friend class Graph;
Anthony Barbier2a07e182017-08-04 18:20:27 +0100247
248protected:
Jakub Sujak0d27b2e2023-08-24 14:01:20 +0100249 Graph *_graph; /**< Backward reference to graph owning the node */
250 NodeID _id; /**< Node ID */
251 NodeParams _common_params; /**< Node common params */
252 std::vector<TensorID> _outputs; /**< Output of the node */
253 std::vector<EdgeID> _input_edges; /**< Inputs edge set */
254 std::set<EdgeID> _output_edges; /**< Output edge set */
255 Target _assigned_target; /**< Assigned target by the Graph executor */
Anthony Barbier2a07e182017-08-04 18:20:27 +0100256};
257} // namespace graph
258} // namespace arm_compute
Jakub Sujak0d27b2e2023-08-24 14:01:20 +0100259#endif // ACL_ARM_COMPUTE_GRAPH_INODE_H