diff options
Diffstat (limited to 'src/backends/backendsCommon/test/PermuteTestImpl.hpp')
-rw-r--r-- | src/backends/backendsCommon/test/PermuteTestImpl.hpp | 246 |
1 files changed, 122 insertions, 124 deletions
diff --git a/src/backends/backendsCommon/test/PermuteTestImpl.hpp b/src/backends/backendsCommon/test/PermuteTestImpl.hpp index c8120a41d8..5f56fbde59 100644 --- a/src/backends/backendsCommon/test/PermuteTestImpl.hpp +++ b/src/backends/backendsCommon/test/PermuteTestImpl.hpp @@ -55,7 +55,8 @@ LayerTestResult<T, 4> SimplePermuteTestImpl( return ret; } -LayerTestResult<float, 4> SimplePermuteFloat32TestCommon( +template<armnn::DataType ArmnnType, typename T = armnn::ResolveType<ArmnnType>> +LayerTestResult<T, 4> SimplePermuteTest( armnn::IWorkloadFactory& workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) { @@ -68,69 +69,39 @@ LayerTestResult<float, 4> SimplePermuteFloat32TestCommon( armnn::PermuteDescriptor descriptor; descriptor.m_DimMappings = {0U, 3U, 1U, 2U}; - inputTensorInfo = armnn::TensorInfo(4, inputShape, armnn::DataType::Float32); - outputTensorInfo = armnn::TensorInfo(4, outputShape, armnn::DataType::Float32); - - std::vector<float> input = std::vector<float>( - { - 1.0f, 2.0f, - 3.0f, 4.0f, - - 5.0f, 6.0f, - 7.0f, 8.0f - }); - - std::vector<float> outputExpected = std::vector<float>( - { - 1.0f, 5.0f, 2.0f, 6.0f, - 3.0f, 7.0f, 4.0f, 8.0f - }); - - return SimplePermuteTestImpl<float>(workloadFactory, memoryManager, - descriptor, inputTensorInfo, - outputTensorInfo, input, outputExpected); + inputTensorInfo = armnn::TensorInfo(4, inputShape, ArmnnType); + outputTensorInfo = armnn::TensorInfo(4, outputShape, ArmnnType); + + // Set quantization parameters if the requested type is a quantized type. + if(armnn::IsQuantizedType<T>()) + { + inputTensorInfo.SetQuantizationScale(0.5f); + inputTensorInfo.SetQuantizationOffset(5); + outputTensorInfo.SetQuantizationScale(0.5f); + outputTensorInfo.SetQuantizationOffset(5); + } + + std::vector<T> input = std::vector<T>( + { + 1, 2, + 3, 4, + 5, 6, + 7, 8 + }); + + std::vector<T> outputExpected = std::vector<T>( + { + 1, 5, 2, 6, + 3, 7, 4, 8 + }); + + return SimplePermuteTestImpl<T>(workloadFactory, memoryManager, + descriptor, inputTensorInfo, + outputTensorInfo, input, outputExpected); } -LayerTestResult<uint8_t, 4> SimplePermuteUint8TestCommon( - armnn::IWorkloadFactory& workloadFactory, - const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) -{ - armnn::TensorInfo inputTensorInfo; - armnn::TensorInfo outputTensorInfo; - - unsigned int inputShape[] = { 1, 2, 2, 2 }; - unsigned int outputShape[] = { 1, 2, 2, 2 }; - - armnn::PermuteDescriptor descriptor; - descriptor.m_DimMappings = {0U, 3U, 1U, 2U}; - - inputTensorInfo = armnn::TensorInfo(4, inputShape, armnn::DataType::QuantisedAsymm8); - inputTensorInfo.SetQuantizationScale(1.0f); - outputTensorInfo = armnn::TensorInfo(4, outputShape, armnn::DataType::QuantisedAsymm8); - outputTensorInfo.SetQuantizationScale(1.0f); - - std::vector<uint8_t> input = std::vector<uint8_t>( - { - 1, 2, - 3, 4, - - 5, 6, - 7, 8 - }); - - std::vector<uint8_t> outputExpected = std::vector<uint8_t>( - { - 1, 5, 2, 6, - 3, 7, 4, 8 - }); - - return SimplePermuteTestImpl<uint8_t>(workloadFactory, memoryManager, - descriptor, inputTensorInfo, - outputTensorInfo, input, outputExpected); -} - -LayerTestResult<float, 4> -PermuteFloat32ValueSet1TestCommon( +template<armnn::DataType ArmnnType, typename T = armnn::ResolveType<ArmnnType>> +LayerTestResult<T, 4> PermuteValueSet1Test( armnn::IWorkloadFactory& workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) { @@ -143,31 +114,40 @@ PermuteFloat32ValueSet1TestCommon( armnn::PermuteDescriptor descriptor; descriptor.m_DimMappings = {0U, 2U, 3U, 1U}; - inputTensorInfo = armnn::TensorInfo(4, inputShape, armnn::DataType::Float32); - outputTensorInfo = armnn::TensorInfo(4, outputShape, armnn::DataType::Float32); - - std::vector<float> input = std::vector<float>( - { - 1.0f, 2.0f, 3.0f, - 11.0f, 12.0f, 13.0f, - 21.0f, 22.0f, 23.0f, - 31.0f, 32.0f, 33.0f, - }); - - std::vector<float> outputExpected = std::vector<float>( - { - 1.0f, 11.0f, 21.0f, 31.0f, - 2.0f, 12.0f, 22.0f, 32.0f, - 3.0f, 13.0f, 23.0f, 33.0f, - }); - - return SimplePermuteTestImpl<float>(workloadFactory, memoryManager, - descriptor, inputTensorInfo, - outputTensorInfo, input, outputExpected); + inputTensorInfo = armnn::TensorInfo(4, inputShape, ArmnnType); + outputTensorInfo = armnn::TensorInfo(4, outputShape, ArmnnType); + + // Set quantization parameters if the requested type is a quantized type. + if(armnn::IsQuantizedType<T>()) + { + inputTensorInfo.SetQuantizationScale(0.5f); + inputTensorInfo.SetQuantizationOffset(5); + outputTensorInfo.SetQuantizationScale(0.5f); + outputTensorInfo.SetQuantizationOffset(5); + } + + std::vector<T> input = std::vector<T>( + { + 1, 2, 3, + 11, 12, 13, + 21, 22, 23, + 31, 32, 33 + }); + + std::vector<T> outputExpected = std::vector<T>( + { + 1, 11, 21, 31, + 2, 12, 22, 32, + 3, 13, 23, 33 + }); + + return SimplePermuteTestImpl<T>(workloadFactory, memoryManager, + descriptor, inputTensorInfo, + outputTensorInfo, input, outputExpected); } -LayerTestResult<float, 4> -PermuteFloat32ValueSet2TestCommon( +template<armnn::DataType ArmnnType, typename T = armnn::ResolveType<ArmnnType>> +LayerTestResult<T, 4> PermuteValueSet2Test( armnn::IWorkloadFactory& workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) { @@ -180,31 +160,40 @@ PermuteFloat32ValueSet2TestCommon( armnn::PermuteDescriptor descriptor; descriptor.m_DimMappings = {0U, 3U, 1U, 2U}; - inputTensorInfo = armnn::TensorInfo(4, inputShape, armnn::DataType::Float32); - outputTensorInfo = armnn::TensorInfo(4, outputShape, armnn::DataType::Float32); - - std::vector<float> input = std::vector<float>( - { - 1.0f, 11.0f, 21.0f, 31.0f, - 2.0f, 12.0f, 22.0f, 32.0f, - 3.0f, 13.0f, 23.0f, 33.0f, - }); - - std::vector<float> outputExpected = std::vector<float>( - { - 1.0f, 2.0f, 3.0f, - 11.0f, 12.0f, 13.0f, - 21.0f, 22.0f, 23.0f, - 31.0f, 32.0f, 33.0f, - }); - - return SimplePermuteTestImpl<float>(workloadFactory, memoryManager, - descriptor, inputTensorInfo, - outputTensorInfo, input, outputExpected); + inputTensorInfo = armnn::TensorInfo(4, inputShape, ArmnnType); + outputTensorInfo = armnn::TensorInfo(4, outputShape, ArmnnType); + + // Set quantization parameters if the requested type is a quantized type. + if(armnn::IsQuantizedType<T>()) + { + inputTensorInfo.SetQuantizationScale(0.5f); + inputTensorInfo.SetQuantizationOffset(5); + outputTensorInfo.SetQuantizationScale(0.5f); + outputTensorInfo.SetQuantizationOffset(5); + } + + std::vector<T> input = std::vector<T>( + { + 1, 11, 21, 31, + 2, 12, 22, 32, + 3, 13, 23, 33 + }); + + std::vector<T> outputExpected = std::vector<T>( + { + 1, 2, 3, + 11, 12, 13, + 21, 22, 23, + 31, 32, 33, + }); + + return SimplePermuteTestImpl<T>(workloadFactory, memoryManager, + descriptor, inputTensorInfo, + outputTensorInfo, input, outputExpected); } -LayerTestResult<float, 4> -PermuteFloat32ValueSet3TestCommon( +template<armnn::DataType ArmnnType, typename T = armnn::ResolveType<ArmnnType>> +LayerTestResult<T, 4> PermuteValueSet3Test( armnn::IWorkloadFactory& workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) { @@ -217,27 +206,36 @@ PermuteFloat32ValueSet3TestCommon( armnn::PermuteDescriptor descriptor; descriptor.m_DimMappings = {0U, 2U, 3U, 1U}; - inputTensorInfo = armnn::TensorInfo(4, inputShape, armnn::DataType::Float32); - outputTensorInfo = armnn::TensorInfo(4, outputShape, armnn::DataType::Float32); + inputTensorInfo = armnn::TensorInfo(4, inputShape, ArmnnType); + outputTensorInfo = armnn::TensorInfo(4, outputShape, ArmnnType); + + // Set quantization parameters if the requested type is a quantized type. + if(armnn::IsQuantizedType<T>()) + { + inputTensorInfo.SetQuantizationScale(0.5f); + inputTensorInfo.SetQuantizationOffset(5); + outputTensorInfo.SetQuantizationScale(0.5f); + outputTensorInfo.SetQuantizationOffset(5); + } - std::vector<float> input = std::vector<float>( + std::vector<T> input = std::vector<T>( { - 1.0f, 2.0f, 3.0f, - 11.0f, 12.0f, 13.0f, - 21.0f, 22.0f, 23.0f, - 31.0f, 32.0f, 33.0f, - 41.0f, 42.0f, 43.0f, - 51.0f, 52.0f, 53.0f, + 1, 2, 3, + 11, 12, 13, + 21, 22, 23, + 31, 32, 33, + 41, 42, 43, + 51, 52, 53 }); - std::vector<float> outputExpected = std::vector<float>( + std::vector<T> outputExpected = std::vector<T>( { - 1.0f, 11.0f, 21.0f, 31.0f, 41.0f, 51.0f, - 2.0f, 12.0f, 22.0f, 32.0f, 42.0f, 52.0f, - 3.0f, 13.0f, 23.0f, 33.0f, 43.0f, 53.0f, + 1, 11, 21, 31, 41, 51, + 2, 12, 22, 32, 42, 52, + 3, 13, 23, 33, 43, 53 }); - return SimplePermuteTestImpl<float>(workloadFactory, memoryManager, - descriptor, inputTensorInfo, - outputTensorInfo, input, outputExpected); + return SimplePermuteTestImpl<T>(workloadFactory, memoryManager, + descriptor, inputTensorInfo, + outputTensorInfo, input, outputExpected); } |