From 0e9b133de56ea360234a7eaad86933dfd728f218 Mon Sep 17 00:00:00 2001 From: Zhang Yi Date: Thu, 2 Mar 2023 23:56:25 +0800 Subject: [PATCH] [CPU] StridedSlice fix execution for empty output tensor (#16045) * stridedslice skip execution with 0 dims * use isExecutable & add subgraph tests * remove useless code --- .../intel_cpu/src/nodes/strided_slice.cpp | 3 +- .../single_layer_tests/strided_slice.cpp | 8 +-- .../src/strided_slice_zero_dims.cpp | 56 +++++++++++++++++++ 3 files changed, 61 insertions(+), 6 deletions(-) create mode 100644 src/plugins/intel_cpu/tests/functional/subgraph_tests/src/strided_slice_zero_dims.cpp diff --git a/src/plugins/intel_cpu/src/nodes/strided_slice.cpp b/src/plugins/intel_cpu/src/nodes/strided_slice.cpp index 5c74e7f1c2e..2ff738c0425 100644 --- a/src/plugins/intel_cpu/src/nodes/strided_slice.cpp +++ b/src/plugins/intel_cpu/src/nodes/strided_slice.cpp @@ -281,7 +281,7 @@ void StridedSlice::initSupportedPrimitiveDescriptors() { } bool StridedSlice::isExecutable() const { - return !isInputTensorAtPortEmpty(0); + return !isInputTensorAtPortEmpty(0) && !isOutputTensorAtPortEmpty(0); } void StridedSlice::createPrimitive() { @@ -310,7 +310,6 @@ void StridedSlice::prepareParams() { dstMemory.push_back(getChildEdgeAt(i)->getMemoryPtr()); } } - execPtr = std::make_shared(attrs, srcMemory, dstMemory, errorPrefix); } diff --git a/src/plugins/intel_cpu/tests/functional/single_layer_tests/strided_slice.cpp b/src/plugins/intel_cpu/tests/functional/single_layer_tests/strided_slice.cpp index c1f3ef47da8..3508818b9fc 100644 --- a/src/plugins/intel_cpu/tests/functional/single_layer_tests/strided_slice.cpp +++ b/src/plugins/intel_cpu/tests/functional/single_layer_tests/strided_slice.cpp @@ -213,10 +213,10 @@ const std::vector inputShapesStatic4D = { const std::vector inputShapesDynamic4D = { {{-1, -1, -1, -1}, - {{ 1, 5, 32, 32 }, { 2, 5, 32, 32 }, { 1, 5, 64, 64 }}}, + {{ 1, 5, 32, 32 }, { 2, 5, 32, 32 }, { 1, 5, 64, 64 }, {0, 0, 0, 0}}}, {{-1, 5, -1, -1}, - {{ 1, 5, 32, 32 }, { 2, 5, 32, 32 }, { 3, 5, 32, 36 }}}, + {{ 1, 5, 32, 32 }, { 2, 5, 32, 32 }, { 3, 5, 32, 36 }, {0, 5, 0, 0}}}, {{{1, 5}, 5, {32, 64}, {32, 64}}, {{ 2, 5, 32, 32 }, { 1, 5, 48, 32 }, { 5, 5, 32, 32 }}}, @@ -352,10 +352,10 @@ const std::vector inputShapesStatic5D = { const std::vector inputShapesDynamic5D = { {{-1, -1, -1, -1, -1}, - {{ 1, 5, 32, 32, 32 }, { 1, 5, 32, 32, 48 }, { 1, 5, 64, 64, 64 }, { 1, 10, 32, 32, 32 }}}, + {{ 1, 5, 32, 32, 32 }, { 1, 5, 32, 32, 48 }, { 1, 5, 64, 64, 64 }, { 1, 10, 32, 32, 32 }, {0, 0, 0, 0, 0}}}, {{-1, 5, -1, -1, -1}, - {{ 1, 5, 32, 32, 48 }, { 1, 5, 32, 48, 32 }, { 1, 5, 48, 32, 32 }}}, + {{ 1, 5, 32, 32, 48 }, { 1, 5, 32, 48, 32 }, { 1, 5, 48, 32, 32 }, {0, 5, 0, 0, 0}}}, {{{1, 5}, 5, {32, 64}, {32, 64}, {32, 64}}, {{ 2, 5, 32, 32, 32 }, { 1, 5, 48, 32, 32 }, { 5, 5, 32, 32, 48 }}}, diff --git a/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/strided_slice_zero_dims.cpp b/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/strided_slice_zero_dims.cpp new file mode 100644 index 00000000000..041a21f047a --- /dev/null +++ b/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/strided_slice_zero_dims.cpp @@ -0,0 +1,56 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "shared_test_classes/base/ov_subgraph.hpp" +#include "ngraph_functions/utils/ngraph_helpers.hpp" +#include "ngraph_functions/builders.hpp" + +using namespace InferenceEngine; +using namespace ov::test; +using namespace ngraph; + +namespace SubgraphTestsDefinitions { + +/* + param1 [56] param2 [-1, -1, 768] (dynamic shape) + \ | + \ | + \ shapeOf [4] (variable) + \ | + \ | + \ Gather (get dynamic element) [1] (static value) + \ | + \ | OtherConstants + \ | / + StridedSlice [47] (Static output shape) + | + | + Result +*/ + +class StridedSliceZeroDimsTest : public SubgraphBaseTest { +public: + void SetUp() override { + targetDevice = CommonTestUtils::DEVICE_CPU; + InputShape inpShape0 = {{}, {{56}}}; + InputShape inpShape1 = {{-1, -1, 768}, {{1, 544, 768}}}; + init_input_shapes({inpShape0, inpShape1}); + auto inputParams = builder::makeDynamicParams(element::f32, inputDynamicShapes); + auto end = builder::makeConstant(element::i64, {1}, std::vector{2147483647}); + auto stride = builder::makeConstant(element::i64, {1}, std::vector{1}); + auto indices = builder::makeConstant(element::i64, {1}, std::vector{1}); + auto axes = builder::makeConstant(element::i64, {1}, std::vector{0}); + auto shapeOf = std::make_shared(inputParams[1]); + auto gather = std::make_shared(shapeOf, indices, axes); + auto strided_slice = builder::makeStridedSlice(inputParams.front(), gather, end, stride, element::f32, {0}, {0}); + NodeVector results{strided_slice}; + function = std::make_shared(results, inputParams, "StridedSliceStaticShape"); + } +}; + +TEST_F(StridedSliceZeroDimsTest, smoke_CompareWithRefs) { + run(); +} + +} // namespace SubgraphTestsDefinitions \ No newline at end of file