From e89ebad9cd78096d9c18a28fa01337dd622f5081 Mon Sep 17 00:00:00 2001 From: Aron Virginas-Tar Date: Tue, 27 Aug 2019 18:14:26 +0100 Subject: IVGCVSW-2325 Reduce duplication in LayerTests by reusing the ElementwiseTestHelper * Refactored tests for element-wise operations to use ElementwiseTestHelper * Moved the etasts for each operation in a separate file under backendsCommon/test/layerTests Signed-off-by: Aron Virginas-Tar Change-Id: Icefb6b35df78b9619f69378229789505bf92670e --- .../test/layerTests/GreaterTestImpl.cpp | 229 +++++++++++++++++++++ 1 file changed, 229 insertions(+) create mode 100644 src/backends/backendsCommon/test/layerTests/GreaterTestImpl.cpp (limited to 'src/backends/backendsCommon/test/layerTests/GreaterTestImpl.cpp') diff --git a/src/backends/backendsCommon/test/layerTests/GreaterTestImpl.cpp b/src/backends/backendsCommon/test/layerTests/GreaterTestImpl.cpp new file mode 100644 index 0000000000..b5bf560e3c --- /dev/null +++ b/src/backends/backendsCommon/test/layerTests/GreaterTestImpl.cpp @@ -0,0 +1,229 @@ +// +// Copyright © 2017 Arm Ltd. All rights reserved. +// SPDX-License-Identifier: MIT +// + +#include "GreaterTestImpl.hpp" + +#include "ElementwiseTestImpl.hpp" + +template<> +std::unique_ptr CreateWorkload( + const armnn::IWorkloadFactory& workloadFactory, + const armnn::WorkloadInfo& info, + const armnn::GreaterQueueDescriptor& descriptor) +{ + return workloadFactory.CreateGreater(descriptor, info); +} + +LayerTestResult GreaterSimpleTest(armnn::IWorkloadFactory& workloadFactory, + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) +{ + const unsigned int width = 2u; + const unsigned int height = 2u; + const unsigned int channelCount = 2u; + const unsigned int batchSize = 2u; + + unsigned int shape[] = { batchSize, channelCount, height, width }; + + std::vector input0 = + { + 1.f, 1.f, 1.f, 1.f, 5.f, 5.f, 5.f, 5.f, + 3.f, 3.f, 3.f, 3.f, 4.f, 4.f, 4.f, 4.f + }; + + std::vector input1 = + { + 1.f, 1.f, 1.f, 1.f, 3.f, 3.f, 3.f, 3.f, + 5.f, 5.f, 5.f, 5.f, 4.f, 4.f, 4.f, 4.f + }; + + std::vector output = + { + 0, 0, 0, 0, 1, 1, 1, 1, + 0, 0, 0, 0, 0, 0, 0, 0 + }; + + return ElementwiseTestHelper<4, + armnn::GreaterQueueDescriptor, + armnn::DataType::Float32, + armnn::DataType::Boolean>( + workloadFactory, + memoryManager, + shape, + input0, + shape, + input1, + shape, + output); +} + +LayerTestResult GreaterBroadcast1ElementTest( + armnn::IWorkloadFactory& workloadFactory, + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) +{ + unsigned int shape0[] = { 1, 2, 2, 2 }; + unsigned int shape1[] = { 1, 1, 1, 1 }; + + std::vector input0 = { 1, 2, 3, 4, 5, 6, 7, 8}; + std::vector input1 = { 1 }; + + std::vector output = { 0, 1, 1, 1, 1, 1, 1, 1}; + + return ElementwiseTestHelper<4, + armnn::GreaterQueueDescriptor, + armnn::DataType::Float32, + armnn::DataType::Boolean>( + workloadFactory, + memoryManager, + shape0, + input0, + shape1, + input1, + shape0, + output); +} + +LayerTestResult GreaterBroadcast1DVectorTest( + armnn::IWorkloadFactory& workloadFactory, + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) +{ + const unsigned int shape0[] = { 1, 2, 2, 3 }; + const unsigned int shape1[] = { 1, 1, 1, 3 }; + + std::vector input0 = + { + 1.0f, 2.9f, 2.1f, 4.0f, 5.0f, 6.0f, + 7.0f, 8.0f, 9.0f, 10.0f, 11.0f, 12.0f + }; + + std::vector input1 = { 1.f, 3.f, 2.f }; + + std::vector output = + { + 0, 0, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1 + }; + + return ElementwiseTestHelper<4, + armnn::GreaterQueueDescriptor, + armnn::DataType::Float32, + armnn::DataType::Boolean>( + workloadFactory, + memoryManager, + shape0, + input0, + shape1, + input1, + shape0, + output); +} + +LayerTestResult GreaterUint8Test( + armnn::IWorkloadFactory& workloadFactory, + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) +{ + unsigned int shape[] = { 2, 2, 2, 2 }; + + // See dequantized values to the right. + std::vector input0 = + { + 1, 1, 1, 1, 6, 6, 6, 6, + 3, 3, 3, 3, 5, 5, 5, 5 + }; + + std::vector input1 = + { + 2, 2, 2, 2, 6, 6, 6, 6, + 2, 2, 2, 2, 5, 5, 5, 5 + }; + + std::vector output = + { + 0, 0, 0, 0, 0, 0, 0, 0, + 1, 1, 1, 1, 0, 0, 0, 0 + }; + + return ElementwiseTestHelper<4, + armnn::GreaterQueueDescriptor, + armnn::DataType::QuantisedAsymm8, + armnn::DataType::Boolean>( + workloadFactory, + memoryManager, + shape, + input0, + shape, + input1, + shape, + output); +} + +LayerTestResult GreaterBroadcast1ElementUint8Test( + armnn::IWorkloadFactory& workloadFactory, + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) +{ + const unsigned int shape0[] = { 1, 2, 2, 3 }; + const unsigned int shape1[] = { 1, 1, 1, 1 }; + + std::vector input0 = + { + 1, 2, 3, 4, 5, 6, + 7, 8, 9, 10, 11, 12 + }; + + std::vector input1 = { 1 }; + + std::vector output = + { + 0, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1 + }; + + return ElementwiseTestHelper<4, + armnn::GreaterQueueDescriptor, + armnn::DataType::QuantisedAsymm8, + armnn::DataType::Boolean>( + workloadFactory, + memoryManager, + shape0, + input0, + shape1, + input1, + shape0, + output); +} + +LayerTestResult GreaterBroadcast1DVectorUint8Test( + armnn::IWorkloadFactory& workloadFactory, + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) +{ + const unsigned int shape0[] = { 1, 2, 2, 3 }; + const unsigned int shape1[] = { 1, 1, 1, 3 }; + + std::vector input0 = + { + 1, 2, 3, 4, 5, 6, + 7, 8, 9, 10, 11, 12 + }; + + std::vector input1 = { 1, 1, 3 }; + + std::vector output = + { + 0, 1, 0, 1, 1, 1, + 1, 1, 1, 1, 1, 1 + }; + + return ElementwiseTestHelper<4, + armnn::GreaterQueueDescriptor, + armnn::DataType::QuantisedAsymm8, + armnn::DataType::Boolean>( + workloadFactory, + memoryManager, + shape0, + input0, + shape1, + input1, + shape0, + output); +} -- cgit v1.2.1