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/SubtractionTestImpl.cpp | 250 +++++++++++++++++++++ 1 file changed, 250 insertions(+) create mode 100644 src/backends/backendsCommon/test/layerTests/SubtractionTestImpl.cpp (limited to 'src/backends/backendsCommon/test/layerTests/SubtractionTestImpl.cpp') diff --git a/src/backends/backendsCommon/test/layerTests/SubtractionTestImpl.cpp b/src/backends/backendsCommon/test/layerTests/SubtractionTestImpl.cpp new file mode 100644 index 0000000000..61225d40e5 --- /dev/null +++ b/src/backends/backendsCommon/test/layerTests/SubtractionTestImpl.cpp @@ -0,0 +1,250 @@ +// +// Copyright © 2017 Arm Ltd. All rights reserved. +// SPDX-License-Identifier: MIT +// + +#include "SubtractionTestImpl.hpp" + +#include "ElementwiseTestImpl.hpp" + +template<> +std::unique_ptr CreateWorkload( + const armnn::IWorkloadFactory& workloadFactory, + const armnn::WorkloadInfo& info, + const armnn::SubtractionQueueDescriptor& descriptor) +{ + return workloadFactory.CreateSubtraction(descriptor, info); +} + +LayerTestResult SubtractionUint8Test( + armnn::IWorkloadFactory& workloadFactory, + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) +{ + const unsigned int shape0[] = { 1, 1, 2, 2 }; + const unsigned int shape1[] = { 1, 1, 2, 2 }; + + std::vector input0 = { 10, 12, 14, 16 }; + std::vector input1 = { 1, 2, 1, 2 }; + std::vector output = { 3, 3, 5, 5 }; + + return ElementwiseTestHelper<4, armnn::SubtractionQueueDescriptor, armnn::DataType::QuantisedAsymm8>( + workloadFactory, + memoryManager, + shape0, + input0, + 0.5f, + 2, + shape1, + input1, + 1.0f, + 0, + shape0, + output, + 1.0f, + 0); +} + +LayerTestResult SubtractionBroadcast1ElementUint8Test( + armnn::IWorkloadFactory& workloadFactory, + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) +{ + const unsigned int shape0[] = { 1, 1, 2, 2 }; + const unsigned int shape1[] = { 1, 1, 1, 1 }; + + std::vector input0 = { 10, 12, 14, 16 }; + + std::vector input1 = { 2 }; + + std::vector output = { 5, 6, 7, 8 }; + + return ElementwiseTestHelper<4, armnn::SubtractionQueueDescriptor, armnn::DataType::QuantisedAsymm8>( + workloadFactory, + memoryManager, + shape0, + input0, + 0.5f, + 2, + shape1, + input1, + 1.0f, + 0, + shape0, + output, + 1.0f, + 3); +} + +LayerTestResult SubtractionBroadcastUint8Test( + armnn::IWorkloadFactory& workloadFactory, + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) +{ + const unsigned int shape0[] = { 1, 1, 2, 2 }; + const unsigned int shape1[] = { 1, 1, 2, 1 }; + + std::vector input0 = { 10, 12, 14, 16 }; + + std::vector input1 = { 2, 1 }; + + std::vector output = { 8, 11, 12, 15 }; + + return ElementwiseTestHelper<4, armnn::SubtractionQueueDescriptor, armnn::DataType::QuantisedAsymm8>( + workloadFactory, + memoryManager, + shape0, + input0, + shape1, + input1, + shape0, + output); +} + +LayerTestResult SubtractionTest( + armnn::IWorkloadFactory& workloadFactory, + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) +{ + const unsigned int shape0[] = { 1, 1, 2, 2 }; + const unsigned int shape1[] = { 1, 1, 2, 2 }; + + std::vector input0 = { 1, 2, 3, 4 }; + std::vector input1 = { 1, -1, 0, 2 }; + std::vector output = { 0, 3, 3, 2 }; + + return ElementwiseTestHelper<4, armnn::SubtractionQueueDescriptor, armnn::DataType::Float32>( + workloadFactory, + memoryManager, + shape0, + input0, + shape1, + input1, + shape0, + output); +} + +LayerTestResult SubtractionBroadcast1ElementTest( + armnn::IWorkloadFactory& workloadFactory, + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) +{ + const unsigned int shape0[] = { 1, 1, 2, 2 }; + const unsigned int shape1[] = { 1, 1, 1, 1 }; + + std::vector input0 = { 1, 2, 3, 4 }; + + std::vector input1 = { 10 }; + + std::vector output = { -9, -8, -7, -6 }; + + return ElementwiseTestHelper<4, armnn::SubtractionQueueDescriptor, armnn::DataType::Float32>( + workloadFactory, + memoryManager, + shape0, + input0, + shape1, + input1, + shape0, + output); +} + +LayerTestResult SubtractionBroadcastTest( + armnn::IWorkloadFactory& workloadFactory, + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) +{ + const unsigned int shape0[] = { 1, 1, 2, 2 }; + const unsigned int shape1[] = { 1, 1, 1, 2 }; + + std::vector input0 = { 1, 2, 3, 4 }; + + std::vector input1 = { 10, -5 }; + + std::vector output = { -9, 7, -7, 9 }; + + return ElementwiseTestHelper<4, armnn::SubtractionQueueDescriptor, armnn::DataType::Float32>( + workloadFactory, + memoryManager, + shape0, + input0, + shape1, + input1, + shape0, + output); +} + +LayerTestResult SubtractionInt16Test( + armnn::IWorkloadFactory& workloadFactory, + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) +{ + const unsigned int shape[] = { 1, 1, 2, 2 }; + + std::vector input0 = { 10, 12, 14, 16 }; + std::vector input1 = { 1, 2, 1, 2 }; + std::vector output = { 3, 3, 5, 5 }; + + return ElementwiseTestHelper<4, armnn::SubtractionQueueDescriptor, armnn::DataType::QuantisedSymm16>( + workloadFactory, + memoryManager, + shape, + input0, + 0.5f, + 0, + shape, + input1, + 1.0f, + 0, + shape, + output, + 1.0f, + 0); +} + +LayerTestResult SubtractionBroadcast1ElementInt16Test( + armnn::IWorkloadFactory& workloadFactory, + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) +{ + const unsigned int shape0[] = { 1, 1, 2, 2 }; + const unsigned int shape1[] = { 1, 1, 1, 1 }; + + std::vector input0 = { 10, 12, 14, 16 }; + + std::vector input1 = { 2 }; + + std::vector output = { 3, 4, 5, 6 }; + + return ElementwiseTestHelper<4, armnn::SubtractionQueueDescriptor, armnn::DataType::QuantisedSymm16>( + workloadFactory, + memoryManager, + shape0, + input0, + 0.5f, + 0, + shape1, + input1, + 1.0f, + 0, + shape0, + output, + 1.0f, + 0); +} + +LayerTestResult SubtractionBroadcastInt16Test( + armnn::IWorkloadFactory& workloadFactory, + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) +{ + const unsigned int shape0[] = { 1, 1, 2, 2 }; + const unsigned int shape1[] = { 1, 1, 2, 1 }; + + std::vector input0 = { 10, 12, 14, 16 }; + + std::vector input1 = { 2, 1 }; + + std::vector output = { 8, 11, 12, 15 }; + + return ElementwiseTestHelper<4, armnn::SubtractionQueueDescriptor, armnn::DataType::QuantisedSymm16>( + workloadFactory, + memoryManager, + shape0, + input0, + shape1, + input1, + shape0, + output); +} -- cgit v1.2.1