From 1d247815be1bad8c1cbaed2d82c38b49d4269c6a Mon Sep 17 00:00:00 2001 From: Maxim Andronov Date: Thu, 31 Mar 2022 15:42:10 +0300 Subject: [PATCH] Don't execute reference::strided_slice if input/output tensor is empty (#11337) --- .../functional/op_reference/strided_slice.cpp | 14 ++++++++++++++ .../src/runtime/reference/strided_slice.cpp | 9 +++++++++ 2 files changed, 23 insertions(+) diff --git a/docs/template_plugin/tests/functional/op_reference/strided_slice.cpp b/docs/template_plugin/tests/functional/op_reference/strided_slice.cpp index c241b7d3b6e..5ce1bebf63b 100644 --- a/docs/template_plugin/tests/functional/op_reference/strided_slice.cpp +++ b/docs/template_plugin/tests/functional/op_reference/strided_slice.cpp @@ -368,6 +368,20 @@ std::vector generateStrideOptionalParams() { std::vector{0, 0, 0}, reference_tests::Tensor(IN_ET, {1, 4}, std::vector{20, 21, 22, 23}), "strided_slice_stride_optional_dynamic"), + // strided_slice_stride_optional_dynamic_empty_output_tensor + StridedSliceStrideOptionalParams( + PartialShape::dynamic(), + reference_tests::Tensor(IN_ET, {2, 3, 4}, std::vector{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, + 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23}), + reference_tests::Tensor(element::i64, {2}, std::vector{0, 0}), + reference_tests::Tensor(element::i64, {2}, std::vector{-1, 0}), + std::vector{1, 0}, + std::vector{1, 0}, + std::vector{}, + std::vector{}, + std::vector{}, + reference_tests::Tensor(IN_ET, {2, 0, 4}, std::vector{}), + "strided_slice_stride_optional_dynamic_empty_output_tensor"), }; return params; } diff --git a/src/core/reference/src/runtime/reference/strided_slice.cpp b/src/core/reference/src/runtime/reference/strided_slice.cpp index dd02f6412fb..e039e4d0917 100644 --- a/src/core/reference/src/runtime/reference/strided_slice.cpp +++ b/src/core/reference/src/runtime/reference/strided_slice.cpp @@ -18,6 +18,15 @@ void runtime::reference::strided_slice(const char* arg, const Shape& arg_shape, const SlicePlan& sp, size_t elem_type) { + auto hasZeroDims = [](const ov::Shape& shape) -> bool { + return std::any_of(shape.begin(), shape.end(), [](const size_t& dim) { + return dim == 0; + }); + }; + if (hasZeroDims(sp.reshape_in_shape) || hasZeroDims(sp.reshape_out_shape)) { + return; + } + runtime::AlignedBuffer slice_out_buffer(shape_size(sp.reshape_in_shape) * elem_type); slice(reinterpret_cast(arg), slice_out_buffer.get_ptr(),