Compute Library
 23.08
INode.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018,2021 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  */
25 
26 #include "arm_compute/core/Error.h"
27 #include "arm_compute/graph/Edge.h"
30 
31 namespace arm_compute
32 {
33 namespace graph
34 {
35 // *INDENT-OFF*
36 // clang-format off
38  : _graph(nullptr), _id(EmptyNodeID), _common_params({ "", Target::UNSPECIFIED}),
39  _outputs(), _input_edges(), _output_edges(), _assigned_target(Target::UNSPECIFIED)
40  ,_post_op_info_list(std::list<std::unique_ptr<ConvPostOpInfo>> {})
41 {
42 }
43 // clang-format on
44 // *INDENT-ON*
45 
47 {
48  return Status{};
49 }
50 
52 {
53  ARM_COMPUTE_ERROR_ON(g == nullptr);
54  _graph = g;
55 }
56 
58 {
59  _id = id;
60 }
61 
63 {
64  _common_params = std::move(common_params);
65 }
66 
68 {
69  _common_params.target = target;
70 }
71 
73 {
74  _assigned_target = target;
75 }
76 
77 void INode::set_output_tensor(TensorID tid, size_t idx)
78 {
79  if(tid != NullTensorID && (idx < _outputs.size()) && (_graph->tensor(tid) != nullptr))
80  {
81  ARM_COMPUTE_ERROR_ON(_graph == nullptr);
82  Tensor *updated_tensor = _graph->tensor(tid);
83  _outputs[idx] = tid;
84 
85  // Set tensor to all output edges of the node
86  for(auto &output_edge_id : _output_edges)
87  {
88  auto output_edge = _graph->edge(output_edge_id);
89  if(output_edge != nullptr)
90  {
91  // Unbind edge from current tensor
92  auto current_output_tensor = output_edge->tensor();
93  current_output_tensor->unbind_edge(output_edge->id());
94 
95  // Update tensor to edge and rebind tensor
96  output_edge->update_bound_tensor(updated_tensor);
97  updated_tensor->bind_edge(output_edge->id());
98  }
99  }
100  }
101 }
102 
104 {
105  return _id;
106 }
107 
108 std::string INode::name() const
109 {
110  return _common_params.name;
111 }
112 
113 const Graph *INode::graph() const
114 {
115  return _graph;
116 }
117 
119 {
120  return _graph;
121 }
122 
123 const std::vector<TensorID> &INode::outputs() const
124 {
125  return _outputs;
126 }
127 
128 const std::vector<EdgeID> &INode::input_edges() const
129 {
130  return _input_edges;
131 }
132 
133 const std::set<EdgeID> &INode::output_edges() const
134 {
135  return _output_edges;
136 }
137 
138 TensorID INode::input_id(size_t idx) const
139 {
140  ARM_COMPUTE_ERROR_ON(idx >= _input_edges.size());
141  Edge *e = _graph->edge(_input_edges[idx]);
142  return (e != nullptr) ? e->tensor_id() : NullTensorID;
143 }
144 
145 TensorID INode::output_id(size_t idx) const
146 {
147  ARM_COMPUTE_ERROR_ON(idx >= _outputs.size());
148  return _outputs[idx];
149 }
150 
151 Tensor *INode::input(size_t idx) const
152 {
153  ARM_COMPUTE_ERROR_ON(_graph == nullptr);
154  ARM_COMPUTE_ERROR_ON(idx >= _input_edges.size());
155  Edge *e = _graph->edge(_input_edges[idx]);
156  return (e != nullptr) ? e->tensor() : nullptr;
157 }
158 
159 Tensor *INode::output(size_t idx) const
160 {
161  ARM_COMPUTE_ERROR_ON(_graph == nullptr);
162  ARM_COMPUTE_ERROR_ON(idx >= _outputs.size());
163  return _graph->tensor(_outputs[idx]);
164 }
165 
166 EdgeID INode::input_edge_id(size_t idx) const
167 {
168  ARM_COMPUTE_ERROR_ON(idx >= _input_edges.size());
169  return _input_edges[idx];
170 }
171 
172 Edge *INode::input_edge(size_t idx) const
173 {
174  ARM_COMPUTE_ERROR_ON(_graph == nullptr);
175  ARM_COMPUTE_ERROR_ON(idx >= _input_edges.size());
176  return _graph->edge(_input_edges[idx]);
177 }
178 
179 size_t INode::num_inputs() const
180 {
181  return _input_edges.size();
182 }
183 
184 size_t INode::num_outputs() const
185 {
186  return _outputs.size();
187 }
188 
190 {
191  return _common_params;
192 }
193 
195 {
196  return _common_params.target;
197 }
198 
200 {
201  return _assigned_target;
202 }
203 
204 const std::list<std::unique_ptr<ConvPostOpInfo>> &INode::post_op_info_list() const
205 {
206  return _post_op_info_list;
207 }
208 
209 std::list<std::unique_ptr<ConvPostOpInfo>> &INode::post_op_info_list()
210 {
211  return _post_op_info_list;
212 }
213 } // namespace graph
214 } // namespace arm_compute
arm_compute::graph::INode::validate
virtual Status validate() const
Validate node.
Definition: INode.cpp:46
arm_compute::graph::NodeParams
Common node parameters.
Definition: Types.h:274
arm_compute::graph::Graph::edge
const Edge * edge(EdgeID id) const
Get edge object given its id.
Definition: Graph.cpp:214
arm_compute::graph::INode::common_node_params
NodeParams common_node_params() const
Returns common node parameters.
Definition: INode.cpp:189
arm_compute::graph::INode::set_output_tensor
void set_output_tensor(TensorID tid, size_t idx)
Sets the output tensor of at a given index.
Definition: INode.cpp:77
arm_compute::graph::INode::input_edge_id
EdgeID input_edge_id(size_t idx) const
Returns the edge ID of a given input of the node.
Definition: INode.cpp:166
Edge.h
arm_compute::graph::INode::input_id
TensorID input_id(size_t idx) const
Returns the tensor ID of a given input of the node.
Definition: INode.cpp:138
arm_compute::graph::INode::output
Tensor * output(size_t idx) const
Returns the tensor of a given output of the node.
Definition: INode.cpp:159
arm_compute::graph::INode::num_inputs
size_t num_inputs() const
Returns number of inputs of the node.
Definition: INode.cpp:179
INode.h
arm_compute::graph::INode::outputs
const std::vector< TensorID > & outputs() const
Returns outputs of the node.
Definition: INode.cpp:123
arm_compute::graph::INode::output_edges
const std::set< EdgeID > & output_edges() const
Returns output edge set.
Definition: INode.cpp:133
arm_compute::graph::INode::INode
INode()
Constructor.
Definition: INode.cpp:37
arm_compute::graph::Tensor
Tensor object.
Definition: Tensor.h:41
arm_compute::graph::NodeParams::name
std::string name
Node name.
Definition: Types.h:276
Error.h
arm_compute::graph::Edge
Graph Edge.
Definition: Edge.h:39
arm_compute::graph::INode::set_assigned_target
void set_assigned_target(Target target)
Sets the final execution target.
Definition: INode.cpp:72
ARM_COMPUTE_ERROR_ON
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
Definition: Error.h:467
arm_compute::graph::Target
Target
Definition: Types.h:104
arm_compute::graph::Edge::tensor
Tensor * tensor() const
Returns the tensor associated with this edge.
Definition: Edge.h:116
arm_compute::graph::INode::post_op_info_list
const std::list< std::unique_ptr< ConvPostOpInfo > > & post_op_info_list() const
Post operator info list.
Definition: INode.cpp:204
arm_compute::graph::Target::UNSPECIFIED
@ UNSPECIFIED
Unspecified Target.
arm_compute::Status
Status class.
Definition: Error.h:52
arm_compute::graph::Tensor::bind_edge
void bind_edge(EdgeID eid)
Binds the tensor with an edge.
Definition: Tensor.cpp:109
arm_compute::graph::INode::name
std::string name() const
Returns node's name.
Definition: INode.cpp:108
arm_compute::graph::Tensor::unbind_edge
void unbind_edge(EdgeID eid)
Unbinds an edge from a tensor.
Definition: Tensor.cpp:114
arm_compute::graph::INode::input_edge
Edge * input_edge(size_t idx) const
Returns the edge of a given input of the node.
Definition: INode.cpp:172
arm_compute::graph::INode::requested_target
Target requested_target() const
Returns requested target for this node.
Definition: INode.cpp:194
arm_compute::graph::INode::set_graph
void set_graph(Graph *g)
Sets the graph that this node is registered to.
Definition: INode.cpp:51
arm_compute::graph::NodeID
unsigned int NodeID
Definition: Types.h:73
arm_compute::graph::INode::input_edges
const std::vector< EdgeID > & input_edges() const
Returns input edge set.
Definition: INode.cpp:128
arm_compute
Copyright (c) 2017-2023 Arm Limited.
Definition: introduction.dox:24
arm_compute::graph::Graph::tensor
const Tensor * tensor(TensorID id) const
Get tensor object given its id.
Definition: Graph.cpp:224
Tensor.h
arm_compute::graph::INode::input
Tensor * input(size_t idx) const
Returns the tensor of a given input of the node.
Definition: INode.cpp:151
arm_compute::graph::INode::graph
const Graph * graph() const
Returns node's Graph.
Definition: INode.cpp:113
arm_compute::graph::INode::output_id
TensorID output_id(size_t idx) const
Returns the tensor ID of a given output of the node.
Definition: INode.cpp:145
arm_compute::graph::INode::num_outputs
size_t num_outputs() const
Returns number of outputs of the node.
Definition: INode.cpp:184
arm_compute::graph::INode::assigned_target
Target assigned_target() const
Returns assigned target for this node.
Definition: INode.cpp:199
arm_compute::graph::Graph
Graph class.
Definition: Graph.h:52
arm_compute::graph::NullTensorID
constexpr TensorID NullTensorID
Constant NodeID specifying an equivalent of null node.
Definition: Types.h:78
arm_compute::graph::INode::set_requested_target
void set_requested_target(Target target)
Sets target preference.
Definition: INode.cpp:67
arm_compute::graph::INode::id
NodeID id() const
Returns node's ID.
Definition: INode.cpp:103
arm_compute::graph::EmptyNodeID
constexpr NodeID EmptyNodeID
Constant EdgeID specifying an equivalent of null edge.
Definition: Types.h:80
Graph.h
arm_compute::graph::INode::set_id
void set_id(NodeID id)
Sets the node id.
Definition: INode.cpp:57
arm_compute::graph::Edge::tensor_id
TensorID tensor_id() const
Returns the tensor id associated with this edge.
Definition: Edge.h:124
arm_compute::graph::TensorID
unsigned int TensorID
Definition: Types.h:72
arm_compute::graph::INode::set_common_node_parameters
void set_common_node_parameters(NodeParams common_params)
Sets common node parameters.
Definition: INode.cpp:62
arm_compute::graph::NodeParams::target
Target target
Node target.
Definition: Types.h:277
arm_compute::graph::EdgeID
unsigned int EdgeID
Definition: Types.h:74