From 369d8fcd93213e37781a58fb9805a59bf14691db Mon Sep 17 00:00:00 2001 From: Nikhil Raj Date: Thu, 24 Nov 2022 13:12:36 +0000 Subject: IVGCVSW-4926 Add support in CpuRef implementation for Gather for axis different to 0 !android-nn-driver:8727 Signed-off-by: Nikhil Raj Signed-off-by: Matthew Sloyan Signed-off-by: Teresa Charlin Change-Id: I4336007ad5a8552f7893ce6253f93cf9d1f5474f --- .../test/layerTests/GatherTestImpl.cpp | 219 ++++++++++++++++++++- .../test/layerTests/GatherTestImpl.hpp | 17 +- 2 files changed, 230 insertions(+), 6 deletions(-) (limited to 'src/backends/backendsCommon/test/layerTests') diff --git a/src/backends/backendsCommon/test/layerTests/GatherTestImpl.cpp b/src/backends/backendsCommon/test/layerTests/GatherTestImpl.cpp index 73da4baca4..4434b0f0c7 100644 --- a/src/backends/backendsCommon/test/layerTests/GatherTestImpl.cpp +++ b/src/backends/backendsCommon/test/layerTests/GatherTestImpl.cpp @@ -1,5 +1,5 @@ // -// Copyright © 2017 Arm Ltd and Contributors. All rights reserved. +// Copyright © 2017,2022 Arm Ltd and Contributors. All rights reserved. // SPDX-License-Identifier: MIT // @@ -7,11 +7,10 @@ #include - #include #include - #include +#include namespace { @@ -30,7 +29,8 @@ LayerTestResult GatherTestImpl( const armnn::TensorInfo& outputInfo, const std::vector& paramsData, const std::vector& indicesData, - const std::vector& outputData) + const std::vector& outputData, + armnn::GatherDescriptor descriptor= armnn::GatherDescriptor()) { IgnoreUnused(memoryManager); @@ -41,6 +41,7 @@ LayerTestResult GatherTestImpl( std::unique_ptr outputHandle = tensorHandleFactory.CreateTensorHandle(outputInfo); armnn::GatherQueueDescriptor data; + data.m_Parameters = std::move(descriptor); armnn::WorkloadInfo info; AddInputToWorkload(data, info, paramsInfo, paramsHandle.get()); AddInputToWorkload(data, info, indicesInfo, indicesHandle.get()); @@ -100,6 +101,47 @@ struct GatherTestHelper expectedOutput); } + static LayerTestResult Gather1dParamsAxisTestImpl( + armnn::IWorkloadFactory& workloadFactory, + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, + const armnn::ITensorHandleFactory& tensorHandleFactory) + { + armnn::GatherDescriptor descriptor; + descriptor.m_Axis=1; + armnn::TensorInfo paramsInfo({ 4, 3 }, ArmnnType); + armnn::TensorInfo indicesInfo({ 2 }, armnn::DataType::Signed32); + armnn::TensorInfo outputInfo({ 4, 2 }, ArmnnType); + + if (armnn::IsQuantizedType()) + { + paramsInfo.SetQuantizationScale(1.0f); + paramsInfo.SetQuantizationOffset(1); + outputInfo.SetQuantizationScale(1.0f); + outputInfo.SetQuantizationOffset(1); + } + const std::vector params ={ 10, 11, 12, + 110, 111, 112, + 120, 121, 122, + 130, 131, 132 }; + const std::vector indices = std::vector({ 2, 1 }); + const std::vector expectedOutput = { 12, 11, + 112, 111, + 122, 121, + 132, 131 } ; + + return GatherTestImpl( + workloadFactory, + memoryManager, + tensorHandleFactory, + paramsInfo, + indicesInfo, + outputInfo, + params, + indices, + expectedOutput, + descriptor); + } + static LayerTestResult GatherMultiDimParamsTestImpl( armnn::IWorkloadFactory& workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, @@ -138,7 +180,7 @@ struct GatherTestHelper const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, const armnn::ITensorHandleFactory& tensorHandleFactory) { - armnn::TensorInfo paramsInfo({ 3, 2, 3}, ArmnnType); + armnn::TensorInfo paramsInfo({ 3, 2, 3 }, ArmnnType); armnn::TensorInfo indicesInfo({ 2, 3 }, armnn::DataType::Signed32); armnn::TensorInfo outputInfo({ 2, 3, 2, 3 }, ArmnnType); @@ -192,6 +234,146 @@ struct GatherTestHelper indices, expectedOutput); } + + static LayerTestResult GatherMultiDimParamsMultiDimIndicesAxis1TestImpl( + armnn::IWorkloadFactory& workloadFactory, + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, + const armnn::ITensorHandleFactory& tensorHandleFactory) + { + armnn::GatherDescriptor descriptor; + descriptor.m_Axis=1; + armnn::TensorInfo paramsInfo({ 3, 2, 3 }, ArmnnType); + armnn::TensorInfo indicesInfo({ 2, 3 }, armnn::DataType::Signed32); + armnn::TensorInfo outputInfo({ 3, 2, 3, 3 }, ArmnnType); + + if (armnn::IsQuantizedType()) + { + paramsInfo.SetQuantizationScale(1.0f); + paramsInfo.SetQuantizationOffset(1); + outputInfo.SetQuantizationScale(1.0f); + outputInfo.SetQuantizationOffset(1); + } + + const std::vector params = + { + 1, 2, 3, + 4, 5, 6, + + 7, 8, 9, + 10, 11, 12, + + 13, 14, 15, + 16, 17, 18 + }; + + const std::vector indices = { 1, 0, 1, 0, 1, 0 }; + + const std::vector expectedOutput = + { + 4, 5, 6, + 1, 2, 3, + 4, 5, 6, + + 1, 2, 3, + 4, 5, 6, + 1, 2, 3, + + 10, 11, 12, + 7, 8, 9, + 10, 11, 12, + + 7, 8, 9, + 10, 11, 12, + 7, 8, 9, + + 16, 17, 18, + 13, 14, 15, + 16, 17, 18, + + 13, 14, 15, + 16, 17, 18, + 13, 14, 15 + }; + + return GatherTestImpl( + workloadFactory, + memoryManager, + tensorHandleFactory, + paramsInfo, + indicesInfo, + outputInfo, + params, + indices, + expectedOutput, + descriptor); + } + + static LayerTestResult GatherMultiDimParamsMultiDimIndicesAxis2TestImpl( + armnn::IWorkloadFactory& workloadFactory, + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, + const armnn::ITensorHandleFactory& tensorHandleFactory) + { + armnn::GatherDescriptor descriptor; + descriptor.m_Axis=2; + armnn::TensorInfo paramsInfo({ 3, 2, 3 }, ArmnnType); + armnn::TensorInfo indicesInfo({ 2, 3 }, armnn::DataType::Signed32); + armnn::TensorInfo outputInfo({ 3, 2, 2, 3 }, ArmnnType); + + if (armnn::IsQuantizedType()) + { + paramsInfo.SetQuantizationScale(1.0f); + paramsInfo.SetQuantizationOffset(1); + outputInfo.SetQuantizationScale(1.0f); + outputInfo.SetQuantizationOffset(1); + } + + const std::vector params = + { + 1, 2, 3, + 4, 5, 6, + + 7, 8, 9, + 10, 11, 12, + + 13, 14, 15, + 16, 17, 18 + }; + + const std::vector indices = { 1, 2, 1, 2, 1, 0 }; + + const std::vector expectedOutput = + { + 2, 3, 2, + 3, 2, 1, + + 5, 6, 5, + 6, 5, 4, + + 8, 9, 8, + 9, 8, 7, + + 11, 12, 11, + 12, 11, 10, + + 14, 15, 14, + 15, 14, 13, + + 17, 18, 17, + 18, 17, 16 + }; + + return GatherTestImpl( + workloadFactory, + memoryManager, + tensorHandleFactory, + paramsInfo, + indicesInfo, + outputInfo, + params, + indices, + expectedOutput, + descriptor); + } }; template @@ -318,6 +500,15 @@ LayerTestResult Gather1dParamsFloat32Test( workloadFactory, memoryManager, tensorHandleFactory); } +LayerTestResult Gather1dParamsAxisTest( + armnn::IWorkloadFactory& workloadFactory, + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, + const armnn::ITensorHandleFactory& tensorHandleFactory) +{ + return GatherTestHelper::Gather1dParamsAxisTestImpl( + workloadFactory, memoryManager, tensorHandleFactory); +} + LayerTestResult Gather1dParamsFloat16Test( armnn::IWorkloadFactory& workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, @@ -408,6 +599,24 @@ LayerTestResult GatherMultiDimParamsMultiDimIndicesFloat32Test( workloadFactory, memoryManager, tensorHandleFactory); } +LayerTestResult GatherMultiDimParamsMultiDimIndicesAxis1Test( + armnn::IWorkloadFactory& workloadFactory, + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, + const armnn::ITensorHandleFactory& tensorHandleFactory) +{ + return GatherTestHelper::GatherMultiDimParamsMultiDimIndicesAxis1TestImpl( + workloadFactory, memoryManager, tensorHandleFactory); +} + +LayerTestResult GatherMultiDimParamsMultiDimIndicesAxis2Test( + armnn::IWorkloadFactory& workloadFactory, + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, + const armnn::ITensorHandleFactory& tensorHandleFactory) +{ + return GatherTestHelper::GatherMultiDimParamsMultiDimIndicesAxis2TestImpl( + workloadFactory, memoryManager, tensorHandleFactory); +} + LayerTestResult GatherMultiDimParamsMultiDimIndicesFloat16Test( armnn::IWorkloadFactory& workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, diff --git a/src/backends/backendsCommon/test/layerTests/GatherTestImpl.hpp b/src/backends/backendsCommon/test/layerTests/GatherTestImpl.hpp index 92b63e50b5..6f6a01364a 100644 --- a/src/backends/backendsCommon/test/layerTests/GatherTestImpl.hpp +++ b/src/backends/backendsCommon/test/layerTests/GatherTestImpl.hpp @@ -1,5 +1,5 @@ // -// Copyright © 2017 Arm Ltd. All rights reserved. +// Copyright © 2017,2022 Arm Ltd and Contributors. All rights reserved. // SPDX-License-Identifier: MIT // @@ -17,6 +17,11 @@ LayerTestResult Gather1dParamsFloat32Test( const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, const armnn::ITensorHandleFactory& tensorHandleFactory); +LayerTestResult Gather1dParamsAxisTest( + armnn::IWorkloadFactory& workloadFactory, + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, + const armnn::ITensorHandleFactory& tensorHandleFactory); + LayerTestResult Gather1dParamsFloat16Test( armnn::IWorkloadFactory& workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, @@ -67,6 +72,16 @@ LayerTestResult GatherMultiDimParamsMultiDimIndicesFloat32Test( const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, const armnn::ITensorHandleFactory& tensorHandleFactory); +LayerTestResult GatherMultiDimParamsMultiDimIndicesAxis1Test( + armnn::IWorkloadFactory& workloadFactory, + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, + const armnn::ITensorHandleFactory& tensorHandleFactory); + +LayerTestResult GatherMultiDimParamsMultiDimIndicesAxis2Test( + armnn::IWorkloadFactory& workloadFactory, + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, + const armnn::ITensorHandleFactory& tensorHandleFactory); + LayerTestResult GatherMultiDimParamsMultiDimIndicesFloat16Test( armnn::IWorkloadFactory& workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, -- cgit v1.2.1