diff options
author | James Conroy <james.conroy@arm.com> | 2018-10-31 11:47:53 +0000 |
---|---|---|
committer | James Conroy <james.conroy@arm.com> | 2018-10-31 12:06:53 +0000 |
commit | 45a9b775bf63283320315d90e4e9a6c641df6e20 (patch) | |
tree | e1f0d33d98410255a6804ea9cccf16805fc6080f /src/backends/reference | |
parent | d84216a013445e86183e39c8b5b904836c71a95b (diff) | |
download | armnn-45a9b775bf63283320315d90e4e9a6c641df6e20.tar.gz |
IVGCVSW-2102: Fix Pooling2D CpuRef indexing bug
* Fixes bug when calcuating indexes for NHWC in
Pooling2D CpuRef implementation, it now uses
TensorBufferArrayView.
* Adds 2-Channel unit tests for Pooling2d on CpuRef,
Cl and Neon. The single channel tests were not
properly exercising Pooling2d using NHWC data layout.
* Refactors Pooling2D NHWC tests so that the input and
output data are permuted to NHWC when necessary,
instead of hard coding the data in NHWC format.
Change-Id: I5b9d41ed425ff283ea8c8ef6b1266ae0bc80f43b
Diffstat (limited to 'src/backends/reference')
-rw-r--r-- | src/backends/reference/test/RefLayerTests.cpp | 20 | ||||
-rw-r--r-- | src/backends/reference/workloads/Pooling2d.cpp | 27 |
2 files changed, 30 insertions, 17 deletions
diff --git a/src/backends/reference/test/RefLayerTests.cpp b/src/backends/reference/test/RefLayerTests.cpp index 40944bf5a6..f5884aee17 100644 --- a/src/backends/reference/test/RefLayerTests.cpp +++ b/src/backends/reference/test/RefLayerTests.cpp @@ -114,10 +114,16 @@ ARMNN_AUTO_TEST_CASE(IgnorePaddingSimpleL2Pooling2dUint8, IgnorePaddingSimpleL2P ARMNN_AUTO_TEST_CASE(IgnorePaddingL2Pooling2dSize3, IgnorePaddingL2Pooling2dSize3Test) ARMNN_AUTO_TEST_CASE(IgnorePaddingL2Pooling2dSize3Uint8, IgnorePaddingL2Pooling2dSize3Uint8Test) -ARMNN_AUTO_TEST_CASE(SimpleAveragePooling2d, SimpleAveragePooling2dTest) -ARMNN_AUTO_TEST_CASE(SimpleAveragePooling2dNhwc, SimpleAveragePooling2dNhwcTest) -ARMNN_AUTO_TEST_CASE(SimpleAveragePooling2dUint8, SimpleAveragePooling2dUint8Test) -ARMNN_AUTO_TEST_CASE(SimpleAveragePooling2dUint8Nhwc, SimpleAveragePooling2dUint8NhwcTest) +ARMNN_AUTO_TEST_CASE(SimpleMaxPooling2d, SimpleMaxPooling2dTest, armnn::DataLayout::NCHW) +ARMNN_AUTO_TEST_CASE(SimpleMaxPooling2dNhwc, SimpleMaxPooling2dTest, armnn::DataLayout::NHWC) +ARMNN_AUTO_TEST_CASE(SimpleMaxPooling2dUint8, SimpleMaxPooling2dUint8Test, armnn::DataLayout::NCHW) +ARMNN_AUTO_TEST_CASE(SimpleMaxPooling2dUint8Nhwc, SimpleMaxPooling2dUint8Test, armnn::DataLayout::NHWC) + +ARMNN_AUTO_TEST_CASE(SimpleAveragePooling2d, SimpleAveragePooling2dTest, armnn::DataLayout::NCHW) +ARMNN_AUTO_TEST_CASE(SimpleAveragePooling2dNhwc, SimpleAveragePooling2dTest, armnn::DataLayout::NHWC) +ARMNN_AUTO_TEST_CASE(SimpleAveragePooling2dUint8, SimpleAveragePooling2dUint8Test, armnn::DataLayout::NCHW) +ARMNN_AUTO_TEST_CASE(SimpleAveragePooling2dUint8Nhwc, SimpleAveragePooling2dUint8Test, armnn::DataLayout::NHWC) + ARMNN_AUTO_TEST_CASE(IgnorePaddingAveragePooling2dSize3x2Stride2x2, IgnorePaddingAveragePooling2dSize3x2Stride2x2Test, false) ARMNN_AUTO_TEST_CASE(IgnorePaddingAveragePooling2dSize3x2Stride2x2NoPadding, @@ -126,8 +132,10 @@ ARMNN_AUTO_TEST_CASE(IgnorePaddingAveragePooling2dSize3x2Stride2x2NoPadding, ARMNN_AUTO_TEST_CASE(LargeTensorsAveragePooling2d, LargeTensorsAveragePooling2dTest) ARMNN_AUTO_TEST_CASE(LargeTensorsAveragePooling2dUint8, LargeTensorsAveragePooling2dUint8Test) -ARMNN_AUTO_TEST_CASE(SimpleL2Pooling2d, SimpleL2Pooling2dTest) -ARMNN_AUTO_TEST_CASE(SimpleL2Pooling2dUint8, SimpleL2Pooling2dUint8Test) +ARMNN_AUTO_TEST_CASE(SimpleL2Pooling2d, SimpleL2Pooling2dTest, armnn::DataLayout::NCHW) +ARMNN_AUTO_TEST_CASE(SimpleL2Pooling2dNhwc, SimpleL2Pooling2dTest, armnn::DataLayout::NHWC) +ARMNN_AUTO_TEST_CASE(SimpleL2Pooling2dUint8, SimpleL2Pooling2dUint8Test, armnn::DataLayout::NCHW) +ARMNN_AUTO_TEST_CASE(SimpleL2Pooling2dNhwcUint8, SimpleL2Pooling2dUint8Test, armnn::DataLayout::NHWC) ARMNN_AUTO_TEST_CASE(L2Pooling2dSize7, L2Pooling2dSize7Test) ARMNN_AUTO_TEST_CASE(L2Pooling2dSize7Uint8, L2Pooling2dSize7Uint8Test) diff --git a/src/backends/reference/workloads/Pooling2d.cpp b/src/backends/reference/workloads/Pooling2d.cpp index 9890920113..d2fd0da42c 100644 --- a/src/backends/reference/workloads/Pooling2d.cpp +++ b/src/backends/reference/workloads/Pooling2d.cpp @@ -4,6 +4,7 @@ // #include "Pooling2d.hpp" +#include "TensorBufferArrayView.hpp" #include <armnn/Exceptions.hpp> #include <armnn/Types.hpp> @@ -143,9 +144,10 @@ void Pooling2d(const float* in, const TensorInfo& outputInfo, const Pooling2dDescriptor& params) { - const unsigned int channelsIndex = params.m_DataLayout.GetChannelsIndex(); - const unsigned int heightIndex = params.m_DataLayout.GetHeightIndex(); - const unsigned int widthIndex = params.m_DataLayout.GetWidthIndex(); + const armnn::DataLayoutIndexed dataLayout = params.m_DataLayout; + auto channelsIndex = dataLayout.GetChannelsIndex(); + auto heightIndex = dataLayout.GetHeightIndex(); + auto widthIndex = dataLayout.GetWidthIndex(); const int batchSize = boost::numeric_cast<int>(outputInfo.GetShape()[0]); const int channels = boost::numeric_cast<int>(outputInfo.GetShape()[channelsIndex]); @@ -167,6 +169,9 @@ void Pooling2d(const float* in, Accumulator accumulate = GetAccumulator(params.m_PoolType); Executor execute = GetExecutor(params.m_PoolType); + TensorBufferArrayView<const float> input(inputInfo.GetShape(), in, dataLayout); + TensorBufferArrayView<float> output(outputInfo.GetShape(), out, dataLayout); + // Check supported padding methods outside the loop to simplify // the inner loop. if (params.m_PaddingMethod != PaddingMethod::Exclude && @@ -221,10 +226,10 @@ void Pooling2d(const float* in, { for (auto xInput = wstart; xInput < wend; xInput++) { - float inval = in[n * widthInput * heightInput * channels + - c * widthInput * heightInput + - yInput * widthInput + - xInput]; + float inval = input.Get(boost::numeric_cast<unsigned int>(n), + boost::numeric_cast<unsigned int>(c), + boost::numeric_cast<unsigned int>(yInput), + boost::numeric_cast<unsigned int>(xInput)); accumulate(result, inval); } @@ -232,10 +237,10 @@ void Pooling2d(const float* in, execute(result, poolAreaSize); - out[n * widthOutput * heightOutput * channels + - c * widthOutput * heightOutput + - yOutput * widthOutput + - xOutput] = result; + output.Get(boost::numeric_cast<unsigned int>(n), + boost::numeric_cast<unsigned int>(c), + boost::numeric_cast<unsigned int>(yOutput), + boost::numeric_cast<unsigned int>(xOutput)) = result; } } } |