From 4a3c61091037e7e86e8b03bb060d8c1ab82731a9 Mon Sep 17 00:00:00 2001 From: josh minor Date: Mon, 6 Jan 2020 16:40:46 -0600 Subject: IVGCVSW-4259 Add frontend and reference workload for UnaryOperationLayer * Added new layer named ElementwiseUnary * Deprecated existing Abs/Rsqrt layer functions * Updated existing Abs/Rsqrt test infrastructure to use new layer * Added boilerplate for new Exp,Neg,Sqrt elemwise op layers * AbsQuantize test removed pending future commit * Serialization support added !android-nn-driver:2550 Change-Id: Ic595c645925e17b45db568187fd05646daf2e87f Signed-off-by: josh minor --- .../backendsCommon/test/layerTests/AbsTestImpl.cpp | 164 ++++----------------- 1 file changed, 28 insertions(+), 136 deletions(-) (limited to 'src/backends/backendsCommon/test/layerTests/AbsTestImpl.cpp') 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 -#include -#include - -#include - -namespace -{ - -template> -LayerTestResult Abs2dTestCommon( - armnn::IWorkloadFactory& workloadFactory, - const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, - const armnn::TensorInfo inputTensorInfo, - const armnn::TensorInfo outputTensorInfo, - const std::vector& inputValues, - const std::vector& expectedOutputValues) -{ - boost::ignore_unused(memoryManager); - auto inputTensor = MakeTensor(inputTensorInfo, ConvertToDataType(inputValues,inputTensorInfo)); - - LayerTestResult result(outputTensorInfo); - - result.outputExpected = MakeTensor(outputTensorInfo, - ConvertToDataType(expectedOutputValues,outputTensorInfo)); - - std::unique_ptr inputHandle = workloadFactory.CreateTensorHandle(inputTensorInfo); - std::unique_ptr 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 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 LayerTestResult 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 inputValues { @@ -98,9 +28,14 @@ LayerTestResult Abs2dTest( std::vector expectedOutputValues(inputValues.size()); std::transform(inputValues.begin(), inputValues.end(), expectedOutputValues.begin(), f); - return Abs2dTestCommon(workloadFactory, memoryManager, - inputTensorInfo, outputTensorInfo, - inputValues, expectedOutputValues); + return ElementwiseUnaryTestHelper<2, ArmnnType>( + workloadFactory, + memoryManager, + armnn::UnaryOperation::Abs, + inputShape, + inputValues, + inputShape, + expectedOutputValues); } template @@ -108,27 +43,7 @@ LayerTestResult 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 inputValues { @@ -143,35 +58,14 @@ LayerTestResult Abs3dTest( std::vectorexpectedOutputValues(inputValues.size()); std::transform(inputValues.begin(), inputValues.end(), expectedOutputValues.begin(), f); - auto inputTensor = MakeTensor(inputTensorInfo, ConvertToDataType(inputValues,inputTensorInfo)); - - LayerTestResult result(outputTensorInfo); - result.outputExpected = MakeTensor(outputTensorInfo, - ConvertToDataType(expectedOutputValues,outputTensorInfo)); - - std::unique_ptr inputHandle = workloadFactory.CreateTensorHandle(inputTensorInfo); - std::unique_ptr 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 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 @@ -179,14 +73,7 @@ LayerTestResult 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 inputValues { @@ -198,9 +85,14 @@ LayerTestResult AbsZeroTest( 0.f, 0.f }; - return Abs2dTestCommon(workloadFactory, memoryManager, - inputTensorInfo, outputTensorInfo, - inputValues, expectedOutputValues); + return ElementwiseUnaryTestHelper<2, ArmnnType>( + workloadFactory, + memoryManager, + armnn::UnaryOperation::Abs, + inputShape, + inputValues, + inputShape, + expectedOutputValues); } // -- cgit v1.2.1