From 2d3aab33b0cf67234283f2f1cf9260dea16bd1a8 Mon Sep 17 00:00:00 2001 From: Yury Gaydaychuk Date: Thu, 31 Aug 2023 16:13:39 +0200 Subject: [PATCH] [CPU] Deformable Convolution minor fixes (#19415) --- src/plugins/intel_cpu/src/nodes/def_conv.cpp | 25 +++++++++++--- .../skip_tests_config.cpp | 2 -- .../deformable_convolution.cpp | 34 +++++++++++++++++++ 3 files changed, 55 insertions(+), 6 deletions(-) diff --git a/src/plugins/intel_cpu/src/nodes/def_conv.cpp b/src/plugins/intel_cpu/src/nodes/def_conv.cpp index d8dd6bb1a6b..057430e8d52 100644 --- a/src/plugins/intel_cpu/src/nodes/def_conv.cpp +++ b/src/plugins/intel_cpu/src/nodes/def_conv.cpp @@ -825,6 +825,9 @@ void DeformableConvolution::initSupportedPrimitiveDescriptors() { auto &weiDims = getInputShapeAtPort(WEI_ID).getDims(); if (weiDims[1] == Shape::UNDEFINED_DIM || weiDims[0] == Shape::UNDEFINED_DIM || + // 1. strict fallback, until devising of multigroup handling in common case + defConvAttr.group != 1 || + // 2. common fallback, except specific n_group / n_channel combinations (defConvAttr.group != 1 && ((weiDims[1] % simd_w != 0) // in_channels_per_gr !% simd_w || ((weiDims[0] / defConvAttr.group) % simd_w != 0)))) { // out_channels_per_gr !% simd_w enforceRef = true; @@ -1140,10 +1143,24 @@ void DeformableConvolution::DefConvRefExecutor::exec(const float* src, const flo const int v12 = pSampledCoordsVector[sampledCoordIndex + 1]; const int v21 = pSampledCoordsVector[sampledCoordIndex + 2]; const int v22 = pSampledCoordsVector[sampledCoordIndex + 3]; - float val = pInterpWeightsVector[sampledCoordIndex++] * data_im_ptr[v11]; // v11 - val += pInterpWeightsVector[sampledCoordIndex++] * data_im_ptr[v12]; // v12 - val += pInterpWeightsVector[sampledCoordIndex++] * data_im_ptr[v21]; // v21 - val += pInterpWeightsVector[sampledCoordIndex++] * data_im_ptr[v22]; // v22 + + float val = 0; + float w11 = pInterpWeightsVector[sampledCoordIndex++]; + float w12 = pInterpWeightsVector[sampledCoordIndex++]; + float w21 = pInterpWeightsVector[sampledCoordIndex++]; + float w22 = pInterpWeightsVector[sampledCoordIndex++]; + + // Prevent access to invalid memory in the case, when + // data_im_ptr[v_i1_i2] is out of the input memory. + // Logic of skipping of such points realized by nullifying + // of corresponding weight, but we must explicitly check it, because + // 0 * (*wrong_pointer) != 0 in common case, i.e. + // 0 * NaN == NaN or throws segfault + val += ((w11 == 0) ? 0 : w11 * data_im_ptr[v11]); + val += ((w12 == 0) ? 0 : w12 * data_im_ptr[v12]); + val += ((w21 == 0) ? 0 : w21 * data_im_ptr[v21]); + val += ((w22 == 0) ? 0 : w22 * data_im_ptr[v22]); + d += val * weights[weiIndex + kh_off + kw_off]; } else { sampledCoordIndex += sampledPointsPerPixel; 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 a691d342fb6..72d2608dc49 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 @@ -181,8 +181,6 @@ std::vector disabledTestPatterns() { R"(.*smoke_Proposal_(Static|Dynamic)_Test_Case1/ProposalLayerCPUTest.*)", // Issue: 111418 R"(.*smoke_Snippets_ConvertStub/ConvertStub\.CompareWithRefImpl/IS.*_OT=\(bf16\)_#N=2_#S=2_targetDevice=CPU.*)", - // Issue: 111944 - R"(.*smoke_DefConvLayoutTest6.*)", // Issue: 106939 R"(.*ScatterNDUpdateLayerCPUTest.*-1.-1.-1.-2.-2.-2.*)", // New plugin API doesn't support changes of pre-processing diff --git a/src/plugins/intel_cpu/tests/functional/single_layer_tests/deformable_convolution.cpp b/src/plugins/intel_cpu/tests/functional/single_layer_tests/deformable_convolution.cpp index 071afdda412..38284cc5769 100644 --- a/src/plugins/intel_cpu/tests/functional/single_layer_tests/deformable_convolution.cpp +++ b/src/plugins/intel_cpu/tests/functional/single_layer_tests/deformable_convolution.cpp @@ -632,5 +632,39 @@ INSTANTIATE_TEST_SUITE_P(DefConvLayoutTest8, DefConvLayerCPUTest, params8, DefCo INSTANTIATE_TEST_SUITE_P(DefConvLayoutTest9, DefConvLayerCPUTest, params9, DefConvLayerCPUTest::getTestCaseName); INSTANTIATE_TEST_SUITE_P(DefConvLayoutTest10, DefConvLayerCPUTest, params10, DefConvLayerCPUTest::getTestCaseName); INSTANTIATE_TEST_SUITE_P(DefConvLayoutTest11, DefConvLayerCPUTest, params11, DefConvLayerCPUTest::getTestCaseName); + +const std::vector> blockMultigroupChParam = { + {2}, // gr. + {1}, // def. gr. + {16}, // in. ch. per gr. + {16} // out. ch. per gr. +}; +const std::vector> blockMultigroupSpatParam = { + {1}, // batch + {2, 2}, // in. spat. shape + {2, 2}, // off. spat. shape + {1, 1} // ker. spat. shape +}; +const auto blockMultigroupAddParam = ::testing::Combine( + ::testing::Values(true), // with_bilinear_interpolation_pad + ::testing::Values(false), // with_modulation + ::testing::Values(OffsetType::ZERO) // offset type +); +const auto blockMultigroupKernelParam = ::testing::Combine( + ::testing::Values(ngraph::op::PadType::EXPLICIT), // pad. type + ::testing::Values(std::vector({0, 0})), // pad. begin + ::testing::Values(std::vector({0, 0})), // pad. end + ::testing::Values(std::vector {1, 1}), // strides + ::testing::Values(std::vector {1, 1}) // dilations +); +const auto blockMultigroupParam = ::testing::Combine( + ::testing::Combine( + blockMultigroupKernelParam, + ::testing::ValuesIn(static_shapes_to_test_representation(buildStaticParams(blockMultigroupSpatParam, blockMultigroupChParam))), + blockMultigroupAddParam, + ::testing::ValuesIn(netPrecisions), + ::testing::Values(ov::test::utils::DEVICE_CPU)), + ::testing::ValuesIn(filterCPUInfoForDevice(true))); +INSTANTIATE_TEST_SUITE_P(blockMultigroupDefConvTest, DefConvLayerCPUTest, blockMultigroupParam, DefConvLayerCPUTest::getTestCaseName); } // namespace } // namespace CPULayerTestsDefinitions