From d7fca093be53b314e100e15a8fa080cb506b60a3 Mon Sep 17 00:00:00 2001 From: David Monahan Date: Thu, 12 Jan 2023 14:53:34 +0000 Subject: IVGCVSW-7173 Add Rsqrt to Tosa Ref Backend * Added ElementwiseUnary support with a mapping for Rsqrt * Added unittests * Added Rsqrt EndtoEnd tests for all backends * Changed TosaRefLayerSupport to default to false on unsupported layers Signed-off-by: David Monahan Change-Id: I3eaa9c684647ead61520a563815581aa68bee51b --- src/backends/tosaReference/TosaRefLayerSupport.cpp | 6 ++-- .../tosaReference/test/TosaRefEndToEndTests.cpp | 9 ++++- .../test/TosaRefLayerSupportTests.cpp | 42 +++++++++++++++++++++- 3 files changed, 53 insertions(+), 4 deletions(-) (limited to 'src/backends/tosaReference') diff --git a/src/backends/tosaReference/TosaRefLayerSupport.cpp b/src/backends/tosaReference/TosaRefLayerSupport.cpp index 6113b5861a..238801cb98 100644 --- a/src/backends/tosaReference/TosaRefLayerSupport.cpp +++ b/src/backends/tosaReference/TosaRefLayerSupport.cpp @@ -1,5 +1,5 @@ // -// Copyright © 2022 Arm Ltd and Contributors. All rights reserved. +// Copyright © 2022-2023 Arm Ltd and Contributors. All rights reserved. // SPDX-License-Identifier: MIT // @@ -68,6 +68,7 @@ bool TosaRefLayerSupport::IsLayerSupported(const LayerType& type, } break; } + case LayerType::ElementwiseUnary: case LayerType::Pooling2d: case LayerType::Reshape: case LayerType::Slice: @@ -89,7 +90,8 @@ bool TosaRefLayerSupport::IsLayerSupported(const LayerType& type, break; } default: - break; + // Default to false for all unsupported layers. + return false; } auto mappings = GetTosaMapping(nullptr, type, inputInfos, outputInfos, descriptor); diff --git a/src/backends/tosaReference/test/TosaRefEndToEndTests.cpp b/src/backends/tosaReference/test/TosaRefEndToEndTests.cpp index e19462e986..26cadd22db 100644 --- a/src/backends/tosaReference/test/TosaRefEndToEndTests.cpp +++ b/src/backends/tosaReference/test/TosaRefEndToEndTests.cpp @@ -1,5 +1,5 @@ // -// Copyright © 2022 Arm Ltd and Contributors. All rights reserved. +// Copyright © 2022-2023 Arm Ltd and Contributors. All rights reserved. // SPDX-License-Identifier: MIT // @@ -11,6 +11,7 @@ #include "backendsCommon/test/MultiplicationEndToEndTestImpl.hpp" #include "backendsCommon/test/Pooling2dEndToEndTestImpl.hpp" #include "backendsCommon/test/ReshapeEndToEndTestImpl.hpp" +#include "backendsCommon/test/ElementwiseUnaryEndToEndTestImpl.hpp" #include "backendsCommon/test/SliceEndToEndTestImpl.hpp" #include "backendsCommon/test/SubtractionEndToEndTestImpl.hpp" #include "backendsCommon/test/TransposeConvolution2dEndToEndTestImpl.hpp" @@ -138,6 +139,12 @@ TEST_CASE("TosaRefReshapeEndtoEndTestFloat16") ReshapeEndToEndFloat16(tosaDefaultBackends); } +TEST_CASE("TosaRefRsqrtEndtoEndTestFloat32") +{ + ElementwiseUnarySimpleEndToEnd(tosaDefaultBackends, + UnaryOperation::Rsqrt); +} + // Slice TEST_CASE("TosaRefSliceEndtoEndTestFloat32") { diff --git a/src/backends/tosaReference/test/TosaRefLayerSupportTests.cpp b/src/backends/tosaReference/test/TosaRefLayerSupportTests.cpp index 66dfbe8dff..e32894f0b6 100644 --- a/src/backends/tosaReference/test/TosaRefLayerSupportTests.cpp +++ b/src/backends/tosaReference/test/TosaRefLayerSupportTests.cpp @@ -1,5 +1,5 @@ // -// Copyright © 2022 Arm Ltd and Contributors. All rights reserved. +// Copyright © 2022-2023 Arm Ltd and Contributors. All rights reserved. // SPDX-License-Identifier: MIT // @@ -374,6 +374,46 @@ TEST_CASE("IsLayerSupportedTosaReferenceReshapeUnsupported") CHECK(!supported); } +TEST_CASE("IsLayerSupportedTosaReferenceRsqrt") +{ + TensorShape shape0 = {2,2}; + TensorShape outShape = {2,2}; + TensorInfo in0(shape0, DataType::Float32); + TensorInfo out(outShape, DataType::Float32); + + ElementwiseUnaryDescriptor desc(UnaryOperation::Rsqrt); + TosaRefLayerSupport supportChecker; + std::string reasonIfNotSupported; + auto supported = supportChecker.IsLayerSupported(LayerType::ElementwiseUnary, + {in0, out}, + desc, + EmptyOptional(), + EmptyOptional(), + reasonIfNotSupported); + + CHECK(supported); +} + +TEST_CASE("IsLayerSupportedTosaReferenceRsqrtUnsupported") +{ + TensorShape shape0 = {1,1,3,4}; + TensorShape outShape = {1,3,1,4}; + TensorInfo in0(shape0, DataType::Signed64); + TensorInfo out(outShape, DataType::Signed64); + + ElementwiseUnaryDescriptor desc(UnaryOperation::Rsqrt); + TosaRefLayerSupport supportChecker; + std::string reasonIfNotSupported; + auto supported = supportChecker.IsLayerSupported(LayerType::ElementwiseUnary, + {in0, out}, + desc, + EmptyOptional(), + EmptyOptional(), + reasonIfNotSupported); + + CHECK(!supported); +} + TEST_CASE("IsLayerSupportedTosaReferenceSlice") { TensorShape inShape = {3,2,3}; -- cgit v1.2.1