From fc9d5e7d1e0c1a4d7fed4ebc363832e03c3e2543 Mon Sep 17 00:00:00 2001 From: Matthew Sloyan Date: Thu, 8 Dec 2022 13:38:23 +0000 Subject: IVGCVSW-7204 Add TransposeConv2d support to TOSA Reference Backend Signed-off-by: Matthew Sloyan Change-Id: I9bfd597afd41468f304edfbe5d7141378ce60d4f --- src/backends/tosaReference/TosaRefLayerSupport.cpp | 13 ++++++ .../tosaReference/test/TosaRefEndToEndTests.cpp | 14 ++++++ .../test/TosaRefLayerSupportTests.cpp | 51 ++++++++++++++++++++-- 3 files changed, 75 insertions(+), 3 deletions(-) (limited to 'src/backends/tosaReference') diff --git a/src/backends/tosaReference/TosaRefLayerSupport.cpp b/src/backends/tosaReference/TosaRefLayerSupport.cpp index 928a19c232..e5427ebc93 100644 --- a/src/backends/tosaReference/TosaRefLayerSupport.cpp +++ b/src/backends/tosaReference/TosaRefLayerSupport.cpp @@ -66,6 +66,19 @@ bool TosaRefLayerSupport::IsLayerSupported(const LayerType& type, inputInfos.push_back(&infos[0]); outputInfos.push_back(&infos[1]); break; + case LayerType::TransposeConvolution2d: + { + inputInfos.push_back(&infos[0]); // input + outputInfos.push_back(&infos[1]); // output + inputInfos.push_back(&infos[2]); // weights + + auto conv2dDesc = PolymorphicDowncast(&descriptor); + if(conv2dDesc->m_BiasEnabled) + { + inputInfos.push_back(&infos[3]); // bias + } + break; + } default: break; } diff --git a/src/backends/tosaReference/test/TosaRefEndToEndTests.cpp b/src/backends/tosaReference/test/TosaRefEndToEndTests.cpp index 2f1231013a..00c0386b51 100644 --- a/src/backends/tosaReference/test/TosaRefEndToEndTests.cpp +++ b/src/backends/tosaReference/test/TosaRefEndToEndTests.cpp @@ -10,6 +10,7 @@ #include "backendsCommon/test/Pooling2dEndToEndTestImpl.hpp" #include "backendsCommon/test/ReshapeEndToEndTestImpl.hpp" #include "backendsCommon/test/SliceEndToEndTestImpl.hpp" +#include "backendsCommon/test/TransposeConvolution2dEndToEndTestImpl.hpp" #include @@ -108,4 +109,17 @@ TEST_CASE("TosaRefSliceEndtoEndTestFloat16") SliceEndToEndFloat16(tosaDefaultBackends); } +// TransposeConvolution2d +TEST_CASE("TosaRefTransposeConvolution2dEndToEndFloatNhwcTest") +{ + TransposeConvolution2dEndToEnd( + tosaDefaultBackends, armnn::DataLayout::NHWC); +} + +TEST_CASE("TosaRefSimpleTransposeConvolution2dEndToEndFloatNhwcTest") +{ + SimpleTransposeConvolution2dEndToEnd( + tosaDefaultBackends, armnn::DataLayout::NHWC); +} + } \ No newline at end of file diff --git a/src/backends/tosaReference/test/TosaRefLayerSupportTests.cpp b/src/backends/tosaReference/test/TosaRefLayerSupportTests.cpp index 0d0cd6eefc..3c3abc2af3 100644 --- a/src/backends/tosaReference/test/TosaRefLayerSupportTests.cpp +++ b/src/backends/tosaReference/test/TosaRefLayerSupportTests.cpp @@ -105,7 +105,7 @@ TEST_CASE("IsLayerSupportedTosaReferenceConv2d") TosaRefLayerSupport supportChecker; std::string reasonIfNotSupported; - auto supported = supportChecker.IsLayerSupported(armnn::LayerType::Convolution2d, + auto supported = supportChecker.IsLayerSupported(LayerType::Convolution2d, {inputInfo, outputInfo, weightsInfo, biasesInfo}, desc, EmptyOptional(), @@ -128,7 +128,7 @@ TEST_CASE("IsLayerSupportedTosaReferenceConv2dUnsupported") TosaRefLayerSupport supportChecker; std::string reasonIfNotSupported; - auto supported = supportChecker.IsLayerSupported(armnn::LayerType::Convolution2d, + auto supported = supportChecker.IsLayerSupported(LayerType::Convolution2d, {inputInfo, outputInfo, weightsInfo, biasesInfo}, desc, EmptyOptional(), @@ -150,7 +150,7 @@ TEST_CASE("IsLayerSupportedTosaReferenceMaxPooling2d") desc.m_PoolWidth = 1; desc.m_StrideX = 1; desc.m_StrideY = 1; - desc.m_PoolType = armnn::PoolingAlgorithm::Max; + desc.m_PoolType = PoolingAlgorithm::Max; TosaRefLayerSupport supportChecker; std::string reasonIfNotSupported; @@ -324,4 +324,49 @@ TEST_CASE("IsLayerSupportedTosaReferenceSliceUnsupported") CHECK(!supported); } +TEST_CASE("IsLayerSupportedTosaReferenceTransposeConv2d") +{ + TensorInfo inputInfo ({ 1, 3, 3, 1 }, DataType::Float32); + TensorInfo outputInfo({ 1, 5, 5, 1 }, DataType::Float32); + TensorInfo weightsInfo({ 1, 3, 3, 1 }, DataType::Float32); + TensorInfo biasesInfo ({ 1 }, DataType::Float32); + + TransposeConvolution2dDescriptor desc; + desc.m_StrideX = 1; + desc.m_StrideY = 1; + desc.m_BiasEnabled = true; + + TosaRefLayerSupport supportChecker; + std::string reasonIfNotSupported; + auto supported = supportChecker.IsLayerSupported(LayerType::TransposeConvolution2d, + {inputInfo, outputInfo, weightsInfo, biasesInfo}, + desc, + EmptyOptional(), + EmptyOptional(), + reasonIfNotSupported); + CHECK(supported); +} + +TEST_CASE("IsLayerSupportedTosaReferenceTransposeConv2dUnsupported") +{ + // If inputs and weights are Fp32, output must match. + TensorInfo inputInfo ({ 1, 3, 3, 1 }, DataType::Float32); + TensorInfo outputInfo({ 1, 5, 5, 1 }, DataType::Float32); + TensorInfo weightsInfo({ 1, 3, 3, 1 }, DataType::Float32, 0.0f, 0, true); + TensorInfo biasesInfo ({ 1 }, DataType::Float32, 0.0f, 0, true); + + TransposeConvolution2dDescriptor desc; + desc.m_BiasEnabled = true; + + TosaRefLayerSupport supportChecker; + std::string reasonIfNotSupported; + auto supported = supportChecker.IsLayerSupported(LayerType::TransposeConvolution2d, + {inputInfo, outputInfo, weightsInfo, biasesInfo}, + desc, + EmptyOptional(), + EmptyOptional(), + reasonIfNotSupported); + CHECK(!supported); +} + } -- cgit v1.2.1