From 0ec008761ab26110dcb108d544be4040a14fd403 Mon Sep 17 00:00:00 2001 From: John Mcloughlin Date: Mon, 15 May 2023 17:03:49 +0100 Subject: IVGCVSW-7400 POW IVGCVSW-7278 SQUARED_DIFFERENCE. * Added 2 new operators as ElementWiseBinary ops * Ref End to End and unit tests * Serialize and Deserialize tests * Delegate and Opaque Delegate tests * TfLite Parser tests Signed-off-by: John Mcloughlin Change-Id: I537158127f602f0c41ca0402aa31655cd3bd4281 --- .../test/layerTests/ElementwiseTestImpl.hpp | 67 ++- .../test/layerTests/PowerTestImpl.cpp | 539 +++++++++++++++++++++ .../test/layerTests/PowerTestImpl.hpp | 88 ++++ .../test/layerTests/SquaredDifferenceTestImpl.cpp | 539 +++++++++++++++++++++ .../test/layerTests/SquaredDifferenceTestImpl.hpp | 88 ++++ 5 files changed, 1319 insertions(+), 2 deletions(-) create mode 100644 src/backends/backendsCommon/test/layerTests/PowerTestImpl.cpp create mode 100644 src/backends/backendsCommon/test/layerTests/PowerTestImpl.hpp create mode 100644 src/backends/backendsCommon/test/layerTests/SquaredDifferenceTestImpl.cpp create mode 100644 src/backends/backendsCommon/test/layerTests/SquaredDifferenceTestImpl.hpp (limited to 'src/backends/backendsCommon/test/layerTests') diff --git a/src/backends/backendsCommon/test/layerTests/ElementwiseTestImpl.hpp b/src/backends/backendsCommon/test/layerTests/ElementwiseTestImpl.hpp index da6e11fe3e..ded53cbb76 100644 --- a/src/backends/backendsCommon/test/layerTests/ElementwiseTestImpl.hpp +++ b/src/backends/backendsCommon/test/layerTests/ElementwiseTestImpl.hpp @@ -1,5 +1,5 @@ // -// Copyright © 2017 Arm Ltd and Contributors. All rights reserved. +// Copyright © 2017-2023 Arm Ltd and Contributors. All rights reserved. // SPDX-License-Identifier: MIT // @@ -206,4 +206,67 @@ LayerTestResult ElementwiseTestHelper( tensorHandleFactory, quantScale, quantOffset); -} \ No newline at end of file +} + +// Elementwise Binary Operations +template, + typename TOutput = armnn::ResolveType> +LayerTestResult ElementwiseTestHelper( + armnn::IWorkloadFactory& workloadFactory, + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, + armnn::BinaryOperation op, + const unsigned int shape0[NumDims], + std::vector values0, + const unsigned int shape1[NumDims], + std::vector values1, + const unsigned int outShape[NumDims], + std::vector outValues, + const armnn::ITensorHandleFactory& tensorHandleFactory) { + + armnn::TensorInfo inputTensorInfo0{NumDims, shape0, ArmnnTypeInput}; + armnn::TensorInfo inputTensorInfo1{NumDims, shape1, ArmnnTypeInput}; + armnn::TensorInfo outputTensorInfo{NumDims, outShape, ArmnnTypeOutput}; + + std::vector actualOutput(outputTensorInfo.GetNumElements()); + + bool isBoolean = false; + if (ArmnnTypeOutput == armnn::DataType::Boolean) + { + isBoolean = true; + } + + std::unique_ptr inputHandle0 = tensorHandleFactory.CreateTensorHandle(inputTensorInfo0); + std::unique_ptr inputHandle1 = tensorHandleFactory.CreateTensorHandle(inputTensorInfo1); + std::unique_ptr outputHandle = tensorHandleFactory.CreateTensorHandle(outputTensorInfo); + + armnn::ElementwiseBinaryQueueDescriptor data; + data.m_Parameters.m_Operation = op; + armnn::WorkloadInfo info; + + AddInputToWorkload(data, info, inputTensorInfo0, inputHandle0.get()); + AddInputToWorkload(data, info, inputTensorInfo1, inputHandle1.get()); + AddOutputToWorkload(data, info, outputTensorInfo, outputHandle.get()); + + auto workload = workloadFactory.CreateWorkload(armnn::LayerType::ElementwiseBinary, data, info); + + inputHandle0->Allocate(); + inputHandle1->Allocate(); + outputHandle->Allocate(); + + CopyDataToITensorHandle(inputHandle0.get(), values0.data()); + CopyDataToITensorHandle(inputHandle1.get(), values1.data()); + + workload->PostAllocationConfigure(); + ExecuteWorkload(*workload, memoryManager); + + CopyDataFromITensorHandle(actualOutput.data(), outputHandle.get()); + + return LayerTestResult(actualOutput, + outValues, + outputHandle->GetShape(), + outputTensorInfo.GetShape(), + isBoolean); +} diff --git a/src/backends/backendsCommon/test/layerTests/PowerTestImpl.cpp b/src/backends/backendsCommon/test/layerTests/PowerTestImpl.cpp new file mode 100644 index 0000000000..dd6d569270 --- /dev/null +++ b/src/backends/backendsCommon/test/layerTests/PowerTestImpl.cpp @@ -0,0 +1,539 @@ +// +// Copyright © 2023 Arm Ltd and Contributors. All rights reserved. +// SPDX-License-Identifier: MIT +// + +#include "PowerTestImpl.hpp" + +#include "ElementwiseTestImpl.hpp" + +LayerTestResult PowerTest( + armnn::IWorkloadFactory& workloadFactory, + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, + const armnn::ITensorHandleFactory& tensorHandleFactory) +{ + IgnoreUnused(memoryManager); + unsigned int shape[] = { 2, 2, 2, 2 }; + + std::vector input0 = + { + 7.f, 3.f, 4.f, 2.f, 6.f, 4.f, 2.f, 1.f, + 1.f, 1.f, 0.f, 2.f, 9.f, 3.f, 5.f, 3.f + }; + + std::vector input1 = + { + 2.f, 3.f, 2.f, 1.f, 2.f, 3.f, 4.f, 3.f, + 4.f, 5.f, 3.f, 5.f, 2.f, 3.f, 2.f, 0.f + }; + + std::vector output + { + 49.f, 27.f, 16.f, 2.f, 36.f, 64.f, 16.f, 1.f, + 1.f, 1.f, 0.f, 32.f, 81.f, 27.f, 25.f, 1.f + }; + + return ElementwiseTestHelper<4, armnn::DataType::Float32, armnn::DataType::Float32>( + workloadFactory, + memoryManager, + armnn::BinaryOperation::Power, + shape, + input0, + shape, + input1, + shape, + output, + tensorHandleFactory); +} + +LayerTestResult PowerBroadcast1ElementTest( + armnn::IWorkloadFactory& workloadFactory, + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, + const armnn::ITensorHandleFactory& tensorHandleFactory) +{ + IgnoreUnused(memoryManager); + unsigned int shape0[] = { 1, 2, 2, 2 }; + unsigned int shape1[] = { 1, 1, 1, 1 }; + + std::vector input0 = + { + 1.f, 2.f, 3.f, 4.f, 5.f, 0.f, 2.f, 1.f + }; + + std::vector input1 = { 2.f }; + + std::vector output = + { + 1.f, 4.f, 9.f, 16.f, 25.f, 0.f, 4.f, 1.f + }; + + return ElementwiseTestHelper<4, armnn::DataType::Float32, armnn::DataType::Float32>( + workloadFactory, + memoryManager, + armnn::BinaryOperation::Power, + shape0, + input0, + shape1, + input1, + shape0, + output, + tensorHandleFactory); +} + +LayerTestResult PowerBroadcastTest( + armnn::IWorkloadFactory & workloadFactory, + const armnn::IBackendInternal::IMemoryManagerSharedPtr & memoryManager, + const armnn::ITensorHandleFactory& tensorHandleFactory) +{ + IgnoreUnused(memoryManager); + const unsigned int shape0[] = { 1, 2, 2, 3 }; + const unsigned int shape1[] = { 1, 1, 1, 3 }; + + std::vector input0 = + { + 1.f, 2.f, 3.f, 3.f, 4.f, 4.f, + 4.f, 0.f, 2.f, 3.f, 4.f, 4.f + }; + + std::vector input1 = { 1.f, 3.f, 1.f }; + + std::vector output = + { + 1.f, 8.f, 3.f, 3.f, 64.f, 4.f, + 4.f, 0.f, 2.f, 3.f, 64.f, 4.f + }; + + return ElementwiseTestHelper<4, armnn::DataType::Float32, armnn::DataType::Float32>( + workloadFactory, + memoryManager, + armnn::BinaryOperation::Power, + shape0, + input0, + shape1, + input1, + shape0, + output, + tensorHandleFactory); +} + +LayerTestResult PowerFloat16Test( + armnn::IWorkloadFactory& workloadFactory, + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, + const armnn::ITensorHandleFactory& tensorHandleFactory) +{ + IgnoreUnused(memoryManager); + using namespace half_float::literal; + + unsigned int shape[] = { 2, 2, 2, 2 }; + + std::vector input0 = + { + 1._h, 5._h, 1._h, 4._h, 6._h, 1._h, 3._h, 5._h, + 3._h, 7._h, 6._h, 3._h, 8._h, 4._h, 4._h, 2._h + }; + + std::vector input1 = + { + 2._h, 2._h, 2._h, 2._h, 2._h, 3._h, 3._h, 2._h, + 1._h, 2._h, 2._h, 4._h, 2._h, 1._h, 3._h, 5._h + }; + + std::vector output + { + 1._h, 25._h, 1._h, 16._h, 36._h, 1._h, 27._h, 25._h, + 3._h, 49._h, 36._h, 81._h, 64._h, 4._h, 64._h, 32._h + }; + + return ElementwiseTestHelper<4, armnn::DataType::Float16, armnn::DataType::Float16>( + workloadFactory, + memoryManager, + armnn::BinaryOperation::Power, + shape, + input0, + shape, + input1, + shape, + output, + tensorHandleFactory); +} + +LayerTestResult PowerBroadcast1ElementFloat16Test( + armnn::IWorkloadFactory& workloadFactory, + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, + const armnn::ITensorHandleFactory& tensorHandleFactory) +{ + IgnoreUnused(memoryManager); + using namespace half_float::literal; + + const unsigned int shape0[] = { 1, 2, 2, 3 }; + const unsigned int shape1[] = { 1, 1, 1, 1 }; + + std::vector input0 = + { + 1._h, 2._h, 3._h, 4._h, 5._h, 4._h, + 1._h, 5._h, 4._h, 2._h, 0._h, 1._h + }; + + std::vector input1 = { 2._h }; + + std::vector output = + { + 1._h, 4._h, 9._h, 16._h, 25._h, 16._h, + 1._h, 25._h, 16._h, 4._h, 0._h, 1._h + }; + + return ElementwiseTestHelper<4, armnn::DataType::Float16, armnn::DataType::Float16>( + workloadFactory, + memoryManager, + armnn::BinaryOperation::Power, + shape0, + input0, + shape1, + input1, + shape0, + output, + tensorHandleFactory); +} + +LayerTestResult PowerBroadcastFloat16Test( + armnn::IWorkloadFactory& workloadFactory, + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, + const armnn::ITensorHandleFactory& tensorHandleFactory) +{ + IgnoreUnused(memoryManager); + using namespace half_float::literal; + + const unsigned int shape0[] = { 1, 2, 2, 3 }; + const unsigned int shape1[] = { 1, 1, 1, 3 }; + + std::vector input0 = + { + 4._h, 2._h, 3._h, 4._h, 1._h, 0._h, + 8._h, 1._h, 1._h, 1._h, 2._h, 4._h + }; + + std::vector input1 = { 1._h, 5._h, 3._h }; + + std::vector output = + { + 4._h, 32._h, 27._h, 4._h, 1._h, 0._h, + 8._h, 1._h, 1._h, 1._h, 32._h, 64._h + }; + + return ElementwiseTestHelper<4, armnn::DataType::Float16, armnn::DataType::Float16>( + workloadFactory, + memoryManager, + armnn::BinaryOperation::Power, + shape0, + input0, + shape1, + input1, + shape0, + output, + tensorHandleFactory); +} + +LayerTestResult PowerUint8Test( + armnn::IWorkloadFactory& workloadFactory, + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, + const armnn::ITensorHandleFactory& tensorHandleFactory) +{ + IgnoreUnused(memoryManager); + const unsigned int shape[] = { 1, 1, 2, 2 }; + + std::vector input0 = { 4, 2, 4, 3 }; + + std::vector input1 = { 1, 2, 2, 2 }; + + std::vector output = { 4, 4, 16, 9 }; + + return ElementwiseTestHelper<4, armnn::DataType::QAsymmU8, armnn::DataType::QAsymmU8>( + workloadFactory, + memoryManager, + armnn::BinaryOperation::Power, + shape, + input0, + shape, + input1, + shape, + output, + tensorHandleFactory); +} + +LayerTestResult PowerBroadcast1ElementUint8Test( + armnn::IWorkloadFactory& workloadFactory, + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, + const armnn::ITensorHandleFactory& tensorHandleFactory) +{ + IgnoreUnused(memoryManager); + const unsigned int shape0[] = { 1, 1, 2, 2 }; + const unsigned int shape1[] = { 1, 1, 1, 1 }; + + std::vector input0 = { 4, 5, 1, 0 }; + + std::vector input1 = { 2 }; + + std::vector output = { 16, 25, 1, 0 }; + + return ElementwiseTestHelper<4, armnn::DataType::QAsymmU8, armnn::DataType::QAsymmU8>( + workloadFactory, + memoryManager, + armnn::BinaryOperation::Power, + shape0, + input0, + shape1, + input1, + shape0, + output, + tensorHandleFactory); +} + +LayerTestResult PowerBroadcastUint8Test( + armnn::IWorkloadFactory& workloadFactory, + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, + const armnn::ITensorHandleFactory& tensorHandleFactory) +{ + IgnoreUnused(memoryManager); + const unsigned int shape0[] = { 1, 1, 2, 2 }; + const unsigned int shape1[] = { 1, 1, 1, 2 }; + + std::vector input0 = { 4, 1, 6, 2 }; + + std::vector input1 = { 2, 6 }; + + std::vector output = { 16, 1, 36, 64 }; + + return ElementwiseTestHelper<4, armnn::DataType::QAsymmU8, armnn::DataType::QAsymmU8>( + workloadFactory, + memoryManager, + armnn::BinaryOperation::Power, + shape0, + input0, + shape1, + input1, + shape0, + output, + tensorHandleFactory); +} + +LayerTestResult PowerInt16Test( + armnn::IWorkloadFactory& workloadFactory, + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, + const armnn::ITensorHandleFactory& tensorHandleFactory) +{ + IgnoreUnused(memoryManager); + unsigned int shape[] = { 2, 2, 2, 2 }; + + std::vector input0 = + { + 1, 5, 1, 4, 4, 9, 3, 7, + 3, 2, 9, 6, 1, 2, 1, 4 + }; + + std::vector input1 = + { + 2, 2, 0, 3, 2, 1, 3, 2, + 4, 4, 2, 1, 7, 5, 4, 2 + }; + + std::vector output + { + 1, 25, 0, 64, 16, 9, 27, 49, + 81, 16, 81, 6, 1, 32, 1, 16 + }; + + return ElementwiseTestHelper<4, armnn::DataType::QSymmS16, armnn::DataType::QSymmS16>( + workloadFactory, + memoryManager, + armnn::BinaryOperation::Power, + shape, + input0, + shape, + input1, + shape, + output, + tensorHandleFactory); +} + +LayerTestResult PowerBroadcast1ElementInt16Test( + armnn::IWorkloadFactory& workloadFactory, + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, + const armnn::ITensorHandleFactory& tensorHandleFactory) +{ + IgnoreUnused(memoryManager); + const unsigned int shape0[] = { 1, 2, 2, 3 }; + const unsigned int shape1[] = { 1, 1, 1, 1 }; + + std::vector input0 = + { + 1, 2, 3, 4, 5, 0, + 5, 4, 1, 4, 5, 2 + }; + + std::vector input1 = { 2 }; + + std::vector output = + { + 1, 4, 9, 16, 25, 0, + 25, 16, 1, 16, 25, 4 + }; + + return ElementwiseTestHelper<4, armnn::DataType::QSymmS16, armnn::DataType::QSymmS16>( + workloadFactory, + memoryManager, + armnn::BinaryOperation::Power, + shape0, + input0, + shape1, + input1, + shape0, + output, + tensorHandleFactory); +} + +LayerTestResult PowerBroadcastInt16Test( + armnn::IWorkloadFactory& workloadFactory, + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, + const armnn::ITensorHandleFactory& tensorHandleFactory) +{ + IgnoreUnused(memoryManager); + const unsigned int shape0[] = { 1, 2, 2, 3 }; + const unsigned int shape1[] = { 1, 1, 1, 3 }; + + std::vector input0 = + { + 4, 2, 1, 4, 5, 3, + 7, 3, 4, 8, 1, 2 + }; + + std::vector input1 = { 1, 2, 3 }; + + std::vector output = + { + 4, 4, 1, 4, 25, 27, + 7, 9, 64, 8, 1, 8 + }; + + return ElementwiseTestHelper<4, armnn::DataType::QSymmS16, armnn::DataType::QSymmS16>( + workloadFactory, + memoryManager, + armnn::BinaryOperation::Power, + shape0, + input0, + shape1, + input1, + shape0, + output, + tensorHandleFactory); +} + +LayerTestResult PowerInt32Test( + armnn::IWorkloadFactory& workloadFactory, + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, + const armnn::ITensorHandleFactory& tensorHandleFactory) +{ + IgnoreUnused(memoryManager); + unsigned int shape[] = { 2, 2, 2, 2 }; + + std::vector input0 = + { + 1, 3, 4, 3, 1, 4, 2, 1, + 2, 1, 2, 1, 4, 3, 4, 3 + }; + + std::vector input1 = + { + 2, 2, 2, 2, 3, 3, 4, 3, + 4, 4, 4, 4, 1, 3, 1, 3 + }; + + std::vector output + { + 1, 9, 16, 9, 1, 64, 16, 1, + 16, 1, 16, 1, 4, 27, 4, 27 + }; + + return ElementwiseTestHelper<4, armnn::DataType::Signed32, armnn::DataType::Signed32>( + workloadFactory, + memoryManager, + armnn::BinaryOperation::Power, + shape, + input0, + shape, + input1, + shape, + output, + tensorHandleFactory); +} + +LayerTestResult PowerBroadcastInt32Test( + armnn::IWorkloadFactory& workloadFactory, + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, + const armnn::ITensorHandleFactory& tensorHandleFactory) +{ + IgnoreUnused(memoryManager); + const unsigned int shape0[] = { 1, 2, 2, 3 }; + const unsigned int shape1[] = { 1, 1, 1, 3 }; + + std::vector input0 = + { + 4, 4, 3, 4, 5, 0, + 5, 8, 1, 3, 9, 2 + }; + + std::vector input1 = { 2, 1, 3 }; + + std::vector output = + { + 16, 4, 27, 16, 5, 0, + 25, 8, 1, 9, 9, 8 + }; + + return ElementwiseTestHelper<4, armnn::DataType::Signed32, armnn::DataType::Signed32>( + workloadFactory, + memoryManager, + armnn::BinaryOperation::Power, + shape0, + input0, + shape1, + input1, + shape0, + output, + tensorHandleFactory); +} + +LayerTestResult PowerBroadcast1ElementInt32Test( + armnn::IWorkloadFactory& workloadFactory, + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, + const armnn::ITensorHandleFactory& tensorHandleFactory) +{ + IgnoreUnused(memoryManager); + const unsigned int shape0[] = { 1, 2, 2, 3 }; + const unsigned int shape1[] = { 1, 1, 1, 1 }; + + std::vector input0 = + { + 1, 2, 3, 4, 5, 3, + 3, 1, 0, 2, 1, 5 + }; + + std::vector input1 = { 2 }; + + std::vector output = + { + 1, 4, 9, 16, 25, 9, + 9, 1, 0, 4, 1, 25 + }; + + return ElementwiseTestHelper<4, armnn::DataType::Signed32, armnn::DataType::Signed32>( + workloadFactory, + memoryManager, + armnn::BinaryOperation::Power, + shape0, + input0, + shape1, + input1, + shape0, + output, + tensorHandleFactory); +} diff --git a/src/backends/backendsCommon/test/layerTests/PowerTestImpl.hpp b/src/backends/backendsCommon/test/layerTests/PowerTestImpl.hpp new file mode 100644 index 0000000000..3707208658 --- /dev/null +++ b/src/backends/backendsCommon/test/layerTests/PowerTestImpl.hpp @@ -0,0 +1,88 @@ +// +// Copyright © 2023 Arm Ltd and Contributors. All rights reserved. +// SPDX-License-Identifier: MIT +// + +#pragma once + +#include + +#include + +#include +#include + +LayerTestResult PowerTest( + armnn::IWorkloadFactory& workloadFactory, + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, + const armnn::ITensorHandleFactory& tensorHandleFactory); + +LayerTestResult PowerBroadcast1ElementTest( + armnn::IWorkloadFactory& workloadFactory, + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, + const armnn::ITensorHandleFactory& tensorHandleFactory); + +LayerTestResult PowerBroadcastTest( + armnn::IWorkloadFactory & workloadFactory, + const armnn::IBackendInternal::IMemoryManagerSharedPtr & memoryManager, + const armnn::ITensorHandleFactory& tensorHandleFactory); + +LayerTestResult PowerFloat16Test( + armnn::IWorkloadFactory& workloadFactory, + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, + const armnn::ITensorHandleFactory& tensorHandleFactory); + +LayerTestResult PowerBroadcast1ElementFloat16Test( + armnn::IWorkloadFactory& workloadFactory, + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, + const armnn::ITensorHandleFactory& tensorHandleFactory); + +LayerTestResult PowerBroadcastFloat16Test( + armnn::IWorkloadFactory& workloadFactory, + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, + const armnn::ITensorHandleFactory& tensorHandleFactory); + +LayerTestResult PowerBroadcast1ElementUint8Test( + armnn::IWorkloadFactory& workloadFactory, + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, + const armnn::ITensorHandleFactory& tensorHandleFactory); + +LayerTestResult PowerUint8Test( + armnn::IWorkloadFactory& workloadFactory, + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, + const armnn::ITensorHandleFactory& tensorHandleFactory); + +LayerTestResult PowerBroadcastUint8Test( + armnn::IWorkloadFactory& workloadFactory, + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, + const armnn::ITensorHandleFactory& tensorHandleFactory); + +LayerTestResult PowerInt16Test( + armnn::IWorkloadFactory& workloadFactory, + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, + const armnn::ITensorHandleFactory& tensorHandleFactory); + +LayerTestResult PowerBroadcast1ElementInt16Test( + armnn::IWorkloadFactory& workloadFactory, + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, + const armnn::ITensorHandleFactory& tensorHandleFactory); + +LayerTestResult PowerBroadcastInt16Test( + armnn::IWorkloadFactory& workloadFactory, + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, + const armnn::ITensorHandleFactory& tensorHandleFactory); + +LayerTestResult PowerInt32Test( + armnn::IWorkloadFactory& workloadFactory, + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, + const armnn::ITensorHandleFactory& tensorHandleFactory); + +LayerTestResult PowerBroadcastInt32Test( + armnn::IWorkloadFactory& workloadFactory, + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, + const armnn::ITensorHandleFactory& tensorHandleFactory); + +LayerTestResult PowerBroadcast1ElementInt32Test( + armnn::IWorkloadFactory& workloadFactory, + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, + const armnn::ITensorHandleFactory& tensorHandleFactory); diff --git a/src/backends/backendsCommon/test/layerTests/SquaredDifferenceTestImpl.cpp b/src/backends/backendsCommon/test/layerTests/SquaredDifferenceTestImpl.cpp new file mode 100644 index 0000000000..8bb31ed16e --- /dev/null +++ b/src/backends/backendsCommon/test/layerTests/SquaredDifferenceTestImpl.cpp @@ -0,0 +1,539 @@ +// +// Copyright © 2023 Arm Ltd and Contributors. All rights reserved. +// SPDX-License-Identifier: MIT +// + +#include "SquaredDifferenceTestImpl.hpp" + +#include "ElementwiseTestImpl.hpp" + +LayerTestResult SquaredDifferenceTest( + armnn::IWorkloadFactory& workloadFactory, + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, + const armnn::ITensorHandleFactory& tensorHandleFactory) +{ + IgnoreUnused(memoryManager); + unsigned int shape[] = { 2, 2, 2, 2 }; + + std::vector input0 = + { + 7.f, 3.f, 4.f, 2.f, 6.f, 4.f, 2.f, 1.f, + 3.f, 1.f, 0.f, 1.f, 4.f, 3.f, 4.f, 3.f + }; + + std::vector input1 = + { + 5.f, 3.f, 2.f, 5.f, 3.f, 3.f, 4.f, 3.f, + 4.f, 4.f, 3.f, 2.f, 5.f, 5.f, 5.f, 5.f + }; + + std::vector output + { + 4.f, 0.f, 4.f, 9.f, 9.f, 1.f, 4.f, 4.f, + 1.f, 9.f, 9.f, 1.f, 1.f, 4.f, 1.f, 4.f + }; + + return ElementwiseTestHelper<4, armnn::DataType::Float32, armnn::DataType::Float32>( + workloadFactory, + memoryManager, + armnn::BinaryOperation::SqDiff, + shape, + input0, + shape, + input1, + shape, + output, + tensorHandleFactory); +} + +LayerTestResult SquaredDiffBroadcast1ElementTest( + armnn::IWorkloadFactory& workloadFactory, + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, + const armnn::ITensorHandleFactory& tensorHandleFactory) +{ + IgnoreUnused(memoryManager); + unsigned int shape0[] = { 1, 2, 2, 2 }; + unsigned int shape1[] = { 1, 1, 1, 1 }; + + std::vector input0 = + { + 1.f, 2.f, 3.f, 4.f, 5.f, 0.f, 2.f, 1.f + }; + + std::vector input1 = { 2.f }; + + std::vector output = + { + 1.f, 0.f, 1.f, 4.f, 9.f, 4.f, 0.f, 1.f + }; + + return ElementwiseTestHelper<4, armnn::DataType::Float32, armnn::DataType::Float32>( + workloadFactory, + memoryManager, + armnn::BinaryOperation::SqDiff, + shape0, + input0, + shape1, + input1, + shape0, + output, + tensorHandleFactory); +} + +LayerTestResult SquaredDiffBroadcastTest( + armnn::IWorkloadFactory & workloadFactory, + const armnn::IBackendInternal::IMemoryManagerSharedPtr & memoryManager, + const armnn::ITensorHandleFactory& tensorHandleFactory) +{ + IgnoreUnused(memoryManager); + const unsigned int shape0[] = { 1, 2, 2, 3 }; + const unsigned int shape1[] = { 1, 1, 1, 3 }; + + std::vector input0 = + { + 1.f, 2.f, 3.f, 3.f, 6.f, 4.f, + 4.f, 0.f, 2.f, 3.f, 4.f, 4.f + }; + + std::vector input1 = { 1.f, 3.f, 1.f }; + + std::vector output = + { + 0.f, 1.f, 4.f, 4.f, 9.f, 9.f, + 9.f, 9.f, 1.f, 4.f, 1.f, 9.f + }; + + return ElementwiseTestHelper<4, armnn::DataType::Float32, armnn::DataType::Float32>( + workloadFactory, + memoryManager, + armnn::BinaryOperation::SqDiff, + shape0, + input0, + shape1, + input1, + shape0, + output, + tensorHandleFactory); +} + +LayerTestResult SquaredDifferenceFloat16Test( + armnn::IWorkloadFactory& workloadFactory, + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, + const armnn::ITensorHandleFactory& tensorHandleFactory) +{ + IgnoreUnused(memoryManager); + using namespace half_float::literal; + + unsigned int shape[] = { 2, 2, 2, 2 }; + + std::vector input0 = + { + 1._h, 5._h, 1._h, 4._h, 6._h, 1._h, 3._h, 5._h, + 3._h, 7._h, 6._h, 3._h, 8._h, 4._h, 4._h, 2._h + }; + + std::vector input1 = + { + 2._h, 2._h, 2._h, 2._h, 3._h, 3._h, 3._h, 3._h, + 4._h, 4._h, 4._h, 4._h, 5._h, 6._h, 5._h, 5._h + }; + + std::vector output + { + 1._h, 9._h, 1._h, 4._h, 9._h, 4._h, 0._h, 4._h, + 1._h, 9._h, 4._h, 1._h, 9._h, 4._h, 1._h, 9._h + }; + + return ElementwiseTestHelper<4, armnn::DataType::Float16, armnn::DataType::Float16>( + workloadFactory, + memoryManager, + armnn::BinaryOperation::SqDiff, + shape, + input0, + shape, + input1, + shape, + output, + tensorHandleFactory); +} + +LayerTestResult SquaredDiffBroadcast1ElementFloat16Test( + armnn::IWorkloadFactory& workloadFactory, + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, + const armnn::ITensorHandleFactory& tensorHandleFactory) +{ + IgnoreUnused(memoryManager); + using namespace half_float::literal; + + const unsigned int shape0[] = { 1, 2, 2, 3 }; + const unsigned int shape1[] = { 1, 1, 1, 1 }; + + std::vector input0 = + { + 1._h, 2._h, 3._h, 4._h, 5._h, 4._h, + 1._h, 5._h, 4._h, 2._h, 0._h, 1._h + }; + + std::vector input1 = { 2._h }; + + std::vector output = + { + 1._h, 0._h, 1._h, 4._h, 9._h, 4._h, + 1._h, 9._h, 4._h, 0._h, 4._h, 1._h + }; + + return ElementwiseTestHelper<4, armnn::DataType::Float16, armnn::DataType::Float16>( + workloadFactory, + memoryManager, + armnn::BinaryOperation::SqDiff, + shape0, + input0, + shape1, + input1, + shape0, + output, + tensorHandleFactory); +} + +LayerTestResult SquaredDiffBroadcastFloat16Test( + armnn::IWorkloadFactory& workloadFactory, + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, + const armnn::ITensorHandleFactory& tensorHandleFactory) +{ + IgnoreUnused(memoryManager); + using namespace half_float::literal; + const unsigned int shape0[] = { 1, 2, 2, 3 }; + const unsigned int shape1[] = { 1, 1, 1, 3 }; + + std::vector input0 = + { + 4._h, 2._h, 3._h, 4._h, 5._h, 5._h, + 2._h, 8._h, 1._h, 1._h, 2._h, 4._h + }; + + std::vector input1 = { 1._h, 5._h, 3._h }; + + std::vector output = + { + 9._h, 9._h, 0._h, 9._h, 0._h, 4._h, + 1._h, 9._h, 4._h, 0._h, 9._h, 1._h + }; + + return ElementwiseTestHelper<4, armnn::DataType::Float16, armnn::DataType::Float16>( + workloadFactory, + memoryManager, + armnn::BinaryOperation::SqDiff, + shape0, + input0, + shape1, + input1, + shape0, + output, + tensorHandleFactory); +} + +LayerTestResult SquaredDifferenceUint8Test( + armnn::IWorkloadFactory& workloadFactory, + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, + const armnn::ITensorHandleFactory& tensorHandleFactory) +{ + IgnoreUnused(memoryManager); + const unsigned int shape0[] = { 1, 1, 2, 2 }; + const unsigned int shape1[] = { 1, 1, 2, 2 }; + + std::vector input0 = { 4, 2, 4, 3 }; + + std::vector input1 = { 1, 2, 2, 2 }; + + std::vector output = { 9, 0, 4, 1 }; + + return ElementwiseTestHelper<4, armnn::DataType::QAsymmU8, armnn::DataType::QAsymmU8>( + workloadFactory, + memoryManager, + armnn::BinaryOperation::SqDiff, + shape0, + input0, + shape1, + input1, + shape0, + output, + tensorHandleFactory); +} + +LayerTestResult SquaredDiffBroadcast1ElementUint8Test( + armnn::IWorkloadFactory& workloadFactory, + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, + const armnn::ITensorHandleFactory& tensorHandleFactory) +{ + IgnoreUnused(memoryManager); + const unsigned int shape0[] = { 1, 1, 2, 2 }; + const unsigned int shape1[] = { 1, 1, 1, 1 }; + + std::vector input0 = { 4, 5, 1, 0 }; + + std::vector input1 = { 2 }; + + std::vector output = { 4, 9, 1, 4 }; + + return ElementwiseTestHelper<4, armnn::DataType::QAsymmU8, armnn::DataType::QAsymmU8>( + workloadFactory, + memoryManager, + armnn::BinaryOperation::SqDiff, + shape0, + input0, + shape1, + input1, + shape0, + output, + tensorHandleFactory); +} + +LayerTestResult SquaredDiffBroadcastUint8Test( + armnn::IWorkloadFactory& workloadFactory, + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, + const armnn::ITensorHandleFactory& tensorHandleFactory) +{ + IgnoreUnused(memoryManager); + const unsigned int shape0[] = { 1, 1, 2, 2 }; + const unsigned int shape1[] = { 1, 1, 1, 2 }; + + std::vector input0 = { 4, 12, 3, 6 }; + + std::vector input1 = { 2, 9 }; + + std::vector output = { 4, 9, 1, 9 }; + + return ElementwiseTestHelper<4, armnn::DataType::QAsymmU8, armnn::DataType::QAsymmU8>( + workloadFactory, + memoryManager, + armnn::BinaryOperation::SqDiff, + shape0, + input0, + shape1, + input1, + shape0, + output, + tensorHandleFactory); +} + +LayerTestResult SquaredDifferenceInt16Test( + armnn::IWorkloadFactory& workloadFactory, + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, + const armnn::ITensorHandleFactory& tensorHandleFactory) +{ + IgnoreUnused(memoryManager); + unsigned int shape[] = { 2, 2, 2, 2 }; + + std::vector input0 = + { + 1, 5, 1, 4, 6, 9, 6, 5, + 3, 2, 3, 6, 4, 4, 1, 4 + }; + + std::vector input1 = + { + 2, 2, 0, 4, 3, 7, 3, 3, + 4, 4, 4, 9, 7, 5, 4, 5 + }; + + std::vector output + { + 1, 9, 1, 0, 9, 4, 9, 4, + 1, 4, 1, 9, 9, 1, 9, 1 + }; + + return ElementwiseTestHelper<4, armnn::DataType::QSymmS16, armnn::DataType::QSymmS16>( + workloadFactory, + memoryManager, + armnn::BinaryOperation::SqDiff, + shape, + input0, + shape, + input1, + shape, + output, + tensorHandleFactory); +} + +LayerTestResult SquaredDiffBroadcast1ElementInt16Test( + armnn::IWorkloadFactory& workloadFactory, + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, + const armnn::ITensorHandleFactory& tensorHandleFactory) +{ + IgnoreUnused(memoryManager); + const unsigned int shape0[] = { 1, 2, 2, 3 }; + const unsigned int shape1[] = { 1, 1, 1, 1 }; + + std::vector input0 = + { + 1, 2, 3, 4, 5, 0, + 5, 4, 1, 4, 5, 2 + }; + + std::vector input1 = { 2 }; + + std::vector output = + { + 1, 0, 1, 4, 9, 4, + 9, 4, 1, 4, 9, 0 + }; + + return ElementwiseTestHelper<4, armnn::DataType::QSymmS16, armnn::DataType::QSymmS16>( + workloadFactory, + memoryManager, + armnn::BinaryOperation::SqDiff, + shape0, + input0, + shape1, + input1, + shape0, + output, + tensorHandleFactory); +} + +LayerTestResult SquaredDiffBroadcastInt16Test( + armnn::IWorkloadFactory& workloadFactory, + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, + const armnn::ITensorHandleFactory& tensorHandleFactory) +{ + IgnoreUnused(memoryManager); + const unsigned int shape0[] = { 1, 2, 2, 3 }; + const unsigned int shape1[] = { 1, 1, 1, 3 }; + + std::vector input0 = + { + 4, 2, 1, 4, 5, 6, + 7, 3, 5, 8, 1, 5 + }; + + std::vector input1 = { 7, 2, 3 }; + + std::vector output = + { + 9, 0, 4, 9, 9, 9, + 0, 1, 4, 1, 1, 4 + }; + + return ElementwiseTestHelper<4, armnn::DataType::QSymmS16, armnn::DataType::QSymmS16>( + workloadFactory, + memoryManager, + armnn::BinaryOperation::SqDiff, + shape0, + input0, + shape1, + input1, + shape0, + output, + tensorHandleFactory); +} + +LayerTestResult SquaredDifferenceInt32Test( + armnn::IWorkloadFactory& workloadFactory, + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, + const armnn::ITensorHandleFactory& tensorHandleFactory) +{ + IgnoreUnused(memoryManager); + unsigned int shape[] = { 2, 2, 2, 2 }; + + std::vector input0 = + { + 1, 3, 4, 3, 6, 4, 2, 6, + 3, 1, 3, 1, 4, 3, 4, 3 + }; + + std::vector input1 = + { + 2, 2, 2, 2, 3, 3, 4, 3, + 4, 4, 4, 4, 5, 5, 5, 5 + }; + + std::vector output + { + 1, 1, 4, 1, 9, 1, 4, 9, + 1, 9, 1, 9, 1, 4, 1, 4 + }; + + return ElementwiseTestHelper<4, armnn::DataType::Signed32, armnn::DataType::Signed32>( + workloadFactory, + memoryManager, + armnn::BinaryOperation::SqDiff, + shape, + input0, + shape, + input1, + shape, + output, + tensorHandleFactory); +} + +LayerTestResult SquaredDiffBroadcastInt32Test( + armnn::IWorkloadFactory& workloadFactory, + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, + const armnn::ITensorHandleFactory& tensorHandleFactory) +{ + IgnoreUnused(memoryManager); + const unsigned int shape0[] = { 1, 2, 2, 3 }; + const unsigned int shape1[] = { 1, 1, 1, 3 }; + + std::vector input0 = + { + 4, 4, 3, 4, 5, 6, + 5, 8, 6, 3, 9, 5 + }; + + std::vector input1 = { 2, 7, 3 }; + + std::vector output = + { + 4, 9, 0, 4, 4, 9, + 9, 1, 9, 1, 4, 4 + }; + + return ElementwiseTestHelper<4, armnn::DataType::Signed32, armnn::DataType::Signed32>( + workloadFactory, + memoryManager, + armnn::BinaryOperation::SqDiff, + shape0, + input0, + shape1, + input1, + shape0, + output, + tensorHandleFactory); +} + +LayerTestResult SquaredDiffBroadcast1ElementInt32Test( + armnn::IWorkloadFactory& workloadFactory, + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, + const armnn::ITensorHandleFactory& tensorHandleFactory) +{ + IgnoreUnused(memoryManager); + const unsigned int shape0[] = { 1, 2, 2, 3 }; + const unsigned int shape1[] = { 1, 1, 1, 1 }; + + std::vector input0 = + { + 1, 2, 3, 4, 5, 3, + 3, 1, 0, 2, 1, 5 + }; + + std::vector input1 = { 2 }; + + std::vector output = + { + 1, 0, 1, 4, 9, 1, + 1, 1, 4, 0, 1, 9 + }; + + return ElementwiseTestHelper<4, armnn::DataType::Signed32, armnn::DataType::Signed32>( + workloadFactory, + memoryManager, + armnn::BinaryOperation::SqDiff, + shape0, + input0, + shape1, + input1, + shape0, + output, + tensorHandleFactory); +} diff --git a/src/backends/backendsCommon/test/layerTests/SquaredDifferenceTestImpl.hpp b/src/backends/backendsCommon/test/layerTests/SquaredDifferenceTestImpl.hpp new file mode 100644 index 0000000000..1d87700d05 --- /dev/null +++ b/src/backends/backendsCommon/test/layerTests/SquaredDifferenceTestImpl.hpp @@ -0,0 +1,88 @@ +// +// Copyright © 2023 Arm Ltd and Contributors. All rights reserved. +// SPDX-License-Identifier: MIT +// + +#pragma once + +#include + +#include + +#include +#include + +LayerTestResult SquaredDifferenceTest( + armnn::IWorkloadFactory& workloadFactory, + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, + const armnn::ITensorHandleFactory& tensorHandleFactory); + +LayerTestResult SquaredDiffBroadcast1ElementTest( + armnn::IWorkloadFactory& workloadFactory, + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, + const armnn::ITensorHandleFactory& tensorHandleFactory); + +LayerTestResult SquaredDiffBroadcastTest( + armnn::IWorkloadFactory & workloadFactory, + const armnn::IBackendInternal::IMemoryManagerSharedPtr & memoryManager, + const armnn::ITensorHandleFactory& tensorHandleFactory); + +LayerTestResult SquaredDifferenceFloat16Test( + armnn::IWorkloadFactory& workloadFactory, + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, + const armnn::ITensorHandleFactory& tensorHandleFactory); + +LayerTestResult SquaredDiffBroadcast1ElementFloat16Test( + armnn::IWorkloadFactory& workloadFactory, + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, + const armnn::ITensorHandleFactory& tensorHandleFactory); + +LayerTestResult SquaredDiffBroadcastFloat16Test( + armnn::IWorkloadFactory& workloadFactory, + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, + const armnn::ITensorHandleFactory& tensorHandleFactory); + +LayerTestResult SquaredDiffBroadcast1ElementUint8Test( + armnn::IWorkloadFactory& workloadFactory, + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, + const armnn::ITensorHandleFactory& tensorHandleFactory); + +LayerTestResult SquaredDifferenceUint8Test( + armnn::IWorkloadFactory& workloadFactory, + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, + const armnn::ITensorHandleFactory& tensorHandleFactory); + +LayerTestResult SquaredDiffBroadcastUint8Test( + armnn::IWorkloadFactory& workloadFactory, + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, + const armnn::ITensorHandleFactory& tensorHandleFactory); + +LayerTestResult SquaredDifferenceInt16Test( + armnn::IWorkloadFactory& workloadFactory, + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, + const armnn::ITensorHandleFactory& tensorHandleFactory); + +LayerTestResult SquaredDiffBroadcast1ElementInt16Test( + armnn::IWorkloadFactory& workloadFactory, + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, + const armnn::ITensorHandleFactory& tensorHandleFactory); + +LayerTestResult SquaredDiffBroadcastInt16Test( + armnn::IWorkloadFactory& workloadFactory, + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, + const armnn::ITensorHandleFactory& tensorHandleFactory); + +LayerTestResult SquaredDifferenceInt32Test( + armnn::IWorkloadFactory& workloadFactory, + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, + const armnn::ITensorHandleFactory& tensorHandleFactory); + +LayerTestResult SquaredDiffBroadcastInt32Test( + armnn::IWorkloadFactory& workloadFactory, + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, + const armnn::ITensorHandleFactory& tensorHandleFactory); + +LayerTestResult SquaredDiffBroadcast1ElementInt32Test( + armnn::IWorkloadFactory& workloadFactory, + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, + const armnn::ITensorHandleFactory& tensorHandleFactory); -- cgit v1.2.1