blob: a21c9b2d489082d97ecf660a736bd0d32821ef7e [file] [log] [blame]
Georgios Pinitasd8734b52017-12-22 15:27:52 +00001/*
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 */
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;
Alex Gildayc357c472018-03-21 13:54:09 +000074 /** Visit EltwiseLayerNode.
75 *
76 * @param[in] n Node to visit.
77 */
78 virtual void visit(EltwiseLayerNode &n) = 0;
79 /** Visit FlattenLayerNode.
80 *
81 * @param[in] n Node to visit.
82 */
83 virtual void visit(FlattenLayerNode &n) = 0;
84 /** Visit FullyConnectedLayerNode.
85 *
86 * @param[in] n Node to visit.
87 */
88 virtual void visit(FullyConnectedLayerNode &n) = 0;
89 /** Visit InputNode.
90 *
91 * @param[in] n Node to visit.
92 */
93 virtual void visit(InputNode &n) = 0;
94 /** Visit NormalizationLayerNode.
95 *
96 * @param[in] n Node to visit.
97 */
98 virtual void visit(NormalizationLayerNode &n) = 0;
99 /** Visit OutputNode.
100 *
101 * @param[in] n Node to visit.
102 */
103 virtual void visit(OutputNode &n) = 0;
Georgios Pinitas57c48242018-08-02 13:41:49 +0100104 /** Visit PermuteLayerNode.
105 *
106 * @param[in] n Node to visit.
107 */
108 virtual void visit(PermuteLayerNode &n) = 0;
Alex Gildayc357c472018-03-21 13:54:09 +0000109 /** Visit PoolingLayerNode.
110 *
111 * @param[in] n Node to visit.
112 */
113 virtual void visit(PoolingLayerNode &n) = 0;
114 /** Visit ReshapeLayerNode.
115 *
116 * @param[in] n Node to visit.
117 */
118 virtual void visit(ReshapeLayerNode &n) = 0;
119 /** Visit SoftmaxLayerNode.
120 *
121 * @param[in] n Node to visit.
122 */
123 virtual void visit(SoftmaxLayerNode &n) = 0;
Georgios Pinitasee33ea52018-03-08 16:01:29 +0000124 /** Visit SplitLayerNode.
125 *
126 * @param[in] n Node to visit.
127 */
128 virtual void visit(SplitLayerNode &n) = 0;
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000129};
130
131/** Default visitor implementation
132 *
133 * Implements visit methods by calling a default function.
134 * Inherit from DefaultNodeVisitor if you don't want to provide specific implementation for all nodes.
135 */
136class DefaultNodeVisitor : public INodeVisitor
137{
138public:
Alex Gildayc357c472018-03-21 13:54:09 +0000139 /** Default destructor */
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000140 virtual ~DefaultNodeVisitor() = default;
141
Alex Gildayc357c472018-03-21 13:54:09 +0000142#ifndef DOXYGEN_SKIP_THIS
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000143 // Inherited methods overridden
144 virtual void visit(INode &n) override
145 {
146 default_visit();
147 }
148 virtual void visit(ActivationLayerNode &n) override
149 {
150 default_visit();
151 }
152 virtual void visit(BatchNormalizationLayerNode &n) override
153 {
154 default_visit();
155 }
Georgios Pinitase2220552018-07-20 13:23:44 +0100156 virtual void visit(ConcatenateLayerNode &n) override
157 {
158 default_visit();
159 }
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000160 virtual void visit(ConstNode &n) override
161 {
162 default_visit();
163 }
164 virtual void visit(ConvolutionLayerNode &n) override
165 {
166 default_visit();
167 }
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000168 virtual void visit(DepthwiseConvolutionLayerNode &n) override
169 {
170 default_visit();
171 }
172 virtual void visit(EltwiseLayerNode &n) override
173 {
174 default_visit();
175 }
176 virtual void visit(FlattenLayerNode &n) override
177 {
178 default_visit();
179 }
180 virtual void visit(FullyConnectedLayerNode &n) override
181 {
182 default_visit();
183 }
184 virtual void visit(InputNode &n) override
185 {
186 default_visit();
187 }
188 virtual void visit(NormalizationLayerNode &n) override
189 {
190 default_visit();
191 }
192 virtual void visit(OutputNode &n) override
193 {
194 default_visit();
195 }
Georgios Pinitas57c48242018-08-02 13:41:49 +0100196 virtual void visit(PermuteLayerNode &n) override
197 {
198 default_visit();
199 }
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000200 virtual void visit(PoolingLayerNode &n) override
201 {
202 default_visit();
203 }
204 virtual void visit(ReshapeLayerNode &n) override
205 {
206 default_visit();
207 }
208 virtual void visit(SoftmaxLayerNode &n) override
209 {
210 default_visit();
211 }
Georgios Pinitasee33ea52018-03-08 16:01:29 +0000212 virtual void visit(SplitLayerNode &n) override
213 {
214 default_visit();
215 }
Alex Gildayc357c472018-03-21 13:54:09 +0000216#endif /* DOXYGEN_SKIP_THIS */
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000217
218 /** Function to be overloaded by the client and implement default behavior for the
219 * non-overloaded visitors
220 */
221 virtual void default_visit() = 0;
222};
Georgios Pinitasd9eb2752018-04-03 13:44:29 +0100223} // namespace graph
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000224} // namespace arm_compute
Georgios Pinitasd9eb2752018-04-03 13:44:29 +0100225#endif /* __ARM_COMPUTE_GRAPH_INODEVISITOR_H__ */