blob: c9f9d2172c495becf91822f179679cd6f37ee591 [file] [log] [blame]
Georgios Pinitasd8734b52017-12-22 15:27:52 +00001/*
giuros01acce5042019-02-21 17:32:34 +00002 * 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 */
Georgios Pinitasd9eb2752018-04-03 13:44:29 +010024#ifndef __ARM_COMPUTE_GRAPH_INODEVISITOR_H__
25#define __ARM_COMPUTE_GRAPH_INODEVISITOR_H__
Georgios Pinitasd8734b52017-12-22 15:27:52 +000026
Georgios Pinitasd9eb2752018-04-03 13:44:29 +010027#include "arm_compute/graph/nodes/NodesFwd.h"
Georgios Pinitasd8734b52017-12-22 15:27:52 +000028
29namespace arm_compute
30{
Georgios Pinitasd9eb2752018-04-03 13:44:29 +010031namespace graph
Georgios Pinitasd8734b52017-12-22 15:27:52 +000032{
33/** Node visitor interface */
34class INodeVisitor
35{
36public:
Alex Gildayc357c472018-03-21 13:54:09 +000037 /** 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 Pinitase2220552018-07-20 13:23:44 +010054 /** Visit ConcatenateLayerNode.
55 *
56 * @param[in] n Node to visit.
57 */
58 virtual void visit(ConcatenateLayerNode &n) = 0;
Alex Gildayc357c472018-03-21 13:54:09 +000059 /** 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 Gildayc357c472018-03-21 13:54:09 +000069 /** Visit DepthwiseConvolutionLayerNode.
70 *
71 * @param[in] n Node to visit.
72 */
Georgios Pinitasd8734b52017-12-22 15:27:52 +000073 virtual void visit(DepthwiseConvolutionLayerNode &n) = 0;
Isabella Gottardi7234ed82018-11-27 08:51:10 +000074 /** Visit DetectionOutputLayerNode.
75 *
76 * @param[in] n Node to visit.
77 */
78 virtual void visit(DetectionOutputLayerNode &n) = 0;
Isabella Gottardia7acb3c2019-01-08 13:48:44 +000079 /** Visit DetectionPostProcessLayerNode.
80 *
81 * @param[in] n Node to visit.
82 */
83 virtual void visit(DetectionPostProcessLayerNode &n) = 0;
Alex Gildayc357c472018-03-21 13:54:09 +000084 /** Visit EltwiseLayerNode.
85 *
86 * @param[in] n Node to visit.
87 */
88 virtual void visit(EltwiseLayerNode &n) = 0;
89 /** Visit FlattenLayerNode.
90 *
91 * @param[in] n Node to visit.
92 */
93 virtual void visit(FlattenLayerNode &n) = 0;
94 /** Visit FullyConnectedLayerNode.
95 *
96 * @param[in] n Node to visit.
97 */
98 virtual void visit(FullyConnectedLayerNode &n) = 0;
giuros01acce5042019-02-21 17:32:34 +000099 /** Visit FusedConvolutionBatchNormalizationNode.
100 *
101 * @param[in] n Node to visit.
102 */
103 virtual void visit(FusedConvolutionBatchNormalizationNode &n) = 0;
Manuel Bottinibffb41e2019-06-20 16:00:27 +0100104 /** Visit FusedDepthwiseConvolutionBatchNormalizationNode.
105 *
106 * @param[in] n Node to visit.
107 */
108 virtual void visit(FusedDepthwiseConvolutionBatchNormalizationNode &n) = 0;
Alex Gildayc357c472018-03-21 13:54:09 +0000109 /** Visit InputNode.
110 *
111 * @param[in] n Node to visit.
112 */
113 virtual void visit(InputNode &n) = 0;
114 /** Visit NormalizationLayerNode.
115 *
116 * @param[in] n Node to visit.
117 */
118 virtual void visit(NormalizationLayerNode &n) = 0;
119 /** Visit OutputNode.
120 *
121 * @param[in] n Node to visit.
122 */
123 virtual void visit(OutputNode &n) = 0;
Georgios Pinitas57c48242018-08-02 13:41:49 +0100124 /** Visit PermuteLayerNode.
125 *
126 * @param[in] n Node to visit.
127 */
128 virtual void visit(PermuteLayerNode &n) = 0;
Alex Gildayc357c472018-03-21 13:54:09 +0000129 /** Visit PoolingLayerNode.
130 *
131 * @param[in] n Node to visit.
132 */
133 virtual void visit(PoolingLayerNode &n) = 0;
Pablo Tello32521432018-11-15 14:43:10 +0000134 /** Visit PriorBoxLayerNode.
135 *
136 * @param[in] n Node to visit.
137 */
138 virtual void visit(PriorBoxLayerNode &n) = 0;
Isabella Gottardi3db1ba92019-05-17 12:35:20 +0100139 /** Visit QuantizationLayerNode.
140 *
141 * @param[in] n Node to visit.
142 */
143 virtual void visit(QuantizationLayerNode &n) = 0;
Alex Gildayc357c472018-03-21 13:54:09 +0000144 /** Visit ReshapeLayerNode.
145 *
146 * @param[in] n Node to visit.
147 */
148 virtual void visit(ReshapeLayerNode &n) = 0;
149 /** Visit SoftmaxLayerNode.
150 *
151 * @param[in] n Node to visit.
152 */
153 virtual void visit(SoftmaxLayerNode &n) = 0;
Georgios Pinitasee33ea52018-03-08 16:01:29 +0000154 /** Visit SplitLayerNode.
155 *
156 * @param[in] n Node to visit.
157 */
158 virtual void visit(SplitLayerNode &n) = 0;
Michele Di Giorgioec699752019-03-22 15:25:32 +0000159 /** Visit StackLayerNode.
160 *
161 * @param[in] n Node to visit.
162 */
163 virtual void visit(StackLayerNode &n) = 0;
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000164};
165
166/** Default visitor implementation
167 *
168 * Implements visit methods by calling a default function.
169 * Inherit from DefaultNodeVisitor if you don't want to provide specific implementation for all nodes.
170 */
171class DefaultNodeVisitor : public INodeVisitor
172{
173public:
Alex Gildayc357c472018-03-21 13:54:09 +0000174 /** Default destructor */
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000175 virtual ~DefaultNodeVisitor() = default;
176
Alex Gildayc357c472018-03-21 13:54:09 +0000177#ifndef DOXYGEN_SKIP_THIS
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000178 // Inherited methods overridden
Michalis Spyrou6bff1952019-10-02 17:22:11 +0100179 virtual void visit(INode &) override
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000180 {
181 default_visit();
182 }
Michalis Spyrou6bff1952019-10-02 17:22:11 +0100183 virtual void visit(ActivationLayerNode &) override
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000184 {
185 default_visit();
186 }
Michalis Spyrou6bff1952019-10-02 17:22:11 +0100187 virtual void visit(BatchNormalizationLayerNode &) override
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000188 {
189 default_visit();
190 }
Michalis Spyrou6bff1952019-10-02 17:22:11 +0100191 virtual void visit(ConcatenateLayerNode &) override
Georgios Pinitase2220552018-07-20 13:23:44 +0100192 {
193 default_visit();
194 }
Michalis Spyrou6bff1952019-10-02 17:22:11 +0100195 virtual void visit(ConstNode &) override
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000196 {
197 default_visit();
198 }
Michalis Spyrou6bff1952019-10-02 17:22:11 +0100199 virtual void visit(ConvolutionLayerNode &) override
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000200 {
201 default_visit();
202 }
Michalis Spyrou6bff1952019-10-02 17:22:11 +0100203 virtual void visit(DetectionOutputLayerNode &) override
Isabella Gottardi7234ed82018-11-27 08:51:10 +0000204 {
205 default_visit();
206 }
Michalis Spyrou6bff1952019-10-02 17:22:11 +0100207 virtual void visit(DetectionPostProcessLayerNode &) override
Isabella Gottardia7acb3c2019-01-08 13:48:44 +0000208 {
209 default_visit();
210 }
Michalis Spyrou6bff1952019-10-02 17:22:11 +0100211 virtual void visit(DepthwiseConvolutionLayerNode &) override
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000212 {
213 default_visit();
214 }
Michalis Spyrou6bff1952019-10-02 17:22:11 +0100215 virtual void visit(EltwiseLayerNode &) override
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000216 {
217 default_visit();
218 }
Michalis Spyrou6bff1952019-10-02 17:22:11 +0100219 virtual void visit(FlattenLayerNode &) override
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000220 {
221 default_visit();
222 }
Michalis Spyrou6bff1952019-10-02 17:22:11 +0100223 virtual void visit(FullyConnectedLayerNode &) override
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000224 {
225 default_visit();
226 }
Michalis Spyrou6bff1952019-10-02 17:22:11 +0100227 virtual void visit(FusedConvolutionBatchNormalizationNode &) override
giuros01acce5042019-02-21 17:32:34 +0000228 {
229 default_visit();
230 }
Michalis Spyrou6bff1952019-10-02 17:22:11 +0100231 virtual void visit(FusedDepthwiseConvolutionBatchNormalizationNode &) override
Manuel Bottinibffb41e2019-06-20 16:00:27 +0100232 {
233 default_visit();
234 }
Michalis Spyrou6bff1952019-10-02 17:22:11 +0100235 virtual void visit(InputNode &) override
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000236 {
237 default_visit();
238 }
Michalis Spyrou6bff1952019-10-02 17:22:11 +0100239 virtual void visit(NormalizationLayerNode &) override
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000240 {
241 default_visit();
242 }
Michalis Spyrou6bff1952019-10-02 17:22:11 +0100243 virtual void visit(OutputNode &) override
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000244 {
245 default_visit();
246 }
Michalis Spyrou6bff1952019-10-02 17:22:11 +0100247 virtual void visit(PermuteLayerNode &) override
Georgios Pinitas57c48242018-08-02 13:41:49 +0100248 {
249 default_visit();
250 }
Michalis Spyrou6bff1952019-10-02 17:22:11 +0100251 virtual void visit(PoolingLayerNode &) override
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000252 {
253 default_visit();
254 }
Michalis Spyrou6bff1952019-10-02 17:22:11 +0100255 virtual void visit(PriorBoxLayerNode &) override
Pablo Tello32521432018-11-15 14:43:10 +0000256 {
257 default_visit();
258 }
Michalis Spyrou6bff1952019-10-02 17:22:11 +0100259 virtual void visit(QuantizationLayerNode &) override
Isabella Gottardi3db1ba92019-05-17 12:35:20 +0100260 {
261 default_visit();
262 }
Michalis Spyrou6bff1952019-10-02 17:22:11 +0100263 virtual void visit(ReshapeLayerNode &) override
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000264 {
265 default_visit();
266 }
Michalis Spyrou6bff1952019-10-02 17:22:11 +0100267 virtual void visit(SoftmaxLayerNode &) override
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000268 {
269 default_visit();
270 }
Michalis Spyrou6bff1952019-10-02 17:22:11 +0100271 virtual void visit(SplitLayerNode &) override
Georgios Pinitasee33ea52018-03-08 16:01:29 +0000272 {
273 default_visit();
274 }
Michalis Spyrou6bff1952019-10-02 17:22:11 +0100275 virtual void visit(StackLayerNode &) override
Michele Di Giorgioec699752019-03-22 15:25:32 +0000276 {
277 default_visit();
278 }
Alex Gildayc357c472018-03-21 13:54:09 +0000279#endif /* DOXYGEN_SKIP_THIS */
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000280
281 /** Function to be overloaded by the client and implement default behavior for the
282 * non-overloaded visitors
283 */
284 virtual void default_visit() = 0;
285};
Georgios Pinitasd9eb2752018-04-03 13:44:29 +0100286} // namespace graph
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000287} // namespace arm_compute
Georgios Pinitasd9eb2752018-04-03 13:44:29 +0100288#endif /* __ARM_COMPUTE_GRAPH_INODEVISITOR_H__ */