Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 1 | /* |
giuros01 | acce504 | 2019-02-21 17:32:34 +0000 | [diff] [blame] | 2 | * Copyright (c) 2018-2019 ARM Limited. |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 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 | */ |
Georgios Pinitas | d9eb275 | 2018-04-03 13:44:29 +0100 | [diff] [blame] | 24 | #ifndef __ARM_COMPUTE_GRAPH_INODEVISITOR_H__ |
| 25 | #define __ARM_COMPUTE_GRAPH_INODEVISITOR_H__ |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 26 | |
Georgios Pinitas | d9eb275 | 2018-04-03 13:44:29 +0100 | [diff] [blame] | 27 | #include "arm_compute/graph/nodes/NodesFwd.h" |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 28 | |
| 29 | namespace arm_compute |
| 30 | { |
Georgios Pinitas | d9eb275 | 2018-04-03 13:44:29 +0100 | [diff] [blame] | 31 | namespace graph |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 32 | { |
| 33 | /** Node visitor interface */ |
| 34 | class INodeVisitor |
| 35 | { |
| 36 | public: |
Alex Gilday | c357c47 | 2018-03-21 13:54:09 +0000 | [diff] [blame] | 37 | /** Default destructor. */ |
| 38 | virtual ~INodeVisitor() = default; |
| 39 | /** Visit INode. |
| 40 | * |
| 41 | * @param[in] n Node to visit. |
| 42 | */ |
| 43 | virtual void visit(INode &n) = 0; |
| 44 | /** Visit ActivationLayerNode. |
| 45 | * |
| 46 | * @param[in] n Node to visit. |
| 47 | */ |
| 48 | virtual void visit(ActivationLayerNode &n) = 0; |
| 49 | /** Visit BatchNormalizationLayerNode. |
| 50 | * |
| 51 | * @param[in] n Node to visit. |
| 52 | */ |
| 53 | virtual void visit(BatchNormalizationLayerNode &n) = 0; |
Georgios Pinitas | e222055 | 2018-07-20 13:23:44 +0100 | [diff] [blame] | 54 | /** Visit ConcatenateLayerNode. |
| 55 | * |
| 56 | * @param[in] n Node to visit. |
| 57 | */ |
| 58 | virtual void visit(ConcatenateLayerNode &n) = 0; |
Alex Gilday | c357c47 | 2018-03-21 13:54:09 +0000 | [diff] [blame] | 59 | /** Visit ConstNode. |
| 60 | * |
| 61 | * @param[in] n Node to visit. |
| 62 | */ |
| 63 | virtual void visit(ConstNode &n) = 0; |
| 64 | /** Visit ConvolutionLayerNode. |
| 65 | * |
| 66 | * @param[in] n Node to visit. |
| 67 | */ |
| 68 | virtual void visit(ConvolutionLayerNode &n) = 0; |
Alex Gilday | c357c47 | 2018-03-21 13:54:09 +0000 | [diff] [blame] | 69 | /** Visit DepthwiseConvolutionLayerNode. |
| 70 | * |
| 71 | * @param[in] n Node to visit. |
| 72 | */ |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 73 | virtual void visit(DepthwiseConvolutionLayerNode &n) = 0; |
Isabella Gottardi | cd4e9ab | 2019-11-05 17:50:27 +0000 | [diff] [blame] | 74 | /** Visit DequantizationLayerNode. |
| 75 | * |
| 76 | * @param[in] n Node to visit. |
| 77 | */ |
| 78 | virtual void visit(DequantizationLayerNode &n) = 0; |
Isabella Gottardi | 7234ed8 | 2018-11-27 08:51:10 +0000 | [diff] [blame] | 79 | /** Visit DetectionOutputLayerNode. |
| 80 | * |
| 81 | * @param[in] n Node to visit. |
| 82 | */ |
| 83 | virtual void visit(DetectionOutputLayerNode &n) = 0; |
Isabella Gottardi | a7acb3c | 2019-01-08 13:48:44 +0000 | [diff] [blame] | 84 | /** Visit DetectionPostProcessLayerNode. |
| 85 | * |
| 86 | * @param[in] n Node to visit. |
| 87 | */ |
| 88 | virtual void visit(DetectionPostProcessLayerNode &n) = 0; |
Alex Gilday | c357c47 | 2018-03-21 13:54:09 +0000 | [diff] [blame] | 89 | /** Visit EltwiseLayerNode. |
| 90 | * |
| 91 | * @param[in] n Node to visit. |
| 92 | */ |
| 93 | virtual void visit(EltwiseLayerNode &n) = 0; |
| 94 | /** Visit FlattenLayerNode. |
| 95 | * |
| 96 | * @param[in] n Node to visit. |
| 97 | */ |
| 98 | virtual void visit(FlattenLayerNode &n) = 0; |
| 99 | /** Visit FullyConnectedLayerNode. |
| 100 | * |
| 101 | * @param[in] n Node to visit. |
| 102 | */ |
| 103 | virtual void visit(FullyConnectedLayerNode &n) = 0; |
giuros01 | acce504 | 2019-02-21 17:32:34 +0000 | [diff] [blame] | 104 | /** Visit FusedConvolutionBatchNormalizationNode. |
| 105 | * |
| 106 | * @param[in] n Node to visit. |
| 107 | */ |
| 108 | virtual void visit(FusedConvolutionBatchNormalizationNode &n) = 0; |
Manuel Bottini | bffb41e | 2019-06-20 16:00:27 +0100 | [diff] [blame] | 109 | /** Visit FusedDepthwiseConvolutionBatchNormalizationNode. |
| 110 | * |
| 111 | * @param[in] n Node to visit. |
| 112 | */ |
| 113 | virtual void visit(FusedDepthwiseConvolutionBatchNormalizationNode &n) = 0; |
Alex Gilday | c357c47 | 2018-03-21 13:54:09 +0000 | [diff] [blame] | 114 | /** Visit InputNode. |
| 115 | * |
| 116 | * @param[in] n Node to visit. |
| 117 | */ |
| 118 | virtual void visit(InputNode &n) = 0; |
| 119 | /** Visit NormalizationLayerNode. |
| 120 | * |
| 121 | * @param[in] n Node to visit. |
| 122 | */ |
| 123 | virtual void visit(NormalizationLayerNode &n) = 0; |
| 124 | /** Visit OutputNode. |
| 125 | * |
| 126 | * @param[in] n Node to visit. |
| 127 | */ |
| 128 | virtual void visit(OutputNode &n) = 0; |
Georgios Pinitas | 57c4824 | 2018-08-02 13:41:49 +0100 | [diff] [blame] | 129 | /** Visit PermuteLayerNode. |
| 130 | * |
| 131 | * @param[in] n Node to visit. |
| 132 | */ |
| 133 | virtual void visit(PermuteLayerNode &n) = 0; |
Alex Gilday | c357c47 | 2018-03-21 13:54:09 +0000 | [diff] [blame] | 134 | /** Visit PoolingLayerNode. |
| 135 | * |
| 136 | * @param[in] n Node to visit. |
| 137 | */ |
| 138 | virtual void visit(PoolingLayerNode &n) = 0; |
Pablo Tello | 3252143 | 2018-11-15 14:43:10 +0000 | [diff] [blame] | 139 | /** Visit PriorBoxLayerNode. |
| 140 | * |
| 141 | * @param[in] n Node to visit. |
| 142 | */ |
| 143 | virtual void visit(PriorBoxLayerNode &n) = 0; |
Isabella Gottardi | 3db1ba9 | 2019-05-17 12:35:20 +0100 | [diff] [blame] | 144 | /** Visit QuantizationLayerNode. |
| 145 | * |
| 146 | * @param[in] n Node to visit. |
| 147 | */ |
| 148 | virtual void visit(QuantizationLayerNode &n) = 0; |
Alex Gilday | c357c47 | 2018-03-21 13:54:09 +0000 | [diff] [blame] | 149 | /** Visit ReshapeLayerNode. |
| 150 | * |
| 151 | * @param[in] n Node to visit. |
| 152 | */ |
| 153 | virtual void visit(ReshapeLayerNode &n) = 0; |
| 154 | /** Visit SoftmaxLayerNode. |
| 155 | * |
| 156 | * @param[in] n Node to visit. |
| 157 | */ |
| 158 | virtual void visit(SoftmaxLayerNode &n) = 0; |
Georgios Pinitas | ee33ea5 | 2018-03-08 16:01:29 +0000 | [diff] [blame] | 159 | /** Visit SplitLayerNode. |
| 160 | * |
| 161 | * @param[in] n Node to visit. |
| 162 | */ |
| 163 | virtual void visit(SplitLayerNode &n) = 0; |
Michele Di Giorgio | ec69975 | 2019-03-22 15:25:32 +0000 | [diff] [blame] | 164 | /** Visit StackLayerNode. |
| 165 | * |
| 166 | * @param[in] n Node to visit. |
| 167 | */ |
| 168 | virtual void visit(StackLayerNode &n) = 0; |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 169 | }; |
| 170 | |
| 171 | /** Default visitor implementation |
| 172 | * |
| 173 | * Implements visit methods by calling a default function. |
| 174 | * Inherit from DefaultNodeVisitor if you don't want to provide specific implementation for all nodes. |
| 175 | */ |
| 176 | class DefaultNodeVisitor : public INodeVisitor |
| 177 | { |
| 178 | public: |
Alex Gilday | c357c47 | 2018-03-21 13:54:09 +0000 | [diff] [blame] | 179 | /** Default destructor */ |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 180 | virtual ~DefaultNodeVisitor() = default; |
| 181 | |
Alex Gilday | c357c47 | 2018-03-21 13:54:09 +0000 | [diff] [blame] | 182 | #ifndef DOXYGEN_SKIP_THIS |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 183 | // Inherited methods overridden |
Michalis Spyrou | 6bff195 | 2019-10-02 17:22:11 +0100 | [diff] [blame] | 184 | virtual void visit(INode &) override |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 185 | { |
| 186 | default_visit(); |
| 187 | } |
Michalis Spyrou | 6bff195 | 2019-10-02 17:22:11 +0100 | [diff] [blame] | 188 | virtual void visit(ActivationLayerNode &) override |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 189 | { |
| 190 | default_visit(); |
| 191 | } |
Michalis Spyrou | 6bff195 | 2019-10-02 17:22:11 +0100 | [diff] [blame] | 192 | virtual void visit(BatchNormalizationLayerNode &) override |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 193 | { |
| 194 | default_visit(); |
| 195 | } |
Michalis Spyrou | 6bff195 | 2019-10-02 17:22:11 +0100 | [diff] [blame] | 196 | virtual void visit(ConcatenateLayerNode &) override |
Georgios Pinitas | e222055 | 2018-07-20 13:23:44 +0100 | [diff] [blame] | 197 | { |
| 198 | default_visit(); |
| 199 | } |
Michalis Spyrou | 6bff195 | 2019-10-02 17:22:11 +0100 | [diff] [blame] | 200 | virtual void visit(ConstNode &) override |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 201 | { |
| 202 | default_visit(); |
| 203 | } |
Michalis Spyrou | 6bff195 | 2019-10-02 17:22:11 +0100 | [diff] [blame] | 204 | virtual void visit(ConvolutionLayerNode &) override |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 205 | { |
| 206 | default_visit(); |
| 207 | } |
Isabella Gottardi | cd4e9ab | 2019-11-05 17:50:27 +0000 | [diff] [blame] | 208 | virtual void visit(DequantizationLayerNode &) override |
| 209 | { |
| 210 | default_visit(); |
| 211 | } |
Michalis Spyrou | 6bff195 | 2019-10-02 17:22:11 +0100 | [diff] [blame] | 212 | virtual void visit(DetectionOutputLayerNode &) override |
Isabella Gottardi | 7234ed8 | 2018-11-27 08:51:10 +0000 | [diff] [blame] | 213 | { |
| 214 | default_visit(); |
| 215 | } |
Michalis Spyrou | 6bff195 | 2019-10-02 17:22:11 +0100 | [diff] [blame] | 216 | virtual void visit(DetectionPostProcessLayerNode &) override |
Isabella Gottardi | a7acb3c | 2019-01-08 13:48:44 +0000 | [diff] [blame] | 217 | { |
| 218 | default_visit(); |
| 219 | } |
Michalis Spyrou | 6bff195 | 2019-10-02 17:22:11 +0100 | [diff] [blame] | 220 | virtual void visit(DepthwiseConvolutionLayerNode &) override |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 221 | { |
| 222 | default_visit(); |
| 223 | } |
Michalis Spyrou | 6bff195 | 2019-10-02 17:22:11 +0100 | [diff] [blame] | 224 | virtual void visit(EltwiseLayerNode &) override |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 225 | { |
| 226 | default_visit(); |
| 227 | } |
Michalis Spyrou | 6bff195 | 2019-10-02 17:22:11 +0100 | [diff] [blame] | 228 | virtual void visit(FlattenLayerNode &) override |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 229 | { |
| 230 | default_visit(); |
| 231 | } |
Michalis Spyrou | 6bff195 | 2019-10-02 17:22:11 +0100 | [diff] [blame] | 232 | virtual void visit(FullyConnectedLayerNode &) override |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 233 | { |
| 234 | default_visit(); |
| 235 | } |
Michalis Spyrou | 6bff195 | 2019-10-02 17:22:11 +0100 | [diff] [blame] | 236 | virtual void visit(FusedConvolutionBatchNormalizationNode &) override |
giuros01 | acce504 | 2019-02-21 17:32:34 +0000 | [diff] [blame] | 237 | { |
| 238 | default_visit(); |
| 239 | } |
Michalis Spyrou | 6bff195 | 2019-10-02 17:22:11 +0100 | [diff] [blame] | 240 | virtual void visit(FusedDepthwiseConvolutionBatchNormalizationNode &) override |
Manuel Bottini | bffb41e | 2019-06-20 16:00:27 +0100 | [diff] [blame] | 241 | { |
| 242 | default_visit(); |
| 243 | } |
Michalis Spyrou | 6bff195 | 2019-10-02 17:22:11 +0100 | [diff] [blame] | 244 | virtual void visit(InputNode &) override |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 245 | { |
| 246 | default_visit(); |
| 247 | } |
Michalis Spyrou | 6bff195 | 2019-10-02 17:22:11 +0100 | [diff] [blame] | 248 | virtual void visit(NormalizationLayerNode &) override |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 249 | { |
| 250 | default_visit(); |
| 251 | } |
Michalis Spyrou | 6bff195 | 2019-10-02 17:22:11 +0100 | [diff] [blame] | 252 | virtual void visit(OutputNode &) override |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 253 | { |
| 254 | default_visit(); |
| 255 | } |
Michalis Spyrou | 6bff195 | 2019-10-02 17:22:11 +0100 | [diff] [blame] | 256 | virtual void visit(PermuteLayerNode &) override |
Georgios Pinitas | 57c4824 | 2018-08-02 13:41:49 +0100 | [diff] [blame] | 257 | { |
| 258 | default_visit(); |
| 259 | } |
Michalis Spyrou | 6bff195 | 2019-10-02 17:22:11 +0100 | [diff] [blame] | 260 | virtual void visit(PoolingLayerNode &) override |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 261 | { |
| 262 | default_visit(); |
| 263 | } |
Michalis Spyrou | 6bff195 | 2019-10-02 17:22:11 +0100 | [diff] [blame] | 264 | virtual void visit(PriorBoxLayerNode &) override |
Pablo Tello | 3252143 | 2018-11-15 14:43:10 +0000 | [diff] [blame] | 265 | { |
| 266 | default_visit(); |
| 267 | } |
Michalis Spyrou | 6bff195 | 2019-10-02 17:22:11 +0100 | [diff] [blame] | 268 | virtual void visit(QuantizationLayerNode &) override |
Isabella Gottardi | 3db1ba9 | 2019-05-17 12:35:20 +0100 | [diff] [blame] | 269 | { |
| 270 | default_visit(); |
| 271 | } |
Michalis Spyrou | 6bff195 | 2019-10-02 17:22:11 +0100 | [diff] [blame] | 272 | virtual void visit(ReshapeLayerNode &) override |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 273 | { |
| 274 | default_visit(); |
| 275 | } |
Michalis Spyrou | 6bff195 | 2019-10-02 17:22:11 +0100 | [diff] [blame] | 276 | virtual void visit(SoftmaxLayerNode &) override |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 277 | { |
| 278 | default_visit(); |
| 279 | } |
Michalis Spyrou | 6bff195 | 2019-10-02 17:22:11 +0100 | [diff] [blame] | 280 | virtual void visit(SplitLayerNode &) override |
Georgios Pinitas | ee33ea5 | 2018-03-08 16:01:29 +0000 | [diff] [blame] | 281 | { |
| 282 | default_visit(); |
| 283 | } |
Michalis Spyrou | 6bff195 | 2019-10-02 17:22:11 +0100 | [diff] [blame] | 284 | virtual void visit(StackLayerNode &) override |
Michele Di Giorgio | ec69975 | 2019-03-22 15:25:32 +0000 | [diff] [blame] | 285 | { |
| 286 | default_visit(); |
| 287 | } |
Alex Gilday | c357c47 | 2018-03-21 13:54:09 +0000 | [diff] [blame] | 288 | #endif /* DOXYGEN_SKIP_THIS */ |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 289 | |
| 290 | /** Function to be overloaded by the client and implement default behavior for the |
| 291 | * non-overloaded visitors |
| 292 | */ |
| 293 | virtual void default_visit() = 0; |
| 294 | }; |
Georgios Pinitas | d9eb275 | 2018-04-03 13:44:29 +0100 | [diff] [blame] | 295 | } // namespace graph |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 296 | } // namespace arm_compute |
Georgios Pinitas | d9eb275 | 2018-04-03 13:44:29 +0100 | [diff] [blame] | 297 | #endif /* __ARM_COMPUTE_GRAPH_INODEVISITOR_H__ */ |