OpenVINO™ is an open source toolkit for optimizing and deploying AI inference
C++ aicomputer-visiondeep-learningdeploy-aidiffusion-modelsgenerative-aigood-first-issueinferencellm-inferencenatural-language-processingnlpopenvinooptimize-aiperformance-boostrecommendation-systemspeech-recognitionstable-diffusiontransformersyolo
[CPU] Fix coordinate transform precision for half pixel modes in interpolate (#36145)
SamareshSingh5eb59706a3ee
diff --git a/src/plugins/intel_cpu/src/nodes/executors/interpolate.cpp b/src/plugins/intel_cpu/src/nodes/executors/interpolate.cppindex 0a571c3456c..e2a946ba0a1 100644--- a/src/plugins/intel_cpu/src/nodes/executors/interpolate.cpp+++ b/src/plugins/intel_cpu/src/nodes/executors/interpolate.cpp@@ -117,13 +117,15 @@ float ov::intel_cpu::InterpolateExecutor::coordTransToInput(int outCoord,if (scale == 1.0F || (inShape == outShape)) {return static_cast<float>(outCoord);}++ const double scaleDouble = static_cast<double>(outShape) / static_cast<double>(inShape);switch (interpAttrs.coordTransMode) {case InterpolateCoordTransMode::half_pixel: {- return (static_cast<float>(outCoord) + 0.5F) / scale - 0.5F;+ return static_cast<float>((static_cast<double>(outCoord) + 0.5) / scaleDouble - 0.5);}case InterpolateCoordTransMode::pytorch_half_pixel: {if (outShape > 1) {- return (static_cast<float>(outCoord) + 0.5F) / scale - 0.5F;+ return static_cast<float>((static_cast<double>(outCoord) + 0.5) / scaleDouble - 0.5);}return 0;}@@ -131,7 +133,7 @@ float ov::intel_cpu::InterpolateExecutor::coordTransToInput(int outCoord,return static_cast<float>(outCoord) / scale;}case InterpolateCoordTransMode::tf_half_pixel_for_nn: {- return (static_cast<float>(outCoord) + 0.5F) / scale;+ return static_cast<float>((static_cast<double>(outCoord) + 0.5) / scaleDouble);}case InterpolateCoordTransMode::align_corners: {if (outShape > 1) {diff --git a/src/plugins/intel_cpu/tests/functional/custom/single_layer_tests/instances/x64/interpolate.cpp b/src/plugins/intel_cpu/tests/functional/custom/single_layer_tests/instances/x64/interpolate.cppindex 4b5cd768226..5b5cfb7d48f 100644--- a/src/plugins/intel_cpu/tests/functional/custom/single_layer_tests/instances/x64/interpolate.cpp+++ b/src/plugins/intel_cpu/tests/functional/custom/single_layer_tests/instances/x64/interpolate.cpp@@ -1022,6 +1022,70 @@ INSTANTIATE_TEST_SUITE_P(smoke_InterpolateBicubicPillow_LayoutAlign_Test, Interp::testing::ValuesIn(filterPillowAdditionalConfig())),InterpolateLayerCPUTest::getTestCaseName);+std::vector<CPUSpecificParams> filterCPUInfoForDevice_HalfPixelPrecision() {+ std::vector<CPUSpecificParams> resCPUParams;+ if (ov::with_cpu_x86_avx512f()) {+ resCPUParams.push_back(CPUSpecificParams{{nhwc, x, x}, {nhwc}, {"jit_avx512"}, "jit_avx512"});+ } else if (ov::with_cpu_x86_avx2()) {+ resCPUParams.push_back(CPUSpecificParams{{nhwc, x, x}, {nhwc}, {"jit_avx2"}, "jit_avx2"});+ resCPUParams.push_back(CPUSpecificParams{{nchw, x, x}, {nchw}, {"jit_avx2"}, "jit_avx2"});+ } else if (ov::with_cpu_x86_sse42()) {+ resCPUParams.push_back(CPUSpecificParams{{nhwc, x, x}, {nhwc}, {"jit_sse42"}, "jit_sse42"});+ resCPUParams.push_back(CPUSpecificParams{{nchw, x, x}, {nchw}, {"jit_sse42"}, "jit_sse42"});+ } else {+ resCPUParams.push_back(CPUSpecificParams{{nchw, x, x}, {nchw}, {"ref"}, "ref"});+ }+ return resCPUParams;+}++const std::vector<ov::op::v11::Interpolate::CoordinateTransformMode>+ coordinateTransformModes_HalfPixelPrecision = {+ ov::op::v11::Interpolate::CoordinateTransformMode::HALF_PIXEL,+ ov::op::v11::Interpolate::CoordinateTransformMode::PYTORCH_HALF_PIXEL,+ ov::op::v11::Interpolate::CoordinateTransformMode::TF_HALF_PIXEL_FOR_NN,+};++const std::vector<size_t> pads4D_zero = {0, 0, 0, 0};++const std::vector<std::vector<int64_t>> axes4D_allDims = {{0, 1, 2, 3}};++const std::vector<ShapeParams> shapeParams4D_HalfPixelPrecision = {+ ShapeParams{+ ov::op::v11::Interpolate::ShapeCalcMode::SIZES,+ InputShape{{}, {{1, 1, 4, 4}}},+ ov::test::utils::InputLayerType::CONSTANT,+ {{1, 1, 1024, 1024}},+ axes4D_allDims.front()+ },+ ShapeParams{+ ov::op::v11::Interpolate::ShapeCalcMode::SIZES,+ InputShape{{}, {{1, 1, 5, 5}}},+ ov::test::utils::InputLayerType::CONSTANT,+ {{1, 1, 1337, 1337}},+ axes4D_allDims.front()+ },+};++const auto interpolateCases_HalfPixelPrecision = ::testing::Combine(+ ::testing::Values(ov::op::v11::Interpolate::InterpolateMode::NEAREST),+ ::testing::ValuesIn(coordinateTransformModes_HalfPixelPrecision),+ ::testing::ValuesIn(defNearestModes()),+ ::testing::ValuesIn(antialias()),+ ::testing::Values(pads4D_zero),+ ::testing::Values(pads4D_zero),+ ::testing::ValuesIn(cubeCoefs()));++INSTANTIATE_TEST_SUITE_P(smoke_InterpolateHalfPixel_PrecisionRegression,+ InterpolateLayerCPUTest,+ ::testing::Combine(+ interpolateCases_HalfPixelPrecision,+ ::testing::ValuesIn(shapeParams4D_HalfPixelPrecision),+ ::testing::Values(ElementType::f32),+ ::testing::ValuesIn(filterCPUInfoForDevice_HalfPixelPrecision()),+ ::testing::Values(emptyFusingSpec),+ ::testing::Values(ov::AnyMap())),+ InterpolateLayerCPUTest::getTestCaseName);+} // namespace} // namespace Interpolate} // namespace testdiff --git a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/interpolate.cpp b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/interpolate.cppindex 1254daa30c0..20c86a933e3 100644--- a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/interpolate.cpp+++ b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/interpolate.cpp@@ -175,4 +175,49 @@ INSTANTIATE_TEST_SUITE_P(smoke_Interpolate_Nearest_Down_Sample_Tail, Interpolate::testing::Values(additional_config)),InterpolateLayerTest::getTestCaseName);+const std::vector<ov::op::v4::Interpolate::CoordinateTransformMode> halfPixel_coordinateTransformModes = {+ ov::op::v4::Interpolate::CoordinateTransformMode::HALF_PIXEL,+ ov::op::v4::Interpolate::CoordinateTransformMode::PYTORCH_HALF_PIXEL,+ ov::op::v4::Interpolate::CoordinateTransformMode::TF_HALF_PIXEL_FOR_NN,+};++const std::vector<ov::Shape> input_shapes_halfPixel = {+ {1, 1, 4, 4},+};++const std::vector<ov::Shape> target_shapes_halfPixel = {+ {1, 1, 1024, 1024},+};++const std::vector<std::vector<float>> scales_halfPixel = {+ {1.f, 1.f, 256.f, 256.f},+};++const std::vector<std::vector<size_t>> pads_halfPixel = {+ {0, 0, 0, 0},+};++const auto interpolateCases_halfPixel = ::testing::Combine(+ ::testing::ValuesIn(nearest_mode),+ ::testing::Values(ov::op::v4::Interpolate::ShapeCalcMode::SIZES),+ ::testing::ValuesIn(halfPixel_coordinateTransformModes),+ ::testing::ValuesIn(default_nearest_mode),+ ::testing::ValuesIn(antialias),+ ::testing::ValuesIn(pads_halfPixel),+ ::testing::ValuesIn(pads_halfPixel),+ ::testing::ValuesIn(cube_coefs),+ ::testing::ValuesIn(default_axes),+ ::testing::ValuesIn(scales_halfPixel));++INSTANTIATE_TEST_SUITE_P(smoke_Interpolate_HalfPixel_PrecisionRegression,+ InterpolateLayerTest,+ ::testing::Combine(+ interpolateCases_halfPixel,+ ::testing::Values(ov::element::f32),+ ::testing::Values(ov::test::static_shapes_to_test_representation(input_shapes_halfPixel)),+ ::testing::ValuesIn(target_shapes_halfPixel),+ ::testing::Values(ov::test::utils::DEVICE_CPU),+ ::testing::Values(additional_config)),+ InterpolateLayerTest::getTestCaseName);+} // namespace