From 0a99a1469f6ca683df65937ae3ad217b732d01c5 Mon Sep 17 00:00:00 2001 From: David Monahan Date: Fri, 13 Mar 2020 07:52:54 +0000 Subject: [PATCH] IVGCVSW-4531 Fix for failing strided slice NNT/VTS tests on Android R Signed-off-by: David Monahan Change-Id: I7f6932f0d21b5678ab9822b0fc69f589bbbb07e5 --- src/armnn/layers/StridedSliceLayer.cpp | 14 +++++--- .../backendsCommon/test/EndToEndTestImpl.hpp | 36 +++++++++++++++++++ src/backends/cl/test/ClEndToEndTests.cpp | 5 +++ src/backends/neon/test/NeonEndToEndTests.cpp | 5 +++ .../reference/test/RefEndToEndTests.cpp | 5 +++ 5 files changed, 61 insertions(+), 4 deletions(-) diff --git a/src/armnn/layers/StridedSliceLayer.cpp b/src/armnn/layers/StridedSliceLayer.cpp index b9c337188..dd4f94208 100644 --- a/src/armnn/layers/StridedSliceLayer.cpp +++ b/src/armnn/layers/StridedSliceLayer.cpp @@ -52,15 +52,21 @@ std::vector StridedSliceLayer::InferOutputShapes( for (unsigned int i = 0; i < inputShape.GetNumDimensions(); i++) { + int stride = m_Param.m_Stride[i]; + int start = m_Param.GetStartForAxis(inputShape, i); + int stop = m_Param.GetStopForAxis(inputShape, i, start); + if (m_Param.m_ShrinkAxisMask & (1 << i)) { + // Don't take a slice from an axis being shrunk + if (m_Param.m_End[i] >= 2) + { + throw LayerValidationException( + "StridedSlice: Attempting to take slice from an axis being shrunk"); + } continue; } - int stride = m_Param.m_Stride[i]; - int start = m_Param.GetStartForAxis(inputShape, i); - int stop = m_Param.GetStopForAxis(inputShape, i, start); - int newSize = stride > 0 ? ((stop - start) + stride - 1) / stride : ((start - stop) - stride - 1) / -stride; diff --git a/src/backends/backendsCommon/test/EndToEndTestImpl.hpp b/src/backends/backendsCommon/test/EndToEndTestImpl.hpp index 358f4e3fc..4221f626d 100644 --- a/src/backends/backendsCommon/test/EndToEndTestImpl.hpp +++ b/src/backends/backendsCommon/test/EndToEndTestImpl.hpp @@ -766,4 +766,40 @@ inline void ExportOutputWithSeveralOutputSlotConnectionsTest(std::vector backends) +{ + using namespace armnn; + + // Create runtime in which test will run + IRuntime::CreationOptions options; + IRuntimePtr runtime(armnn::IRuntime::Create(options)); + + // build up the structure of the network + INetworkPtr net(INetwork::Create()); + + IConnectableLayer* input = net->AddInputLayer(0); + + // Configure a strided slice with a stride the same size as the input but with a ShrinkAxisMask on the first + // dim of the output to make it too small to hold the specified slice. + StridedSliceDescriptor descriptor; + descriptor.m_Begin = {0, 0}; + descriptor.m_End = {2, 3}; + descriptor.m_Stride = {1, 1}; + descriptor.m_BeginMask = 0; + descriptor.m_EndMask = 0; + descriptor.m_ShrinkAxisMask = 1; + IConnectableLayer* stridedSlice = net->AddStridedSliceLayer(descriptor); + + IConnectableLayer* output0 = net->AddOutputLayer(0); + + input->GetOutputSlot(0).Connect(stridedSlice->GetInputSlot(0)); + stridedSlice->GetOutputSlot(0).Connect(output0->GetInputSlot(0)); + + input->GetOutputSlot(0).SetTensorInfo(TensorInfo({ 2, 3 }, DataType::Float32)); + stridedSlice->GetOutputSlot(0).SetTensorInfo(TensorInfo({ 3 }, DataType::Float32)); + + // Attempt to optimize the network and check that the correct exception is thrown + BOOST_CHECK_THROW(Optimize(*net, backends, runtime->GetDeviceSpec()), armnn::LayerValidationException); +} + } // anonymous namespace diff --git a/src/backends/cl/test/ClEndToEndTests.cpp b/src/backends/cl/test/ClEndToEndTests.cpp index 10abcc9fe..05f9538d6 100644 --- a/src/backends/cl/test/ClEndToEndTests.cpp +++ b/src/backends/cl/test/ClEndToEndTests.cpp @@ -126,6 +126,11 @@ BOOST_AUTO_TEST_CASE(DequantizeEndToEndOffsetTest) DequantizeEndToEndOffset(defaultBackends); } +BOOST_AUTO_TEST_CASE(ClStridedSliceInvalidSliceEndToEndTest) +{ + StridedSliceInvalidSliceEndToEndTest(defaultBackends); +} + BOOST_AUTO_TEST_CASE(ClGreaterSimpleEndToEndTest) { const std::vector expectedOutput({ 0, 0, 0, 0, 1, 1, 1, 1, diff --git a/src/backends/neon/test/NeonEndToEndTests.cpp b/src/backends/neon/test/NeonEndToEndTests.cpp index abded6491..081b8af60 100644 --- a/src/backends/neon/test/NeonEndToEndTests.cpp +++ b/src/backends/neon/test/NeonEndToEndTests.cpp @@ -513,6 +513,11 @@ BOOST_AUTO_TEST_CASE(NeonArgMinAxis3TestQuantisedAsymm8) ArgMinAxis3EndToEnd(defaultBackends); } +BOOST_AUTO_TEST_CASE(NeonStridedSliceInvalidSliceEndToEndTest) +{ + StridedSliceInvalidSliceEndToEndTest(defaultBackends); +} + BOOST_AUTO_TEST_CASE(NeonDetectionPostProcessRegularNmsTest, * boost::unit_test::disabled()) { std::vector boxEncodings({ diff --git a/src/backends/reference/test/RefEndToEndTests.cpp b/src/backends/reference/test/RefEndToEndTests.cpp index 54a68810f..bdda12f39 100644 --- a/src/backends/reference/test/RefEndToEndTests.cpp +++ b/src/backends/reference/test/RefEndToEndTests.cpp @@ -1210,6 +1210,11 @@ BOOST_AUTO_TEST_CASE(RefExportOutputWithSeveralOutputSlotConnectionsTest) ExportOutputWithSeveralOutputSlotConnectionsTest(defaultBackends); } +BOOST_AUTO_TEST_CASE(RefStridedSliceInvalidSliceEndToEndTest) +{ + StridedSliceInvalidSliceEndToEndTest(defaultBackends); +} + #endif BOOST_AUTO_TEST_SUITE_END() -- 2.34.1