diff options
author | Finn Williams <Finn.Williams@arm.com> | 2021-02-09 15:56:23 +0000 |
---|---|---|
committer | Finn Williams <Finn.Williams@arm.com> | 2021-02-12 13:10:20 +0000 |
commit | b454c5c65efb238c130b042ace390b2bc7f0bf75 (patch) | |
tree | d6681d0abf416b3cc280bc3bb70e7d55dfd40a0d /include/armnn | |
parent | 8eae955f665f371b0a2c7c1a06e8ba442afa2298 (diff) | |
download | armnn-b454c5c65efb238c130b042ace390b2bc7f0bf75.tar.gz |
IVGCVSW-4893 Refactor ILayerVisitor using unified interface strategy.
Signed-off-by: Jan Eilers <jan.eilers@arm.com>
Signed-off-by: Finn Williams <Finn.Williams@arm.com>
Signed-off-by: Francis Murtagh <francis.murtagh@arm.com>
Change-Id: Id7bc8255a8e3f9e5aac65d510bec8a559bf37246
Diffstat (limited to 'include/armnn')
-rw-r--r-- | include/armnn/Descriptors.hpp | 92 | ||||
-rw-r--r-- | include/armnn/DescriptorsFwd.hpp | 1 | ||||
-rw-r--r-- | include/armnn/INetwork.hpp | 10 | ||||
-rw-r--r-- | include/armnn/IStrategy.hpp | 31 | ||||
-rw-r--r-- | include/armnn/Types.hpp | 83 |
5 files changed, 178 insertions, 39 deletions
diff --git a/include/armnn/Descriptors.hpp b/include/armnn/Descriptors.hpp index a8e68aa8c1..20511ab00f 100644 --- a/include/armnn/Descriptors.hpp +++ b/include/armnn/Descriptors.hpp @@ -9,6 +9,8 @@ #include <cstdint> #include <initializer_list> +#include <iostream> +#include <sstream> #include "Tensor.hpp" #include "Types.hpp" @@ -16,8 +18,11 @@ namespace armnn { +/// Base class for all descriptors. +struct BaseDescriptor {}; + /// An ActivationDescriptor for the ActivationLayer. -struct ActivationDescriptor +struct ActivationDescriptor : BaseDescriptor { ActivationDescriptor() : m_Function(ActivationFunction::Sigmoid) @@ -48,7 +53,7 @@ struct ActivationDescriptor }; /// An ArgMinMaxDescriptor for ArgMinMaxLayer -struct ArgMinMaxDescriptor +struct ArgMinMaxDescriptor : BaseDescriptor { ArgMinMaxDescriptor() : m_Function(ArgMinMaxFunction::Min) @@ -70,7 +75,7 @@ struct ArgMinMaxDescriptor }; /// A ComparisonDescriptor for the ComparisonLayer -struct ComparisonDescriptor +struct ComparisonDescriptor : BaseDescriptor { ComparisonDescriptor() : ComparisonDescriptor(ComparisonOperation::Equal) @@ -90,7 +95,7 @@ struct ComparisonDescriptor }; /// A ElementwiseUnaryDescriptor for the ElementwiseUnaryLayer -struct ElementwiseUnaryDescriptor +struct ElementwiseUnaryDescriptor : BaseDescriptor { ElementwiseUnaryDescriptor() : ElementwiseUnaryDescriptor(UnaryOperation::Abs) @@ -110,7 +115,7 @@ struct ElementwiseUnaryDescriptor }; /// A PermuteDescriptor for the PermuteLayer. -struct PermuteDescriptor +struct PermuteDescriptor : BaseDescriptor { PermuteDescriptor() : m_DimMappings{} @@ -131,7 +136,7 @@ struct PermuteDescriptor }; /// A SoftmaxDescriptor for the SoftmaxLayer. -struct SoftmaxDescriptor +struct SoftmaxDescriptor : BaseDescriptor { SoftmaxDescriptor() : m_Beta(1.0f) @@ -155,7 +160,7 @@ using LogSoftmaxDescriptor = SoftmaxDescriptor; /// @brief An OriginsDescriptor for the ConcatLayer. /// Descriptor to configure the concatenation 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. -struct OriginsDescriptor +struct OriginsDescriptor : BaseDescriptor { OriginsDescriptor(); OriginsDescriptor(uint32_t numViews, uint32_t numDimensions = 4); @@ -198,7 +203,7 @@ private: /// @brief A ViewsDescriptor for the SplitterLayer. /// Descriptor 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. -struct ViewsDescriptor +struct ViewsDescriptor : BaseDescriptor { ViewsDescriptor(uint32_t numViews, uint32_t numDimensions = 4); ViewsDescriptor(const ViewsDescriptor& other); @@ -321,7 +326,7 @@ OriginsDescriptor CreateDescriptorForConcatenation(TensorShapeIt first, } /// A Pooling2dDescriptor for the Pooling2dLayer. -struct Pooling2dDescriptor +struct Pooling2dDescriptor : BaseDescriptor { Pooling2dDescriptor() : m_PoolType(PoolingAlgorithm::Max) @@ -381,7 +386,7 @@ struct Pooling2dDescriptor }; /// A FullyConnectedDescriptor for the FullyConnectedLayer. -struct FullyConnectedDescriptor +struct FullyConnectedDescriptor : BaseDescriptor { FullyConnectedDescriptor() : m_BiasEnabled(false) @@ -400,7 +405,7 @@ struct FullyConnectedDescriptor }; /// A Convolution2dDescriptor for the Convolution2dLayer. -struct Convolution2dDescriptor +struct Convolution2dDescriptor : BaseDescriptor { Convolution2dDescriptor() : m_PadLeft(0) @@ -452,7 +457,7 @@ struct Convolution2dDescriptor }; /// A DepthwiseConvolution2dDescriptor for the DepthwiseConvolution2dLayer. -struct DepthwiseConvolution2dDescriptor +struct DepthwiseConvolution2dDescriptor : BaseDescriptor { DepthwiseConvolution2dDescriptor() : m_PadLeft(0) @@ -503,7 +508,7 @@ struct DepthwiseConvolution2dDescriptor DataLayout m_DataLayout; }; -struct DetectionPostProcessDescriptor +struct DetectionPostProcessDescriptor : BaseDescriptor { DetectionPostProcessDescriptor() : m_MaxDetections(0) @@ -559,7 +564,7 @@ struct DetectionPostProcessDescriptor }; /// A NormalizationDescriptor for the NormalizationLayer. -struct NormalizationDescriptor +struct NormalizationDescriptor : BaseDescriptor { NormalizationDescriptor() : m_NormChannelType(NormalizationAlgorithmChannel::Across) @@ -599,7 +604,7 @@ struct NormalizationDescriptor }; /// A L2NormalizationDescriptor for the L2NormalizationLayer. -struct L2NormalizationDescriptor +struct L2NormalizationDescriptor : BaseDescriptor { L2NormalizationDescriptor() : m_Eps(1e-12f) @@ -618,7 +623,7 @@ struct L2NormalizationDescriptor }; /// A BatchNormalizationDescriptor for the BatchNormalizationLayer. -struct BatchNormalizationDescriptor +struct BatchNormalizationDescriptor : BaseDescriptor { BatchNormalizationDescriptor() : m_Eps(0.0001f) @@ -637,7 +642,7 @@ struct BatchNormalizationDescriptor }; /// An InstanceNormalizationDescriptor for InstanceNormalizationLayer -struct InstanceNormalizationDescriptor +struct InstanceNormalizationDescriptor : BaseDescriptor { InstanceNormalizationDescriptor() : m_Gamma(1.0f) @@ -665,7 +670,7 @@ struct InstanceNormalizationDescriptor }; /// A BatchToSpaceNdDescriptor for the BatchToSpaceNdLayer. -struct BatchToSpaceNdDescriptor +struct BatchToSpaceNdDescriptor : BaseDescriptor { BatchToSpaceNdDescriptor() : m_BlockShape({1, 1}) @@ -696,7 +701,7 @@ struct BatchToSpaceNdDescriptor }; /// A FakeQuantizationDescriptor for the FakeQuantizationLayer. -struct FakeQuantizationDescriptor +struct FakeQuantizationDescriptor : BaseDescriptor { FakeQuantizationDescriptor() : m_Min(-6.0f) @@ -715,7 +720,7 @@ struct FakeQuantizationDescriptor }; /// A FillDescriptor for the FillLayer -struct FillDescriptor +struct FillDescriptor : BaseDescriptor { FillDescriptor() : m_Value(0) @@ -734,7 +739,7 @@ struct FillDescriptor }; /// A GatherDescriptor for the GatherLayer. -struct GatherDescriptor +struct GatherDescriptor : BaseDescriptor { GatherDescriptor() : m_Axis(0) @@ -754,7 +759,7 @@ struct GatherDescriptor }; /// A ResizeBilinearDescriptor for the ResizeBilinearLayer. -struct ResizeBilinearDescriptor +struct ResizeBilinearDescriptor : BaseDescriptor { ResizeBilinearDescriptor() : m_TargetWidth(0) @@ -764,6 +769,15 @@ struct ResizeBilinearDescriptor , m_HalfPixelCenters(false) {} + bool operator ==(const ResizeBilinearDescriptor& rhs) const + { + return m_TargetWidth == rhs.m_TargetWidth && + m_TargetHeight == rhs.m_TargetHeight && + m_DataLayout == rhs.m_DataLayout && + m_AlignCorners == rhs.m_AlignCorners && + m_HalfPixelCenters == rhs.m_HalfPixelCenters; + } + /// Target width value. uint32_t m_TargetWidth; /// Target height value. @@ -777,7 +791,7 @@ struct ResizeBilinearDescriptor }; /// A ResizeDescriptor for the ResizeLayer. -struct ResizeDescriptor +struct ResizeDescriptor : BaseDescriptor { ResizeDescriptor() : m_TargetWidth(0) @@ -815,7 +829,7 @@ struct ResizeDescriptor /// A ReshapeDescriptor for the ReshapeLayer. -struct ReshapeDescriptor +struct ReshapeDescriptor : BaseDescriptor { ReshapeDescriptor() : m_TargetShape() @@ -835,7 +849,7 @@ struct ReshapeDescriptor }; /// A SpaceToBatchNdDescriptor for the SpaceToBatchNdLayer. -struct SpaceToBatchNdDescriptor +struct SpaceToBatchNdDescriptor : BaseDescriptor { SpaceToBatchNdDescriptor() : m_BlockShape({1, 1}) @@ -867,7 +881,7 @@ struct SpaceToBatchNdDescriptor }; /// A SpaceToDepthDescriptor for the SpaceToDepthLayer -struct SpaceToDepthDescriptor +struct SpaceToDepthDescriptor : BaseDescriptor { SpaceToDepthDescriptor() : SpaceToDepthDescriptor(1u, DataLayout::NHWC) @@ -894,7 +908,7 @@ struct SpaceToDepthDescriptor using DepthToSpaceDescriptor = SpaceToDepthDescriptor; /// An LstmDescriptor for the LstmLayer. -struct LstmDescriptor +struct LstmDescriptor : BaseDescriptor { LstmDescriptor() : m_ActivationFunc(1) // 0: None, 1: Relu, 3: Relu6, 4: Tanh, 6: Sigmoid @@ -934,7 +948,7 @@ struct LstmDescriptor }; /// A MeanDescriptor for the MeanLayer. -struct MeanDescriptor +struct MeanDescriptor : BaseDescriptor { MeanDescriptor() : m_Axis() @@ -958,7 +972,7 @@ struct MeanDescriptor }; /// A PadDescriptor for the PadLayer. -struct PadDescriptor +struct PadDescriptor : BaseDescriptor { PadDescriptor() : m_PadValue(0) {} @@ -984,7 +998,7 @@ struct PadDescriptor }; /// A SliceDescriptor for the SliceLayer. -struct SliceDescriptor +struct SliceDescriptor : BaseDescriptor { SliceDescriptor(const std::vector<unsigned int>& begin, const std::vector<unsigned int>& size) : m_Begin(begin) @@ -1007,7 +1021,7 @@ struct SliceDescriptor }; /// A StackDescriptor for the StackLayer. -struct StackDescriptor +struct StackDescriptor : BaseDescriptor { StackDescriptor() : m_Axis(0) @@ -1037,7 +1051,7 @@ struct StackDescriptor }; /// A StandInDescriptor for the StandIn layer -struct StandInDescriptor +struct StandInDescriptor : BaseDescriptor { StandInDescriptor() {}; @@ -1059,7 +1073,7 @@ struct StandInDescriptor }; /// A StridedSliceDescriptor for the StridedSliceLayer. -struct StridedSliceDescriptor +struct StridedSliceDescriptor : BaseDescriptor { StridedSliceDescriptor(const std::vector<int>& begin, const std::vector<int>& end, @@ -1123,7 +1137,7 @@ struct StridedSliceDescriptor }; /// A PreCompiledDescriptor for the PreCompiledLayer. -struct PreCompiledDescriptor +struct PreCompiledDescriptor : BaseDescriptor { PreCompiledDescriptor(unsigned int numInputSlots = 1u, unsigned int numOutputSlots = 1u) : m_NumInputSlots(numInputSlots), m_NumOutputSlots(numOutputSlots) @@ -1136,7 +1150,7 @@ struct PreCompiledDescriptor }; /// A QLstmDescriptor for the QLstmLayer. -struct QLstmDescriptor +struct QLstmDescriptor : BaseDescriptor { QLstmDescriptor() : m_CellClip(0.0) @@ -1196,7 +1210,7 @@ struct QLstmDescriptor }; /// A TransposeConvolution2dDescriptor for the TransposeConvolution2dLayer. -struct TransposeConvolution2dDescriptor +struct TransposeConvolution2dDescriptor : BaseDescriptor { TransposeConvolution2dDescriptor() : m_PadLeft(0), @@ -1246,7 +1260,7 @@ struct TransposeConvolution2dDescriptor }; /// A TransposeDescriptor for the TransposeLayer. -struct TransposeDescriptor +struct TransposeDescriptor : BaseDescriptor { TransposeDescriptor() : m_DimMappings{} @@ -1267,7 +1281,7 @@ struct TransposeDescriptor }; /// A LogicalBinaryDescriptor for the LogicalBinaryLayer -struct LogicalBinaryDescriptor +struct LogicalBinaryDescriptor : BaseDescriptor { LogicalBinaryDescriptor() : LogicalBinaryDescriptor(LogicalBinaryOperation::LogicalAnd) @@ -1287,7 +1301,7 @@ struct LogicalBinaryDescriptor }; /// A ReduceDescriptor for the REDUCE operators. -struct ReduceDescriptor +struct ReduceDescriptor : BaseDescriptor { ReduceDescriptor() : m_KeepDims(false) diff --git a/include/armnn/DescriptorsFwd.hpp b/include/armnn/DescriptorsFwd.hpp index 054ce51144..4e7082e88f 100644 --- a/include/armnn/DescriptorsFwd.hpp +++ b/include/armnn/DescriptorsFwd.hpp @@ -7,6 +7,7 @@ namespace armnn { +struct BaseDescriptor; struct ActivationDescriptor; struct ArgMinMaxDescriptor; diff --git a/include/armnn/INetwork.hpp b/include/armnn/INetwork.hpp index ca1b725d48..c667d9ce8b 100644 --- a/include/armnn/INetwork.hpp +++ b/include/armnn/INetwork.hpp @@ -8,6 +8,7 @@ #include <armnn/Deprecated.hpp> #include <armnn/DescriptorsFwd.hpp> #include <armnn/ILayerVisitor.hpp> +#include <armnn/IStrategy.hpp> #include <armnn/NetworkFwd.hpp> #include <armnn/Optional.hpp> #include <armnn/TensorFwd.hpp> @@ -91,8 +92,15 @@ public: /// Apply a visitor to this layer virtual void Accept(ILayerVisitor& visitor) const = 0; + /// Apply a visitor to this layer + virtual void ExecuteStrategy(IStrategy& strategy) const = 0; + /// Provide a hint for the optimizer as to which backend to prefer for this layer virtual void BackendSelectionHint(Optional<BackendId> backend) = 0; + + /// Returns the armnn::LayerType of this layer + virtual LayerType GetType() const = 0; + protected: /// Objects are not deletable via the handle ~IConnectableLayer() {} @@ -600,6 +608,8 @@ public: virtual void Accept(ILayerVisitor& visitor) const = 0; + virtual void ExecuteStrategy(IStrategy& strategy) const = 0; + protected: ~INetwork() {} }; diff --git a/include/armnn/IStrategy.hpp b/include/armnn/IStrategy.hpp new file mode 100644 index 0000000000..8d29565dcc --- /dev/null +++ b/include/armnn/IStrategy.hpp @@ -0,0 +1,31 @@ +// +// Copyright © 2021 Arm Ltd and Contributors. All rights reserved. +// SPDX-License-Identifier: MIT +// +#pragma once + +#include <armnn/DescriptorsFwd.hpp> +#include <armnn/Types.hpp> + +namespace armnn +{ + +class IStrategy +{ +protected: +IStrategy() {} +virtual ~IStrategy() {} + +public: +virtual void ExecuteStrategy(const armnn::IConnectableLayer* layer, + const armnn::BaseDescriptor& descriptor, + const std::vector<armnn::ConstTensor>& constants, + const char* name, + const armnn::LayerBindingId id = 0) = 0; + +virtual void FinishStrategy() {}; + +}; + + +} // namespace armnn diff --git a/include/armnn/Types.hpp b/include/armnn/Types.hpp index 22004bd0a4..e1ff46b023 100644 --- a/include/armnn/Types.hpp +++ b/include/armnn/Types.hpp @@ -344,6 +344,89 @@ struct ProfilingStaticGuid : public ProfilingGuid } // namespace profiling +/// This list uses X macro technique. +/// See https://en.wikipedia.org/wiki/X_Macro for more info +#define LIST_OF_LAYER_TYPE \ + X(Activation) \ + X(Addition) \ + X(ArgMinMax) \ + X(BatchNormalization) \ + X(BatchToSpaceNd) \ + X(Comparison) \ + X(Concat) \ + X(Constant) \ + X(ConvertBf16ToFp32) \ + X(ConvertFp16ToFp32) \ + X(ConvertFp32ToBf16) \ + X(ConvertFp32ToFp16) \ + X(Convolution2d) \ + X(Debug) \ + X(DepthToSpace) \ + X(DepthwiseConvolution2d) \ + X(Dequantize) \ + X(DetectionPostProcess) \ + X(Division) \ + X(ElementwiseUnary) \ + X(FakeQuantization) \ + X(Fill) \ + X(Floor) \ + X(FullyConnected) \ + X(Gather) \ + X(Input) \ + X(InstanceNormalization) \ + X(L2Normalization) \ + X(LogicalBinary) \ + X(LogSoftmax) \ + X(Lstm) \ + X(QLstm) \ + X(Map) \ + X(Maximum) \ + X(Mean) \ + X(MemCopy) \ + X(MemImport) \ + X(Merge) \ + X(Minimum) \ + X(Multiplication) \ + X(Normalization) \ + X(Output) \ + X(Pad) \ + X(Permute) \ + X(Pooling2d) \ + X(PreCompiled) \ + X(Prelu) \ + X(Quantize) \ + X(QuantizedLstm) \ + X(Reshape) \ + X(Rank) \ + X(Resize) \ + X(Reduce) \ + X(Slice) \ + X(Softmax) \ + X(SpaceToBatchNd) \ + X(SpaceToDepth) \ + X(Splitter) \ + X(Stack) \ + X(StandIn) \ + X(StridedSlice) \ + X(Subtraction) \ + X(Switch) \ + X(Transpose) \ + X(TransposeConvolution2d) \ + X(Unmap) + +/// When adding a new layer, adapt also the LastLayer enum value in the +/// enum class LayerType below +enum class LayerType +{ +#define X(name) name, + LIST_OF_LAYER_TYPE +#undef X + FirstLayer = Activation, + LastLayer = Unmap +}; + +const char* GetLayerTypeAsCString(LayerType type); + } // namespace armnn |