aboutsummaryrefslogtreecommitdiff
path: root/src/backends/tosaCommon/test/OneToOneMappingTests.cpp
diff options
context:
space:
mode:
authorTeresa Charlin <teresa.charlinreyes@arm.com>2023-11-21 15:44:13 +0000
committerTeresaARM <teresa.charlinreyes@arm.com>2023-12-13 14:33:54 +0000
commitce65588484ed1e553bdebf24123a30b5575f1bce (patch)
treeba5229241cdeee6d9c6ed0c0db9ffbd510574b34 /src/backends/tosaCommon/test/OneToOneMappingTests.cpp
parent1685bcca5dae227d90be62b36d66e9897298ce84 (diff)
downloadarmnn-ce65588484ed1e553bdebf24123a30b5575f1bce.tar.gz
Add Resize Nearest Neighbour support to TOSA Reference Backend
* Add support for quantized data in TosaRefPreCompiledWorkloadGetOutput. * Remove extra includes from all TOSA operators headers. * Added positive and negative unit tests for resize. * Resolves: IVGCVSW-7346 Signed-off-by: Teresa Charlin <teresa.charlinreyes@arm.com> Change-Id: Ib6e30d018a7a1bf26b380fc794560aae108b26c3
Diffstat (limited to 'src/backends/tosaCommon/test/OneToOneMappingTests.cpp')
-rw-r--r--src/backends/tosaCommon/test/OneToOneMappingTests.cpp142
1 files changed, 142 insertions, 0 deletions
diff --git a/src/backends/tosaCommon/test/OneToOneMappingTests.cpp b/src/backends/tosaCommon/test/OneToOneMappingTests.cpp
index 0cf8002cd1..267c9fb49d 100644
--- a/src/backends/tosaCommon/test/OneToOneMappingTests.cpp
+++ b/src/backends/tosaCommon/test/OneToOneMappingTests.cpp
@@ -553,6 +553,148 @@ TEST_CASE("GetTosaMappingFromLayer_ReshapeLayer")
LayerType::Reshape);
}
+
+TEST_CASE("GetTosaMapping_ResizeLayer")
+{
+ TensorInfo inputInfo = TensorInfo({ 1, 2, 3, 3 }, DataType::Float32);
+ TensorInfo outputInfo = TensorInfo({ 1, 4, 6, 3 }, DataType::Float32);
+
+ std::vector<std::vector<int32_t>> inputShape = {{ 1, 2, 3, 3 }};
+ std::vector<std::vector<int32_t>> outputShape = {{ 1, 4, 6, 3 }};
+
+ ResizeDescriptor descriptor;
+ descriptor.m_DataLayout = DataLayout::NHWC;
+ descriptor.m_TargetHeight = 4;
+ descriptor.m_TargetWidth = 6;
+
+ TosaSerializationBasicBlock* basicBlock = GetTosaMapping(nullptr,
+ LayerType::Resize,
+ {&inputInfo},
+ {&outputInfo},
+ descriptor);
+ AssertTosaOneToOneMappingBasicBlock(basicBlock,
+ inputShape,
+ outputShape,
+ Op_RESIZE,
+ Attribute_ResizeAttribute,
+ descriptor,
+ LayerType::Resize);
+}
+
+TEST_CASE("GetTosaMappingFromLayer_ResizeLayer")
+{
+ IRuntime::CreationOptions options;
+ IRuntimePtr runtime(IRuntime::Create(options));
+
+ // Builds up the structure of the network.
+ INetworkPtr net(INetwork::Create());
+
+ ResizeDescriptor descriptor;
+ descriptor.m_DataLayout = DataLayout::NHWC;
+ descriptor.m_TargetHeight = 2;
+ descriptor.m_TargetWidth = 3;
+
+ IConnectableLayer* input = net->AddInputLayer(0, "input");
+ IConnectableLayer* resize = net->AddResizeLayer(descriptor, "resize");
+ IConnectableLayer* output = net->AddOutputLayer(0, "output");
+
+ input->GetOutputSlot(0).Connect(resize->GetInputSlot(0));
+ resize->GetOutputSlot(0).Connect(output->GetInputSlot(0));
+
+ TensorInfo inputInfo = TensorInfo({ 1, 4, 6, 3 }, DataType::Float32);
+ TensorInfo outputInfo = TensorInfo({ 1, 2, 3, 3 }, DataType::Float32);
+
+ input->GetOutputSlot(0).SetTensorInfo(inputInfo);
+ resize->GetOutputSlot(0).SetTensorInfo(outputInfo);
+
+ std::vector<std::vector<int32_t>> inputShape = {{ 1, 4, 6, 3 }};
+ std::vector<std::vector<int32_t>> outputShape = {{ 1, 2, 3, 3 }};
+
+ TosaSerializationBasicBlock* basicBlock = GetTosaMappingFromLayer(PolymorphicDowncast<Layer*>(resize));
+ AssertTosaOneToOneMappingBasicBlock(basicBlock,
+ inputShape,
+ outputShape,
+ Op_RESIZE,
+ Attribute_ResizeAttribute,
+ descriptor,
+ LayerType::Resize);
+}
+
+TEST_CASE("UNSUPPORTED_GetTosaMapping_ResizeLayer_NCHW")
+{
+ TensorInfo inputInfo = TensorInfo({ 1, 3, 2, 3 }, DataType::Float32);
+ TensorInfo outputInfo = TensorInfo({ 1, 3, 4, 6 }, DataType::Float32);
+
+ std::vector<std::vector<int32_t>> inputShape = {{ 1, 3, 2, 3 }};
+ std::vector<std::vector<int32_t>> outputShape = {{ 1, 3, 4, 6 }};
+
+ ResizeDescriptor descriptor;
+ descriptor.m_DataLayout = DataLayout::NCHW;
+ descriptor.m_TargetHeight = 4;
+ descriptor.m_TargetWidth = 6;
+
+ try
+ {
+ TosaSerializationBasicBlock* basicBlock = GetTosaMapping(nullptr,
+ LayerType::Resize,
+ {&inputInfo},
+ {&outputInfo},
+ descriptor);
+
+ AssertTosaOneToOneMappingBasicBlock(basicBlock,
+ inputShape,
+ outputShape,
+ Op_RESIZE,
+ Attribute_ResizeAttribute,
+ descriptor,
+ LayerType::Resize);
+
+ FAIL("An exception should have been thrown");
+ }
+ catch (const armnn::InvalidArgumentException& e)
+ {
+ CHECK(strcmp(e.what(), "ConvertResizeToTosaOperator: NCHW not supported.") == 0);
+ }
+}
+
+TEST_CASE("UNSUPPORTED_GetTosaMapping_ResizeLayer_Bilinear")
+{
+ TensorInfo inputInfo = TensorInfo({ 1, 2, 3, 3 }, DataType::Float32);
+ TensorInfo outputInfo = TensorInfo({ 1, 4, 6, 3 }, DataType::Float32);
+
+ std::vector<std::vector<int32_t>> inputShape = {{ 1, 2, 3, 3 }};
+ std::vector<std::vector<int32_t>> outputShape = {{ 1, 4, 6, 3 }};
+
+ ResizeDescriptor descriptor;
+ descriptor.m_Method = ResizeMethod::Bilinear;
+ descriptor.m_DataLayout = DataLayout::NHWC;
+ descriptor.m_TargetHeight = 4;
+ descriptor.m_TargetWidth = 6;
+
+ try
+ {
+ TosaSerializationBasicBlock* basicBlock = GetTosaMapping(nullptr,
+ LayerType::Resize,
+ {&inputInfo},
+ {&outputInfo},
+ descriptor);
+
+ AssertTosaOneToOneMappingBasicBlock(basicBlock,
+ inputShape,
+ outputShape,
+ Op_RESIZE,
+ Attribute_ResizeAttribute,
+ descriptor,
+ LayerType::Resize);
+
+ FAIL("An exception should have been thrown");
+ }
+ catch (const armnn::InvalidArgumentException& e)
+ {
+ CHECK(strcmp(e.what(), "ConvertResizeToTosaOperator: Unimplemented Resize method.") == 0);
+ }
+}
+
TEST_CASE("GetTosaMapping_SliceLayer")
{
TensorInfo inputInfo = TensorInfo({ 3, 2, 3 }, DataType::Float32);