blob: eabad583663bd5a11045a8d8c559aa2f7e152be0 [file] [log] [blame]
jimfly015f4e41f2019-01-23 16:10:17 +00001//
2// Copyright © 2017 Arm Ltd. All rights reserved.
3// SPDX-License-Identifier: MIT
4//
5#pragma once
6
jimfly015f4e41f2019-01-23 16:10:17 +00007#include <armnn/DescriptorsFwd.hpp>
Matthew Bentham313e1c82019-03-25 17:37:47 +00008#include <armnn/NetworkFwd.hpp>
Aron Virginas-Tar00859782019-02-11 12:21:27 +00009#include <armnn/Optional.hpp>
jimfly015f4e41f2019-01-23 16:10:17 +000010#include <armnn/TensorFwd.hpp>
11#include <armnn/Types.hpp>
12
13namespace armnn
14{
15class ILayerVisitor
16{
jimfly01e9e7bfd2019-01-24 22:29:33 +000017protected:
18 ILayerVisitor() {}
19 virtual ~ILayerVisitor() {}
20
jimfly015f4e41f2019-01-23 16:10:17 +000021public:
Derek Lamberti61f54632019-03-25 16:28:44 +000022 /// Function that an activation layer should call back to when its Accept(ILayerVisitor&) function is invoked.
jimfly015f4e41f2019-01-23 16:10:17 +000023 /// @param layer - pointer to the layer which is calling back to this visit function.
Derek Lamberti61f54632019-03-25 16:28:44 +000024 /// @param activationDescriptor - ActivationDescriptor to configure the activation.
jimfly015f4e41f2019-01-23 16:10:17 +000025 /// @param name - Optional name for the layer.
Derek Lamberti61f54632019-03-25 16:28:44 +000026 virtual void VisitActivationLayer(const IConnectableLayer* layer,
27 const ActivationDescriptor& activationDescriptor,
28 const char* name = nullptr) = 0;
29
30 /// Function that an addition layer should call back to when its Accept(ILayerVisitor&) function is invoked.
31 /// @param layer - pointer to the layer which is calling back to this visit function.
32 /// @param name - Optional name for the layer.
33 virtual void VisitAdditionLayer(const IConnectableLayer* layer,
34 const char* name = nullptr) = 0;
35
36 /// Function that a batch normalization layer should call back to when its Accept(ILayerVisitor&)
37 /// function is invoked.
38 /// @param layer - pointer to the layer which is calling back to this visit function.
39 /// @param mean - Pre-calculated mean for each channel.
40 /// @param variance - Pre-calculated variance for each channel.
41 /// @param beta - Per-channel additive factor.
42 /// @param gamma - Per-channel multiplicative factor.
43 /// @param name - Optional name for the layer.
44 virtual void VisitBatchNormalizationLayer(const IConnectableLayer* layer,
45 const BatchNormalizationDescriptor& desc,
46 const ConstTensor& mean,
47 const ConstTensor& variance,
48 const ConstTensor& beta,
49 const ConstTensor& gamma,
50 const char* name = nullptr) = 0;
51
52 /// Function that a batch to space ND layer should call back to when its Accept(ILayerVisitor&)
53 /// function is invoked.
54 /// @param layer - pointer to the layer which is calling back to this visit function.
55 /// @param batchToSpaceNdDescriptor - Description of the layer.
56 /// @param name - Optional name for the layer.
57 virtual void VisitBatchToSpaceNdLayer(const IConnectableLayer* layer,
58 const BatchToSpaceNdDescriptor& batchToSpaceNdDescriptor,
59 const char* name = nullptr) = 0;
60
61 /// Function a layer with no inputs and a single output, which always corresponds to
62 /// the passed in constant tensor should call back to when its Accept(ILayerVisitor&) function is invoked.
63 /// @param layer - pointer to the layer which is calling back to this visit function.
64 /// @param input - Tensor to be provided as the only output of the layer. The layer will maintain
65 /// its own copy of the tensor data, meaning the memory referenced by @a input can
66 /// be freed or reused after this function is called.
67 /// @param name - Optional name for the layer.
68 virtual void VisitConstantLayer(const IConnectableLayer* layer,
69 const ConstTensor& input,
70 const char* name = nullptr) = 0;
jimfly015f4e41f2019-01-23 16:10:17 +000071
Aron Virginas-Tar00859782019-02-11 12:21:27 +000072 /// Function that a 2D convolution layer should call back to when its Accept(ILayerVisitor&)
jimfly015f4e41f2019-01-23 16:10:17 +000073 /// function is invoked.
74 /// @param layer - pointer to the layer which is calling back to this visit function.
75 /// @param convolution2dDescriptor - Description of the 2D convolution layer.
76 /// @param weights - Tensor for the weights data.
Aron Virginas-Tar00859782019-02-11 12:21:27 +000077 /// @param biases - Optional tensor for the bias data. If specified, must match the output tensor shape.
jimfly015f4e41f2019-01-23 16:10:17 +000078 /// @param name - Optional name for the layer.
79 virtual void VisitConvolution2dLayer(const IConnectableLayer* layer,
80 const Convolution2dDescriptor& convolution2dDescriptor,
81 const ConstTensor& weights,
Aron Virginas-Tar00859782019-02-11 12:21:27 +000082 const Optional<ConstTensor>& biases,
jimfly015f4e41f2019-01-23 16:10:17 +000083 const char* name = nullptr) = 0;
84
jimfly015f4e41f2019-01-23 16:10:17 +000085 /// Function that a 2D depthwise convolution layer with biases should call back to when its
86 /// Accept(ILayerVisitor&) function is invoked.
87 /// @param layer - pointer to the layer which is calling back to this visit function.
88 /// @param convolution2dDescriptor - Description of the 2D depthwise convolution layer.
89 /// @param weights - Tensor for the weights. Expected format: [channelMultiplier, inputChannels, height, width].
Aron Virginas-Tar00859782019-02-11 12:21:27 +000090 /// @param biases - Optional tensor for the bias data. If specified, must match the output tensor shape.
jimfly015f4e41f2019-01-23 16:10:17 +000091 /// @param name - Optional name for the layer.
92 virtual void VisitDepthwiseConvolution2dLayer(const IConnectableLayer* layer,
93 const DepthwiseConvolution2dDescriptor& convolution2dDescriptor,
94 const ConstTensor& weights,
Aron Virginas-Tar00859782019-02-11 12:21:27 +000095 const Optional<ConstTensor>& biases,
jimfly015f4e41f2019-01-23 16:10:17 +000096 const char* name = nullptr) = 0;
97
Nattapat Chaimanowonge4294fd2019-03-28 09:56:53 +000098 /// Function that a Dequantize layer should call back to when its
99 /// Accept(ILayerVisitor&) function is invoked.
100 /// @param layer - pointer to the layer which is calling back to this visit function.
101 /// @param name - Optional name for the layer.
102 virtual void VisitDequantizeLayer(const IConnectableLayer* layer,
103 const char* name = nullptr) = 0;
104
jimfly01d161ba02019-01-28 12:51:53 +0000105 /// Function that a Detection PostProcess layer should call back to when its
106 /// Accept(ILayerVisitor&) function is invoked.
107 /// @param layer - pointer to the layer which is calling back to this visit function.
108 /// @param descriptor - Description of the Detection PostProcess layer.
Narumol Prangnawarat6d302bf2019-02-04 11:46:26 +0000109 /// @param anchors - Tensor for the anchors.
jimfly01d161ba02019-01-28 12:51:53 +0000110 /// @param name - Optional name for the layer.
111 virtual void VisitDetectionPostProcessLayer(const IConnectableLayer* layer,
112 const DetectionPostProcessDescriptor& descriptor,
Narumol Prangnawarat6d302bf2019-02-04 11:46:26 +0000113 const ConstTensor& anchors,
jimfly01d161ba02019-01-28 12:51:53 +0000114 const char* name = nullptr) = 0;
115
Derek Lamberti61f54632019-03-25 16:28:44 +0000116 /// Function a division layer should call back to when its Accept(ILayerVisitor&) function is invoked.
117 /// @param layer - pointer to the layer which is calling back to this visit function.
118 /// @param name - Optional name for the layer.
119 virtual void VisitDivisionLayer(const IConnectableLayer* layer,
120 const char* name = nullptr) = 0;
121
122 /// Function an Equal layer should call back to when its Accept(ILayerVisitor&) function is invoked.
123 /// @param layer - pointer to the layer which is calling back to this visit function.
124 /// @param name - Optional name for the layer.
125 virtual void VisitEqualLayer(const IConnectableLayer* layer,
126 const char* name = nullptr) = 0;
127
128 /// Function a floor layer should call back to when its Accept(ILayerVisitor&) function is invoked.
129 /// @param layer - pointer to the layer which is calling back to this visit function.
130 /// @param name - Optional name for the layer.
131 virtual void VisitFloorLayer(const IConnectableLayer* layer,
132 const char* name = nullptr) = 0;
133
Aron Virginas-Tar00859782019-02-11 12:21:27 +0000134 /// Function that a fully connected layer should call back to when its Accept(ILayerVisitor&)
jimfly015f4e41f2019-01-23 16:10:17 +0000135 /// function is invoked.
136 /// @param layer - pointer to the layer which is calling back to this visit function.
137 /// @param fullyConnectedDescriptor - Description of the fully connected layer.
138 /// @param weights - Tensor for the weights data.
Aron Virginas-Tar00859782019-02-11 12:21:27 +0000139 /// @param biases - Optional tensor for the bias data.
jimfly015f4e41f2019-01-23 16:10:17 +0000140 /// @param name - Optional name for the layer.
141 virtual void VisitFullyConnectedLayer(const IConnectableLayer* layer,
142 const FullyConnectedDescriptor& fullyConnectedDescriptor,
143 const ConstTensor& weights,
Aron Virginas-Tar00859782019-02-11 12:21:27 +0000144 const Optional<ConstTensor>& biases,
jimfly015f4e41f2019-01-23 16:10:17 +0000145 const char* name = nullptr) = 0;
146
Derek Lamberti61f54632019-03-25 16:28:44 +0000147 /// Function a Gather layer should call back to when its Accept(ILayerVisitor&) function is invoked.
jimfly015f4e41f2019-01-23 16:10:17 +0000148 /// @param layer - pointer to the layer which is calling back to this visit function.
jimfly015f4e41f2019-01-23 16:10:17 +0000149 /// @param name - Optional name for the layer.
Derek Lamberti61f54632019-03-25 16:28:44 +0000150 virtual void VisitGatherLayer(const IConnectableLayer* layer,
jimfly015f4e41f2019-01-23 16:10:17 +0000151 const char* name = nullptr) = 0;
152
Derek Lamberti61f54632019-03-25 16:28:44 +0000153 /// Function a Greater layer should call back to when its Accept(ILayerVisitor&) function is invoked.
jimfly015f4e41f2019-01-23 16:10:17 +0000154 /// @param layer - pointer to the layer which is calling back to this visit function.
155 /// @param name - Optional name for the layer.
Derek Lamberti61f54632019-03-25 16:28:44 +0000156 virtual void VisitGreaterLayer(const IConnectableLayer* layer,
157 const char* name = nullptr) = 0;
jimfly015f4e41f2019-01-23 16:10:17 +0000158
Derek Lamberti61f54632019-03-25 16:28:44 +0000159 /// Function that an InputLayer should call back to when its Accept(ILayerVisitor&) function is invoked.
jimfly015f4e41f2019-01-23 16:10:17 +0000160 /// @param layer - pointer to the layer which is calling back to this visit function.
Derek Lamberti61f54632019-03-25 16:28:44 +0000161 /// @param id - User generated id to uniquely identify a particular input. The same id needs to be specified
162 /// when passing the inputs to the IRuntime::EnqueueWorkload() function.
jimfly015f4e41f2019-01-23 16:10:17 +0000163 /// @param name - Optional name for the layer.
Derek Lamberti61f54632019-03-25 16:28:44 +0000164 virtual void VisitInputLayer(const IConnectableLayer* layer,
165 LayerBindingId id,
166 const char* name = nullptr) = 0;
jimfly015f4e41f2019-01-23 16:10:17 +0000167
jimfly015f4e41f2019-01-23 16:10:17 +0000168
169 /// Function that an L2 normalization layer should call back to when its Accept(ILayerVisitor&)
170 /// function is invoked. Normalization is performed along dimension 1, but requires a 4d input.
171 /// @param layer - pointer to the layer which is calling back to this visit function.
172 /// @param desc - Parameters for the L2 normalization operation.
173 /// @param name - Optional name for the layer.
174 virtual void VisitL2NormalizationLayer(const IConnectableLayer* layer,
175 const L2NormalizationDescriptor& desc,
176 const char* name = nullptr) = 0;
177
jimfly015f4e41f2019-01-23 16:10:17 +0000178 /// Function an Lstm layer should call back to when its Accept(ILayerVisitor&) function is invoked.
179 /// @param layer - pointer to the layer which is calling back to this visit function.
180 /// @param descriptor - Parameters controlling the operation of the Lstm operation.
181 /// @param params - The weights and biases for the LSTM cell.
182 /// @param name - Optional name for the layer.
183 virtual void VisitLstmLayer(const IConnectableLayer* layer,
184 const LstmDescriptor& descriptor,
185 const LstmInputParams& params,
186 const char* name = nullptr) = 0;
187
jimfly015f4e41f2019-01-23 16:10:17 +0000188 /// Function a Maximum layer should call back to when its Accept(ILayerVisitor&) function is invoked.
189 /// @param layer - pointer to the layer which is calling back to this visit function.
190 /// @param name - Optional name for the layer.
191 virtual void VisitMaximumLayer(const IConnectableLayer* layer,
192 const char* name = nullptr) = 0;
193
194 /// Function a Mean layer should call back to when its Accept(ILayerVisitor&) function is invoked.
195 /// @param layer - pointer to the layer which is calling back to this visit function.
196 /// @param meanDescriptor - Parameters for the mean operation.
197 /// @param name - Optional name for the layer.
198 virtual void VisitMeanLayer(const IConnectableLayer* layer,
199 const MeanDescriptor& meanDescriptor,
200 const char* name = nullptr) = 0;
201
Nattapat Chaimanowong1f886302019-04-05 13:37:19 +0100202 /// Function that a merge layer should call back to when its Accept(ILayerVisitor&) function is invoked.
203 /// @param layer - pointer to the layer which is calling back to this visit function.
204 /// @param name - Optional name for the layer.
205 virtual void VisitMergeLayer(const IConnectableLayer* layer,
206 const char* name = nullptr) = 0;
207
Derek Lamberti61f54632019-03-25 16:28:44 +0000208 /// Function that a merger layer should call back to when its Accept(ILayerVisitor&) function is invoked.
209 /// @param layer - pointer to the layer which is calling back to this visit function.
210 /// @param mergerDescriptor - WindowsDescriptor to configure the merging process. Number of Views must be equal to
211 /// the number of inputs, and their order must match - e.g. first view corresponds to
212 /// the first input, second view to the second input, etc....
213 /// @param name - Optional name for the layer.
214 virtual void VisitMergerLayer(const IConnectableLayer* layer,
215 const OriginsDescriptor& mergerDescriptor,
216 const char* name = nullptr) = 0;
217
218 /// Function a Minimum layer should call back to when its Accept(ILayerVisitor&) function is invoked.
219 /// @param layer - pointer to the layer which is calling back to this visit function.
220 /// @param name - Optional name for the layer.
221 virtual void VisitMinimumLayer(const IConnectableLayer* layer,
222 const char* name = nullptr) = 0;
223
224 /// Function that a multiplication layer should call back to when its Accept(ILayerVisitor&) function is invoked.
225 /// @param layer - pointer to the layer which is calling back to this visit function.
226 /// @param name - Optional name for the layer.
227 virtual void VisitMultiplicationLayer(const IConnectableLayer* layer,
228 const char* name = nullptr) = 0;
229
230 /// Function that a normalization layer should call back to when its Accept(ILayerVisitor&) function is invoked.
231 /// @param layer - pointer to the layer which is calling back to this visit function.
232 /// @param normalizationDescriptor - NormalizationDescriptor to configure the normalization.
233 /// @param name - Optional name for the layer.
234 virtual void VisitNormalizationLayer(const IConnectableLayer* layer,
235 const NormalizationDescriptor& normalizationDescriptor,
236 const char* name = nullptr) = 0;
237
238 /// Function an output layer should call back to when its Accept(ILayerVisitor&) function is invoked.
239 /// @param layer - pointer to the layer which is calling back to this visit function.
240 /// @param id - User generated id to uniquely identify a particular output. The same id needs to be specified
241 /// when passing the outputs to the IRuntime::EnqueueWorkload() function.
242 /// @param name - Optional name for the layer.
243 virtual void VisitOutputLayer(const IConnectableLayer* layer,
244 LayerBindingId id,
245 const char* name = nullptr) = 0;
246
jimfly015f4e41f2019-01-23 16:10:17 +0000247 /// Function a pad layer should call back to when its Accept(ILayerVisitor&) function is invoked.
248 /// @param layer - pointer to the layer which is calling back to this visit function.
249 /// @param paddings - n by 2 tensor, where n is the rank of the input tensor,
250 /// such that paddings[i,0] indicates the amount of padding to add in front of dimension i, and
251 /// paddings[i,1] indicates the amount of padding to add after the end of dimension i
252 /// @param name - Optional name for the layer.
253 virtual void VisitPadLayer(const IConnectableLayer* layer,
254 const PadDescriptor& padDescriptor,
255 const char* name = nullptr) = 0;
256
Derek Lamberti61f54632019-03-25 16:28:44 +0000257 /// Function that a permute layer should call back to when its Accept(ILayerVisitor&) function is invoked.
258 /// @param layer - pointer to the layer which is calling back to this visit function.
259 /// @param permuteDescriptor - PermuteDescriptor to configure the permute.
260 /// @param name - Optional name for the layer.
261 virtual void VisitPermuteLayer(const IConnectableLayer* layer,
262 const PermuteDescriptor& permuteDescriptor,
263 const char* name = nullptr) = 0;
264
265 /// Function that a pooling layer should call back to when its Accept(ILayerVisitor&) function is invoked.
266 /// @param layer - pointer to the layer which is calling back to this visit function.
267 /// @param pooling2dDescriptor - Pooling2dDescriptor to configure the pooling.
268 /// @param name - Optional name for the layer.
269 virtual void VisitPooling2dLayer(const IConnectableLayer* layer,
270 const Pooling2dDescriptor& pooling2dDescriptor,
271 const char* name = nullptr) = 0;
272
Derek Lambertia9cca6a2019-03-25 15:41:58 +0000273 /// Function a quantize layer should call back to when its Accept(ILayerVisitor&) function is invoked.
274 /// @param layer - pointer to the layer which is calling back to this visit function.
275 /// @param name - Optional name for the layer.
276 virtual void VisitQuantizeLayer(const IConnectableLayer* layer,
277 const char* name = nullptr) = 0;
278
Derek Lamberti61f54632019-03-25 16:28:44 +0000279 /// Function a reshape layer should call back to when its Accept(ILayerVisitor&) function is invoked.
280 /// @param layer - pointer to the layer which is calling back to this visit function.
281 /// @param reshapeDescriptor - Parameters for the reshape operation.
282 /// @param name - Optional name for the layer.
283 virtual void VisitReshapeLayer(const IConnectableLayer* layer,
284 const ReshapeDescriptor& reshapeDescriptor,
285 const char* name = nullptr) = 0;
286
287 /// Function that a resize bilinear layer should call back to when its Accept(ILayerVisitor&) function is invoked.
288 /// @param layer - pointer to the layer which is calling back to this visit function.
289 /// @param resizeDesc - Parameters for the resize operation.
290 /// @param name - Optional name for the layer.
291 virtual void VisitResizeBilinearLayer(const IConnectableLayer* layer,
292 const ResizeBilinearDescriptor& resizeDesc,
293 const char* name = nullptr) = 0;
294
295 /// Function a Reciprocal of square root layer should call back to when its Accept(ILayerVisitor&)
296 /// function is invoked.
297 /// @param layer - pointer to the layer which is calling back to this visit function.
298 /// @param name - Optional name for the layer.
299 virtual void VisitRsqrtLayer(const IConnectableLayer* layer,
300 const char* name = nullptr) = 0;
301
302
303 /// Function that a softmax layer should call back to when its Accept(ILayerVisitor&) function is invoked.
304 /// @param layer - pointer to the layer which is calling back to this visit function.
305 /// @param softmaxDescriptor - SoftmaxDescriptor to configure the softmax.
306 /// @param name - Optional name for the layer.
307 virtual void VisitSoftmaxLayer(const IConnectableLayer* layer,
308 const SoftmaxDescriptor& softmaxDescriptor,
309 const char* name = nullptr) = 0;
310
311 /// Function a space to batch layer should call back to when its Accept(ILayerVisitor&) function is invoked.
312 /// @param layer - pointer to the layer which is calling back to this visit function.
313 /// @param spaceToBatchNdDescriptor - Parameters for the space to batch operation.
314 /// @param name - Optional name for the layer.
315 virtual void VisitSpaceToBatchNdLayer(const IConnectableLayer* layer,
316 const SpaceToBatchNdDescriptor& spaceToBatchNdDescriptor,
317 const char* name = nullptr) = 0;
318
319 /// Function that a splitter layer should call back to when its Accept(ILayerVisitor&) function is invoked.
320 /// @param layer - pointer to the layer which is calling back to this visit function.
321 /// @param splitterDescriptor - WindowsDescriptor to configure the splitting process.
322 /// Number of Views must be equal to the number of outputs,
323 /// and their order must match - e.g. first view corresponds to
324 /// the first output, second view to the second output, etc....
325 /// @param name - Optional name for the layer.
326 virtual void VisitSplitterLayer(const IConnectableLayer* layer,
327 const ViewsDescriptor& splitterDescriptor,
328 const char* name = nullptr) = 0;
329
jimfly015f4e41f2019-01-23 16:10:17 +0000330 /// Function a strided slice layer should call back to when its Accept(ILayerVisitor&) function is invoked.
331 /// @param layer - pointer to the layer which is calling back to this visit function.
332 /// @param StridedSliceDescriptor - Parameters for the strided slice operation.
333 /// @param name - Optional name for the layer.
334 virtual void VisitStridedSliceLayer(const IConnectableLayer* layer,
335 const StridedSliceDescriptor& stridedSliceDescriptor,
336 const char* name = nullptr) = 0;
337
Derek Lamberti61f54632019-03-25 16:28:44 +0000338 /// Function a subtraction layer should call back to when its Accept(ILayerVisitor&) function is invoked.
jimfly015f4e41f2019-01-23 16:10:17 +0000339 /// @param layer - pointer to the layer which is calling back to this visit function.
340 /// @param name - Optional name for the layer.
Derek Lamberti61f54632019-03-25 16:28:44 +0000341 virtual void VisitSubtractionLayer(const IConnectableLayer* layer,
342 const char* name = nullptr) = 0;
jimfly015f4e41f2019-01-23 16:10:17 +0000343
Sadik Armaganeff363d2019-04-05 15:25:46 +0100344 /// Function a switch layer should call back to when its Accept(ILayerVisitor&) function is invoked.
345 /// @param layer - pointer to the layer which is calling back to this visit function.
346 /// @param name - Optional name for the layer.
347 virtual void VisitSwitchLayer(const IConnectableLayer* layer,
348 const char* name = nullptr) = 0;
349
jimfly015f4e41f2019-01-23 16:10:17 +0000350
351};
Nattapat Chaimanowong1f886302019-04-05 13:37:19 +0100352} // namespace armnn