diff --git a/src/plugins/intel_cpu/src/nodes/gather.cpp b/src/plugins/intel_cpu/src/nodes/gather.cpp index cf54fcd0b6f..c6753543ee7 100644 --- a/src/plugins/intel_cpu/src/nodes/gather.cpp +++ b/src/plugins/intel_cpu/src/nodes/gather.cpp @@ -140,18 +140,40 @@ void Gather::initSupportedPrimitiveDescriptors() { // Let's check for the special inPlace memory use case // in place only makes sense when we split by dense blocks since strided tensors are not supported by most nodes - const auto& parentdDims = inputShapes[0].getDims(); - if (isAxisInputConst && - 0 == batchDims && - 1 == constIndices.size() && - parentdDims[axis] != Shape::UNDEFINED_DIM && - std::all_of(parentdDims.begin(), parentdDims.begin() + axis, [](size_t dim) { return dim == 1; })) { - addSupportedPrimDesc({{LayoutType::ncsp, dataPrecision}, - {LayoutType::ncsp, Precision::I32}, - {LayoutType::ncsp, Precision::I32, isAxisInputConst}}, - {{LayoutType::ncsp, dataPrecision, false, GATHER_DATA}}, - unknown); + if (!isAxisInputConst) { + return; } + + if (batchDims != 0) { + return; + } + + if (constIndices.size() != 1) { + return; + } + + const auto& parentDims = inputShapes[0].getDims(); + const auto axisDim = parentDims[axis]; + if (Shape::UNDEFINED_DIM == axisDim) { + return; + } + + const auto indx = constIndices.front(); + const auto normIndex = indx < 0 ? static_cast(axisDim) + indx : indx; + + if (normIndex < 0 || normIndex >= static_cast(axisDim)) { + return; + } + + if (std::any_of(parentDims.begin(), parentDims.begin() + axis, [](size_t dim) { return dim != 1; })) { + return; + } + + addSupportedPrimDesc({{LayoutType::ncsp, dataPrecision}, + {LayoutType::ncsp, Precision::I32}, + {LayoutType::ncsp, Precision::I32, isAxisInputConst}}, + {{LayoutType::ncsp, dataPrecision, false, GATHER_DATA}}, + unknown); } void Gather::createPrimitive() { @@ -293,6 +315,9 @@ void Gather::prepareParams() { } void Gather::execute(dnnl::stream strm) { + if (isInPlace()) { + return; + } #if defined(OPENVINO_ARCH_X86_64) if (jitKernel && jitKernel->isSupportedConfiguration(afterAxisSize)) { const void* srcIndices = getParentEdgeAt(GATHER_INDICES)->getMemoryPtr()->getData(); @@ -349,6 +374,9 @@ void Gather::execute(dnnl::stream strm) { } void Gather::executeDynamicImpl(dnnl::stream strm) { + if (isInPlace()) { + return; + } #if defined(OPENVINO_ARCH_X86_64) if (jitKernel && jitKernel->isSupportedConfiguration(afterAxisSize)) { const void* srcIndices = getParentEdgeAt(GATHER_INDICES)->getMemoryPtr()->getData(); @@ -530,11 +558,11 @@ void Gather::resolveInPlaceEdges(Edge::LOOK look) { auto& config = selected_pd->getConfig(); size_t inplaceInpIndx = selected_pd->getConfig().outConfs[outputPort].inPlace(); - auto baseDim = inputShapes.front().getDims()[axis]; + const auto baseDim = inputShapes.front().getDims()[axis]; IE_ASSERT(baseDim != Shape::UNDEFINED_DIM) << "Gather node: " << getName() << " can not use inPlace memory with splitting on dynamic dimention"; auto baseMemMngr = getParentEdgesAtPort(inplaceInpIndx).front()->getMemory().getMemoryMngr(); - auto index = constIndices.at(0); - ptrdiff_t offset = index < 0 ? baseDim + index : index; + const auto index = constIndices.front(); + const ptrdiff_t offset = index < 0 ? baseDim + index : index; const auto& childEdges = getChildEdgesAtPort(outputPort); for (auto& childEdge : childEdges) { IE_ASSERT(childEdge->getStatus() == Edge::Status::NotAllocated) << " Unexpected edge status in node: " << diff --git a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/skip_tests_config.cpp b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/skip_tests_config.cpp index 97ed417528e..74e927b6bad 100644 --- a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/skip_tests_config.cpp +++ b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/skip_tests_config.cpp @@ -190,6 +190,8 @@ std::vector disabledTestPatterns() { R"(.*(Auto|Multi|Hetero).*InferRequestPreprocessTest.*SetPreProcessToInferRequest.*)", // TODO: for 22.2 (Issue 68949) R"(.*smoke_AutoBatching_CPU/AutoBatching_Test_DetectionOutput.*)", + // Issue: 117837 + R"(.*smoke_4D_out_of_range/GatherInPlaceLayerTestCPU.*_indices=\(\-15\).*)", }; #if defined(OPENVINO_ARCH_X86) diff --git a/src/plugins/intel_cpu/tests/functional/single_layer_tests/gather.cpp b/src/plugins/intel_cpu/tests/functional/single_layer_tests/gather.cpp index 70570d32172..9bfd1673cfc 100644 --- a/src/plugins/intel_cpu/tests/functional/single_layer_tests/gather.cpp +++ b/src/plugins/intel_cpu/tests/functional/single_layer_tests/gather.cpp @@ -148,7 +148,7 @@ protected: typedef std::tuple< InputShape, // Input shapes - std::vector, // Indices + std::vector, // Indices int, // Axis ElementType, // Network precision CPUSpecificParams // CPU specific params @@ -159,7 +159,7 @@ class GatherInPlaceLayerTestCPU : public testing::WithParamInterface obj) { InputShape inputShapes; - std::vector indices; + std::vector indices; int axis; ElementType netPrecision; CPUSpecificParams cpuParams; @@ -187,7 +187,7 @@ public: protected: void SetUp() override { InputShape inputShapes; - std::vector indices; + std::vector indices; int axis; ElementType netPrecision; CPUSpecificParams cpuParams; @@ -924,32 +924,41 @@ INSTANTIATE_TEST_SUITE_P(smoke_static_4D_ref8_Bmax, GatherLayerTestCPU, // InPlace const std::vector shapesInPlace4D_0 = { - { {}, { {5, 4, 4, 19} } }, // Static shapes - { {5, 4, -1, -1}, { {5, 4, 4, 19}, {5, 4, 4, 25}, {5, 4, 2, 19} } }, // Static shapes + { {}, { {5, 4, 4, 19} } }, + { {5, 4, -1, -1}, { {5, 4, 4, 19}, {5, 4, 4, 25}, {5, 4, 2, 19} } }, }; INSTANTIATE_TEST_SUITE_P(smoke_inplace_4D_0, GatherInPlaceLayerTestCPU, ::testing::Combine( ::testing::ValuesIn(shapesInPlace4D_0), - ::testing::Values(std::vector{ 2 }), + ::testing::Values(std::vector{ 2 }), ::testing::Values(0), ::testing::Values(ElementType::f32), ::testing::Values(CPUSpecificParams{{}, {}, {}, "unknown"})), GatherInPlaceLayerTestCPU::getTestCaseName); const std::vector shapesInPlace4D_1 = { - { {}, { {1, 9, 4, 19} } }, // Static shapes - { {1, 9, -1, -1}, { {1, 9, 4, 19}, {1, 9, 4, 25}, {1, 9, 2, 19} } }, // Static shapes + { {}, { {1, 9, 4, 19} } }, + { {1, 9, -1, -1}, { {1, 9, 4, 19}, {1, 9, 4, 25}, {1, 9, 2, 19} } }, }; INSTANTIATE_TEST_SUITE_P(smoke_inplace_4D_1, GatherInPlaceLayerTestCPU, ::testing::Combine( ::testing::ValuesIn(shapesInPlace4D_1), - ::testing::Values(std::vector{ 4 }), + ::testing::Values(std::vector{ -4 }, std::vector{ 5 }), ::testing::Values(1), ::testing::Values(ElementType::f32), ::testing::Values(CPUSpecificParams{{}, {}, {}, "unknown"})), GatherInPlaceLayerTestCPU::getTestCaseName); +INSTANTIATE_TEST_SUITE_P(smoke_4D_out_of_range, GatherInPlaceLayerTestCPU, + ::testing::Combine( + ::testing::ValuesIn(shapesInPlace4D_1), + ::testing::Values(std::vector{ 10 }, std::vector{ -15 }), + ::testing::Values(1), + ::testing::Values(ElementType::f32), + ::testing::Values(CPUSpecificParams{{}, {}, {}, "ref_any"})), + GatherInPlaceLayerTestCPU::getTestCaseName); + } // namespace } // namespace CPULayerTestsDefinitions