From 5f4e41ff596170dad9c073b007b3f53783a9e1f3 Mon Sep 17 00:00:00 2001 From: jimfly01 Date: Wed, 23 Jan 2019 16:10:17 +0000 Subject: [PATCH] IVGCVSW-2546 Add ILayerVisitor to the public API Change-Id: I803de435a538856de2daa7872e27d3f5beabba4f --- CMakeLists.txt | 1 + include/armnn/ILayerVisitor.hpp | 341 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 342 insertions(+) create mode 100644 include/armnn/ILayerVisitor.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 82f7d11..3c1932d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -155,6 +155,7 @@ list(APPEND armnn_sources include/armnn/DescriptorsFwd.hpp include/armnn/Exceptions.hpp include/armnn/ILayerSupport.hpp + include/armnn/ILayerVisitor.hpp include/armnn/INetwork.hpp include/armnn/IProfiler.hpp include/armnn/IRuntime.hpp diff --git a/include/armnn/ILayerVisitor.hpp b/include/armnn/ILayerVisitor.hpp new file mode 100644 index 0000000..dd73a6f --- /dev/null +++ b/include/armnn/ILayerVisitor.hpp @@ -0,0 +1,341 @@ +// +// Copyright © 2017 Arm Ltd. All rights reserved. +// SPDX-License-Identifier: MIT +// +#pragma once + +#include +#include +#include +#include + +namespace armnn +{ +class ILayerVisitor +{ +public: + /// Function that an InputLayer should call back to when its Accept(ILayerVisitor&) function is invoked. + /// @param layer - pointer to the layer which is calling back to this visit function. + /// @param id - User generated id to uniquely identify a particular input. The same id needs to be specified + /// when passing the inputs to the IRuntime::EnqueueWorkload() function. + /// @param name - Optional name for the layer. + virtual void VisitInputLayer(const IConnectableLayer* layer, + LayerBindingId id, + const char* name = nullptr) = 0; + + /// Function that a 2D convolution layer without biases should call back to when its Accept(ILayerVisitor&) + /// function is invoked. + /// @param layer - pointer to the layer which is calling back to this visit function. + /// @param convolution2dDescriptor - Description of the 2D convolution layer. + /// @param weights - Tensor for the weights data. + /// @param name - Optional name for the layer. + virtual void VisitConvolution2dLayer(const IConnectableLayer* layer, + const Convolution2dDescriptor& convolution2dDescriptor, + const ConstTensor& weights, + const char* name = nullptr) = 0; + + /// Function that a 2D convolution layer with bias should call back to when its Accept(ILayerVisitor&) + /// function is invoked. + /// @param layer - pointer to the layer which is calling back to this visit function. + /// @param convolution2dDescriptor - Description of the 2D convolution layer. + /// @param weights - Tensor for the weights data. + /// @param biases - Tensor for the bias data. Must match the output tensor shape. + /// @param name - Optional name for the layer. + virtual void VisitConvolution2dLayer(const IConnectableLayer* layer, + const Convolution2dDescriptor& convolution2dDescriptor, + const ConstTensor& weights, + const ConstTensor& biases, + const char* name = nullptr) = 0; + + /// Function that a 2D depthwise convolution layer without biases should call back to when its + /// Accept(ILayerVisitor&) function is invoked. + /// @param layer - pointer to the layer which is calling back to this visit function. + /// @param convolution2dDescriptor - Description of the 2D depthwise convolution layer. + /// @param weights - Tensor for the weights. Expected format: [channelMultiplier, inputChannels, height, width]. + /// @param name - Optional name for the layer. + virtual void VisitDepthwiseConvolution2dLayer(const IConnectableLayer* layer, + const DepthwiseConvolution2dDescriptor& convolution2dDescriptor, + const ConstTensor& weights, + const char* name = nullptr) = 0; + + /// Function that a 2D depthwise convolution layer with biases should call back to when its + /// Accept(ILayerVisitor&) function is invoked. + /// @param layer - pointer to the layer which is calling back to this visit function. + /// @param convolution2dDescriptor - Description of the 2D depthwise convolution layer. + /// @param weights - Tensor for the weights. Expected format: [channelMultiplier, inputChannels, height, width]. + /// @param biases - Tensor for the bias data. Must match the output tensor shape. + /// @param name - Optional name for the layer. + virtual void VisitDepthwiseConvolution2dLayer(const IConnectableLayer* layer, + const DepthwiseConvolution2dDescriptor& convolution2dDescriptor, + const ConstTensor& weights, + const ConstTensor& biases, + const char* name = nullptr) = 0; + + /// Function that a fully connected layer without biases should call back to when its Accept(ILayerVisitor&) + /// function is invoked. + /// @param layer - pointer to the layer which is calling back to this visit function. + /// @param fullyConnectedDescriptor - Description of the fully connected layer. + /// @param weights - Tensor for the weights data. + /// @param name - Optional name for the layer. + virtual void VisitFullyConnectedLayer(const IConnectableLayer* layer, + const FullyConnectedDescriptor& fullyConnectedDescriptor, + const ConstTensor& weights, + const char* name = nullptr) = 0; + + /// Function that a fully connected layer with biases should call back to when its Accept(ILayerVisitor&) + /// function is invoked. + /// @param layer - pointer to the layer which is calling back to this visit function. + /// @param fullyConnectedDescriptor - Description of the fully connected layer. + /// @param weights - Tensor for the weights data. + /// @param biases - Tensor for the bias data. + /// @param name - Optional name for the layer. + virtual void VisitFullyConnectedLayer(const IConnectableLayer* layer, + const FullyConnectedDescriptor& fullyConnectedDescriptor, + const ConstTensor& weights, + const ConstTensor& biases, + const char* name = nullptr) = 0; + + /// Function that a permute layer should call back to when its Accept(ILayerVisitor&) function is invoked. + /// @param layer - pointer to the layer which is calling back to this visit function. + /// @param permuteDescriptor - PermuteDescriptor to configure the permute. + /// @param name - Optional name for the layer. + virtual void VisitPermuteLayer(const IConnectableLayer* layer, + const PermuteDescriptor& permuteDescriptor, + const char* name = nullptr) = 0; + + /// Function that a batch to space ND layer should call back to when its Accept(ILayerVisitor&) + /// function is invoked. + /// @param layer - pointer to the layer which is calling back to this visit function. + /// @param batchToSpaceNdDescriptor - Description of the layer. + /// @param name - Optional name for the layer. + virtual void VisitBatchToSpaceNdLayer(const IConnectableLayer* layer, + const BatchToSpaceNdDescriptor& batchToSpaceNdDescriptor, + const char* name = nullptr) = 0; + + /// Function that a pooling layer should call back to when its Accept(ILayerVisitor&) function is invoked. + /// @param layer - pointer to the layer which is calling back to this visit function. + /// @param pooling2dDescriptor - Pooling2dDescriptor to configure the pooling. + /// @param name - Optional name for the layer. + virtual void VisitPooling2dLayer(const IConnectableLayer* layer, + const Pooling2dDescriptor& pooling2dDescriptor, + const char* name = nullptr) = 0; + + /// Function that an activation layer should call back to when its Accept(ILayerVisitor&) function is invoked. + /// @param layer - pointer to the layer which is calling back to this visit function. + /// @param activationDescriptor - ActivationDescriptor to configure the activation. + /// @param name - Optional name for the layer. + virtual void VisitActivationLayer(const IConnectableLayer* layer, + const ActivationDescriptor& activationDescriptor, + const char* name = nullptr) = 0; + + /// Function that a normalization layer should call back to when its Accept(ILayerVisitor&) function is invoked. + /// @param layer - pointer to the layer which is calling back to this visit function. + /// @param normalizationDescriptor - NormalizationDescriptor to configure the normalization. + /// @param name - Optional name for the layer. + virtual void VisitNormalizationLayer(const IConnectableLayer* layer, + const NormalizationDescriptor& normalizationDescriptor, + const char* name = nullptr) = 0; + + /// Function that a softmax layer should call back to when its Accept(ILayerVisitor&) function is invoked. + /// @param layer - pointer to the layer which is calling back to this visit function. + /// @param softmaxDescriptor - SoftmaxDescriptor to configure the softmax. + /// @param name - Optional name for the layer. + virtual void VisitSoftmaxLayer(const IConnectableLayer* layer, + const SoftmaxDescriptor& softmaxDescriptor, + const char* name = nullptr) = 0; + + /// Function that a splitter layer should call back to when its Accept(ILayerVisitor&) function is invoked. + /// @param layer - pointer to the layer which is calling back to this visit function. + /// @param splitterDescriptor - WindowsDescriptor to configure the splitting process. + /// Number of Views must be equal to the number of outputs, + /// and their order must match - e.g. first view corresponds to + /// the first output, second view to the second output, etc.... + /// @param name - Optional name for the layer. + virtual void VisitSplitterLayer(const IConnectableLayer* layer, + const ViewsDescriptor& splitterDescriptor, + const char* name = nullptr) = 0; + + /// Function that a merger layer should call back to when its Accept(ILayerVisitor&) function is invoked. + /// @param layer - pointer to the layer which is calling back to this visit function. + /// @param mergerDescriptor - WindowsDescriptor to configure the merging process. Number of Views must be equal to + /// the number of inputs, and their order must match - e.g. first view corresponds to + /// the first input, second view to the second input, etc.... + /// @param name - Optional name for the layer. + virtual void VisitMergerLayer(const IConnectableLayer* layer, + const OriginsDescriptor& mergerDescriptor, + const char* name = nullptr) = 0; + + /// Function that an addition layer should call back to when its Accept(ILayerVisitor&) function is invoked. + /// @param layer - pointer to the layer which is calling back to this visit function. + /// @param name - Optional name for the layer. + virtual void VisitAdditionLayer(const IConnectableLayer* layer, + const char* name = nullptr) = 0; + + /// Function that a multiplication layer should call back to when its Accept(ILayerVisitor&) function is invoked. + /// @param layer - pointer to the layer which is calling back to this visit function. + /// @param name - Optional name for the layer. + virtual void VisitMultiplicationLayer(const IConnectableLayer* layer, + const char* name = nullptr) = 0; + + /// Function that a batch normalization layer should call back to when its Accept(ILayerVisitor&) + /// function is invoked. + /// @param layer - pointer to the layer which is calling back to this visit function. + /// @param mean - Pre-calculated mean for each channel. + /// @param variance - Pre-calculated variance for each channel. + /// @param beta - Per-channel additive factor. + /// @param gamma - Per-channel multiplicative factor. + /// @param name - Optional name for the layer. + virtual void VisitBatchNormalizationLayer(const IConnectableLayer* layer, + const BatchNormalizationDescriptor& desc, + const ConstTensor& mean, + const ConstTensor& variance, + const ConstTensor& beta, + const ConstTensor& gamma, + const char* name = nullptr) = 0; + + /// Function that a resize bilinear layer should call back to when its Accept(ILayerVisitor&) function is invoked. + /// @param layer - pointer to the layer which is calling back to this visit function. + /// @param resizeDesc - Parameters for the resize operation. + /// @param name - Optional name for the layer. + virtual void VisitResizeBilinearLayer(const IConnectableLayer* layer, + const ResizeBilinearDescriptor& resizeDesc, + const char* name = nullptr) = 0; + + /// Function that an L2 normalization layer should call back to when its Accept(ILayerVisitor&) + /// function is invoked. Normalization is performed along dimension 1, but requires a 4d input. + /// @param layer - pointer to the layer which is calling back to this visit function. + /// @param desc - Parameters for the L2 normalization operation. + /// @param name - Optional name for the layer. + virtual void VisitL2NormalizationLayer(const IConnectableLayer* layer, + const L2NormalizationDescriptor& desc, + const char* name = nullptr) = 0; + + /// Function a layer with no inputs and a single output, which always corresponds to + /// the passed in constant tensor should call back to when its Accept(ILayerVisitor&) function is invoked. + /// @param layer - pointer to the layer which is calling back to this visit function. + /// @param input - Tensor to be provided as the only output of the layer. The layer will maintain + /// its own copy of the tensor data, meaning the memory referenced by @a input can + /// be freed or reused after this function is called. + /// @param name - Optional name for the layer. + virtual void VisitConstantLayer(const IConnectableLayer* layer, + const ConstTensor& input, + const char* name = nullptr) = 0; + + /// Function a reshape layer should call back to when its Accept(ILayerVisitor&) function is invoked. + /// @param layer - pointer to the layer which is calling back to this visit function. + /// @param reshapeDescriptor - Parameters for the reshape operation. + /// @param name - Optional name for the layer. + virtual void VisitReshapeLayer(const IConnectableLayer* layer, + const ReshapeDescriptor& reshapeDescriptor, + const char* name = nullptr) = 0; + + /// Function a space to batch layer should call back to when its Accept(ILayerVisitor&) function is invoked. + /// @param layer - pointer to the layer which is calling back to this visit function. + /// @param spaceToBatchNdDescriptor - Parameters for the space to batch operation. + /// @param name - Optional name for the layer. + virtual void VisitSpaceToBatchNdLayer(const IConnectableLayer* layer, + const SpaceToBatchNdDescriptor& spaceToBatchNdDescriptor, + const char* name = nullptr) = 0; + + /// Function a floor layer should call back to when its Accept(ILayerVisitor&) function is invoked. + /// @param layer - pointer to the layer which is calling back to this visit function. + /// @param name - Optional name for the layer. + virtual void VisitFloorLayer(const IConnectableLayer* layer, + const char* name = nullptr) = 0; + + /// Function an output layer should call back to when its Accept(ILayerVisitor&) function is invoked. + /// @param layer - pointer to the layer which is calling back to this visit function. + /// @param id - User generated id to uniquely identify a particular output. The same id needs to be specified + /// when passing the outputs to the IRuntime::EnqueueWorkload() function. + /// @param name - Optional name for the layer. + virtual void VisitOutputLayer(const IConnectableLayer* layer, + LayerBindingId id, + const char* name = nullptr) = 0; + + /// Function an Lstm layer should call back to when its Accept(ILayerVisitor&) function is invoked. + /// @param layer - pointer to the layer which is calling back to this visit function. + /// @param descriptor - Parameters controlling the operation of the Lstm operation. + /// @param params - The weights and biases for the LSTM cell. + /// @param name - Optional name for the layer. + virtual void VisitLstmLayer(const IConnectableLayer* layer, + const LstmDescriptor& descriptor, + const LstmInputParams& params, + const char* name = nullptr) = 0; + + /// Function a division layer should call back to when its Accept(ILayerVisitor&) function is invoked. + /// @param layer - pointer to the layer which is calling back to this visit function. + /// @param name - Optional name for the layer. + virtual void VisitDivisionLayer(const IConnectableLayer* layer, + const char* name = nullptr) = 0; + + /// Function a subtraction layer should call back to when its Accept(ILayerVisitor&) function is invoked. + /// @param layer - pointer to the layer which is calling back to this visit function. + /// @param name - Optional name for the layer. + virtual void VisitSubtractionLayer(const IConnectableLayer* layer, + const char* name = nullptr) = 0; + + /// Function a Maximum layer should call back to when its Accept(ILayerVisitor&) function is invoked. + /// @param layer - pointer to the layer which is calling back to this visit function. + /// @param name - Optional name for the layer. + virtual void VisitMaximumLayer(const IConnectableLayer* layer, + const char* name = nullptr) = 0; + + /// Function a Mean layer should call back to when its Accept(ILayerVisitor&) function is invoked. + /// @param layer - pointer to the layer which is calling back to this visit function. + /// @param meanDescriptor - Parameters for the mean operation. + /// @param name - Optional name for the layer. + virtual void VisitMeanLayer(const IConnectableLayer* layer, + const MeanDescriptor& meanDescriptor, + const char* name = nullptr) = 0; + + /// Function a pad layer should call back to when its Accept(ILayerVisitor&) function is invoked. + /// @param layer - pointer to the layer which is calling back to this visit function. + /// @param paddings - n by 2 tensor, where n is the rank of the input tensor, + /// such that paddings[i,0] indicates the amount of padding to add in front of dimension i, and + /// paddings[i,1] indicates the amount of padding to add after the end of dimension i + /// @param name - Optional name for the layer. + virtual void VisitPadLayer(const IConnectableLayer* layer, + const PadDescriptor& padDescriptor, + const char* name = nullptr) = 0; + + /// Function a strided slice layer should call back to when its Accept(ILayerVisitor&) function is invoked. + /// @param layer - pointer to the layer which is calling back to this visit function. + /// @param StridedSliceDescriptor - Parameters for the strided slice operation. + /// @param name - Optional name for the layer. + virtual void VisitStridedSliceLayer(const IConnectableLayer* layer, + const StridedSliceDescriptor& stridedSliceDescriptor, + const char* name = nullptr) = 0; + + /// Function a Minimum layer should call back to when its Accept(ILayerVisitor&) function is invoked. + /// @param layer - pointer to the layer which is calling back to this visit function. + /// @param name - Optional name for the layer. + virtual void VisitMinimumLayer(const IConnectableLayer* layer, + const char* name = nullptr) = 0; + + /// Function a Greater layer should call back to when its Accept(ILayerVisitor&) function is invoked. + /// @param layer - pointer to the layer which is calling back to this visit function. + /// @param name - Optional name for the layer. + virtual void VisitGreaterLayer(const IConnectableLayer* layer, + const char* name = nullptr) = 0; + + /// Function an Equal layer should call back to when its Accept(ILayerVisitor&) function is invoked. + /// @param layer - pointer to the layer which is calling back to this visit function. + /// @param name - Optional name for the layer. + virtual void VisitEqualLayer(const IConnectableLayer* layer, + const char* name = nullptr) = 0; + + /// Function a Reciprocal of square root layer should call back to when its Accept(ILayerVisitor&) + /// function is invoked. + /// @param layer - pointer to the layer which is calling back to this visit function. + /// @param name - Optional name for the layer. + virtual void VisitRsqrtLayer(const IConnectableLayer* layer, + const char* name = nullptr) = 0; + + /// Function a Gather layer should call back to when its Accept(ILayerVisitor&) function is invoked. + /// @param layer - pointer to the layer which is calling back to this visit function. + /// @param name - Optional name for the layer. + virtual void VisitGatherLayer(const IConnectableLayer* layer, + const char* name = nullptr) = 0; + +}; +} // namespace armnn \ No newline at end of file -- 2.7.4