Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2018 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_GRAPH2_EDGE_H__ |
| 25 | #define __ARM_COMPUTE_GRAPH2_EDGE_H__ |
| 26 | |
| 27 | #include "arm_compute/graph2/INode.h" |
| 28 | #include "arm_compute/graph2/Tensor.h" |
| 29 | #include "arm_compute/graph2/Types.h" |
| 30 | |
| 31 | namespace arm_compute |
| 32 | { |
| 33 | namespace graph2 |
| 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 | */ |
| 68 | NodeID producer_id() const |
| 69 | { |
| 70 | return (_producer == nullptr) ? EmptyNodeID : _producer->id(); |
| 71 | } |
| 72 | /** Returns sink node id |
| 73 | * |
| 74 | * @return Sink node id |
| 75 | */ |
| 76 | NodeID consumer_id() const |
| 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 | */ |
| 124 | TensorID tensor_id() const |
| 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 | */ |
| 134 | void update_bound_tensor(Tensor *tensor) |
| 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 graph2 |
| 151 | } // namespace arm_compute |
| 152 | #endif /* __ARM_COMPUTE_GRAPH2_EDGE_H__ */ |