From 57f13d5905a1fbdc89b53d68b2bdc6b753b9e8d5 Mon Sep 17 00:00:00 2001 From: Francis Murtagh Date: Mon, 24 Jun 2019 14:24:36 +0100 Subject: IVGCVSW-3334 Refactor BatchToSpace tests to be generic * Generify and reformat test BatchToSpace tests * Add missing RefCreateWorkload test Change-Id: I08af018c07ee41df5b9d1e578d99bc03f38090ac Signed-off-by: Francis Murtagh --- src/backends/backendsCommon/test/LayerTests.cpp | 432 --------------------- src/backends/backendsCommon/test/LayerTests.hpp | 475 +++++++++++++++++++++++- 2 files changed, 461 insertions(+), 446 deletions(-) (limited to 'src/backends/backendsCommon/test') diff --git a/src/backends/backendsCommon/test/LayerTests.cpp b/src/backends/backendsCommon/test/LayerTests.cpp index c9a5731190..64b9676a4b 100644 --- a/src/backends/backendsCommon/test/LayerTests.cpp +++ b/src/backends/backendsCommon/test/LayerTests.cpp @@ -9290,440 +9290,8 @@ LayerTestResult SpaceToDepthNCHWFloat32Test( namespace { -template -LayerTestResult BatchToSpaceNdHelper( - armnn::IWorkloadFactory &workloadFactory, - const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, - const armnn::DataLayout& dataLayout, - const unsigned int *inputShape, - const std::vector &inputData, - const std::vector &blockShape, - const std::vector> &crops, - const unsigned int *outputShape, - const std::vector &outputData, - float scale = 1.0f, - int32_t offset = 0) -{ - auto dataType = (std::is_same::value ? armnn::DataType::QuantisedAsymm8 : armnn::DataType::Float32); - - armnn::TensorInfo inputTensorInfo(InputDim, inputShape, dataType); - armnn::TensorInfo outputTensorInfo(OutputDim, outputShape, dataType); - - inputTensorInfo.SetQuantizationScale(scale); - inputTensorInfo.SetQuantizationOffset(offset); - - outputTensorInfo.SetQuantizationScale(scale); - outputTensorInfo.SetQuantizationOffset(offset); - - auto input = MakeTensor(inputTensorInfo, inputData); - - LayerTestResult result(outputTensorInfo); - result.outputExpected = MakeTensor(outputTensorInfo, outputData); - - std::unique_ptr inputHandle = workloadFactory.CreateTensorHandle(inputTensorInfo); - std::unique_ptr outputHandle = workloadFactory.CreateTensorHandle(outputTensorInfo); - - armnn::BatchToSpaceNdQueueDescriptor data; - data.m_Parameters.m_DataLayout = dataLayout; - data.m_Parameters.m_BlockShape = blockShape; - data.m_Parameters.m_Crops = crops; - armnn::WorkloadInfo info; - AddInputToWorkload(data, info, inputTensorInfo, inputHandle.get()); - AddOutputToWorkload(data, info, outputTensorInfo, outputHandle.get()); - - std::unique_ptr workload = workloadFactory.CreateBatchToSpaceNd(data, info); - - inputHandle->Allocate(); - outputHandle->Allocate(); - - CopyDataToITensorHandle(inputHandle.get(), input.origin()); - - workload->PostAllocationConfigure(); - workload->Execute(); - - CopyDataFromITensorHandle(&result.output[0][0][0][0], outputHandle.get()); - - return result; -} - } // anonymous namespace -LayerTestResult BatchToSpaceNdNhwcFloat32Test1( - armnn::IWorkloadFactory& workloadFactory, - const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) -{ - const unsigned int inputShape[] = {4, 2, 2, 1}; - const unsigned int outputShape[] = {1, 4, 4, 1}; - - std::vector input({ - // Batch 0, Height 0, Width (2) x Channel (1) - 1.0f, 3.0f, - // Batch 0, Height 1, Width (2) x Channel (1) - 9.0f, 11.0f, - - - // Batch 1, Height 0, Width (2) x Channel (1) - 2.0f, 4.0f, - // Batch 1, Height 1, Width (2) x Channel (1) - 10.0f, 12.0f, - - - // Batch 2, Height 0, Width (2) x Channel (1) - 5.0f, 7.0f, - // Batch 2, Height 1, Width (2) x Channel (1) - 13.0f, 15.0f, - - // Batch 3, Height 0, Width (2) x Channel (3) - 6.0f, 8.0f, - // Batch 3, Height 1, Width (2) x Channel (1) - 14.0f, 16.0f - }); - - std::vector expectedOutput({ - 1.0f, 2.0f, 3.0f, 4.0f, - 5.0f, 6.0f, 7.0f, 8.0f, - 9.0f, 10.0f, 11.0f, 12.0f, - 13.0f, 14.0f, 15.0f, 16.0f - }); - - std::vector blockShape {2, 2}; - std::vector> crops = {{0, 0}, {0, 0}}; - - return BatchToSpaceNdHelper(workloadFactory, memoryManager, - armnn::DataLayout::NHWC, inputShape, input, blockShape, - crops, outputShape, expectedOutput); -} - -LayerTestResult BatchToSpaceNdNhwcFloat32Test2( - armnn::IWorkloadFactory& workloadFactory, - const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) -{ - const unsigned int inputShape[] = {4, 1, 1, 1}; - const unsigned int outputShape[] = {1, 2, 2, 1}; - - std::vector input({ - // Batch 0, Height 0, Width (2) x Channel (1) - 1.0f, 2.0f, 3.0f, 4.0f - }); - - std::vector expectedOutput({1.0f, 2.0f, 3.0f, 4.0f}); - - std::vector blockShape({2, 2}); - std::vector> crops = {{0, 0}, {0, 0}}; - - return BatchToSpaceNdHelper(workloadFactory, memoryManager, - armnn::DataLayout::NHWC, inputShape, input, blockShape, - crops, outputShape, expectedOutput); -} - -LayerTestResult BatchToSpaceNdNhwcFloat32Test3( - armnn::IWorkloadFactory& workloadFactory, - const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) -{ - const unsigned int inputShape[] = {4, 1, 1, 3}; - const unsigned int outputShape[] = {1, 2, 2, 3}; - - std::vector input({1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, 11.0f, 12.0f}); - - std::vector expectedOutput({1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, 11.0f, 12.0f}); - - std::vector blockShape({2, 2}); - std::vector> crops = {{0, 0}, {0, 0}}; - - return BatchToSpaceNdHelper(workloadFactory, memoryManager, - armnn::DataLayout::NHWC, inputShape, input, blockShape, - crops, outputShape, expectedOutput); -} - -LayerTestResult BatchToSpaceNdNhwcFloat32Test4( - armnn::IWorkloadFactory& workloadFactory, - const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) -{ - const unsigned int inputShape[] = {8, 1, 3, 1}; - const unsigned int outputShape[] = {2, 2, 4, 1}; - - std::vector input({ - 0.0f, 1.0f, 3.0f, - 0.0f, 9.0f, 11.0f, - 0.0f, 2.0f, 4.0f, - 0.0f, 10.0f, 12.0f, - 0.0f, 5.0f, 7.0f, - 0.0f, 13.0f, 15.0f, - 0.0f, 6.0f, 8.0f, - 0.0f, 14.0f, 16.0f - }); - - std::vector expectedOutput({ - 1.0f, 2.0f, 3.0f, 4.0f, - 5.0f, 6.0f, 7.0f, 8.0f, - 9.0f, 10.0f, 11.0f, 12.0f, - 13.0f, 14.0f, 15.0f, 16.0f - }); - - std::vector blockShape({2, 2}); - std::vector> crops = {{0, 0}, {2, 0}}; - - return BatchToSpaceNdHelper(workloadFactory, memoryManager, - armnn::DataLayout::NHWC, inputShape, input, blockShape, - crops, outputShape, expectedOutput); -} - -LayerTestResult BatchToSpaceNdNchwFloat32Test1( - armnn::IWorkloadFactory &workloadFactory, - const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) -{ - const unsigned int inputShape[] = {4, 3, 1, 1}; - const unsigned int outputShape[] = {1, 3, 2, 2}; - - std::vector input({1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, 11.0f, 12.0f}); - - std::vector expectedOutput({ - // Batch 0, Channel 0, Height (2) x Width (2) - 1.0f, 4.0f, - 7.0f, 10.0f, - - // Batch 0, Channel 1, Height (2) x Width (2) - 2.0f, 5.0f, - 8.0f, 11.0f, - - // Batch 0, Channel 2, Height (2) x Width (2) - 3.0f, 6.0f, - 9.0f, 12.0f, - }); - - std::vector blockShape({2, 2}); - std::vector> crops = {{0, 0}, {0, 0}}; - - return BatchToSpaceNdHelper(workloadFactory, memoryManager, - armnn::DataLayout::NCHW, inputShape, input, blockShape, - crops, outputShape, expectedOutput); -} - -LayerTestResult BatchToSpaceNdNchwFloat32Test2( - armnn::IWorkloadFactory& workloadFactory, - const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) -{ - const unsigned int inputShape[] = {4, 1, 1, 1}; - const unsigned int outputShape[] = {1, 1, 2, 2}; - - std::vector input({ - // Batch 0, Height 0, Width (2) x Channel (1) - 1.0f, 2.0f, 3.0f, 4.0f - }); - - std::vector expectedOutput({1.0f, 2.0f, 3.0f, 4.0f}); - - std::vector blockShape({2, 2}); - std::vector> crops = {{0, 0}, {0, 0}}; - - return BatchToSpaceNdHelper(workloadFactory, memoryManager, - armnn::DataLayout::NCHW, inputShape, input, blockShape, - crops, outputShape, expectedOutput); -} - -LayerTestResult BatchToSpaceNdNchwFloat32Test3( - armnn::IWorkloadFactory& workloadFactory, - const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) -{ - const unsigned int inputShape[] = {4, 3, 1, 1}; - const unsigned int outputShape[] = {1, 3, 2, 2}; - - std::vector input({1.0f, 3.0f, 5.0f, 7.0f, 9.0f, 11.0f, 2.0f, 4.0f, 6.0f, 8.0f, 10.0f, 12.0f}); - - std::vector expectedOutput({ - // Batch 0, Channel 0, Height (2) x Width (2) - 1.0f, 7.0f, - 2.0f, 8.0f, - - // Batch 0, Channel 1, Height (2) x Width (2) - 3.0f, 9.0f, - 4.0f, 10.0f, - - // Batch 0, Channel 2, Height (2) x Width (2) - 5.0f, 11.0f, - 6.0f, 12.0f, - }); - - std::vector blockShape({2, 2}); - std::vector> crops = {{0, 0}, {0, 0}}; - - return BatchToSpaceNdHelper(workloadFactory, memoryManager, - armnn::DataLayout::NCHW, inputShape, input, blockShape, - crops, outputShape, expectedOutput); -} - -LayerTestResult BatchToSpaceNdNhwcUintTest1( - armnn::IWorkloadFactory& workloadFactory, - const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) -{ - const unsigned int inputShape[] = {4, 2, 2, 1}; - const unsigned int outputShape[] = {1, 4, 4, 1}; - - std::vector input({1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}); - std::vector expectedOutput({1, 5, 2, 6, 9, 13, 10, 14, 3, 7, 4, 8, 11, 15, 12, 16}); - - std::vector blockShape({2, 2}); - std::vector> crops = {{0, 0}, {0, 0}}; - - return BatchToSpaceNdHelper(workloadFactory, memoryManager, armnn::DataLayout::NHWC, inputShape, - input, blockShape, crops, outputShape, expectedOutput); -} - -LayerTestResult BatchToSpaceNdNhwcUintTest2( - armnn::IWorkloadFactory& workloadFactory, - const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) -{ - const unsigned int inputShape[] = {4, 1, 1, 1}; - const unsigned int outputShape[] = {1, 2, 2, 1}; - - std::vector input({ - // Batch 0, Height 0, Width (2) x Channel (1) - 1, 2, 3, 4 - }); - - std::vector expectedOutput({1, 2, 3, 4}); - - std::vector blockShape({2, 2}); - std::vector> crops = {{0, 0}, {0, 0}}; - - return BatchToSpaceNdHelper(workloadFactory, memoryManager, - armnn::DataLayout::NHWC, inputShape, input, blockShape, - crops, outputShape, expectedOutput); -} - -LayerTestResult BatchToSpaceNdNhwcUintTest3( - armnn::IWorkloadFactory& workloadFactory, - const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) -{ - const unsigned int inputShape[] = {4, 1, 1, 3}; - const unsigned int outputShape[] = {1, 2, 2, 3}; - - std::vector input({1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}); - - std::vector expectedOutput({1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}); - - std::vector blockShape({2, 2}); - std::vector> crops = {{0, 0}, {0, 0}}; - - return BatchToSpaceNdHelper(workloadFactory, memoryManager, - armnn::DataLayout::NHWC, inputShape, input, blockShape, - crops, outputShape, expectedOutput); -} - - -LayerTestResult BatchToSpaceNdNchwUintTest1( - armnn::IWorkloadFactory &workloadFactory, - const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) -{ - const unsigned int inputShape[] = {4, 3, 1, 1}; - const unsigned int outputShape[] = {1, 3, 2, 2}; - - std::vector input({1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}); - - std::vector expectedOutput({ - // Batch 0, Channel 0, Height (2) x Width (2) - 1, 4, - 7, 10, - - // Batch 0, Channel 1, Height (2) x Width (2) - 2, 5, - 8, 11, - - // Batch 0, Channel 2, Height (2) x Width (2) - 3, 6, - 9, 12, - }); - - std::vector blockShape({2, 2}); - std::vector> crops = {{0, 0}, {0, 0}}; - - return BatchToSpaceNdHelper(workloadFactory, memoryManager, - armnn::DataLayout::NCHW, inputShape, input, blockShape, - crops, outputShape, expectedOutput); -} - -LayerTestResult BatchToSpaceNdNchwUintTest2( - armnn::IWorkloadFactory& workloadFactory, - const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) -{ - const unsigned int inputShape[] = {4, 1, 1, 1}; - const unsigned int outputShape[] = {1, 1, 2, 2}; - - std::vector input({ - // Batch 0, Height 0, Width (2) x Channel (1) - 1, 2, 3, 4 - }); - - std::vector expectedOutput({1, 2, 3, 4}); - - std::vector blockShape({2, 2}); - std::vector> crops = {{0, 0}, {0, 0}}; - - return BatchToSpaceNdHelper(workloadFactory, memoryManager, - armnn::DataLayout::NCHW, inputShape, input, blockShape, - crops, outputShape, expectedOutput); -} - -LayerTestResult BatchToSpaceNdNchwUintTest3( - armnn::IWorkloadFactory& workloadFactory, - const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) -{ - const unsigned int inputShape[] = {4, 3, 1, 1}; - const unsigned int outputShape[] = {1, 3, 2, 2}; - - std::vector input({1, 3, 5, 7, 9, 11, 2, 4, 6, 8, 10, 12}); - - std::vector expectedOutput({ - // Batch 0, Channel 0, Height (2) x Width (2) - 1, 7, - 2, 8, - - // Batch 0, Channel 1, Height (2) x Width (2) - 3, 9, - 4, 10, - - // Batch 0, Channel 2, Height (2) x Width (2) - 5, 11, - 6, 12, - }); - - std::vector blockShape({2, 2}); - std::vector> crops = {{0, 0}, {0, 0}}; - - return BatchToSpaceNdHelper(workloadFactory, memoryManager, - armnn::DataLayout::NCHW, inputShape, input, blockShape, - crops, outputShape, expectedOutput); -} - -LayerTestResult BatchToSpaceNdNchwUintTest4( - armnn::IWorkloadFactory& workloadFactory, - const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) -{ - const unsigned int inputShape[] = {8, 1, 1, 3}; - const unsigned int outputShape[] = {2, 1, 2, 4}; - - std::vector input({ - 0, 1, 3, 0, 9, 11, - 0, 2, 4, 0, 10, 12, - 0, 5, 7, 0, 13, 15, - 0, 6, 8, 0, 14, 16 - }); - - std::vector expectedOutput({ - 1, 2, 3, 4, - 5, 6, 7, 8, - 9, 10, 11, 12, - 13, 14, 15, 16 - }); - - std::vector blockShape({2, 2}); - std::vector> crops = {{0, 0}, {2, 0}}; - - return BatchToSpaceNdHelper(workloadFactory, memoryManager, - armnn::DataLayout::NCHW, inputShape, input, blockShape, - crops, outputShape, expectedOutput); -} - LayerTestResult StridedSlice4DFloat32Test( armnn::IWorkloadFactory& workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) diff --git a/src/backends/backendsCommon/test/LayerTests.hpp b/src/backends/backendsCommon/test/LayerTests.hpp index be16819990..77adca1ac7 100644 --- a/src/backends/backendsCommon/test/LayerTests.hpp +++ b/src/backends/backendsCommon/test/LayerTests.hpp @@ -1653,59 +1653,59 @@ LayerTestResult SpaceToBatchNdPaddingNHWCUint16Test( armnn::IWorkloadFactory& workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager); -LayerTestResult BatchToSpaceNdNhwcFloat32Test1( +LayerTestResult BatchToSpaceNdNhwcTest1( armnn::IWorkloadFactory& workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager); -LayerTestResult BatchToSpaceNdNhwcFloat32Test2( +LayerTestResult BatchToSpaceNdNhwcTest2( armnn::IWorkloadFactory& workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager); -LayerTestResult BatchToSpaceNdNhwcFloat32Test3( +LayerTestResult BatchToSpaceNdNhwcTest3( armnn::IWorkloadFactory& workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager); -LayerTestResult BatchToSpaceNdNhwcFloat32Test4( +LayerTestResult BatchToSpaceNdNhwcTest4( armnn::IWorkloadFactory& workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager); -LayerTestResult BatchToSpaceNdNchwFloat32Test1( +LayerTestResult BatchToSpaceNdNchwTest1( armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager); -LayerTestResult BatchToSpaceNdNchwFloat32Test2( +LayerTestResult BatchToSpaceNdNchwTest2( armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager); -LayerTestResult BatchToSpaceNdNchwFloat32Test3( +LayerTestResult BatchToSpaceNdNchwTest3( armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager); -LayerTestResult BatchToSpaceNdNhwcUintTest1( +LayerTestResult BatchToSpaceNdNhwcTest5( armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager); -LayerTestResult BatchToSpaceNdNhwcUintTest2( +LayerTestResult BatchToSpaceNdNhwcTest6( armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager); -LayerTestResult BatchToSpaceNdNhwcUintTest3( +LayerTestResult BatchToSpaceNdNhwcTest7( armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager); -LayerTestResult BatchToSpaceNdNchwUintTest1( +LayerTestResult BatchToSpaceNdNchwTest4( armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager); -LayerTestResult BatchToSpaceNdNchwUintTest2( +LayerTestResult BatchToSpaceNdNchwTest5( armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager); -LayerTestResult BatchToSpaceNdNchwUintTest3( +LayerTestResult BatchToSpaceNdNchwTest6( armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager); -LayerTestResult BatchToSpaceNdNchwUintTest4( +LayerTestResult BatchToSpaceNdNchwTest7( armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager); @@ -3287,6 +3287,453 @@ LayerTestResult PreluTest( return result; } +template> +LayerTestResult BatchToSpaceNdHelper( + armnn::IWorkloadFactory &workloadFactory, + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, + const armnn::DataLayout& dataLayout, + const unsigned int *inputShape, + const std::vector &inputData, + const std::vector &blockShape, + const std::vector> &crops, + const unsigned int *outputShape, + const std::vector &outputData, + float scale = 1.0f, + int32_t offset = 0) +{ + armnn::TensorInfo inputTensorInfo(InputDim, inputShape, ArmnnType); + armnn::TensorInfo outputTensorInfo(OutputDim, outputShape, ArmnnType); + + inputTensorInfo.SetQuantizationScale(scale); + inputTensorInfo.SetQuantizationOffset(offset); + + outputTensorInfo.SetQuantizationScale(scale); + outputTensorInfo.SetQuantizationOffset(offset); +; + auto input = MakeTensor(inputTensorInfo, ConvertToDataType(inputData, inputTensorInfo)); + + LayerTestResult result(outputTensorInfo); + result.outputExpected = MakeTensor(outputTensorInfo, + ConvertToDataType(outputData, outputTensorInfo)); + + std::unique_ptr inputHandle = workloadFactory.CreateTensorHandle(inputTensorInfo); + std::unique_ptr outputHandle = workloadFactory.CreateTensorHandle(outputTensorInfo); + + armnn::BatchToSpaceNdQueueDescriptor data; + data.m_Parameters.m_DataLayout = dataLayout; + data.m_Parameters.m_BlockShape = blockShape; + data.m_Parameters.m_Crops = crops; + armnn::WorkloadInfo info; + AddInputToWorkload(data, info, inputTensorInfo, inputHandle.get()); + AddOutputToWorkload(data, info, outputTensorInfo, outputHandle.get()); + + std::unique_ptr workload = workloadFactory.CreateBatchToSpaceNd(data, info); + + inputHandle->Allocate(); + outputHandle->Allocate(); + + CopyDataToITensorHandle(inputHandle.get(), input.origin()); + + workload->PostAllocationConfigure(); + workload->Execute(); + + CopyDataFromITensorHandle(&result.output[0][0][0][0], outputHandle.get()); + + return result; +} + +template> +LayerTestResult BatchToSpaceNdNhwcTest1( + armnn::IWorkloadFactory& workloadFactory, + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) +{ + const unsigned int inputShape[] = {4, 2, 2, 1}; + const unsigned int outputShape[] = {1, 4, 4, 1}; + + std::vector input({ + // Batch 0, Height 0, Width (2) x Channel (1) + 1.0f, 3.0f, + // Batch 0, Height 1, Width (2) x Channel (1) + 9.0f, 11.0f, + + + // Batch 1, Height 0, Width (2) x Channel (1) + 2.0f, 4.0f, + // Batch 1, Height 1, Width (2) x Channel (1) + 10.0f, 12.0f, + + + // Batch 2, Height 0, Width (2) x Channel (1) + 5.0f, 7.0f, + // Batch 2, Height 1, Width (2) x Channel (1) + 13.0f, 15.0f, + + // Batch 3, Height 0, Width (2) x Channel (3) + 6.0f, 8.0f, + // Batch 3, Height 1, Width (2) x Channel (1) + 14.0f, 16.0f + }); + + std::vector expectedOutput({ + 1.0f, 2.0f, 3.0f, 4.0f, + 5.0f, 6.0f, 7.0f, 8.0f, + 9.0f, 10.0f, 11.0f, 12.0f, + 13.0f, 14.0f, 15.0f, 16.0f + }); + + std::vector blockShape {2, 2}; + std::vector> crops = {{0, 0}, {0, 0}}; + + return BatchToSpaceNdHelper(workloadFactory, memoryManager, + armnn::DataLayout::NHWC, inputShape, input, blockShape, + crops, outputShape, expectedOutput); +} + +template> +LayerTestResult BatchToSpaceNdNhwcTest2( + armnn::IWorkloadFactory& workloadFactory, + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) +{ + const unsigned int inputShape[] = {4, 1, 1, 1}; + const unsigned int outputShape[] = {1, 2, 2, 1}; + + std::vector input({ + // Batch 0, Height 0, Width (2) x Channel (1) + 1.0f, 2.0f, 3.0f, 4.0f + }); + + std::vector expectedOutput({1.0f, 2.0f, 3.0f, 4.0f}); + + std::vector blockShape({2, 2}); + std::vector> crops = {{0, 0}, {0, 0}}; + + return BatchToSpaceNdHelper(workloadFactory, memoryManager, + armnn::DataLayout::NHWC, inputShape, input, blockShape, + crops, outputShape, expectedOutput); +} + +template> +LayerTestResult BatchToSpaceNdNhwcTest3( + armnn::IWorkloadFactory& workloadFactory, + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) +{ + const unsigned int inputShape[] = {4, 1, 1, 3}; + const unsigned int outputShape[] = {1, 2, 2, 3}; + + std::vector input({1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, 11.0f, 12.0f}); + + std::vector expectedOutput({1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, 11.0f, 12.0f}); + + std::vector blockShape({2, 2}); + std::vector> crops = {{0, 0}, {0, 0}}; + + return BatchToSpaceNdHelper(workloadFactory, memoryManager, + armnn::DataLayout::NHWC, inputShape, input, blockShape, + crops, outputShape, expectedOutput); +} + +template> +LayerTestResult BatchToSpaceNdNhwcTest4( + armnn::IWorkloadFactory& workloadFactory, + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) +{ + const unsigned int inputShape[] = {8, 1, 3, 1}; + const unsigned int outputShape[] = {2, 2, 4, 1}; + + std::vector input({ + 0.0f, 1.0f, 3.0f, + 0.0f, 9.0f, 11.0f, + 0.0f, 2.0f, 4.0f, + 0.0f, 10.0f, 12.0f, + 0.0f, 5.0f, 7.0f, + 0.0f, 13.0f, 15.0f, + 0.0f, 6.0f, 8.0f, + 0.0f, 14.0f, 16.0f + }); + + std::vector expectedOutput({ + 1.0f, 2.0f, 3.0f, 4.0f, + 5.0f, 6.0f, 7.0f, 8.0f, + 9.0f, 10.0f, 11.0f, 12.0f, + 13.0f, 14.0f, 15.0f, 16.0f + }); + + std::vector blockShape({2, 2}); + std::vector> crops = {{0, 0}, {2, 0}}; + + return BatchToSpaceNdHelper(workloadFactory, memoryManager, + armnn::DataLayout::NHWC, inputShape, input, blockShape, + crops, outputShape, expectedOutput); +} + +template> +LayerTestResult BatchToSpaceNdNhwcTest5( + armnn::IWorkloadFactory& workloadFactory, + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) +{ + const unsigned int inputShape[] = {4, 2, 2, 1}; + const unsigned int outputShape[] = {1, 4, 4, 1}; + + std::vector input({1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}); + std::vector expectedOutput({1, 5, 2, 6, 9, 13, 10, 14, 3, 7, 4, 8, 11, 15, 12, 16}); + + std::vector blockShape({2, 2}); + std::vector> crops = {{0, 0}, {0, 0}}; + + return BatchToSpaceNdHelper(workloadFactory, memoryManager, armnn::DataLayout::NHWC, inputShape, + input, blockShape, crops, outputShape, expectedOutput); +} + +template> +LayerTestResult BatchToSpaceNdNhwcTest6( + armnn::IWorkloadFactory& workloadFactory, + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) +{ + const unsigned int inputShape[] = {4, 1, 1, 1}; + const unsigned int outputShape[] = {1, 2, 2, 1}; + + std::vector input({ + // Batch 0, Height 0, Width (2) x Channel (1) + 1, 2, 3, 4 + }); + + std::vector expectedOutput({1, 2, 3, 4}); + + std::vector blockShape({2, 2}); + std::vector> crops = {{0, 0}, {0, 0}}; + + return BatchToSpaceNdHelper(workloadFactory, memoryManager, + armnn::DataLayout::NHWC, inputShape, input, blockShape, + crops, outputShape, expectedOutput); +} + +template> +LayerTestResult BatchToSpaceNdNhwcTest7( + armnn::IWorkloadFactory& workloadFactory, + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) +{ + const unsigned int inputShape[] = {4, 1, 1, 3}; + const unsigned int outputShape[] = {1, 2, 2, 3}; + + std::vector input({1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}); + + std::vector expectedOutput({1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}); + + std::vector blockShape({2, 2}); + std::vector> crops = {{0, 0}, {0, 0}}; + + return BatchToSpaceNdHelper(workloadFactory, memoryManager, + armnn::DataLayout::NHWC, inputShape, input, blockShape, + crops, outputShape, expectedOutput); +} + +template> +LayerTestResult BatchToSpaceNdNchwTest1( + armnn::IWorkloadFactory &workloadFactory, + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) +{ + const unsigned int inputShape[] = {4, 3, 1, 1}; + const unsigned int outputShape[] = {1, 3, 2, 2}; + + std::vector input({1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, 11.0f, 12.0f}); + + std::vector expectedOutput({ + // Batch 0, Channel 0, Height (2) x Width (2) + 1.0f, 4.0f, + 7.0f, 10.0f, + + // Batch 0, Channel 1, Height (2) x Width (2) + 2.0f, 5.0f, + 8.0f, 11.0f, + + // Batch 0, Channel 2, Height (2) x Width (2) + 3.0f, 6.0f, + 9.0f, 12.0f, + }); + + std::vector blockShape({2, 2}); + std::vector> crops = {{0, 0}, {0, 0}}; + + return BatchToSpaceNdHelper(workloadFactory, memoryManager, + armnn::DataLayout::NCHW, inputShape, input, blockShape, + crops, outputShape, expectedOutput); +} + +template> +LayerTestResult BatchToSpaceNdNchwTest2( + armnn::IWorkloadFactory& workloadFactory, + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) +{ + const unsigned int inputShape[] = {4, 1, 1, 1}; + const unsigned int outputShape[] = {1, 1, 2, 2}; + + std::vector input({ + // Batch 0, Height 0, Width (2) x Channel (1) + 1.0f, 2.0f, 3.0f, 4.0f + }); + + std::vector expectedOutput({1.0f, 2.0f, 3.0f, 4.0f}); + + std::vector blockShape({2, 2}); + std::vector> crops = {{0, 0}, {0, 0}}; + + return BatchToSpaceNdHelper(workloadFactory, memoryManager, + armnn::DataLayout::NCHW, inputShape, input, blockShape, + crops, outputShape, expectedOutput); +} + +template> +LayerTestResult BatchToSpaceNdNchwTest3( + armnn::IWorkloadFactory& workloadFactory, + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) +{ + const unsigned int inputShape[] = {4, 3, 1, 1}; + const unsigned int outputShape[] = {1, 3, 2, 2}; + + std::vector input({1.0f, 3.0f, 5.0f, 7.0f, 9.0f, 11.0f, 2.0f, 4.0f, 6.0f, 8.0f, 10.0f, 12.0f}); + + std::vector expectedOutput({ + // Batch 0, Channel 0, Height (2) x Width (2) + 1.0f, 7.0f, + 2.0f, 8.0f, + + // Batch 0, Channel 1, Height (2) x Width (2) + 3.0f, 9.0f, + 4.0f, 10.0f, + + // Batch 0, Channel 2, Height (2) x Width (2) + 5.0f, 11.0f, + 6.0f, 12.0f, + }); + + std::vector blockShape({2, 2}); + std::vector> crops = {{0, 0}, {0, 0}}; + + return BatchToSpaceNdHelper(workloadFactory, memoryManager, + armnn::DataLayout::NCHW, inputShape, input, blockShape, + crops, outputShape, expectedOutput); +} + +template> +LayerTestResult BatchToSpaceNdNchwTest4( + armnn::IWorkloadFactory &workloadFactory, + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) +{ + const unsigned int inputShape[] = {4, 3, 1, 1}; + const unsigned int outputShape[] = {1, 3, 2, 2}; + + std::vector input({1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}); + + std::vector expectedOutput({ + // Batch 0, Channel 0, Height (2) x Width (2) + 1, 4, + 7, 10, + + // Batch 0, Channel 1, Height (2) x Width (2) + 2, 5, + 8, 11, + + // Batch 0, Channel 2, Height (2) x Width (2) + 3, 6, + 9, 12, + }); + + std::vector blockShape({2, 2}); + std::vector> crops = {{0, 0}, {0, 0}}; + + return BatchToSpaceNdHelper(workloadFactory, memoryManager, + armnn::DataLayout::NCHW, inputShape, input, blockShape, + crops, outputShape, expectedOutput); +} + +template> +LayerTestResult BatchToSpaceNdNchwTest5( + armnn::IWorkloadFactory& workloadFactory, + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) +{ + const unsigned int inputShape[] = {4, 1, 1, 1}; + const unsigned int outputShape[] = {1, 1, 2, 2}; + + std::vector input({ + // Batch 0, Height 0, Width (2) x Channel (1) + 1, 2, 3, 4 + }); + + std::vector expectedOutput({1, 2, 3, 4}); + + std::vector blockShape({2, 2}); + std::vector> crops = {{0, 0}, {0, 0}}; + + return BatchToSpaceNdHelper(workloadFactory, memoryManager, + armnn::DataLayout::NCHW, inputShape, input, blockShape, + crops, outputShape, expectedOutput); +} + +template> +LayerTestResult BatchToSpaceNdNchwTest6( + armnn::IWorkloadFactory& workloadFactory, + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) +{ + const unsigned int inputShape[] = {4, 3, 1, 1}; + const unsigned int outputShape[] = {1, 3, 2, 2}; + + std::vector input({1, 3, 5, 7, 9, 11, 2, 4, 6, 8, 10, 12}); + + std::vector expectedOutput({ + // Batch 0, Channel 0, Height (2) x Width (2) + 1, 7, + 2, 8, + + // Batch 0, Channel 1, Height (2) x Width (2) + 3, 9, + 4, 10, + + // Batch 0, Channel 2, Height (2) x Width (2) + 5, 11, + 6, 12, + }); + + std::vector blockShape({2, 2}); + std::vector> crops = {{0, 0}, {0, 0}}; + + return BatchToSpaceNdHelper(workloadFactory, memoryManager, + armnn::DataLayout::NCHW, inputShape, input, blockShape, + crops, outputShape, expectedOutput); +} + +template> +LayerTestResult BatchToSpaceNdNchwTest7( + armnn::IWorkloadFactory& workloadFactory, + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) +{ + const unsigned int inputShape[] = {8, 1, 1, 3}; + const unsigned int outputShape[] = {2, 1, 2, 4}; + + std::vector input({ + 0, 1, 3, 0, 9, 11, + 0, 2, 4, 0, 10, 12, + 0, 5, 7, 0, 13, 15, + 0, 6, 8, 0, 14, 16 + }); + + std::vector expectedOutput({ + 1, 2, 3, 4, + 5, 6, 7, 8, + 9, 10, 11, 12, + 13, 14, 15, 16 + }); + + std::vector blockShape({2, 2}); + std::vector> crops = {{0, 0}, {2, 0}}; + + return BatchToSpaceNdHelper(workloadFactory, memoryManager, + armnn::DataLayout::NCHW, inputShape, input, blockShape, + crops, outputShape, expectedOutput); +} + template LayerTestResult, 4> PreluTest( armnn::IWorkloadFactory& workloadFactory, -- cgit v1.2.1