31 : _id(id), _name(
std::move(name)), _nodes(), _edges(), _tensors(), _tagged_nodes(), _mtx()
37 if(nid >= _nodes.size())
42 std::unique_ptr<INode> &
node = _nodes[nid];
47 for(
auto &input_eid : node->_input_edges)
53 std::set<EdgeID> output_edges_copy = node->output_edges();
54 for(
auto &output_eid : output_edges_copy)
60 std::vector<NodeID> &tnodes = _tagged_nodes.at(node->type());
61 tnodes.erase(std::remove(tnodes.begin(), tnodes.end(), nid), tnodes.end());
74 ARM_COMPUTE_ERROR_ON((source >= _nodes.size()) || (_nodes[source] ==
nullptr) || (source_idx >= _nodes[
source]->num_outputs()));
75 ARM_COMPUTE_ERROR_ON((sink >= _nodes.size()) || (_nodes[sink] ==
nullptr) || (sink_idx >= _nodes[sink]->num_inputs()));
78 std::unique_ptr<INode> &source_node = _nodes[
source];
79 std::unique_ptr<INode> &sink_node = _nodes[sink];
82 Edge *sink_node_edge = sink_node->input_edge(sink_idx);
86 return sink_node_edge->
id();
90 TensorID tid = source_node->output_id(source_idx);
93 tid = create_tensor();
95 std::unique_ptr<Tensor> &
tensor = _tensors[tid];
98 EdgeID eid = _edges.size();
99 auto connection = std::make_unique<Edge>(eid, source_node.get(), source_idx, sink_node.get(), sink_idx, tensor.get());
100 _edges.push_back(std::move(connection));
103 source_node->_output_edges.insert(eid);
104 sink_node->_input_edges[sink_idx] = eid;
107 source_node->_outputs[source_idx] = tid;
110 tensor->bind_edge(eid);
113 sink_node->forward_descriptors();
120 if(eid >= _edges.size())
125 std::unique_ptr<Edge> &
edge = _edges[eid];
131 if(edge->tensor() !=
nullptr)
133 edge->tensor()->unbind_edge(eid);
137 if(edge->producer() !=
nullptr)
139 edge->producer()->_output_edges.erase(eid);
143 if((edge->consumer() !=
nullptr) && (edge->consumer_idx() < edge->consumer()->_input_edges.size()))
145 edge->consumer()->_input_edges[edge->consumer_idx()] =
EmptyEdgeID;
158 auto tensor = std::make_unique<Tensor>(tid, desc);
159 _tensors.push_back(std::move(
tensor));
176 return _tagged_nodes[
type];
206 return (
id >= _nodes.size()) ?
nullptr : _nodes[
id].
get();
211 return (
id >= _nodes.size()) ?
nullptr : _nodes[
id].
get();
216 return (
id >= _edges.size()) ?
nullptr : _edges[
id].
get();
221 return (
id >= _edges.size()) ?
nullptr : _edges[
id].
get();
226 return (
id >= _tensors.size()) ?
nullptr : _tensors[
id].
get();
231 return (
id >= _tensors.size()) ?
nullptr : _tensors[
id].
get();
unsigned int consumer_idx() const
Returns the index of the input that consumes the result in the consumer node.
GraphID id() const
Returns graph id.
bool remove_connection(EdgeID eid)
Removes an edge (connection)
const std::vector< std::unique_ptr< Edge > > & edges() const
Returns edges of graph.
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
unsigned int producer_idx() const
Returns the index of the output that produces the result in the producer node.
decltype(strategy::transforms) typedef type
EdgeID id() const
Returns edge id.
std::string name() const
Returns graph name.
Copyright (c) 2017-2021 Arm Limited.
std::vector< std::unique_ptr< INode > > & nodes()
Returns nodes of graph.
std::vector< std::unique_ptr< Tensor > > & tensors()
Returns tensors of graph.
bool remove_node(NodeID nid)
Remove the node with the given ID.
NodeID producer_id() const
Returns producer node id.
EdgeID add_connection(NodeID source, size_t source_idx, NodeID sink, size_t sink_idx)
Adds a connection between two nodes.
constexpr EdgeID EmptyEdgeID
const INode * node(NodeID id) const
Get node object given its id.
const Edge * edge(EdgeID id) const
Get edge object given its id.
NodeID consumer_id() const
Returns sink node id.
constexpr TensorID NullTensorID
Constant NodeID specifying an equivalent of null node.
std::lock_guard< Mutex > lock_guard
Wrapper of lock_guard data-object.
const Tensor * tensor(TensorID id) const
Get tensor object given its id.