From c9ea45adefdde2890e9aa191a5b31563a3dd35ea Mon Sep 17 00:00:00 2001 From: Mike Kelly Date: Fri, 28 Feb 2020 18:11:58 +0000 Subject: IVGCVSW-4375 Add support for Transpose * Added TransposeLayer * Added CL, Neon and Ref Workloads * Added Transpose utilities * Added Serializer and Deserializer support * Added Quantizer support Signed-off-by: Mike Kelly Change-Id: I04c755ba7cb5b1edf72b3c9f3c0314878032e3c7 --- include/armnn/Descriptors.hpp | 21 +++++++++++++++++++++ include/armnn/DescriptorsFwd.hpp | 1 + include/armnn/ILayerSupport.hpp | 5 +++++ include/armnn/ILayerVisitor.hpp | 8 ++++++++ include/armnn/INetwork.hpp | 8 +++++++- include/armnn/LayerVisitorBase.hpp | 4 ++++ include/armnnUtils/Transpose.hpp | 21 +++++++++++++++++++++ 7 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 include/armnnUtils/Transpose.hpp (limited to 'include') diff --git a/include/armnn/Descriptors.hpp b/include/armnn/Descriptors.hpp index 2d7b17edbb..f1b29cc6c7 100644 --- a/include/armnn/Descriptors.hpp +++ b/include/armnn/Descriptors.hpp @@ -1119,4 +1119,25 @@ struct TransposeConvolution2dDescriptor DataLayout m_DataLayout; }; +/// A TransposeDescriptor for the TransposeLayer. +struct TransposeDescriptor +{ + TransposeDescriptor() + : m_DimMappings{} + {} + + TransposeDescriptor(const PermutationVector& dimMappings) + : m_DimMappings(dimMappings) + {} + + bool operator ==(const TransposeDescriptor &rhs) const + { + return m_DimMappings.IsEqual(rhs.m_DimMappings); + } + + /// @brief Indicates how to translate tensor elements from a given source into the target destination, when + /// source and target potentially have different memory layouts e.g. {0U, 3U, 1U, 2U}. + PermutationVector m_DimMappings; +}; + } // namespace armnn diff --git a/include/armnn/DescriptorsFwd.hpp b/include/armnn/DescriptorsFwd.hpp index d03c61d452..144c1ef7fd 100644 --- a/include/armnn/DescriptorsFwd.hpp +++ b/include/armnn/DescriptorsFwd.hpp @@ -40,6 +40,7 @@ struct StackDescriptor; struct StandInDescriptor; struct StridedSliceDescriptor; struct TransposeConvolution2dDescriptor; +struct TransposeDescriptor; struct ViewsDescriptor; using ConcatDescriptor = OriginsDescriptor; diff --git a/include/armnn/ILayerSupport.hpp b/include/armnn/ILayerSupport.hpp index d1bbf99d5e..af91e87376 100644 --- a/include/armnn/ILayerSupport.hpp +++ b/include/armnn/ILayerSupport.hpp @@ -369,6 +369,11 @@ public: const Optional& biases, Optional reasonIfUnsupported = EmptyOptional()) const = 0; + virtual bool IsTransposeSupported(const TensorInfo& input, + const TensorInfo& output, + const TransposeDescriptor& descriptor, + Optional reasonIfUnsupported = EmptyOptional()) const = 0; + }; // class ILayerSupport using ILayerSupportSharedPtr = std::shared_ptr; diff --git a/include/armnn/ILayerVisitor.hpp b/include/armnn/ILayerVisitor.hpp index 46f9e5698f..972915dc0f 100644 --- a/include/armnn/ILayerVisitor.hpp +++ b/include/armnn/ILayerVisitor.hpp @@ -494,6 +494,14 @@ public: const Optional& biases, const char* name = nullptr) = 0; + /// Function that a transpose 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 transposeDescriptor - TransposeDescriptor to configure the transpose. + /// @param name - Optional name for the layer. + virtual void VisitTransposeLayer(const IConnectableLayer* layer, + const TransposeDescriptor& transposeDescriptor, + const char* name = nullptr) = 0; + virtual void StartVisit() {} virtual void FinishVisit() {} diff --git a/include/armnn/INetwork.hpp b/include/armnn/INetwork.hpp index 1b1c874f8c..71eb9ff802 100644 --- a/include/armnn/INetwork.hpp +++ b/include/armnn/INetwork.hpp @@ -511,6 +511,13 @@ public: const Optional& biases, const char* name = nullptr) = 0; + /// Adds a transpose layer to the network. + /// @param transposeDescriptor - TransposeDescriptor to configure the transpose. + /// @param name - Optional name for the layer. + /// @return - Interface for configuring the layer. + virtual IConnectableLayer* AddTransposeLayer(const TransposeDescriptor& transposeDescriptor, + const char* name = nullptr) = 0; + /// Adds a stack layer to the network. /// @param descriptor - Description of the stack layer. /// @param name - Optional name for the layer. @@ -518,7 +525,6 @@ public: virtual IConnectableLayer* AddStackLayer(const StackDescriptor& descriptor, const char* name = nullptr) = 0; - /// Add a stand-in layer for a type unknown to the Arm NN framework. /// Note: Due to the nature of this layer, no validation can be performed by the framework. /// Furthermore, Any model containing this layer cannot make use of dynamic tensors since the diff --git a/include/armnn/LayerVisitorBase.hpp b/include/armnn/LayerVisitorBase.hpp index 6fd9a66c76..511917cd19 100644 --- a/include/armnn/LayerVisitorBase.hpp +++ b/include/armnn/LayerVisitorBase.hpp @@ -246,6 +246,10 @@ public: const Optional&, const char*) override { DefaultPolicy::Apply(__func__); } + void VisitTransposeLayer(const IConnectableLayer*, + const TransposeDescriptor&, + const char*) override { DefaultPolicy::Apply(__func__); } + }; } // namespace armnn diff --git a/include/armnnUtils/Transpose.hpp b/include/armnnUtils/Transpose.hpp new file mode 100644 index 0000000000..0a1ba7dfc1 --- /dev/null +++ b/include/armnnUtils/Transpose.hpp @@ -0,0 +1,21 @@ +// +// Copyright © 2020 Arm Ltd. All rights reserved. +// SPDX-License-Identifier: MIT +// + +#pragma once + +#include +#include + +namespace armnnUtils +{ + +armnn::TensorShape TransposeTensorShape(const armnn::TensorShape& srcShape, const armnn::PermutationVector& mappings); + +armnn::TensorInfo TransposeTensorShape(const armnn::TensorInfo& info, const armnn::PermutationVector& mappings); + +void Transpose(const armnn::TensorShape& dstShape, const armnn::PermutationVector& mappings, + const void* src, void* dst, size_t dataTypeSize); + +} // namespace armnnUtils -- cgit v1.2.1