blob: 7f5075d88526f56a012d88331c11126a341adde3 [file] [log] [blame]
Georgios Pinitasd8734b52017-12-22 15:27:52 +00001/*
Michele Di Giorgiod9eaf612020-07-08 11:12:57 +01002 * Copyright (c) 2018-2019 Arm Limited.
Georgios Pinitasd8734b52017-12-22 15:27:52 +00003 *
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 */
Michalis Spyrouf4643372019-11-29 16:17:13 +000024#ifndef ARM_COMPUTE_GRAPH_EDGE_H
25#define ARM_COMPUTE_GRAPH_EDGE_H
Georgios Pinitasd8734b52017-12-22 15:27:52 +000026
Georgios Pinitasd9eb2752018-04-03 13:44:29 +010027#include "arm_compute/graph/INode.h"
28#include "arm_compute/graph/Tensor.h"
29#include "arm_compute/graph/Types.h"
Georgios Pinitasd8734b52017-12-22 15:27:52 +000030
31namespace arm_compute
32{
Georgios Pinitasd9eb2752018-04-03 13:44:29 +010033namespace graph
Georgios Pinitasd8734b52017-12-22 15:27:52 +000034{
35// Forward declarations
36class Graph;
37
38/** Graph Edge */
39class Edge final
40{
41public:
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 */
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010051 Edge(EdgeID id,
52 INode *producer,
53 unsigned int producer_idx,
54 INode *consumer,
55 unsigned int consumer_idx,
56 Tensor *tensor)
57 : _id(id),
58 _producer(producer),
59 _consumer(consumer),
60 _producer_idx(producer_idx),
61 _consumer_idx(consumer_idx),
62 _tensor(tensor)
Georgios Pinitasd8734b52017-12-22 15:27:52 +000063
64 {
65 }
66 /** Returns edge id
67 *
68 * @return Edge id
69 */
70 EdgeID id() const
71 {
72 return _id;
73 }
74 /** Returns producer node id
75 *
76 * @return Producer node id
77 */
78 NodeID producer_id() const
79 {
80 return (_producer == nullptr) ? EmptyNodeID : _producer->id();
81 }
82 /** Returns sink node id
83 *
84 * @return Sink node id
85 */
86 NodeID consumer_id() const
87 {
88 return (_consumer == nullptr) ? EmptyNodeID : _consumer->id();
89 }
90 /** Returns producer node
91 *
92 * @return Producer node
93 */
94 INode *producer() const
95 {
96 return _producer;
97 }
98 /** Returns consumer node
99 *
100 * @return Consumer node
101 */
102 INode *consumer() const
103 {
104 return _consumer;
105 }
106 /** Returns the index of the output that produces the result in the producer node
107 *
108 * @return Producer node output index
109 */
110 unsigned int producer_idx() const
111 {
112 return _producer_idx;
113 }
114 /** Returns the index of the input that consumes the result in the consumer node
115 *
116 * @return Consumer node input index
117 */
118 unsigned int consumer_idx() const
119 {
120 return _consumer_idx;
121 }
122 /** Returns the tensor associated with this edge
123 *
124 * @return Tensor id
125 */
126 Tensor *tensor() const
127 {
128 return _tensor;
129 }
130 /** Returns the tensor id associated with this edge
131 *
132 * @return Tensor id
133 */
134 TensorID tensor_id() const
135 {
136 return (_tensor == nullptr) ? NullTensorID : _tensor->id();
137 }
138 /** Bind the edge to another tensor
139 *
140 * @note If tensor is nullptr then nothing happens
141 *
142 * @param[in] tensor Tensor to bind the edge to
143 */
144 void update_bound_tensor(Tensor *tensor)
145 {
146 _tensor = (tensor != nullptr) ? tensor : _tensor;
147 }
148
149private:
150 friend class Graph;
151
152private:
153 EdgeID _id;
154 INode *_producer;
155 INode *_consumer;
156 unsigned int _producer_idx;
157 unsigned int _consumer_idx;
158 Tensor *_tensor;
159};
Georgios Pinitasd9eb2752018-04-03 13:44:29 +0100160} // namespace graph
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000161} // namespace arm_compute
Michalis Spyrouf4643372019-11-29 16:17:13 +0000162#endif /* ARM_COMPUTE_GRAPH_EDGE_H */