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