From e69c399dcee1e75ebf9b2b12f72f3ad628c4e104 Mon Sep 17 00:00:00 2001 From: Matthew Jackson Date: Mon, 9 Sep 2019 14:31:21 +0100 Subject: [PATCH] IVGCVSW-3824 Implement Float 16 Encoder and Decoder * Implement Float 16 Encoder and Decoder * Add Stack Float 16 layer and create workload tests Signed-off-by: Matthew Jackson Change-Id: Ice4678226f4d22c06ebcc6db3052d42ce0c1bd67 --- src/backends/backendsCommon/common.mk | 1 + src/backends/backendsCommon/test/CMakeLists.txt | 1 + .../test/layerTests/StackTestImpl.cpp | 611 +++++++++++++++++++++ .../test/layerTests/StackTestImpl.hpp | 482 +--------------- src/backends/cl/test/ClCreateWorkloadTests.cpp | 5 + src/backends/cl/test/ClLayerTests.cpp | 13 +- src/backends/neon/test/NeonCreateWorkloadTests.cpp | 7 + src/backends/neon/test/NeonLayerTests.cpp | 12 +- src/backends/reference/RefLayerSupport.cpp | 3 +- src/backends/reference/RefWorkloadFactory.cpp | 4 - src/backends/reference/test/RefLayerTests.cpp | 13 +- src/backends/reference/workloads/BaseIterator.hpp | 57 +- src/backends/reference/workloads/Decoders.hpp | 15 +- src/backends/reference/workloads/Encoders.hpp | 6 +- 14 files changed, 726 insertions(+), 504 deletions(-) create mode 100644 src/backends/backendsCommon/test/layerTests/StackTestImpl.cpp diff --git a/src/backends/backendsCommon/common.mk b/src/backends/backendsCommon/common.mk index f75870a..39e0265 100644 --- a/src/backends/backendsCommon/common.mk +++ b/src/backends/backendsCommon/common.mk @@ -66,6 +66,7 @@ COMMON_TEST_SOURCES := \ test/layerTests/SpaceToBatchNdTestImpl.cpp \ test/layerTests/SpaceToDepthTestImpl.cpp \ test/layerTests/SplitterTestImpl.cpp \ + test/layerTests/StackTestImpl.cpp \ test/layerTests/StridedSliceTestImpl.cpp \ test/layerTests/SubtractionTestImpl.cpp diff --git a/src/backends/backendsCommon/test/CMakeLists.txt b/src/backends/backendsCommon/test/CMakeLists.txt index 49604b0..e46d481 100644 --- a/src/backends/backendsCommon/test/CMakeLists.txt +++ b/src/backends/backendsCommon/test/CMakeLists.txt @@ -113,6 +113,7 @@ list(APPEND armnnBackendsCommonUnitTests_sources layerTests/SpaceToDepthTestImpl.hpp layerTests/SplitterTestImpl.cpp layerTests/SplitterTestImpl.hpp + layerTests/StackTestImpl.cpp layerTests/StackTestImpl.hpp layerTests/StridedSliceTestImpl.cpp layerTests/StridedSliceTestImpl.hpp diff --git a/src/backends/backendsCommon/test/layerTests/StackTestImpl.cpp b/src/backends/backendsCommon/test/layerTests/StackTestImpl.cpp new file mode 100644 index 0000000..80058c6 --- /dev/null +++ b/src/backends/backendsCommon/test/layerTests/StackTestImpl.cpp @@ -0,0 +1,611 @@ +// +// Copyright © 2019 Arm Ltd. All rights reserved. +// SPDX-License-Identifier: MIT +// + +#include "StackTestImpl.hpp" +#include "LayerTestResult.hpp" + +#include + +#include + +#include +#include + +#include +#include + +#include + +namespace +{ + +template +LayerTestResult StackTestHelper( + armnn::IWorkloadFactory& workloadFactory, + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, + const armnn::TensorInfo& inputTensorInfo, + const armnn::TensorInfo& outputTensorInfo, + unsigned int axis, + const std::vector>& inputData, + const std::vector& outputExpectedData) +{ + unsigned int numInputs = static_cast(inputData.size()); + std::vector> inputs; + for (unsigned int i = 0; i < numInputs; ++i) + { + inputs.push_back(MakeTensor(inputTensorInfo, inputData[i])); + } + + LayerTestResult result(outputTensorInfo); + result.outputExpected = MakeTensor(outputTensorInfo, outputExpectedData); + + std::vector> inputHandles; + for (unsigned int i = 0; i < numInputs; ++i) + { + inputHandles.push_back(workloadFactory.CreateTensorHandle(inputTensorInfo)); + } + std::unique_ptr outputHandle = workloadFactory.CreateTensorHandle(outputTensorInfo); + + armnn::StackQueueDescriptor descriptor; + descriptor.m_Parameters.m_Axis = axis; + descriptor.m_Parameters.m_InputShape = inputTensorInfo.GetShape(); + descriptor.m_Parameters.m_NumInputs = numInputs; + + armnn::WorkloadInfo info; + for (unsigned int i = 0; i < numInputs; ++i) + { + std::unique_ptr& inputHandle = inputHandles[i]; + AddInputToWorkload(descriptor, info, inputTensorInfo, inputHandle.get()); + inputHandle->Allocate(); + CopyDataToITensorHandle(inputHandle.get(), inputs[i].origin()); + } + + AddOutputToWorkload(descriptor, info, outputTensorInfo, outputHandle.get()); + outputHandle->Allocate(); + + std::unique_ptr workload = workloadFactory.CreateStack(descriptor, info); + + workload->Execute(); + + CopyDataFromITensorHandle(result.output.origin(), outputHandle.get()); + + return result; +} + +} // anonymous namespace + +// +// Implementation templates +// + +template> +LayerTestResult StackAxis0TestImpl( + armnn::IWorkloadFactory& workloadFactory, + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) +{ + armnn::TensorInfo inputTensorInfo ({ 3, 2, 3 }, ArmnnType); + armnn::TensorInfo outputTensorInfo({ 2, 3, 2, 3 }, ArmnnType); + + std::vector> inputData; + + inputData.push_back( + { + 1, 2, 3, + 4, 5, 6, + + 7, 8, 9, + 10, 11, 12, + + 13, 14, 15, + 16, 17, 18 + }); + + inputData.push_back( + { + 19, 20, 21, + 22, 23, 24, + + 25, 26, 27, + 28, 29, 30, + + 31, 32, 33, + 34, 35, 36 + }); + + std::vector outputExpectedData = + { + 1, 2, 3, + 4, 5, 6, + + 7, 8, 9, + 10, 11, 12, + + 13, 14, 15, + 16, 17, 18, + + + 19, 20, 21, + 22, 23, 24, + + 25, 26, 27, + 28, 29, 30, + + 31, 32, 33, + 34, 35, 36 + }; + + return StackTestHelper( + workloadFactory, + memoryManager, + inputTensorInfo, + outputTensorInfo, + 0U, + inputData, + outputExpectedData + ); +} + +template> +LayerTestResult StackOutput4DAxis1TestImpl( + armnn::IWorkloadFactory& workloadFactory, + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) +{ + armnn::TensorInfo inputTensorInfo ({ 3, 2, 3 }, ArmnnType); + armnn::TensorInfo outputTensorInfo({ 3, 2, 2, 3 }, ArmnnType); + + std::vector> inputData; + + inputData.push_back( + { + 1, 2, 3, + 4, 5, 6, + + 7, 8, 9, + 10, 11, 12, + + 13, 14, 15, + 16, 17, 18 + }); + + inputData.push_back( + { + 19, 20, 21, + 22, 23, 24, + + 25, 26, 27, + 28, 29, 30, + + 31, 32, 33, + 34, 35, 36 + }); + + std::vector outputExpectedData = + { + 1, 2, 3, + 4, 5, 6, + + 19, 20, 21, + 22, 23, 24, + + + 7, 8, 9, + 10, 11, 12, + + 25, 26, 27, + 28, 29, 30, + + + 13, 14, 15, + 16, 17, 18, + + 31, 32, 33, + 34, 35, 36 + }; + + return StackTestHelper( + workloadFactory, + memoryManager, + inputTensorInfo, + outputTensorInfo, + 1U, + inputData, + outputExpectedData + ); +} + +template> +LayerTestResult StackOutput4DAxis2TestImpl( + armnn::IWorkloadFactory& workloadFactory, + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) +{ + armnn::TensorInfo inputTensorInfo ({ 3, 2, 3 }, ArmnnType); + armnn::TensorInfo outputTensorInfo({ 3, 2, 2, 3 }, ArmnnType); + + std::vector> inputData; + + inputData.push_back( + { + 1, 2, 3, + 4, 5, 6, + + 7, 8, 9, + 10, 11, 12, + + 13, 14, 15, + 16, 17, 18 + }); + + inputData.push_back( + { + 19, 20, 21, + 22, 23, 24, + + 25, 26, 27, + 28, 29, 30, + + 31, 32, 33, + 34, 35, 36 + }); + + std::vector outputExpectedData = + { + 1, 2, 3, + 19, 20, 21, + + 4, 5, 6, + 22, 23, 24, + + 7, 8, 9, + 25, 26, 27, + + 10, 11, 12, + 28, 29, 30, + + 13, 14, 15, + 31, 32, 33, + + 16, 17, 18, + 34, 35, 36 + }; + + return StackTestHelper( + workloadFactory, + memoryManager, + inputTensorInfo, + outputTensorInfo, + 2U, + inputData, + outputExpectedData + ); +} + +template> +LayerTestResult StackOutput4DAxis3TestImpl( + armnn::IWorkloadFactory& workloadFactory, + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) +{ + armnn::TensorInfo inputTensorInfo ({ 3, 2, 3 }, ArmnnType); + armnn::TensorInfo outputTensorInfo({ 3, 2, 3, 2 }, ArmnnType); + + std::vector> inputData; + + inputData.push_back( + { + 1, 2, 3, + 4, 5, 6, + + 7, 8, 9, + 10, 11, 12, + + 13, 14, 15, + 16, 17, 18 + }); + + inputData.push_back( + { + 19, 20, 21, + 22, 23, 24, + + 25, 26, 27, + 28, 29, 30, + + 31, 32, 33, + 34, 35, 36 + }); + + std::vector outputExpectedData = + { + 1, 19, + 2, 20, + 3, 21, + + 4, 22, + 5, 23, + 6, 24, + + + 7, 25, + 8, 26, + 9, 27, + + 10, 28, + 11, 29, + 12, 30, + + + 13, 31, + 14, 32, + 15, 33, + + 16, 34, + 17, 35, + 18, 36 + }; + + return StackTestHelper( + workloadFactory, + memoryManager, + inputTensorInfo, + outputTensorInfo, + 3U, + inputData, + outputExpectedData + ); +} + +template> +LayerTestResult StackOutput3DInputs3TestImpl( + armnn::IWorkloadFactory& workloadFactory, + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) +{ + armnn::TensorInfo inputTensorInfo ({ 3, 3 }, ArmnnType); + armnn::TensorInfo outputTensorInfo({ 3, 3, 3 }, ArmnnType); + + std::vector> inputData; + + inputData.push_back( + { + 1, 2, 3, + 4, 5, 6, + 7, 8, 9 + }); + + inputData.push_back( + { + 10, 11, 12, + 13, 14, 15, + 16, 17, 18 + }); + + inputData.push_back( + { + 19, 20, 21, + 22, 23, 24, + 25, 26, 27 + }); + + std::vector outputExpectedData = + { + 1, 2, 3, + 10, 11, 12, + 19, 20, 21, + + 4, 5, 6, + 13, 14, 15, + 22, 23, 24, + + 7, 8, 9, + 16, 17, 18, + 25, 26, 27 + }; + + return StackTestHelper( + workloadFactory, + memoryManager, + inputTensorInfo, + outputTensorInfo, + 1U, + inputData, + outputExpectedData + ); +} + +template> +LayerTestResult StackOutput5DTestImpl( + armnn::IWorkloadFactory& workloadFactory, + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) +{ + armnn::TensorInfo inputTensorInfo ({ 2, 2, 2, 3 }, ArmnnType); + armnn::TensorInfo outputTensorInfo({ 2, 2, 2, 2, 3 }, ArmnnType); + + std::vector> inputData; + + inputData.push_back( + { + 1, 2, 3, + 4, 5, 6, + + 7, 8, 9, + 10, 11, 12, + + + 13, 14, 15, + 16, 17, 18, + + 19, 20, 21, + 22, 23, 24 + }); + + inputData.push_back( + { + 25, 26, 27, + 28, 29, 30, + + 31, 32, 33, + 34, 35, 36, + + + 37, 38, 39, + 40, 41, 42, + + 43, 44, 45, + 46, 47, 48 + }); + + std::vector outputExpectedData = + { + 1, 2, 3, + 4, 5, 6, + + 7, 8, 9, + 10, 11, 12, + + + 25, 26, 27, + 28, 29, 30, + + 31, 32, 33, + 34, 35, 36, + + + + 13, 14, 15, + 16, 17, 18, + + 19, 20, 21, + 22, 23, 24, + + + 37, 38, 39, + 40, 41, 42, + + 43, 44, 45, + 46, 47, 48 + + }; + + return StackTestHelper( + workloadFactory, + memoryManager, + inputTensorInfo, + outputTensorInfo, + 1U, + inputData, + outputExpectedData + ); +} + +// +// Implementation functions +// + +LayerTestResult StackAxis0Float32Test( + armnn::IWorkloadFactory& workloadFactory, + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) +{ + return StackAxis0TestImpl(workloadFactory, memoryManager); +} + +LayerTestResult StackOutput4DAxis1Float32Test( + armnn::IWorkloadFactory& workloadFactory, + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) +{ + return StackOutput4DAxis1TestImpl(workloadFactory, memoryManager); +} + +LayerTestResult StackOutput4DAxis2Float32Test( + armnn::IWorkloadFactory& workloadFactory, + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) +{ + return StackOutput4DAxis2TestImpl(workloadFactory, memoryManager); +} + +LayerTestResult StackOutput4DAxis3Float32Test( + armnn::IWorkloadFactory& workloadFactory, + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) +{ + return StackOutput4DAxis3TestImpl(workloadFactory, memoryManager); +} + +LayerTestResult StackOutput3DInputs3Float32Test( + armnn::IWorkloadFactory& workloadFactory, + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) +{ + return StackOutput3DInputs3TestImpl(workloadFactory, memoryManager); +} + +LayerTestResult StackOutput5DFloat32Test( + armnn::IWorkloadFactory& workloadFactory, + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) +{ + return StackOutput5DTestImpl(workloadFactory, memoryManager); +} + +LayerTestResult StackFloat16Test( + armnn::IWorkloadFactory& workloadFactory, + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) +{ + using namespace half_float::literal; + + armnn::TensorInfo inputTensorInfo ({ 3, 2, 3 }, armnn::DataType::Float16); + armnn::TensorInfo outputTensorInfo({ 3, 2, 2, 3 }, armnn::DataType::Float16); + + std::vector> inputData; + + inputData.push_back( + { + 1.0_h, 2.0_h, 3.0_h, + 4.0_h, 5.0_h, 6.0_h, + + 7.0_h, 8.0_h, 9.0_h, + 10.0_h, 11.0_h, 12.0_h, + + 13.0_h, 14.0_h, 15.0_h, + 16.0_h, 17.0_h, 18.0_h + }); + + inputData.push_back( + { + 19.0_h, 20.0_h, 21.0_h, + 22.0_h, 23.0_h, 24.0_h, + + 25.0_h, 26.0_h, 27.0_h, + 28.0_h, 29.0_h, 30.0_h, + + 31.0_h, 32.0_h, 33.0_h, + 34.0_h, 35.0_h, 36.0_h + }); + + std::vector outputExpectedData = + { + 1.0_h, 2.0_h, 3.0_h, + 19.0_h, 20.0_h, 21.0_h, + + 4.0_h, 5.0_h, 6.0_h, + 22.0_h, 23.0_h, 24.0_h, + + 7.0_h, 8.0_h, 9.0_h, + 25.0_h, 26.0_h, 27.0_h, + + 10.0_h, 11.0_h, 12.0_h, + 28.0_h, 29.0_h, 30.0_h, + + 13.0_h, 14.0_h, 15.0_h, + 31.0_h, 32.0_h, 33.0_h, + + 16.0_h, 17.0_h, 18.0_h, + 34.0_h, 35.0_h, 36.0_h + }; + + return StackTestHelper( + workloadFactory, + memoryManager, + inputTensorInfo, + outputTensorInfo, + 2U, + inputData, + outputExpectedData + ); +} \ No newline at end of file diff --git a/src/backends/backendsCommon/test/layerTests/StackTestImpl.hpp b/src/backends/backendsCommon/test/layerTests/StackTestImpl.hpp index f063fbb..a2eb3a1 100644 --- a/src/backends/backendsCommon/test/layerTests/StackTestImpl.hpp +++ b/src/backends/backendsCommon/test/layerTests/StackTestImpl.hpp @@ -1,5 +1,5 @@ // -// Copyright © 2017 Arm Ltd. All rights reserved. +// Copyright © 2019 Arm Ltd. All rights reserved. // SPDX-License-Identifier: MIT // @@ -14,482 +14,30 @@ #include #include -#include -#include - -#include - -namespace -{ - -template -LayerTestResult StackTestHelper( +LayerTestResult StackAxis0Float32Test( armnn::IWorkloadFactory& workloadFactory, - const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, - const armnn::TensorInfo& inputTensorInfo, - const armnn::TensorInfo& outputTensorInfo, - unsigned int axis, - const std::vector>& inputData, - const std::vector& outputExpectedData) -{ - unsigned int numInputs = static_cast(inputData.size()); - std::vector> inputs; - for (unsigned int i = 0; i < numInputs; ++i) - { - inputs.push_back(MakeTensor(inputTensorInfo, inputData[i])); - } - - LayerTestResult result(outputTensorInfo); - result.outputExpected = MakeTensor(outputTensorInfo, outputExpectedData); - - std::vector> inputHandles; - for (unsigned int i = 0; i < numInputs; ++i) - { - inputHandles.push_back(workloadFactory.CreateTensorHandle(inputTensorInfo)); - } - std::unique_ptr outputHandle = workloadFactory.CreateTensorHandle(outputTensorInfo); - - armnn::StackQueueDescriptor descriptor; - descriptor.m_Parameters.m_Axis = axis; - descriptor.m_Parameters.m_InputShape = inputTensorInfo.GetShape(); - descriptor.m_Parameters.m_NumInputs = numInputs; - - armnn::WorkloadInfo info; - for (unsigned int i = 0; i < numInputs; ++i) - { - std::unique_ptr& inputHandle = inputHandles[i]; - AddInputToWorkload(descriptor, info, inputTensorInfo, inputHandle.get()); - inputHandle->Allocate(); - CopyDataToITensorHandle(inputHandle.get(), inputs[i].origin()); - } + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager); - AddOutputToWorkload(descriptor, info, outputTensorInfo, outputHandle.get()); - outputHandle->Allocate(); - - std::unique_ptr workload = workloadFactory.CreateStack(descriptor, info); - - workload->Execute(); - - CopyDataFromITensorHandle(result.output.origin(), outputHandle.get()); - - return result; -} - -} // anonymous namespace - -template> -LayerTestResult Stack0AxisTest( +LayerTestResult StackOutput4DAxis1Float32Test( armnn::IWorkloadFactory& workloadFactory, - const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) -{ - armnn::TensorInfo inputTensorInfo ({ 3, 2, 3 }, ArmnnType); - armnn::TensorInfo outputTensorInfo({ 2, 3, 2, 3 }, ArmnnType); - - std::vector> inputData; - - inputData.push_back( - { - 1, 2, 3, - 4, 5, 6, - - 7, 8, 9, - 10, 11, 12, - - 13, 14, 15, - 16, 17, 18 - }); - - inputData.push_back( - { - 19, 20, 21, - 22, 23, 24, - - 25, 26, 27, - 28, 29, 30, - - 31, 32, 33, - 34, 35, 36 - }); - - std::vector outputExpectedData = - { - 1, 2, 3, - 4, 5, 6, - - 7, 8, 9, - 10, 11, 12, - - 13, 14, 15, - 16, 17, 18, - - - 19, 20, 21, - 22, 23, 24, - - 25, 26, 27, - 28, 29, 30, - - 31, 32, 33, - 34, 35, 36 - }; + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager); - return StackTestHelper( - workloadFactory, - memoryManager, - inputTensorInfo, - outputTensorInfo, - 0U, - inputData, - outputExpectedData - ); -} - -template> -LayerTestResult Stack4dOutput1AxisTest( +LayerTestResult StackOutput4DAxis2Float32Test( armnn::IWorkloadFactory& workloadFactory, - const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) -{ - armnn::TensorInfo inputTensorInfo ({ 3, 2, 3 }, ArmnnType); - armnn::TensorInfo outputTensorInfo({ 3, 2, 2, 3 }, ArmnnType); - - std::vector> inputData; - - inputData.push_back( - { - 1, 2, 3, - 4, 5, 6, - - 7, 8, 9, - 10, 11, 12, - - 13, 14, 15, - 16, 17, 18 - }); - - inputData.push_back( - { - 19, 20, 21, - 22, 23, 24, - - 25, 26, 27, - 28, 29, 30, - - 31, 32, 33, - 34, 35, 36 - }); - - std::vector outputExpectedData = - { - 1, 2, 3, - 4, 5, 6, - - 19, 20, 21, - 22, 23, 24, - - - 7, 8, 9, - 10, 11, 12, - - 25, 26, 27, - 28, 29, 30, - + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager); - 13, 14, 15, - 16, 17, 18, - - 31, 32, 33, - 34, 35, 36 - }; - - return StackTestHelper( - workloadFactory, - memoryManager, - inputTensorInfo, - outputTensorInfo, - 1U, - inputData, - outputExpectedData - ); -} - -template> -LayerTestResult Stack4dOutput2AxisTest( +LayerTestResult StackOutput4DAxis3Float32Test( armnn::IWorkloadFactory& workloadFactory, - const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) -{ - armnn::TensorInfo inputTensorInfo ({ 3, 2, 3 }, ArmnnType); - armnn::TensorInfo outputTensorInfo({ 3, 2, 2, 3 }, ArmnnType); - - std::vector> inputData; - - inputData.push_back( - { - 1, 2, 3, - 4, 5, 6, - - 7, 8, 9, - 10, 11, 12, - - 13, 14, 15, - 16, 17, 18 - }); - - inputData.push_back( - { - 19, 20, 21, - 22, 23, 24, - - 25, 26, 27, - 28, 29, 30, - - 31, 32, 33, - 34, 35, 36 - }); - - std::vector outputExpectedData = - { - 1, 2, 3, - 19, 20, 21, - - 4, 5, 6, - 22, 23, 24, - - 7, 8, 9, - 25, 26, 27, + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager); - 10, 11, 12, - 28, 29, 30, - - 13, 14, 15, - 31, 32, 33, - - 16, 17, 18, - 34, 35, 36 - }; - - return StackTestHelper( - workloadFactory, - memoryManager, - inputTensorInfo, - outputTensorInfo, - 2U, - inputData, - outputExpectedData - ); -} - -template> -LayerTestResult Stack4dOutput3AxisTest( +LayerTestResult StackOutput3DInputs3Float32Test( armnn::IWorkloadFactory& workloadFactory, - const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) -{ - armnn::TensorInfo inputTensorInfo ({ 3, 2, 3 }, ArmnnType); - armnn::TensorInfo outputTensorInfo({ 3, 2, 3, 2 }, ArmnnType); - - std::vector> inputData; - - inputData.push_back( - { - 1, 2, 3, - 4, 5, 6, - - 7, 8, 9, - 10, 11, 12, - - 13, 14, 15, - 16, 17, 18 - }); - - inputData.push_back( - { - 19, 20, 21, - 22, 23, 24, - - 25, 26, 27, - 28, 29, 30, - - 31, 32, 33, - 34, 35, 36 - }); - - std::vector outputExpectedData = - { - 1, 19, - 2, 20, - 3, 21, - - 4, 22, - 5, 23, - 6, 24, - + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager); - 7, 25, - 8, 26, - 9, 27, - - 10, 28, - 11, 29, - 12, 30, - - - 13, 31, - 14, 32, - 15, 33, - - 16, 34, - 17, 35, - 18, 36 - }; - - return StackTestHelper( - workloadFactory, - memoryManager, - inputTensorInfo, - outputTensorInfo, - 3U, - inputData, - outputExpectedData - ); -} - -template> -LayerTestResult Stack3dOutput1Axis3InputTest( +LayerTestResult StackOutput5DFloat32Test( armnn::IWorkloadFactory& workloadFactory, - const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) -{ - armnn::TensorInfo inputTensorInfo ({ 3, 3 }, ArmnnType); - armnn::TensorInfo outputTensorInfo({ 3, 3, 3 }, ArmnnType); - - std::vector> inputData; - - inputData.push_back( - { - 1, 2, 3, - 4, 5, 6, - 7, 8, 9 - }); - - inputData.push_back( - { - 10, 11, 12, - 13, 14, 15, - 16, 17, 18 - }); - - inputData.push_back( - { - 19, 20, 21, - 22, 23, 24, - 25, 26, 27 - }); - - std::vector outputExpectedData = - { - 1, 2, 3, - 10, 11, 12, - 19, 20, 21, - - 4, 5, 6, - 13, 14, 15, - 22, 23, 24, - - 7, 8, 9, - 16, 17, 18, - 25, 26, 27 - }; + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager); - return StackTestHelper( - workloadFactory, - memoryManager, - inputTensorInfo, - outputTensorInfo, - 1U, - inputData, - outputExpectedData - ); -} - -template> -LayerTestResult Stack5dOutputTest( +LayerTestResult StackFloat16Test( armnn::IWorkloadFactory& workloadFactory, - const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) -{ - armnn::TensorInfo inputTensorInfo ({ 2, 2, 2, 3 }, ArmnnType); - armnn::TensorInfo outputTensorInfo({ 2, 2, 2, 2, 3 }, ArmnnType); - - std::vector> inputData; - - inputData.push_back( - { - 1, 2, 3, - 4, 5, 6, - - 7, 8, 9, - 10, 11, 12, - - - 13, 14, 15, - 16, 17, 18, - - 19, 20, 21, - 22, 23, 24 - }); - - inputData.push_back( - { - 25, 26, 27, - 28, 29, 30, - - 31, 32, 33, - 34, 35, 36, - - - 37, 38, 39, - 40, 41, 42, - - 43, 44, 45, - 46, 47, 48 - }); - - std::vector outputExpectedData = - { - 1, 2, 3, - 4, 5, 6, - - 7, 8, 9, - 10, 11, 12, - - - 25, 26, 27, - 28, 29, 30, - - 31, 32, 33, - 34, 35, 36, - - - - 13, 14, 15, - 16, 17, 18, - - 19, 20, 21, - 22, 23, 24, - - - 37, 38, 39, - 40, 41, 42, - - 43, 44, 45, - 46, 47, 48 - - }; - - return StackTestHelper( - workloadFactory, - memoryManager, - inputTensorInfo, - outputTensorInfo, - 1U, - inputData, - outputExpectedData - ); -} + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager); diff --git a/src/backends/cl/test/ClCreateWorkloadTests.cpp b/src/backends/cl/test/ClCreateWorkloadTests.cpp index 833918c..bb6d041 100644 --- a/src/backends/cl/test/ClCreateWorkloadTests.cpp +++ b/src/backends/cl/test/ClCreateWorkloadTests.cpp @@ -976,6 +976,11 @@ BOOST_AUTO_TEST_CASE(CreateStackFloat32Workload) ClCreateStackWorkloadTest({ 3, 4, 5 }, { 3, 4, 2, 5 }, 2, 2); } +BOOST_AUTO_TEST_CASE(CreateStackFloat16Workload) +{ + ClCreateStackWorkloadTest({ 3, 4, 5 }, { 3, 4, 2, 5 }, 2, 2); +} + BOOST_AUTO_TEST_CASE(CreateStackUint8Workload) { ClCreateStackWorkloadTest({ 3, 4, 5 }, { 3, 4, 2, 5 }, 2, 2); diff --git a/src/backends/cl/test/ClLayerTests.cpp b/src/backends/cl/test/ClLayerTests.cpp index 3f7b282..92f8db7 100644 --- a/src/backends/cl/test/ClLayerTests.cpp +++ b/src/backends/cl/test/ClLayerTests.cpp @@ -495,12 +495,13 @@ ARMNN_AUTO_TEST_CASE(SpaceToDepthNhwcQSymm16, SpaceToDepthNhwcQSymm16Test) ARMNN_AUTO_TEST_CASE(SpaceToDepthNchwQSymm16, SpaceToDepthNchwQSymm16Test) // Stack -ARMNN_AUTO_TEST_CASE(Stack0Axis, Stack0AxisTest) -ARMNN_AUTO_TEST_CASE(Stack4dOutput1Axis, Stack4dOutput1AxisTest) -ARMNN_AUTO_TEST_CASE(Stack4dOutput2Axis, Stack4dOutput2AxisTest) -ARMNN_AUTO_TEST_CASE(Stack4dOutput3Axis, Stack4dOutput3AxisTest) -ARMNN_AUTO_TEST_CASE(Stack3dOutput1Axis3Input, Stack3dOutput1Axis3InputTest) -ARMNN_AUTO_TEST_CASE(Stack5dOutput, Stack5dOutputTest) +ARMNN_AUTO_TEST_CASE(Stack0Axis, StackAxis0Float32Test) +ARMNN_AUTO_TEST_CASE(StackOutput4DAxis1, StackOutput4DAxis1Float32Test) +ARMNN_AUTO_TEST_CASE(StackOutput4DAxis2, StackOutput4DAxis2Float32Test) +ARMNN_AUTO_TEST_CASE(StackOutput4DAxis3, StackOutput4DAxis3Float32Test) +ARMNN_AUTO_TEST_CASE(StackOutput3DInputs3, StackOutput3DInputs3Float32Test) +ARMNN_AUTO_TEST_CASE(StackOutput5D, StackOutput5DFloat32Test) +ARMNN_AUTO_TEST_CASE(StackFloat16, StackFloat16Test) // Strided Slice ARMNN_AUTO_TEST_CASE(StridedSlice4dFloat32, StridedSlice4dFloat32Test) diff --git a/src/backends/neon/test/NeonCreateWorkloadTests.cpp b/src/backends/neon/test/NeonCreateWorkloadTests.cpp index e6e1574..643ecd5 100644 --- a/src/backends/neon/test/NeonCreateWorkloadTests.cpp +++ b/src/backends/neon/test/NeonCreateWorkloadTests.cpp @@ -875,6 +875,13 @@ BOOST_AUTO_TEST_CASE(CreateStackFloat32Workload) NeonCreateStackWorkloadTest({ 3, 4, 5 }, { 3, 4, 2, 5 }, 2, 2); } +#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC +BOOST_AUTO_TEST_CASE(CreateStackFloat16Workload) +{ + NeonCreateStackWorkloadTest({ 3, 4, 5 }, { 3, 4, 2, 5 }, 2, 2); +} +#endif + BOOST_AUTO_TEST_CASE(CreateStackUint8Workload) { NeonCreateStackWorkloadTest({ 3, 4, 5 }, { 3, 4, 2, 5 }, 2, 2); diff --git a/src/backends/neon/test/NeonLayerTests.cpp b/src/backends/neon/test/NeonLayerTests.cpp index 5a0c966..d9f78e8 100644 --- a/src/backends/neon/test/NeonLayerTests.cpp +++ b/src/backends/neon/test/NeonLayerTests.cpp @@ -730,12 +730,12 @@ ARMNN_AUTO_TEST_CASE(PreluFloat32, PreluTest) ARMNN_AUTO_TEST_CASE(PreluUint8, PreluTest) // Stack -ARMNN_AUTO_TEST_CASE(Stack0Axis, Stack0AxisTest) -ARMNN_AUTO_TEST_CASE(Stack4dOutput1Axis, Stack4dOutput1AxisTest) -ARMNN_AUTO_TEST_CASE(Stack4dOutput2Axis, Stack4dOutput2AxisTest) -ARMNN_AUTO_TEST_CASE(Stack4dOutput3Axis, Stack4dOutput3AxisTest) -ARMNN_AUTO_TEST_CASE(Stack3dOutput1Axis3Input, Stack3dOutput1Axis3InputTest) -ARMNN_AUTO_TEST_CASE(Stack5dOutput, Stack5dOutputTest) +ARMNN_AUTO_TEST_CASE(Stack0Axis, StackAxis0Float32Test) +ARMNN_AUTO_TEST_CASE(StackOutput4DAxis1, StackOutput4DAxis1Float32Test) +ARMNN_AUTO_TEST_CASE(StackOutput4DAxis2, StackOutput4DAxis2Float32Test) +ARMNN_AUTO_TEST_CASE(StackOutput4DAxis3, StackOutput4DAxis3Float32Test) +ARMNN_AUTO_TEST_CASE(StackOutput3DInputs3, StackOutput3DInputs3Float32Test) +ARMNN_AUTO_TEST_CASE(StackOutput5D, StackOutput5DFloat32Test) // TransposeConvolution2d ARMNN_AUTO_TEST_CASE(SimpleTransposeConvolution2dFloatNchw, diff --git a/src/backends/reference/RefLayerSupport.cpp b/src/backends/reference/RefLayerSupport.cpp index 5c53f12..5692f9e 100644 --- a/src/backends/reference/RefLayerSupport.cpp +++ b/src/backends/reference/RefLayerSupport.cpp @@ -1481,9 +1481,10 @@ bool RefLayerSupport::IsStackSupported(const std::vector& inp ignore_unused(descriptor); bool supported = true; - std::array supportedTypes = + std::array supportedTypes = { DataType::Float32, + DataType::Float16, DataType::QuantisedAsymm8, DataType::QuantisedSymm16 }; diff --git a/src/backends/reference/RefWorkloadFactory.cpp b/src/backends/reference/RefWorkloadFactory.cpp index dc97356..f2dfb98 100644 --- a/src/backends/reference/RefWorkloadFactory.cpp +++ b/src/backends/reference/RefWorkloadFactory.cpp @@ -528,10 +528,6 @@ std::unique_ptr RefWorkloadFactory::CreateTransposeConvolution2d( std::unique_ptr RefWorkloadFactory::CreateStack(const StackQueueDescriptor& descriptor, const WorkloadInfo& info) const { - if (IsFloat16(info)) - { - return MakeWorkload(descriptor, info); - } return std::make_unique(descriptor, info); } diff --git a/src/backends/reference/test/RefLayerTests.cpp b/src/backends/reference/test/RefLayerTests.cpp index af9f645..da036a6 100644 --- a/src/backends/reference/test/RefLayerTests.cpp +++ b/src/backends/reference/test/RefLayerTests.cpp @@ -1335,11 +1335,12 @@ ARMNN_AUTO_TEST_CASE(MultiChannelTransposeConvolution2dInt16Nhwc, DataLayout::NCHW) // Stack -ARMNN_AUTO_TEST_CASE(Stack0Axis, Stack0AxisTest) -ARMNN_AUTO_TEST_CASE(Stack4dOutput1Axis, Stack4dOutput1AxisTest) -ARMNN_AUTO_TEST_CASE(Stack4dOutput2Axis, Stack4dOutput2AxisTest) -ARMNN_AUTO_TEST_CASE(Stack4dOutput3Axis, Stack4dOutput3AxisTest) -ARMNN_AUTO_TEST_CASE(Stack3dOutput1Axis3Input, Stack3dOutput1Axis3InputTest) -ARMNN_AUTO_TEST_CASE(Stack5dOutput, Stack5dOutputTest) +ARMNN_AUTO_TEST_CASE(Stack0Axis, StackAxis0Float32Test) +ARMNN_AUTO_TEST_CASE(StackOutput4DAxis1, StackOutput4DAxis1Float32Test) +ARMNN_AUTO_TEST_CASE(StackOutput4DAxis2, StackOutput4DAxis2Float32Test) +ARMNN_AUTO_TEST_CASE(StackOutput4DAxis3, StackOutput4DAxis3Float32Test) +ARMNN_AUTO_TEST_CASE(StackOutput3DInputs3, StackOutput3DInputs3Float32Test) +ARMNN_AUTO_TEST_CASE(StackOutput5D, StackOutput5DFloat32Test) +ARMNN_AUTO_TEST_CASE(StackFloat16, StackFloat16Test) BOOST_AUTO_TEST_SUITE_END() diff --git a/src/backends/reference/workloads/BaseIterator.hpp b/src/backends/reference/workloads/BaseIterator.hpp index c9fd773..18270fa 100644 --- a/src/backends/reference/workloads/BaseIterator.hpp +++ b/src/backends/reference/workloads/BaseIterator.hpp @@ -5,6 +5,8 @@ #pragma once +#include "FloatingPointConverter.hpp" + #include #include @@ -142,14 +144,31 @@ private: const int32_t m_Offset; }; -class FloatDecoder : public TypedIterator> +class Float16Decoder : public TypedIterator> { public: - FloatDecoder(const float* data) + Float16Decoder(const Half* data) : TypedIterator(data) {} - FloatDecoder() - : FloatDecoder(nullptr) {} + Float16Decoder() + : Float16Decoder(nullptr) {} + + float Get() const override + { + float val = 0.f; + armnnUtils::FloatingPointConverter::ConvertFloat16To32(m_Iterator, 1, &val); + return val; + } +}; + +class Float32Decoder : public TypedIterator> +{ +public: + Float32Decoder(const float* data) + : TypedIterator(data) {} + + Float32Decoder() + : Float32Decoder(nullptr) {} float Get() const override { @@ -238,14 +257,36 @@ private: const int32_t m_Offset; }; -class FloatEncoder : public TypedIterator> +class Float16Encoder : public TypedIterator> +{ +public: + Float16Encoder(Half* data) + : TypedIterator(data) {} + + Float16Encoder() + : Float16Encoder(nullptr) {} + + void Set(float right) override + { + armnnUtils::FloatingPointConverter::ConvertFloat32To16(&right, 1, m_Iterator); + } + + float Get() const override + { + float val = 0.f; + armnnUtils::FloatingPointConverter::ConvertFloat16To32(m_Iterator, 1, &val); + return val; + } +}; + +class Float32Encoder : public TypedIterator> { public: - FloatEncoder(float* data) + Float32Encoder(float* data) : TypedIterator(data) {} - FloatEncoder() - : FloatEncoder(nullptr) {} + Float32Encoder() + : Float32Encoder(nullptr) {} void Set(float right) override { diff --git a/src/backends/reference/workloads/Decoders.hpp b/src/backends/reference/workloads/Decoders.hpp index 0101789..328a5eb 100644 --- a/src/backends/reference/workloads/Decoders.hpp +++ b/src/backends/reference/workloads/Decoders.hpp @@ -6,6 +6,7 @@ #pragma once #include "BaseIterator.hpp" +#include "FloatingPointConverter.hpp" #include @@ -20,25 +21,29 @@ inline std::unique_ptr> MakeDecoder(const TensorInfo& info, const { switch(info.GetDataType()) { - case armnn::DataType::QuantisedAsymm8: + case DataType::QuantisedAsymm8: { return std::make_unique( static_cast(data), info.GetQuantizationScale(), info.GetQuantizationOffset()); } - case armnn::DataType::QuantisedSymm16: + case DataType::QuantisedSymm16: { return std::make_unique( static_cast(data), info.GetQuantizationScale(), info.GetQuantizationOffset()); } - case armnn::DataType::Float32: + case DataType::Float16: { - return std::make_unique(static_cast(data)); + return std::make_unique(static_cast(data)); } - case armnn::DataType::Signed32: + case DataType::Float32: + { + return std::make_unique(static_cast(data)); + } + case DataType::Signed32: { const float scale = info.GetQuantizationScale(); if (scale == 0.f) diff --git a/src/backends/reference/workloads/Encoders.hpp b/src/backends/reference/workloads/Encoders.hpp index f0e40d2..2b3a11a 100644 --- a/src/backends/reference/workloads/Encoders.hpp +++ b/src/backends/reference/workloads/Encoders.hpp @@ -38,9 +38,13 @@ inline std::unique_ptr> MakeEncoder(const TensorInfo& info, void* { return std::make_unique(static_cast(data)); } + case armnn::DataType::Float16: + { + return std::make_unique(static_cast(data)); + } case armnn::DataType::Float32: { - return std::make_unique(static_cast(data)); + return std::make_unique(static_cast(data)); } default: { -- 2.7.4