a22de878ca028e337b4e64b7b5106b5203fc60c6
[platform/upstream/armnn.git] / include / armnn / ILayerVisitor.hpp
1 //
2 // Copyright © 2017 Arm Ltd. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 #pragma once
6
7 #include <armnn/Deprecated.hpp>
8 #include <armnn/DescriptorsFwd.hpp>
9 #include <armnn/NetworkFwd.hpp>
10 #include <armnn/Optional.hpp>
11 #include <armnn/TensorFwd.hpp>
12 #include <armnn/Types.hpp>
13
14 namespace armnn
15 {
16 class ILayerVisitor
17 {
18 protected:
19     ILayerVisitor() {}
20     virtual ~ILayerVisitor() {}
21
22 public:
23     /// Function an absolute layer should call back to when its Accept(ILayerVisitor&)
24     /// function is invoked.
25     /// @param layer - pointer to the layer which is calling back to this visit function.
26     /// @param name - Optional name for the layer.
27     virtual void VisitAbsLayer(const IConnectableLayer* layer,
28                                const char* name = nullptr) = 0;
29
30     /// Function that an activation 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 activationDescriptor - ActivationDescriptor to configure the activation.
33     /// @param name - Optional name for the layer.
34     virtual void VisitActivationLayer(const IConnectableLayer* layer,
35                                       const ActivationDescriptor& activationDescriptor,
36                                       const char* name = nullptr) = 0;
37
38     /// Function that an addition layer should call back to when its Accept(ILayerVisitor&) function is invoked.
39     /// @param layer - pointer to the layer which is calling back to this visit function.
40     /// @param name - Optional name for the layer.
41     virtual void VisitAdditionLayer(const IConnectableLayer* layer,
42                                     const char* name = nullptr) = 0;
43
44     /// Function that a batch normalization layer should call back to when its Accept(ILayerVisitor&)
45     /// function is invoked.
46     /// @param layer - pointer to the layer which is calling back to this visit function.
47     /// @param mean - Pre-calculated mean for each channel.
48     /// @param variance - Pre-calculated variance for each channel.
49     /// @param beta - Per-channel additive factor.
50     /// @param gamma - Per-channel multiplicative factor.
51     /// @param name - Optional name for the layer.
52     virtual void VisitBatchNormalizationLayer(const IConnectableLayer* layer,
53                                               const BatchNormalizationDescriptor& desc,
54                                               const ConstTensor& mean,
55                                               const ConstTensor& variance,
56                                               const ConstTensor& beta,
57                                               const ConstTensor& gamma,
58                                               const char* name = nullptr) = 0;
59
60     /// Function that a batch to space ND layer should call back to when its Accept(ILayerVisitor&)
61     /// function is invoked.
62     /// @param layer - pointer to the layer which is calling back to this visit function.
63     /// @param batchToSpaceNdDescriptor - Description of the layer.
64     /// @param name - Optional name for the layer.
65     virtual void VisitBatchToSpaceNdLayer(const IConnectableLayer* layer,
66                                           const BatchToSpaceNdDescriptor& batchToSpaceNdDescriptor,
67                                           const char* name = nullptr) = 0;
68
69     /// Function that a concat layer should call back to when its Accept(ILayerVisitor&) function is invoked.
70     /// @param layer - pointer to the layer which is calling back to this visit function.
71     /// @param concatDescriptor - ConcatDescriptor (synonym for OriginsDescriptor) to configure the concatenation
72     ///                           process. Number of Views must be equal to the number of inputs, and their order
73     ///                           must match - e.g. first view corresponds to the first input, second view to the
74     ///                           second input, etc....
75     /// @param name - Optional name for the layer.
76     virtual void VisitConcatLayer(const IConnectableLayer* layer,
77                                   const OriginsDescriptor& concatDescriptor,
78                                   const char* name = nullptr)
79     {
80         // default implementation to ease transition while MergerLayer is being deprecated
81         ARMNN_NO_DEPRECATE_WARN_BEGIN
82         VisitMergerLayer(layer, concatDescriptor, name);
83         ARMNN_NO_DEPRECATE_WARN_END
84     }
85
86     /// Function a layer with no inputs and a single output, which always corresponds to
87     /// the passed in constant tensor should call back to when its Accept(ILayerVisitor&) function is invoked.
88     /// @param layer - pointer to the layer which is calling back to this visit function.
89     /// @param input - Tensor to be provided as the only output of the layer. The layer will maintain
90     ///                its own copy of the tensor data, meaning the memory referenced by @a input can
91     ///                be freed or reused after this function is called.
92     /// @param name - Optional name for the layer.
93     virtual void VisitConstantLayer(const IConnectableLayer* layer,
94                                     const ConstTensor& input,
95                                     const char* name = nullptr) = 0;
96
97     /// Function that a 2D convolution layer should call back to when its Accept(ILayerVisitor&)
98     /// function is invoked.
99     /// @param layer - pointer to the layer which is calling back to this visit function.
100     /// @param convolution2dDescriptor - Description of the 2D convolution layer.
101     /// @param weights - Tensor for the weights data.
102     /// @param biases - Optional tensor for the bias data. If specified, must match the output tensor shape.
103     /// @param name - Optional name for the layer.
104     virtual void VisitConvolution2dLayer(const IConnectableLayer* layer,
105                                          const Convolution2dDescriptor& convolution2dDescriptor,
106                                          const ConstTensor& weights,
107                                          const Optional<ConstTensor>& biases,
108                                          const char* name = nullptr) = 0;
109
110     /// Function that a 2D depthwise convolution layer with biases should call back to when its
111     /// Accept(ILayerVisitor&) function is invoked.
112     /// @param layer - pointer to the layer which is calling back to this visit function.
113     /// @param convolution2dDescriptor - Description of the 2D depthwise convolution layer.
114     /// @param weights - Tensor for the weights. Expected format: [channelMultiplier, inputChannels, height, width].
115     /// @param biases - Optional tensor for the bias data. If specified, must match the output tensor shape.
116     /// @param name - Optional name for the layer.
117     virtual void VisitDepthwiseConvolution2dLayer(const IConnectableLayer* layer,
118                                                   const DepthwiseConvolution2dDescriptor& convolution2dDescriptor,
119                                                   const ConstTensor& weights,
120                                                   const Optional<ConstTensor>& biases,
121                                                   const char* name = nullptr) = 0;
122
123     /// Function that a Dequantize layer should call back to when its
124     /// Accept(ILayerVisitor&) function is invoked.
125     /// @param layer - pointer to the layer which is calling back to this visit function.
126     /// @param name - Optional name for the layer.
127     virtual void VisitDequantizeLayer(const IConnectableLayer* layer,
128                                       const char* name = nullptr) = 0;
129
130     /// Function that a Detection PostProcess layer should call back to when its
131     /// Accept(ILayerVisitor&) function is invoked.
132     /// @param layer - pointer to the layer which is calling back to this visit function.
133     /// @param descriptor - Description of the Detection PostProcess layer.
134     /// @param anchors - Tensor for the anchors.
135     /// @param name - Optional name for the layer.
136     virtual void VisitDetectionPostProcessLayer(const IConnectableLayer* layer,
137                                                 const DetectionPostProcessDescriptor& descriptor,
138                                                 const ConstTensor& anchors,
139                                                 const char* name = nullptr) = 0;
140
141     /// Function a division layer should call back to when its Accept(ILayerVisitor&) function is invoked.
142     /// @param layer - pointer to the layer which is calling back to this visit function.
143     /// @param name - Optional name for the layer.
144     virtual void VisitDivisionLayer(const IConnectableLayer* layer,
145                                     const char* name = nullptr) = 0;
146
147     /// Function an Equal layer should call back to when its Accept(ILayerVisitor&) function is invoked.
148     /// @param layer - pointer to the layer which is calling back to this visit function.
149     /// @param name - Optional name for the layer.
150     virtual void VisitEqualLayer(const IConnectableLayer* layer,
151                                  const char* name = nullptr) = 0;
152
153     /// Function a floor layer should call back to when its Accept(ILayerVisitor&) function is invoked.
154     /// @param layer - pointer to the layer which is calling back to this visit function.
155     /// @param name - Optional name for the layer.
156     virtual void VisitFloorLayer(const IConnectableLayer* layer,
157                                  const char* name = nullptr) = 0;
158
159     /// Function that a fully connected layer should call back to when its Accept(ILayerVisitor&)
160     /// function is invoked.
161     /// @param layer - pointer to the layer which is calling back to this visit function.
162     /// @param fullyConnectedDescriptor - Description of the fully connected layer.
163     /// @param weights - Tensor for the weights data.
164     /// @param biases - Optional tensor for the bias data.
165     /// @param name - Optional name for the layer.
166     virtual void VisitFullyConnectedLayer(const IConnectableLayer* layer,
167                                           const FullyConnectedDescriptor& fullyConnectedDescriptor,
168                                           const ConstTensor& weights,
169                                           const Optional<ConstTensor>& biases,
170                                           const char* name = nullptr) = 0;
171
172     /// Function a Gather layer should call back to when its Accept(ILayerVisitor&) function is invoked.
173     /// @param layer - pointer to the layer which is calling back to this visit function.
174     /// @param name - Optional name for the layer.
175     virtual void VisitGatherLayer(const IConnectableLayer* layer,
176                                   const char* name = nullptr) = 0;
177
178     /// Function a Greater 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 name - Optional name for the layer.
181     virtual void VisitGreaterLayer(const IConnectableLayer* layer,
182                                    const char* name = nullptr) = 0;
183
184     /// Function that an InputLayer should call back to when its Accept(ILayerVisitor&) function is invoked.
185     /// @param layer - pointer to the layer which is calling back to this visit function.
186     /// @param id - User generated id to uniquely identify a particular input. The same id needs to be specified
187     ///             when passing the inputs to the IRuntime::EnqueueWorkload() function.
188     /// @param name - Optional name for the layer.
189     virtual void VisitInputLayer(const IConnectableLayer* layer,
190                                  LayerBindingId id,
191                                  const char* name = nullptr) = 0;
192
193
194     /// Function that an L2 normalization layer should call back to when its Accept(ILayerVisitor&)
195     /// function is invoked. Normalization is performed along dimension 1, but requires a 4d input.
196     /// @param layer - pointer to the layer which is calling back to this visit function.
197     /// @param desc - Parameters for the L2 normalization operation.
198     /// @param name - Optional name for the layer.
199     virtual void VisitL2NormalizationLayer(const IConnectableLayer* layer,
200                                            const L2NormalizationDescriptor& desc,
201                                            const char* name = nullptr) = 0;
202
203     /// Function an Lstm layer should call back to when its Accept(ILayerVisitor&) function is invoked.
204     /// @param layer - pointer to the layer which is calling back to this visit function.
205     /// @param descriptor - Parameters controlling the operation of the Lstm operation.
206     /// @param params - The weights and biases for the LSTM cell.
207     /// @param name - Optional name for the layer.
208     virtual void VisitLstmLayer(const IConnectableLayer* layer,
209                                 const LstmDescriptor& descriptor,
210                                 const LstmInputParams& params,
211                                 const char* name = nullptr) = 0;
212
213     /// Function a Maximum layer should call back to when its Accept(ILayerVisitor&) function is invoked.
214     /// @param layer - pointer to the layer which is calling back to this visit function.
215     /// @param name - Optional name for the layer.
216     virtual void VisitMaximumLayer(const IConnectableLayer* layer,
217                                    const char* name = nullptr) = 0;
218
219     /// Function a Mean layer should call back to when its Accept(ILayerVisitor&) function is invoked.
220     /// @param layer - pointer to the layer which is calling back to this visit function.
221     /// @param meanDescriptor - Parameters for the mean operation.
222     /// @param name - Optional name for the layer.
223     virtual void VisitMeanLayer(const IConnectableLayer* layer,
224                                 const MeanDescriptor& meanDescriptor,
225                                 const char* name = nullptr) = 0;
226
227     /// Function that a merge layer should call back to when its Accept(ILayerVisitor&) function is invoked.
228     /// @param layer - pointer to the layer which is calling back to this visit function.
229     /// @param name - Optional name for the layer.
230     virtual void VisitMergeLayer(const IConnectableLayer* layer,
231                                  const char* name = nullptr) = 0;
232
233     /// Function that a merger layer should call back to when its Accept(ILayerVisitor&) function is invoked.
234     /// @param layer - pointer to the layer which is calling back to this visit function.
235     /// @param mergerDescriptor - MergerDescriptor (synonym for OriginsDescriptor) to configure the concatenation
236     ///                           process. Number of Views must be equal to the number of inputs, and their order
237     ///                           must match - e.g. first view corresponds to the first input, second view to the
238     ///                           second input, etc....
239     /// @param name - Optional name for the layer.
240     ARMNN_DEPRECATED_MSG("Use VisitConcatLayer instead")
241     virtual void VisitMergerLayer(const IConnectableLayer* layer,
242                                   const MergerDescriptor& mergerDescriptor,
243                                   const char* name = nullptr) = 0;
244
245     /// Function a Minimum layer should call back to when its Accept(ILayerVisitor&) function is invoked.
246     /// @param layer - pointer to the layer which is calling back to this visit function.
247     /// @param name - Optional name for the layer.
248     virtual void VisitMinimumLayer(const IConnectableLayer* layer,
249                                    const char* name = nullptr) = 0;
250
251     /// Function that a multiplication layer should call back to when its Accept(ILayerVisitor&) function is invoked.
252     /// @param layer - pointer to the layer which is calling back to this visit function.
253     /// @param name - Optional name for the layer.
254     virtual void VisitMultiplicationLayer(const IConnectableLayer* layer,
255                                           const char* name = nullptr) = 0;
256
257     /// Function that a normalization 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 normalizationDescriptor - NormalizationDescriptor to configure the normalization.
260     /// @param name - Optional name for the layer.
261     virtual void VisitNormalizationLayer(const IConnectableLayer* layer,
262                                          const NormalizationDescriptor& normalizationDescriptor,
263                                          const char* name = nullptr) = 0;
264
265     /// Function an output 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 id - User generated id to uniquely identify a particular output. The same id needs to be specified
268     /// when passing the outputs to the IRuntime::EnqueueWorkload() function.
269     /// @param name - Optional name for the layer.
270     virtual void VisitOutputLayer(const IConnectableLayer* layer,
271                                   LayerBindingId id,
272                                   const char* name = nullptr) = 0;
273
274     /// Function a pad layer should call back to when its Accept(ILayerVisitor&) function is invoked.
275     /// @param layer - pointer to the layer which is calling back to this visit function.
276     /// @param paddings - n by 2 tensor, where n is the rank of the input tensor,
277     ///                   such that paddings[i,0] indicates the amount of padding to add in front of dimension i, and
278     ///                   paddings[i,1] indicates the amount of padding to add after the end of dimension i
279     /// @param name - Optional name for the layer.
280     virtual void VisitPadLayer(const IConnectableLayer* layer,
281                                const PadDescriptor& padDescriptor,
282                                const char* name = nullptr) = 0;
283
284     /// Function that a permute layer should call back to when its Accept(ILayerVisitor&) function is invoked.
285     /// @param layer - pointer to the layer which is calling back to this visit function.
286     /// @param permuteDescriptor - PermuteDescriptor to configure the permute.
287     /// @param name - Optional name for the layer.
288     virtual void VisitPermuteLayer(const IConnectableLayer* layer,
289                                    const PermuteDescriptor& permuteDescriptor,
290                                    const char* name = nullptr) = 0;
291
292     /// Function that a pooling layer should call back to when its Accept(ILayerVisitor&) function is invoked.
293     /// @param layer - pointer to the layer which is calling back to this visit function.
294     /// @param pooling2dDescriptor - Pooling2dDescriptor to configure the pooling.
295     /// @param name - Optional name for the layer.
296     virtual void VisitPooling2dLayer(const IConnectableLayer* layer,
297                                      const Pooling2dDescriptor& pooling2dDescriptor,
298                                      const char* name = nullptr) = 0;
299
300     /// Function that a PReLU activation layer should call back to when its Accept(ILayerVisitor&) function is invoked.
301     /// @param layer - pointer to the layer which is calling back to this visit function.
302     /// @param name - Optional name for the layer.
303     virtual void VisitPreluLayer(const IConnectableLayer* layer,
304                                  const char* name = nullptr) = 0;
305
306     /// Function a quantize layer should call back to when its Accept(ILayerVisitor&) function is invoked.
307     /// @param layer - pointer to the layer which is calling back to this visit function.
308     /// @param name - Optional name for the layer.
309     virtual void VisitQuantizeLayer(const IConnectableLayer* layer,
310                                     const char* name = nullptr) = 0;
311
312     /// Function a QuantizedLstm layer should call back to when its Accept(ILayerVisitor&) function is invoked.
313     /// @param layer - pointer to the layer which is calling back to this visit function.
314     /// @param params - The weights and biases for the Quantized LSTM cell
315     /// @param name - Optional name for the layer.
316     virtual void VisitQuantizedLstmLayer(const IConnectableLayer* layer,
317                                          const QuantizedLstmInputParams& params,
318                                          const char* name = nullptr) = 0;
319
320     /// Function a reshape layer should call back to when its Accept(ILayerVisitor&) function is invoked.
321     /// @param layer - pointer to the layer which is calling back to this visit function.
322     /// @param reshapeDescriptor - Parameters for the reshape operation.
323     /// @param name - Optional name for the layer.
324     virtual void VisitReshapeLayer(const IConnectableLayer* layer,
325                                    const ReshapeDescriptor& reshapeDescriptor,
326                                    const char* name = nullptr) = 0;
327
328     /// Function that a resize bilinear layer should call back to when its Accept(ILayerVisitor&) function is invoked.
329     /// @param layer - pointer to the layer which is calling back to this visit function.
330     /// @param resizeDesc - Parameters for the resize operation.
331     /// @param name - Optional name for the layer.
332     ARMNN_DEPRECATED_MSG("Use VisitResizeLayer instead")
333     virtual void VisitResizeBilinearLayer(const IConnectableLayer* layer,
334                                           const ResizeBilinearDescriptor& resizeDesc,
335                                           const char* name = nullptr) = 0;
336
337     /// Function that a resize layer should call back to when its Accept(ILayerVisitor&) function is invoked.
338     /// @param layer - pointer to the layer which is calling back to this visit function.
339     /// @param resizeDescriptor - Parameters for the resize operation.
340     /// @param name - Optional name for the layer.
341     virtual void VisitResizeLayer(const IConnectableLayer* layer,
342                                   const ResizeDescriptor& resizeDescriptor,
343                                   const char* name = nullptr) = 0;
344
345     /// Function a Reciprocal of square root layer should call back to when its Accept(ILayerVisitor&)
346     /// function is invoked.
347     /// @param layer - pointer to the layer which is calling back to this visit function.
348     /// @param name - Optional name for the layer.
349     virtual void VisitRsqrtLayer(const IConnectableLayer* layer,
350                                  const char* name = nullptr) = 0;
351
352
353     /// Function that a softmax layer should call back to when its Accept(ILayerVisitor&) function is invoked.
354     /// @param layer - pointer to the layer which is calling back to this visit function.
355     /// @param softmaxDescriptor - SoftmaxDescriptor to configure the softmax.
356     /// @param name - Optional name for the layer.
357     virtual void VisitSoftmaxLayer(const IConnectableLayer* layer,
358                                    const SoftmaxDescriptor& softmaxDescriptor,
359                                    const char* name = nullptr) = 0;
360
361     /// Function a space to batch layer should call back to when its Accept(ILayerVisitor&) function is invoked.
362     /// @param layer - pointer to the layer which is calling back to this visit function.
363     /// @param spaceToBatchNdDescriptor - Parameters for the space to batch operation.
364     /// @param name - Optional name for the layer.
365     virtual void VisitSpaceToBatchNdLayer(const IConnectableLayer* layer,
366                                           const SpaceToBatchNdDescriptor& spaceToBatchNdDescriptor,
367                                           const char* name = nullptr) = 0;
368
369     /// Function a space to depth layer should call back to when its Accept(ILayerVisitor&) function is invoked.
370     /// @param layer - pointer to the layer which is calling back to this visit function.
371     /// @param spaceToDepthDescriptor - Parameters for the space to depth operation.
372     /// @param name - Optional name for the layer.
373     virtual void VisitSpaceToDepthLayer(const IConnectableLayer* layer,
374                                         const SpaceToDepthDescriptor& spaceToDepthDescriptor,
375                                         const char* name = nullptr) = 0;
376
377     /// Function that a splitter layer should call back to when its Accept(ILayerVisitor&) function is invoked.
378     /// @param layer - pointer to the layer which is calling back to this visit function.
379     /// @param splitterDescriptor - ViewsDescriptor to configure the splitting process.
380     ///                             Number of Views must be equal to the number of outputs,
381     ///                             and their order must match - e.g. first view corresponds to
382     ///                             the first output, second view to the second output, etc....
383     /// @param name - Optional name for the layer.
384     virtual void VisitSplitterLayer(const IConnectableLayer* layer,
385                                     const ViewsDescriptor& splitterDescriptor,
386                                     const char* name = nullptr) = 0;
387
388     /// Function a stack layer should call back to when its Accept(ILayerVisitor&) function is invoked.
389     /// @param layer - pointer to the layer which is calling back to this visit function.
390     /// @param stackDescriptor - Parameters for the stack operation.
391     /// @param name - Optional name for the layer.
392     virtual void VisitStackLayer(const IConnectableLayer* layer,
393                                  const StackDescriptor& stackDescriptor,
394                                  const char* name = nullptr) = 0;
395
396     /// Function a strided slice layer should call back to when its Accept(ILayerVisitor&) function is invoked.
397     /// @param layer - pointer to the layer which is calling back to this visit function.
398     /// @param stridedSliceDescriptor - Parameters for the strided slice operation.
399     /// @param name - Optional name for the layer.
400     virtual void VisitStridedSliceLayer(const IConnectableLayer* layer,
401                                         const StridedSliceDescriptor& stridedSliceDescriptor,
402                                         const char* name = nullptr) = 0;
403
404     /// Function a subtraction layer should call back to when its Accept(ILayerVisitor&) function is invoked.
405     /// @param layer - pointer to the layer which is calling back to this visit function.
406     /// @param name - Optional name for the layer.
407     virtual void VisitSubtractionLayer(const IConnectableLayer* layer,
408                                        const char* name = nullptr) = 0;
409
410     /// Function a switch layer should call back to when its Accept(ILayerVisitor&) function is invoked.
411     /// @param layer - pointer to the layer which is calling back to this visit function.
412     /// @param name - Optional name for the layer.
413     virtual void VisitSwitchLayer(const IConnectableLayer* layer,
414                                   const char* name = nullptr) = 0;
415
416     /// Function that a 2D transpose convolution layer should call back to when its Accept(ILayerVisitor&)
417     /// function is invoked.
418     /// @param layer - pointer to the layer which is calling back to this visit function.
419     /// @param descriptor - Description of the 2D transpose convolution layer.
420     /// @param weights - Tensor for the weights data.
421     /// @param biases - Optional tensor for the bias data.
422     /// @param name - Optional name for the layer.
423     virtual void VisitTransposeConvolution2dLayer(const IConnectableLayer* layer,
424                                                   const TransposeConvolution2dDescriptor& descriptor,
425                                                   const ConstTensor& weights,
426                                                   const Optional<ConstTensor>& biases,
427                                                   const char* name = nullptr) = 0;
428
429     virtual void StartVisit() {}
430     virtual void FinishVisit() {}
431
432 };
433 } // namespace armnn