IVGCVSW-7204 Add TransposeConv2d support to TOSA Reference Backend

Signed-off-by: Matthew Sloyan <matthew.sloyan@arm.com>
Change-Id: I9bfd597afd41468f304edfbe5d7141378ce60d4f
diff --git a/src/backends/tosaReference/TosaRefLayerSupport.cpp b/src/backends/tosaReference/TosaRefLayerSupport.cpp
index 928a19c..e5427eb 100644
--- a/src/backends/tosaReference/TosaRefLayerSupport.cpp
+++ b/src/backends/tosaReference/TosaRefLayerSupport.cpp
@@ -66,6 +66,19 @@
             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<const TransposeConvolution2dDescriptor*>(&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 2f12310..00c0386 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 <doctest/doctest.h>
 
@@ -108,4 +109,17 @@
     SliceEndToEndFloat16<DataType::Float16>(tosaDefaultBackends);
 }
 
+// TransposeConvolution2d
+TEST_CASE("TosaRefTransposeConvolution2dEndToEndFloatNhwcTest")
+{
+    TransposeConvolution2dEndToEnd<armnn::DataType::Float32, armnn::DataType::Float32>(
+        tosaDefaultBackends, armnn::DataLayout::NHWC);
+}
+
+TEST_CASE("TosaRefSimpleTransposeConvolution2dEndToEndFloatNhwcTest")
+{
+    SimpleTransposeConvolution2dEndToEnd<armnn::DataType::Float32, armnn::DataType::Float32>(
+        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 0d0cd6e..3c3abc2 100644
--- a/src/backends/tosaReference/test/TosaRefLayerSupportTests.cpp
+++ b/src/backends/tosaReference/test/TosaRefLayerSupportTests.cpp
@@ -105,7 +105,7 @@
 
     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 @@
 
     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 @@
     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 @@
     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);
+}
+
 }