diff options
Diffstat (limited to 'src/backends/backendsCommon/test/layerTests/AbsTestImpl.cpp')
-rw-r--r-- | src/backends/backendsCommon/test/layerTests/AbsTestImpl.cpp | 164 |
1 files changed, 28 insertions, 136 deletions
diff --git a/src/backends/backendsCommon/test/layerTests/AbsTestImpl.cpp b/src/backends/backendsCommon/test/layerTests/AbsTestImpl.cpp index cc57893439..7706809e8b 100644 --- a/src/backends/backendsCommon/test/layerTests/AbsTestImpl.cpp +++ b/src/backends/backendsCommon/test/layerTests/AbsTestImpl.cpp @@ -4,85 +4,15 @@ // #include "AbsTestImpl.hpp" +#include "ElementwiseUnaryTestImpl.hpp" -#include <backendsCommon/test/DataTypeUtils.hpp> -#include <backendsCommon/test/TensorCopyUtils.hpp> -#include <backendsCommon/test/WorkloadTestUtils.hpp> - -#include <test/TensorHelpers.hpp> - -namespace -{ - -template<armnn::DataType ArmnnType, typename T = armnn::ResolveType<ArmnnType>> -LayerTestResult<T, 2> Abs2dTestCommon( - armnn::IWorkloadFactory& workloadFactory, - const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, - const armnn::TensorInfo inputTensorInfo, - const armnn::TensorInfo outputTensorInfo, - const std::vector<float>& inputValues, - const std::vector<float>& expectedOutputValues) -{ - boost::ignore_unused(memoryManager); - auto inputTensor = MakeTensor<T, 2>(inputTensorInfo, ConvertToDataType<ArmnnType>(inputValues,inputTensorInfo)); - - LayerTestResult<T, 2> result(outputTensorInfo); - - result.outputExpected = MakeTensor<T, 2>(outputTensorInfo, - ConvertToDataType<ArmnnType>(expectedOutputValues,outputTensorInfo)); - - std::unique_ptr<armnn::ITensorHandle> inputHandle = workloadFactory.CreateTensorHandle(inputTensorInfo); - std::unique_ptr<armnn::ITensorHandle> outputHandle = workloadFactory.CreateTensorHandle(outputTensorInfo); - - armnn::AbsQueueDescriptor descriptor; - - armnn::WorkloadInfo info; - - AddInputToWorkload(descriptor, info, inputTensorInfo, inputHandle.get()); - AddOutputToWorkload(descriptor, info, outputTensorInfo, outputHandle.get()); - - std::unique_ptr<armnn::IWorkload> workload = workloadFactory.CreateAbs(descriptor, info); - - inputHandle->Allocate(); - outputHandle->Allocate(); - - CopyDataToITensorHandle(inputHandle.get(), &inputTensor[0][0]); - - workload->PostAllocationConfigure(); - workload->Execute(); - - CopyDataFromITensorHandle(&result.output[0][0], outputHandle.get()); - - return result; -} - -} // anonymous namespace - template<armnn::DataType ArmnnType, typename T> LayerTestResult<T, 2> Abs2dTest( armnn::IWorkloadFactory& workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) { - const armnn::TensorShape inputShape{ 2, 2 }; - const armnn::TensorShape outputShape{ 2, 2 }; - - float qScale = 0.0625f; - int32_t qOffset = 64; - - if (ArmnnType == armnn::DataType::QSymmS16) - { - qScale = 0.1f; - qOffset = 0; - } - - armnn::TensorInfo inputTensorInfo(inputShape, ArmnnType); - inputTensorInfo.SetQuantizationScale(qScale); - inputTensorInfo.SetQuantizationOffset(qOffset); - - armnn::TensorInfo outputTensorInfo(outputShape, ArmnnType); - outputTensorInfo.SetQuantizationScale(qScale); - outputTensorInfo.SetQuantizationOffset(qOffset); + const unsigned int inputShape[] = { 2, 2 }; std::vector<float> inputValues { @@ -98,9 +28,14 @@ LayerTestResult<T, 2> Abs2dTest( std::vector<float> expectedOutputValues(inputValues.size()); std::transform(inputValues.begin(), inputValues.end(), expectedOutputValues.begin(), f); - return Abs2dTestCommon<ArmnnType>(workloadFactory, memoryManager, - inputTensorInfo, outputTensorInfo, - inputValues, expectedOutputValues); + return ElementwiseUnaryTestHelper<2, ArmnnType>( + workloadFactory, + memoryManager, + armnn::UnaryOperation::Abs, + inputShape, + inputValues, + inputShape, + expectedOutputValues); } template<armnn::DataType ArmnnType, typename T> @@ -108,27 +43,7 @@ LayerTestResult<T, 3> Abs3dTest( armnn::IWorkloadFactory& workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) { - boost::ignore_unused(memoryManager); - - const armnn::TensorShape inputShape{ 3, 1, 2 }; - const armnn::TensorShape outputShape{ 3, 1, 2 }; - - float qScale = 0.0625f; - int32_t qOffset = 64; - - if (ArmnnType == armnn::DataType::QSymmS16) - { - qScale = 0.1f; - qOffset = 0; - } - - armnn::TensorInfo inputTensorInfo(inputShape, ArmnnType); - inputTensorInfo.SetQuantizationScale(qScale); - inputTensorInfo.SetQuantizationOffset(qOffset); - - armnn::TensorInfo outputTensorInfo(outputShape, ArmnnType); - outputTensorInfo.SetQuantizationScale(qScale); - outputTensorInfo.SetQuantizationOffset(qOffset); + const unsigned int inputShape[] = { 3, 1, 2 }; std::vector<float> inputValues { @@ -143,35 +58,14 @@ LayerTestResult<T, 3> Abs3dTest( std::vector<float>expectedOutputValues(inputValues.size()); std::transform(inputValues.begin(), inputValues.end(), expectedOutputValues.begin(), f); - auto inputTensor = MakeTensor<T, 3>(inputTensorInfo, ConvertToDataType<ArmnnType>(inputValues,inputTensorInfo)); - - LayerTestResult<T, 3> result(outputTensorInfo); - result.outputExpected = MakeTensor<T, 3>(outputTensorInfo, - ConvertToDataType<ArmnnType>(expectedOutputValues,outputTensorInfo)); - - std::unique_ptr<armnn::ITensorHandle> inputHandle = workloadFactory.CreateTensorHandle(inputTensorInfo); - std::unique_ptr<armnn::ITensorHandle> outputHandle = workloadFactory.CreateTensorHandle(outputTensorInfo); - - armnn::AbsQueueDescriptor descriptor; - - armnn::WorkloadInfo info; - - AddInputToWorkload(descriptor, info, inputTensorInfo, inputHandle.get()); - AddOutputToWorkload(descriptor, info, outputTensorInfo, outputHandle.get()); - - std::unique_ptr<armnn::IWorkload> workload = workloadFactory.CreateAbs(descriptor, info); - - inputHandle->Allocate(); - outputHandle->Allocate(); - - CopyDataToITensorHandle(inputHandle.get(), &inputTensor[0][0][0]); - - workload->PostAllocationConfigure(); - workload->Execute(); - - CopyDataFromITensorHandle(&result.output[0][0][0], outputHandle.get()); - - return result; + return ElementwiseUnaryTestHelper<3, ArmnnType>( + workloadFactory, + memoryManager, + armnn::UnaryOperation::Abs, + inputShape, + inputValues, + inputShape, + expectedOutputValues); } template<armnn::DataType ArmnnType, typename T> @@ -179,14 +73,7 @@ LayerTestResult<T, 2> AbsZeroTest( armnn::IWorkloadFactory& workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) { - const armnn::TensorShape inputShape{ 1, 2 }; - const armnn::TensorShape outputShape{ 1, 2 }; - - armnn::TensorInfo inputTensorInfo(inputShape, ArmnnType); - inputTensorInfo.SetQuantizationScale(0.1f); - - armnn::TensorInfo outputTensorInfo(outputShape, ArmnnType); - outputTensorInfo.SetQuantizationScale(0.1f); + const unsigned int inputShape[] = { 1, 2 }; std::vector<float> inputValues { @@ -198,9 +85,14 @@ LayerTestResult<T, 2> AbsZeroTest( 0.f, 0.f }; - return Abs2dTestCommon<ArmnnType>(workloadFactory, memoryManager, - inputTensorInfo, outputTensorInfo, - inputValues, expectedOutputValues); + return ElementwiseUnaryTestHelper<2, ArmnnType>( + workloadFactory, + memoryManager, + armnn::UnaryOperation::Abs, + inputShape, + inputValues, + inputShape, + expectedOutputValues); } // |