From 5306dc893bbd6a203744e11c242b9811c8cf1d0c Mon Sep 17 00:00:00 2001 From: Teresa Charlin Date: Mon, 30 Oct 2023 22:29:58 +0000 Subject: IVGCVSW-7889 Add support for Signed64 data type in Cast layer * Remove mention of "isDepthwise" variable name when not needed and therefore IgnoreUnused call * Improve error messages and change them to throws in Encoder and Decoder Signed-off-by: Teresa Charlin Change-Id: I8ce30b5075e1e47d54abc12390265ba8e9ee1405 --- src/backends/reference/RefLayerSupport.cpp | 5 +- .../reference/test/RefPerAxisIteratorTests.cpp | 2 + src/backends/reference/workloads/ArgMinMax.cpp | 1 + src/backends/reference/workloads/BaseIterator.hpp | 111 +++++++++++---------- src/backends/reference/workloads/Decoders.hpp | 26 ++++- .../reference/workloads/DetectionPostProcess.cpp | 1 + src/backends/reference/workloads/Encoders.hpp | 26 ++++- 7 files changed, 110 insertions(+), 62 deletions(-) diff --git a/src/backends/reference/RefLayerSupport.cpp b/src/backends/reference/RefLayerSupport.cpp index 167639a733..2be227ae8f 100644 --- a/src/backends/reference/RefLayerSupport.cpp +++ b/src/backends/reference/RefLayerSupport.cpp @@ -847,7 +847,7 @@ bool RefLayerSupport::IsCastSupported(const TensorInfo& input, const TensorInfo& output, Optional reasonIfUnsupported) const { - std::array supportedInputTypes = + std::array supportedInputTypes = { DataType::Float32, DataType::Float16, @@ -855,7 +855,8 @@ bool RefLayerSupport::IsCastSupported(const TensorInfo& input, DataType::QAsymmS8, DataType::QAsymmU8, DataType::QSymmS16, - DataType::Signed32 + DataType::Signed32, + DataType::Signed64 }; bool supported = true; diff --git a/src/backends/reference/test/RefPerAxisIteratorTests.cpp b/src/backends/reference/test/RefPerAxisIteratorTests.cpp index 92b828e067..d437f4da77 100644 --- a/src/backends/reference/test/RefPerAxisIteratorTests.cpp +++ b/src/backends/reference/test/RefPerAxisIteratorTests.cpp @@ -5,6 +5,8 @@ #include +#include + #include #include diff --git a/src/backends/reference/workloads/ArgMinMax.cpp b/src/backends/reference/workloads/ArgMinMax.cpp index 3bf2853a20..abc0512021 100644 --- a/src/backends/reference/workloads/ArgMinMax.cpp +++ b/src/backends/reference/workloads/ArgMinMax.cpp @@ -7,6 +7,7 @@ #include +#include #include namespace armnn diff --git a/src/backends/reference/workloads/BaseIterator.hpp b/src/backends/reference/workloads/BaseIterator.hpp index 1665c1ff46..694c22913c 100644 --- a/src/backends/reference/workloads/BaseIterator.hpp +++ b/src/backends/reference/workloads/BaseIterator.hpp @@ -7,7 +7,6 @@ #include #include -#include #include #include #include @@ -45,9 +44,7 @@ public: virtual IType Get() const = 0; - virtual std::vector - DecodeTensor(const TensorShape &tensorShape, - bool isDepthwise = false) = 0; + virtual std::vector DecodeTensor(const TensorShape &tensorShape, bool isDepthwise = false) = 0; }; template @@ -125,11 +122,8 @@ public: { return armnn::Dequantize(*m_Iterator, m_Scale, m_Offset); } - std::vector DecodeTensor (const TensorShape& tensorShape, - const bool isDepthwise) override + std::vector DecodeTensor (const TensorShape& tensorShape, const bool) override { - IgnoreUnused(isDepthwise); - const unsigned int size = tensorShape.GetNumElements(); std::vector decodedTensor; decodedTensor.reserve(size); @@ -162,11 +156,8 @@ public: { return armnn::Dequantize(*m_Iterator, m_Scale, m_Offset); } - std::vector DecodeTensor (const TensorShape& tensorShape, - const bool isDepthwise) override + std::vector DecodeTensor (const TensorShape& tensorShape, const bool) override { - IgnoreUnused(isDepthwise); - const unsigned int size = tensorShape.GetNumElements(); std::vector decodedTensor; decodedTensor.reserve(size); @@ -199,11 +190,8 @@ public: { return armnn::Dequantize(*m_Iterator, m_Scale, m_Offset); } - std::vector DecodeTensor (const TensorShape& tensorShape, - const bool isDepthwise) override + std::vector DecodeTensor (const TensorShape& tensorShape, const bool) override { - IgnoreUnused(isDepthwise); - const unsigned int size = tensorShape.GetNumElements(); std::vector decodedTensor; decodedTensor.reserve(size); @@ -236,11 +224,8 @@ public: { return armnn::Dequantize(*m_Iterator, m_Scale, m_Offset); } - std::vector DecodeTensor (const TensorShape& tensorShape, - const bool isDepthwise) override + std::vector DecodeTensor (const TensorShape& tensorShape, const bool) override { - IgnoreUnused(isDepthwise); - const unsigned int size = tensorShape.GetNumElements(); std::vector decodedTensor; decodedTensor.reserve(size); @@ -275,11 +260,8 @@ public: armnnUtils::FloatingPointConverter::ConvertFloat16To32(m_Iterator, 1, &val); return val; } - std::vector DecodeTensor (const TensorShape& tensorShape, - const bool isDepthwise) override + std::vector DecodeTensor (const TensorShape& tensorShape, const bool ) override { - IgnoreUnused(isDepthwise); - const unsigned int size = tensorShape.GetNumElements(); std::vector decodedTensor; decodedTensor.reserve(size); @@ -311,10 +293,8 @@ public: { return *m_Iterator; } - std::vector DecodeTensor (const TensorShape& tensorShape, - const bool isDepthwise) override + std::vector DecodeTensor (const TensorShape& tensorShape, const bool) override { - IgnoreUnused(isDepthwise); const unsigned int size = tensorShape.GetNumElements(); std::vector decodedTensor; @@ -338,11 +318,8 @@ public: { return static_cast(*m_Iterator) * m_Scale; } - std::vector DecodeTensor (const TensorShape& tensorShape, - const bool isDepthwise) override + std::vector DecodeTensor (const TensorShape& tensorShape, const bool) override { - IgnoreUnused(isDepthwise); - const unsigned int size = tensorShape.GetNumElements(); std::vector decodedTensor; decodedTensor.reserve(size); @@ -374,11 +351,8 @@ public: { return static_cast(*m_Iterator); } - std::vector DecodeTensor (const TensorShape& tensorShape, - const bool isDepthwise) override + std::vector DecodeTensor (const TensorShape& tensorShape, const bool) override { - IgnoreUnused(isDepthwise); - const unsigned int size = tensorShape.GetNumElements(); std::vector decodedTensor; decodedTensor.reserve(size); @@ -406,11 +380,37 @@ public: { return *m_Iterator; } - std::vector DecodeTensor (const TensorShape& tensorShape, - const bool isDepthwise) override + std::vector DecodeTensor (const TensorShape& tensorShape, const bool) override { - IgnoreUnused(isDepthwise); + const unsigned int size = tensorShape.GetNumElements(); + std::vector decodedTensor; + decodedTensor.reserve(size); + for (uint32_t i = 0; i < size; ++i) + { + this->operator[](i); + decodedTensor.emplace_back(static_cast(*m_Iterator)); + } + + return decodedTensor; + } +}; + +class Int64Decoder : public TypedIterator> +{ +public: + Int64Decoder(const int64_t* data) + : TypedIterator(data) {} + + Int64Decoder() + : Int64Decoder(nullptr) {} + + double_t Get() const override + { + return static_cast(*m_Iterator); + } + std::vector DecodeTensor (const TensorShape& tensorShape, const bool) override + { const unsigned int size = tensorShape.GetNumElements(); std::vector decodedTensor; decodedTensor.reserve(size); @@ -438,11 +438,8 @@ public: { return *m_Iterator; } - std::vector DecodeTensor (const TensorShape& tensorShape, - const bool isDepthwise) override + std::vector DecodeTensor (const TensorShape& tensorShape, const bool) override { - IgnoreUnused(isDepthwise); - const unsigned int size = tensorShape.GetNumElements(); std::vector decodedTensor; decodedTensor.reserve(size); @@ -471,11 +468,8 @@ public: return *m_Iterator; } - std::vector DecodeTensor(const TensorShape& tensorShape, - const bool isDepthwise) override + std::vector DecodeTensor(const TensorShape& tensorShape, const bool) override { - IgnoreUnused(isDepthwise); - const unsigned int size = tensorShape.GetNumElements(); std::vector decodedTensor; decodedTensor.reserve(size); @@ -668,6 +662,26 @@ public: } }; +class Int64Encoder : public TypedIterator> +{ +public: + Int64Encoder(int64_t* data) + : TypedIterator(data) {} + + Int64Encoder() + : Int64Encoder(nullptr) {} + + void Set(double right) override + { + *m_Iterator = static_cast(right); + } + + double_t Get() const override + { + return static_cast(*m_Iterator); + } +}; + class BooleanEncoder : public TypedIterator> { public: @@ -797,11 +811,8 @@ public: return m_Scales[m_AxisIndex]; } - std::vector DecodeTensor(const TensorShape &tensorShape, - bool isDepthwise) override + std::vector DecodeTensor(const TensorShape &tensorShape, const bool) override { - IgnoreUnused(isDepthwise); - const unsigned int size = tensorShape.GetNumElements(); std::vector decodedTensor; decodedTensor.reserve(size); diff --git a/src/backends/reference/workloads/Decoders.hpp b/src/backends/reference/workloads/Decoders.hpp index 54e7008d50..3bf3db7967 100644 --- a/src/backends/reference/workloads/Decoders.hpp +++ b/src/backends/reference/workloads/Decoders.hpp @@ -10,8 +10,6 @@ #include #include -#include - namespace armnn { @@ -121,7 +119,25 @@ inline std::unique_ptr> MakeDecoder(const TensorInfo& info, const } default: { - ARMNN_ASSERT_MSG(false, "Unsupported Data Type!"); + throw InvalidArgumentException("Unsupported target Data Type!"); + break; + } + } + return nullptr; +} + +template<> +inline std::unique_ptr> MakeDecoder(const TensorInfo& info, const void* data) +{ + switch(info.GetDataType()) + { + case DataType::Signed64: + { + return std::make_unique(static_cast(data)); + } + default: + { + throw InvalidArgumentException("Cannot decode to double. Unsupported origin Data Type!"); break; } } @@ -139,7 +155,7 @@ inline std::unique_ptr> MakeDecoder(const TensorInfo& info, const } default: { - ARMNN_ASSERT_MSG(false, "Unsupported Data Type!"); + throw InvalidArgumentException("Cannot decode to bool. Unsupported origin Data Type!"); break; } } @@ -157,7 +173,7 @@ inline std::unique_ptr> MakeDecoder(const TensorInfo& info, con } default: { - ARMNN_ASSERT_MSG(false, "Unsupported Data Type!"); + throw InvalidArgumentException("Cannot decode to int32. Unsupported origin Data Type!"); break; } } diff --git a/src/backends/reference/workloads/DetectionPostProcess.cpp b/src/backends/reference/workloads/DetectionPostProcess.cpp index 2108efe8f3..c5ab327f90 100644 --- a/src/backends/reference/workloads/DetectionPostProcess.cpp +++ b/src/backends/reference/workloads/DetectionPostProcess.cpp @@ -6,6 +6,7 @@ #include "DetectionPostProcess.hpp" #include +#include #include #include diff --git a/src/backends/reference/workloads/Encoders.hpp b/src/backends/reference/workloads/Encoders.hpp index 8a702377b2..5de361590a 100644 --- a/src/backends/reference/workloads/Encoders.hpp +++ b/src/backends/reference/workloads/Encoders.hpp @@ -9,8 +9,6 @@ #include -#include - namespace armnn { @@ -89,7 +87,25 @@ inline std::unique_ptr> MakeEncoder(const TensorInfo& info, void* } default: { - ARMNN_ASSERT_MSG(false, "Unsupported target Data Type!"); + throw InvalidArgumentException("Unsupported target Data Type!"); + break; + } + } + return nullptr; +} + +template<> +inline std::unique_ptr> MakeEncoder(const TensorInfo& info, void* data) +{ + switch(info.GetDataType()) + { + case armnn::DataType::Signed64: + { + return std::make_unique(static_cast(data)); + } + default: + { + throw InvalidArgumentException("Cannot encode from double. Unsupported target Data Type!"); break; } } @@ -107,7 +123,7 @@ inline std::unique_ptr> MakeEncoder(const TensorInfo& info, void* } default: { - ARMNN_ASSERT_MSG(false, "Cannot encode from boolean. Not supported target Data Type!"); + throw InvalidArgumentException("Cannot encode from boolean. Unsupported target Data Type!"); break; } } @@ -125,7 +141,7 @@ inline std::unique_ptr> MakeEncoder(const TensorInfo& info, voi } default: { - ARMNN_ASSERT_MSG(false, "Unsupported Data Type!"); + throw InvalidArgumentException("Cannot encode from int32. Unsupported Data Type!"); break; } } -- cgit v1.2.1