Compute Library
 21.05
Edge.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018-2019 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_EDGE_H
25 #define ARM_COMPUTE_GRAPH_EDGE_H
26 
30 
31 namespace arm_compute
32 {
33 namespace graph
34 {
35 // Forward declarations
36 class Graph;
37 
38 /** Graph Edge */
39 class Edge final
40 {
41 public:
42  /** Default Constructor
43  *
44  * @param[in] id Edge id
45  * @param[in] producer Producer node id
46  * @param[in] producer_idx Producer node output index
47  * @param[in] consumer Consumer node id
48  * @param[in] consumer_idx Consumer node input index
49  * @param[in] tensor Tensor associated with the edge
50  */
51  Edge(EdgeID id, INode *producer, unsigned int producer_idx, INode *consumer, unsigned int consumer_idx, Tensor *tensor)
52  : _id(id), _producer(producer), _consumer(consumer), _producer_idx(producer_idx), _consumer_idx(consumer_idx), _tensor(tensor)
53 
54  {
55  }
56  /** Returns edge id
57  *
58  * @return Edge id
59  */
60  EdgeID id() const
61  {
62  return _id;
63  }
64  /** Returns producer node id
65  *
66  * @return Producer node id
67  */
69  {
70  return (_producer == nullptr) ? EmptyNodeID : _producer->id();
71  }
72  /** Returns sink node id
73  *
74  * @return Sink node id
75  */
77  {
78  return (_consumer == nullptr) ? EmptyNodeID : _consumer->id();
79  }
80  /** Returns producer node
81  *
82  * @return Producer node
83  */
84  INode *producer() const
85  {
86  return _producer;
87  }
88  /** Returns consumer node
89  *
90  * @return Consumer node
91  */
92  INode *consumer() const
93  {
94  return _consumer;
95  }
96  /** Returns the index of the output that produces the result in the producer node
97  *
98  * @return Producer node output index
99  */
100  unsigned int producer_idx() const
101  {
102  return _producer_idx;
103  }
104  /** Returns the index of the input that consumes the result in the consumer node
105  *
106  * @return Consumer node input index
107  */
108  unsigned int consumer_idx() const
109  {
110  return _consumer_idx;
111  }
112  /** Returns the tensor associated with this edge
113  *
114  * @return Tensor id
115  */
116  Tensor *tensor() const
117  {
118  return _tensor;
119  }
120  /** Returns the tensor id associated with this edge
121  *
122  * @return Tensor id
123  */
125  {
126  return (_tensor == nullptr) ? NullTensorID : _tensor->id();
127  }
128  /** Bind the edge to another tensor
129  *
130  * @note If tensor is nullptr then nothing happens
131  *
132  * @param[in] tensor Tensor to bind the edge to
133  */
135  {
136  _tensor = (tensor != nullptr) ? tensor : _tensor;
137  }
138 
139 private:
140  friend class Graph;
141 
142 private:
143  EdgeID _id;
144  INode *_producer;
145  INode *_consumer;
146  unsigned int _producer_idx;
147  unsigned int _consumer_idx;
148  Tensor *_tensor;
149 };
150 } // namespace graph
151 } // namespace arm_compute
152 #endif /* ARM_COMPUTE_GRAPH_EDGE_H */
unsigned int consumer_idx() const
Returns the index of the input that consumes the result in the consumer node.
Definition: Edge.h:108
INode * consumer() const
Returns consumer node.
Definition: Edge.h:92
void update_bound_tensor(Tensor *tensor)
Bind the edge to another tensor.
Definition: Edge.h:134
Tensor * tensor() const
Returns the tensor associated with this edge.
Definition: Edge.h:116
TensorID tensor_id() const
Returns the tensor id associated with this edge.
Definition: Edge.h:124
unsigned int producer_idx() const
Returns the index of the output that produces the result in the producer node.
Definition: Edge.h:100
EdgeID id() const
Returns edge id.
Definition: Edge.h:60
Copyright (c) 2017-2021 Arm Limited.
Edge(EdgeID id, INode *producer, unsigned int producer_idx, INode *consumer, unsigned int consumer_idx, Tensor *tensor)
Default Constructor.
Definition: Edge.h:51
Node interface.
Definition: INode.h:45
NodeID id() const
Returns node's ID.
Definition: INode.cpp:102
NodeID producer_id() const
Returns producer node id.
Definition: Edge.h:68
unsigned int EdgeID
Definition: Types.h:69
Graph class.
Definition: Graph.h:53
TensorID id() const
Tensor ID accessor.
Definition: Tensor.cpp:35
unsigned int NodeID
Definition: Types.h:68
Graph Edge.
Definition: Edge.h:39
constexpr NodeID EmptyNodeID
Constant EdgeID specifying an equivalent of null edge.
Definition: Types.h:75
NodeID consumer_id() const
Returns sink node id.
Definition: Edge.h:76
constexpr TensorID NullTensorID
Constant NodeID specifying an equivalent of null node.
Definition: Types.h:73
unsigned int TensorID
Definition: Types.h:67
INode * producer() const
Returns producer node.
Definition: Edge.h:84
Tensor object.
Definition: Tensor.h:41