From 7b885b3cce70154596b1994b013ea91527117c26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tam=C3=A1s=20Ny=C3=ADri?= Date: Tue, 26 Oct 2021 14:47:57 +0100 Subject: IVGCVSW-6509 Front End + Reference Workload implementation Subtask of story: IVGCVSW-6164 Add a Pooling3d FrontEnd and Ref Implementation * Add front end * Add reference workload * Add corresponding unit tests Change-Id: Icce4146dd0a06a1da46a2def00a82d343e171750 Signed-off-by: Tamas Nyiri --- include/armnn/BackendHelper.hpp | 5 +++ include/armnn/Descriptors.hpp | 76 ++++++++++++++++++++++++++++++++ include/armnn/DescriptorsFwd.hpp | 1 + include/armnn/ILayerVisitor.hpp | 8 ++++ include/armnn/INetwork.hpp | 9 +++- include/armnn/Types.hpp | 1 + include/armnn/backends/ILayerSupport.hpp | 5 +++ include/armnnUtils/TensorUtils.hpp | 8 ++++ 8 files changed, 112 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/armnn/BackendHelper.hpp b/include/armnn/BackendHelper.hpp index 03731ac24a..0c625a6062 100644 --- a/include/armnn/BackendHelper.hpp +++ b/include/armnn/BackendHelper.hpp @@ -282,6 +282,11 @@ public: const Pooling2dDescriptor& descriptor, Optional reasonIfUnsupported = EmptyOptional()); + bool IsPooling3dSupported(const TensorInfo& input, + const TensorInfo& output, + const Pooling3dDescriptor& descriptor, + Optional reasonIfUnsupported = EmptyOptional()); + bool IsPreCompiledSupported(const TensorInfo& input, const PreCompiledDescriptor& descriptor, Optional reasonIfUnsupported = EmptyOptional()); diff --git a/include/armnn/Descriptors.hpp b/include/armnn/Descriptors.hpp index a8ad12ff8f..342d952277 100644 --- a/include/armnn/Descriptors.hpp +++ b/include/armnn/Descriptors.hpp @@ -377,6 +377,82 @@ struct Pooling2dDescriptor : BaseDescriptor DataLayout m_DataLayout; }; +/// A Pooling3dDescriptor for the Pooling3dLayer. +struct Pooling3dDescriptor : BaseDescriptor +{ + Pooling3dDescriptor() + : m_PoolType(PoolingAlgorithm::Max) + , m_PadLeft(0) + , m_PadRight(0) + , m_PadTop(0) + , m_PadBottom(0) + , m_PadFront(0) + , m_PadBack(0) + , m_PoolWidth(0) + , m_PoolHeight(0) + , m_PoolDepth(0) + , m_StrideX(0) + , m_StrideY(0) + , m_StrideZ(0) + , m_OutputShapeRounding(OutputShapeRounding::Floor) + , m_PaddingMethod(PaddingMethod::Exclude) + , m_DataLayout(DataLayout::NCDHW) + {} + + bool operator ==(const Pooling3dDescriptor& rhs) const + { + return m_PoolType == rhs.m_PoolType && + m_PadLeft == rhs.m_PadLeft && + m_PadRight == rhs.m_PadRight && + m_PadTop == rhs.m_PadTop && + m_PadBottom == rhs.m_PadBottom && + m_PadFront == rhs.m_PadFront && + m_PadBack == rhs.m_PadBack && + m_PoolWidth == rhs.m_PoolWidth && + m_PoolHeight == rhs.m_PoolHeight && + m_PoolDepth == rhs.m_PoolDepth && + m_StrideX == rhs.m_StrideX && + m_StrideY == rhs.m_StrideY && + m_StrideZ == rhs.m_StrideZ && + m_OutputShapeRounding == rhs.m_OutputShapeRounding && + m_PaddingMethod == rhs.m_PaddingMethod && + m_DataLayout == rhs.m_DataLayout; + } + + /// The pooling algorithm to use (Max. Average, L2). + PoolingAlgorithm m_PoolType; + /// Padding left value in the width dimension. + uint32_t m_PadLeft; + /// Padding right value in the width dimension. + uint32_t m_PadRight; + /// Padding top value in the height dimension. + uint32_t m_PadTop; + /// Padding bottom value in the height dimension. + uint32_t m_PadBottom; + /// Padding front value in the depth dimension. + uint32_t m_PadFront; + /// Padding back value in the depth dimension. + uint32_t m_PadBack; + /// Pooling width value. + uint32_t m_PoolWidth; + /// Pooling height value. + uint32_t m_PoolHeight; + /// Pooling depth value. + uint32_t m_PoolDepth; + /// Stride value when proceeding through input for the width dimension. + uint32_t m_StrideX; + /// Stride value when proceeding through input for the height dimension. + uint32_t m_StrideY; + /// Stride value when proceeding through input for the depth dimension. + uint32_t m_StrideZ; + /// The rounding method for the output shape. (Floor, Ceiling). + OutputShapeRounding m_OutputShapeRounding; + /// The padding method to be used. (Exclude, IgnoreValue). + PaddingMethod m_PaddingMethod; + /// The data layout to be used (NCDHW, NDHWC). + DataLayout m_DataLayout; +}; + /// A FullyConnectedDescriptor for the FullyConnectedLayer. struct FullyConnectedDescriptor : BaseDescriptor { diff --git a/include/armnn/DescriptorsFwd.hpp b/include/armnn/DescriptorsFwd.hpp index 5c4615d6bb..ab6c7d235a 100644 --- a/include/armnn/DescriptorsFwd.hpp +++ b/include/armnn/DescriptorsFwd.hpp @@ -34,6 +34,7 @@ struct OriginsDescriptor; struct PadDescriptor; struct PermuteDescriptor; struct Pooling2dDescriptor; +struct Pooling3dDescriptor; struct PreCompiledDescriptor; struct QLstmDescriptor; struct ReshapeDescriptor; diff --git a/include/armnn/ILayerVisitor.hpp b/include/armnn/ILayerVisitor.hpp index a57db3ce18..3961ae347a 100644 --- a/include/armnn/ILayerVisitor.hpp +++ b/include/armnn/ILayerVisitor.hpp @@ -338,6 +338,14 @@ public: const Pooling2dDescriptor& pooling2dDescriptor, 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 pooling3dDescriptor - Pooling3dDescriptor to configure the pooling. + /// @param name - Optional name for the layer. + virtual void VisitPooling3dLayer(const IConnectableLayer* layer, + const Pooling3dDescriptor& pooling3dDescriptor, + const char* name = nullptr) = 0; + /// Function that a PReLU 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 name - Optional name for the layer. diff --git a/include/armnn/INetwork.hpp b/include/armnn/INetwork.hpp index a79afead95..a4b37f37eb 100644 --- a/include/armnn/INetwork.hpp +++ b/include/armnn/INetwork.hpp @@ -371,13 +371,20 @@ public: IConnectableLayer* AddBatchToSpaceNdLayer(const BatchToSpaceNdDescriptor& batchToSpaceNdDescriptor, const char* name = nullptr); - /// Adds a pooling layer to the network. + /// Adds a 2D pooling layer to the network. /// @param pooling2dDescriptor - Pooling2dDescriptor to configure the pooling. /// @param name - Optional name for the layer. /// @return - Interface for configuring the layer. IConnectableLayer* AddPooling2dLayer(const Pooling2dDescriptor& pooling2dDescriptor, const char* name = nullptr); + /// Adds a 3D pooling layer to the network. + /// @param pooling3dDescriptor - Pooling3dDescriptor to configure the pooling. + /// @param name - Optional name for the layer. + /// @return - Interface for configuring the layer. + IConnectableLayer* AddPooling3dLayer(const Pooling3dDescriptor& pooling3dDescriptor, + const char* name = nullptr); + /// Adds an activation layer to the network. /// @param activationDescriptor - ActivationDescriptor to configure the activation. /// @param name - Optional name for the layer. diff --git a/include/armnn/Types.hpp b/include/armnn/Types.hpp index 72c59d9daa..b5a4266e36 100644 --- a/include/armnn/Types.hpp +++ b/include/armnn/Types.hpp @@ -435,6 +435,7 @@ using InferenceTimingPair = std::pair; X(UnidirectionalSequenceLstm) \ X(ChannelShuffle) \ X(Convolution3d) \ + X(Pooling3d) \ // New layers should be added at last to minimize instability. diff --git a/include/armnn/backends/ILayerSupport.hpp b/include/armnn/backends/ILayerSupport.hpp index 2fbb081fbf..519a006416 100644 --- a/include/armnn/backends/ILayerSupport.hpp +++ b/include/armnn/backends/ILayerSupport.hpp @@ -281,6 +281,11 @@ public: const Pooling2dDescriptor& descriptor, Optional reasonIfUnsupported = EmptyOptional()) const = 0; + virtual bool IsPooling3dSupported(const TensorInfo& input, + const TensorInfo& output, + const Pooling3dDescriptor& descriptor, + Optional reasonIfUnsupported = EmptyOptional()) const = 0; + virtual bool IsPreCompiledSupported(const TensorInfo& input, const PreCompiledDescriptor& descriptor, Optional reasonIfUnsupported = EmptyOptional()) const = 0; diff --git a/include/armnnUtils/TensorUtils.hpp b/include/armnnUtils/TensorUtils.hpp index cc5f780f10..6a975255c6 100644 --- a/include/armnnUtils/TensorUtils.hpp +++ b/include/armnnUtils/TensorUtils.hpp @@ -22,6 +22,14 @@ armnn::TensorInfo GetTensorInfo(unsigned int numberOfBatches, const armnn::DataLayout dataLayout, const armnn::DataType dataType); +armnn::TensorInfo GetTensorInfo(unsigned int numberOfBatches, + unsigned int numberOfChannels, + unsigned int depth, + unsigned int height, + unsigned int width, + const armnn::DataLayout dataLayout, + const armnn::DataType dataType); + std::pair FindMinMax(armnn::ITensorHandle* tensorHandle); armnn::TensorShape ExpandDims(const armnn::TensorShape& tensorShape, int axis); -- cgit v1.2.1