diff options
Diffstat (limited to 'src/backends/tosaCommon/test/OneToOneMappingTests.cpp')
-rw-r--r-- | src/backends/tosaCommon/test/OneToOneMappingTests.cpp | 142 |
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); |