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
[GPU] Interpolate perf regression (#38684)
Nikolay Shchegolev31360fef8749
diff --git a/src/plugins/intel_gpu/src/kernel_selector/cl_kernels/include/resample_utils.cl b/src/plugins/intel_gpu/src/kernel_selector/cl_kernels/include/resample_utils.clnew file mode 100644index 00000000000..0382ebf4c72--- /dev/null+++ b/src/plugins/intel_gpu/src/kernel_selector/cl_kernels/include/resample_utils.cl@@ -0,0 +1,20 @@+// Copyright (C) 2018-2026 Intel Corporation+// SPDX-License-Identifier: Apache-2.0+//++inline int FUNC(get_nearest_val)(float num, bool is_downsample)+{+#if defined(NEAREST_ROUND_PREFER_FLOOR)+ return (num == (int)num + 0.5f) ? (int)floor(num) : (int)round(num);+#elif defined(NEAREST_ROUND_PREFER_CEIL)+ return (int)round(num);+#elif defined(NEAREST_FLOOR)+ return (int)floor(num);+#elif defined(NEAREST_CEIL)+ return (int)ceil(num);+#elif defined(NEAREST_SIMPLE)+ return is_downsample ? (int)ceil(num) : (int)num;+#else+#error [clDNN resample]: nearest mode - not supported+#endif+}diff --git a/src/plugins/intel_gpu/src/kernel_selector/cl_kernels/resample_opt.cl b/src/plugins/intel_gpu/src/kernel_selector/cl_kernels/resample_opt.clindex dde5e3678a7..39d66207c89 100644--- a/src/plugins/intel_gpu/src/kernel_selector/cl_kernels/resample_opt.cl+++ b/src/plugins/intel_gpu/src/kernel_selector/cl_kernels/resample_opt.cl@@ -3,6 +3,7 @@//#include "include/fetch_utils.cl"+#include "include/resample_utils.cl"#include "include/batch_headers/sub_group_block_read.cl"#include "include/batch_headers/sub_group_block_write.cl"@@ -246,12 +247,21 @@ KERNEL (resample_opt)(__global INPUT0_TYPE* input,const int in_size[5] = { INPUT0_BATCH_NUM, INPUT0_FEATURE_NUM, INPUT0_SIZE_Z, INPUT0_SIZE_Y, INPUT0_SIZE_X };#ifdef SAMPLE_TYPE_NEAREST+ // Coordinates that do not depend on out_x are computed once per work-item.+ // NOTE: resample_opt.cl uses the "legacy" scale convention (SCALES[i] == input_size / output_size),+ // so a downsampling axis is the one where SCALES[i] > 1 (unlike resample_ref.cl's generic path).+ const float iy_coord = FUNC_CALL(get_original_coordinate)(y, SCALES[3], OUTPUT_SIZE_Y, INPUT0_SIZE_Y);+ const int iy = clamp(FUNC_CALL(get_nearest_val)(iy_coord, SCALES[3] > 1.0f), 0, INPUT0_SIZE_Y - 1);+#if OUTPUT_DIMS == 5+ const float iz_coord = FUNC_CALL(get_original_coordinate)(z, SCALES[2], OUTPUT_SIZE_Z, INPUT0_SIZE_Z);+ const int iz = clamp(FUNC_CALL(get_nearest_val)(iz_coord, SCALES[2] > 1.0f), 0, INPUT0_SIZE_Z - 1);+#endif+unroll_for (uint out_x = 0; out_x < OUTPUT_X_BLOCK_SIZE; out_x++) {- const int ix = floor((x + out_x) * SCALES[4]);- const int iy = floor(y * SCALES[3]);+ const float ix_coord = FUNC_CALL(get_original_coordinate)(x + out_x, SCALES[4], OUTPUT_SIZE_X, INPUT0_SIZE_X);+ const int ix = clamp(FUNC_CALL(get_nearest_val)(ix_coord, SCALES[4] > 1.0f), 0, INPUT0_SIZE_X - 1);#if OUTPUT_DIMS == 5- const int iz = floor(z * SCALES[2]);in_vec_t res = READ_FUNC(input, INPUT0_GET_INDEX(b, feature_block, iz, iy, ix));#elsein_vec_t res = READ_FUNC(input, INPUT0_GET_INDEX(b, feature_block, iy, ix));diff --git a/src/plugins/intel_gpu/src/kernel_selector/cl_kernels/resample_ref.cl b/src/plugins/intel_gpu/src/kernel_selector/cl_kernels/resample_ref.clindex 0948978bca4..a36ba9899a1 100644--- a/src/plugins/intel_gpu/src/kernel_selector/cl_kernels/resample_ref.cl+++ b/src/plugins/intel_gpu/src/kernel_selector/cl_kernels/resample_ref.cl@@ -3,28 +3,12 @@//#include "include/fetch_utils.cl"+#include "include/resample_utils.cl"#ifdef RTE_OUTPUT#define TO_OUTPUT_COMPUTE_TYPE(x) CAT(CAT(convert_, OUTPUT_TYPE), _rte)(x)#endif-inline int FUNC(get_nearest_val)(float num, bool is_downsample)-{-#if defined(NEAREST_ROUND_PREFER_FLOOR)- return (num == (int)num + 0.5f) ? (int)floor(num) : (int)round(num);-#elif defined(NEAREST_ROUND_PREFER_CEIL)- return (int)round(num);-#elif defined(NEAREST_FLOOR)- return (int)floor(num);-#elif defined(NEAREST_CEIL)- return (int)ceil(num);-#elif defined(NEAREST_SIMPLE)- return is_downsample ? (int)ceil(num) : (int)num;-#else-#error [clDNN resample_ref.cl]: nearest mode - not supported-#endif-}-inline float FUNC(ref_divide)(float numerator, float denominator){volatile float numerator_value = numerator;diff --git a/src/plugins/intel_gpu/src/kernel_selector/kernels/resample/resample_kernel_opt.cpp b/src/plugins/intel_gpu/src/kernel_selector/kernels/resample/resample_kernel_opt.cppindex 8bc443f35ae..83af1bc5b5d 100644--- a/src/plugins/intel_gpu/src/kernel_selector/kernels/resample/resample_kernel_opt.cpp+++ b/src/plugins/intel_gpu/src/kernel_selector/kernels/resample/resample_kernel_opt.cpp@@ -100,55 +100,6 @@ static int get_feature_slice_size(const resample_params ¶ms) {return static_cast<int>(16 * get_vec_size(params));}-static bool is_asymmetric_simple_optimized_case(const resample_params& params) {- const auto& input = params.inputs[0];- const auto& output = params.outputs[0];-- if (params.coordTransMode != CoordinateTransformationMode::ASYMMETRIC || params.nearestMode != NearestMode::SIMPLE) {- return false;- }-- if (!is_integral_upsampling_ratio(output.X().v, input.X().v) ||- !is_integral_upsampling_ratio(output.Y().v, input.Y().v)) {- return false;- }-- return input.Dimentions() != 5 || is_integral_upsampling_ratio(output.Z().v, input.Z().v);-}--static bool is_tf_half_pixel_for_nn_floor_optimized_case(const resample_params& params) {- const auto& input = params.inputs[0];- const auto& output = params.outputs[0];-- if (params.coordTransMode != CoordinateTransformationMode::TF_HALF_PIXEL_FOR_NN ||- params.nearestMode != NearestMode::FLOOR) {- return false;- }-- if (!is_integral_upsampling_ratio(output.X().v, input.X().v) ||- !is_integral_upsampling_ratio(output.Y().v, input.Y().v)) {- return false;- }-- return input.Dimentions() != 5 || is_integral_upsampling_ratio(output.Z().v, input.Z().v);-}--static bool is_half_pixel_round_prefer_floor_optimized_case(const resample_params& params) {- const auto& input = params.inputs[0];- const auto& output = params.outputs[0];-- if (params.coordTransMode != CoordinateTransformationMode::HALF_PIXEL ||- params.nearestMode != NearestMode::ROUND_PREFER_FLOOR) {- return false;- }-- if (!is_integral_ratio(output.X().v, input.X().v) || !is_integral_ratio(output.Y().v, input.Y().v)) {- return false;- }-- return input.Dimentions() != 5 || is_integral_ratio(output.Z().v, input.Z().v);-}-ResampleKernelBase::DispatchData ResampleKernelOpt::SetDefault(const kernel_selector::resample_params &arg) const {DispatchData dispatchData;auto in_layout = arg.inputs[0].GetLayout();@@ -240,14 +191,9 @@ bool ResampleKernelOpt::Validate(const Params& p) const {}if (params.resampleType == ResampleType::NEAREST_NEIGHBOR) {- const auto optimized_nearest_case =- (params.coordTransMode == CoordinateTransformationMode::ASYMMETRIC && params.nearestMode == NearestMode::FLOOR) ||- is_asymmetric_simple_optimized_case(params) ||- is_tf_half_pixel_for_nn_floor_optimized_case(params) ||- is_half_pixel_round_prefer_floor_optimized_case(params);-+ // The NEAREST kernel handles every CoordinateTransformationMode/NearestMode combination+ // via get_original_coordinate()/get_nearest_val(); padding and batch/feature resize are not supported.if (has_padding ||- !optimized_nearest_case ||input.Batch().v != output.Batch().v ||input.Feature().v != output.Feature().v) {DO_NOT_USE_THIS_KERNEL(p.layerID);diff --git a/src/plugins/intel_gpu/tests/unit/test_cases/resample_gpu_test.cpp b/src/plugins/intel_gpu/tests/unit/test_cases/resample_gpu_test.cppindex c57a9fb39ed..92636ae0488 100644--- a/src/plugins/intel_gpu/tests/unit/test_cases/resample_gpu_test.cpp+++ b/src/plugins/intel_gpu/tests/unit/test_cases/resample_gpu_test.cpp@@ -1991,6 +1991,10 @@ struct resample_opt_random_test_params {format::type out_format;std::vector<size_t> pads_begin;std::vector<size_t> pads_end;+ resample::InterpolateOp::CoordinateTransformMode coord_trans_mode =+ resample::InterpolateOp::CoordinateTransformMode::ASYMMETRIC;+ resample::InterpolateOp::NearestMode nearest_mode =+ resample::InterpolateOp::NearestMode::FLOOR;};struct resample_opt_random_test : testing::TestWithParam<resample_opt_random_test_params>@@ -2100,10 +2104,13 @@ struct resample_opt_random_test : testing::TestWithParam<resample_opt_random_tesauto prim = resample("resample", input_info("in"), params.output_size, params.num_filter, params.operation_type);prim.pads_begin = params.pads_begin;prim.pads_end = params.pads_end;+ prim.coord_trans_mode = params.coord_trans_mode;+ prim.round_mode = params.nearest_mode;topo.add(prim);ExecutionConfig config = get_test_default_config(engine);config.set_property(ov::intel_gpu::custom_outputs(std::vector<std::string>{"resample"}));+ config.set_property(ov::intel_gpu::force_implementations(ov::intel_gpu::ImplForcingMap{ {"resample", {origin_format, "resample_ref"}} }));network net(engine, topo, config);net.set_input_data("in", in_mem);@@ -2118,11 +2125,16 @@ struct resample_opt_random_test : testing::TestWithParam<resample_opt_random_tesauto prim_opt = resample("resample_opt", input_info("in_to_input_type"), params.output_size, params.num_filter, params.operation_type);prim_opt.pads_begin = params.pads_begin;prim_opt.pads_end = params.pads_end;+ prim_opt.coord_trans_mode = params.coord_trans_mode;+ prim_opt.round_mode = params.nearest_mode;topo_opt.add(prim_opt);topo_opt.add(reorder("res_to_bfyx", input_info("resample_opt"), origin_format, params.input_type));ExecutionConfig config_opt = get_test_default_config(engine);config_opt.set_property(ov::intel_gpu::custom_outputs(std::vector<std::string>{"resample_opt", "res_to_bfyx"}));+ if (params.operation_type != resample::InterpolateOp::InterpolateMode::LINEAR_ONNX) {+ config_opt.set_property(ov::intel_gpu::force_implementations(ov::intel_gpu::ImplForcingMap{ {"resample_opt", {params.in_format, "resample_opt"}} }));+ }cldnn::network::ptr net_opt = get_network(engine, topo_opt, config_opt, get_test_stream_ptr(), is_caching_test);@@ -2388,6 +2400,84 @@ INSTANTIATE_TEST_SUITE_P(resample_opt_smoke_nearest,}));+INSTANTIATE_TEST_SUITE_P(resample_opt_smoke_nearest_modes,+ resample_opt_random_test,+ testing::ValuesIn(+ std::vector<resample_opt_random_test_params>{+ // upsampling, 13 -> 26+ { data_types::i8, {1, 128, 13, 13}, {1, 128, 26, 26}, 1, resample::InterpolateOp::InterpolateMode::NEAREST, 1, format::b_fs_yx_fsv16, format::b_fs_yx_fsv16, {}, {},+ resample::InterpolateOp::CoordinateTransformMode::HALF_PIXEL, resample::InterpolateOp::NearestMode::ROUND_PREFER_FLOOR },+ { data_types::i8, {1, 128, 13, 13}, {1, 128, 26, 26}, 1, resample::InterpolateOp::InterpolateMode::NEAREST, 1, format::b_fs_yx_fsv16, format::b_fs_yx_fsv16, {}, {},+ resample::InterpolateOp::CoordinateTransformMode::HALF_PIXEL, resample::InterpolateOp::NearestMode::ROUND_PREFER_CEIL },+ { data_types::i8, {1, 128, 13, 13}, {1, 128, 26, 26}, 1, resample::InterpolateOp::InterpolateMode::NEAREST, 1, format::b_fs_yx_fsv16, format::b_fs_yx_fsv16, {}, {},+ resample::InterpolateOp::CoordinateTransformMode::HALF_PIXEL, resample::InterpolateOp::NearestMode::CEIL },+ { data_types::i8, {1, 128, 13, 13}, {1, 128, 26, 26}, 1, resample::InterpolateOp::InterpolateMode::NEAREST, 1, format::b_fs_yx_fsv16, format::b_fs_yx_fsv16, {}, {},+ resample::InterpolateOp::CoordinateTransformMode::HALF_PIXEL, resample::InterpolateOp::NearestMode::FLOOR },+ { data_types::i8, {1, 128, 13, 13}, {1, 128, 26, 26}, 1, resample::InterpolateOp::InterpolateMode::NEAREST, 1, format::b_fs_yx_fsv16, format::b_fs_yx_fsv16, {}, {},+ resample::InterpolateOp::CoordinateTransformMode::HALF_PIXEL, resample::InterpolateOp::NearestMode::SIMPLE },+ { data_types::i8, {1, 128, 13, 13}, {1, 128, 26, 26}, 1, resample::InterpolateOp::InterpolateMode::NEAREST, 1, format::b_fs_yx_fsv16, format::b_fs_yx_fsv16, {}, {},+ resample::InterpolateOp::CoordinateTransformMode::PYTORCH_HALF_PIXEL, resample::InterpolateOp::NearestMode::ROUND_PREFER_FLOOR },+ { data_types::i8, {1, 128, 13, 13}, {1, 128, 26, 26}, 1, resample::InterpolateOp::InterpolateMode::NEAREST, 1, format::b_fs_yx_fsv16, format::b_fs_yx_fsv16, {}, {},+ resample::InterpolateOp::CoordinateTransformMode::TF_HALF_PIXEL_FOR_NN, resample::InterpolateOp::NearestMode::ROUND_PREFER_FLOOR },+ { data_types::i8, {1, 128, 13, 13}, {1, 128, 26, 26}, 1, resample::InterpolateOp::InterpolateMode::NEAREST, 1, format::b_fs_yx_fsv16, format::b_fs_yx_fsv16, {}, {},+ resample::InterpolateOp::CoordinateTransformMode::ALIGN_CORNERS, resample::InterpolateOp::NearestMode::ROUND_PREFER_FLOOR },++ { data_types::f16, {1, 128, 13, 13}, {1, 128, 26, 26}, 1, resample::InterpolateOp::InterpolateMode::NEAREST, 1, format::bs_fs_yx_bsv32_fsv16, format::bs_fs_yx_bsv32_fsv16, {}, {},+ resample::InterpolateOp::CoordinateTransformMode::HALF_PIXEL, resample::InterpolateOp::NearestMode::ROUND_PREFER_FLOOR },+ { data_types::f16, {1, 128, 13, 13}, {1, 128, 26, 26}, 1, resample::InterpolateOp::InterpolateMode::NEAREST, 1, format::bs_fs_yx_bsv32_fsv16, format::bs_fs_yx_bsv32_fsv16, {}, {},+ resample::InterpolateOp::CoordinateTransformMode::TF_HALF_PIXEL_FOR_NN, resample::InterpolateOp::NearestMode::ROUND_PREFER_FLOOR },+ { data_types::f16, {1, 128, 13, 13}, {1, 128, 26, 26}, 1, resample::InterpolateOp::InterpolateMode::NEAREST, 1, format::bs_fs_yx_bsv32_fsv16, format::bs_fs_yx_bsv32_fsv16, {}, {},+ resample::InterpolateOp::CoordinateTransformMode::ALIGN_CORNERS, resample::InterpolateOp::NearestMode::ROUND_PREFER_FLOOR },++ { data_types::u8, {1, 128, 13, 13}, {1, 128, 26, 26}, 1, resample::InterpolateOp::InterpolateMode::NEAREST, 1, format::b_fs_yx_fsv32, format::b_fs_yx_fsv32, {}, {},+ resample::InterpolateOp::CoordinateTransformMode::ALIGN_CORNERS, resample::InterpolateOp::NearestMode::ROUND_PREFER_FLOOR },++ // Small, non-power-of-two-friendly shapes (e.g. ALIGN_CORNERS 2->3) that stress exact+ // "x.5" tie-breaking coordinates most, since resample_opt computes+ // num * (in/out) [legacy-scale multiply] while the generic (non "is_fast_nearest_case")+ // path in resample_ref computes ref_divide(num, out/in) [true-scale division] for the+ // same mathematical coordinate: these are different floating-point operations that+ // could in principle round differently right at a ROUND_PREFER_FLOOR/CEIL tie point.+ { data_types::i8, {1, 16, 2, 2}, {1, 16, 3, 3}, 1, resample::InterpolateOp::InterpolateMode::NEAREST, 1, format::b_fs_yx_fsv16, format::b_fs_yx_fsv16, {}, {},+ resample::InterpolateOp::CoordinateTransformMode::ALIGN_CORNERS, resample::InterpolateOp::NearestMode::ROUND_PREFER_FLOOR },+ { data_types::i8, {1, 16, 2, 2}, {1, 16, 3, 3}, 1, resample::InterpolateOp::InterpolateMode::NEAREST, 1, format::b_fs_yx_fsv16, format::b_fs_yx_fsv16, {}, {},+ resample::InterpolateOp::CoordinateTransformMode::ALIGN_CORNERS, resample::InterpolateOp::NearestMode::ROUND_PREFER_CEIL },+ { data_types::i8, {1, 16, 3, 3}, {1, 16, 2, 2}, 1, resample::InterpolateOp::InterpolateMode::NEAREST, 1, format::b_fs_yx_fsv16, format::b_fs_yx_fsv16, {}, {},+ resample::InterpolateOp::CoordinateTransformMode::ALIGN_CORNERS, resample::InterpolateOp::NearestMode::ROUND_PREFER_FLOOR },+ { data_types::i8, {1, 16, 3, 3}, {1, 16, 2, 2}, 1, resample::InterpolateOp::InterpolateMode::NEAREST, 1, format::b_fs_yx_fsv16, format::b_fs_yx_fsv16, {}, {},+ resample::InterpolateOp::CoordinateTransformMode::ALIGN_CORNERS, resample::InterpolateOp::NearestMode::ROUND_PREFER_CEIL },+ { data_types::i8, {1, 16, 2, 2}, {1, 16, 5, 5}, 1, resample::InterpolateOp::InterpolateMode::NEAREST, 1, format::b_fs_yx_fsv16, format::b_fs_yx_fsv16, {}, {},+ resample::InterpolateOp::CoordinateTransformMode::ALIGN_CORNERS, resample::InterpolateOp::NearestMode::ROUND_PREFER_CEIL },+ { data_types::i8, {1, 16, 5, 5}, {1, 16, 2, 2}, 1, resample::InterpolateOp::InterpolateMode::NEAREST, 1, format::b_fs_yx_fsv16, format::b_fs_yx_fsv16, {}, {},+ resample::InterpolateOp::CoordinateTransformMode::ALIGN_CORNERS, resample::InterpolateOp::NearestMode::ROUND_PREFER_CEIL },+ { data_types::i8, {1, 16, 4, 4}, {1, 16, 3, 3}, 1, resample::InterpolateOp::InterpolateMode::NEAREST, 1, format::b_fs_yx_fsv16, format::b_fs_yx_fsv16, {}, {},+ resample::InterpolateOp::CoordinateTransformMode::ALIGN_CORNERS, resample::InterpolateOp::NearestMode::ROUND_PREFER_FLOOR },+ { data_types::i8, {1, 16, 2, 2}, {1, 16, 3, 3}, 1, resample::InterpolateOp::InterpolateMode::NEAREST, 1, format::b_fs_yx_fsv16, format::b_fs_yx_fsv16, {}, {},+ resample::InterpolateOp::CoordinateTransformMode::HALF_PIXEL, resample::InterpolateOp::NearestMode::ROUND_PREFER_CEIL },+ { data_types::i8, {1, 16, 3, 3}, {1, 16, 2, 2}, 1, resample::InterpolateOp::InterpolateMode::NEAREST, 1, format::b_fs_yx_fsv16, format::b_fs_yx_fsv16, {}, {},+ resample::InterpolateOp::CoordinateTransformMode::HALF_PIXEL, resample::InterpolateOp::NearestMode::ROUND_PREFER_CEIL },++ // downsampling, 26 -> 13 (boundary math differs most from ASYMMETRIC/FLOOR here)+ { data_types::i8, {1, 128, 26, 26}, {1, 128, 13, 13}, 1, resample::InterpolateOp::InterpolateMode::NEAREST, 1, format::b_fs_yx_fsv16, format::b_fs_yx_fsv16, {}, {},+ resample::InterpolateOp::CoordinateTransformMode::HALF_PIXEL, resample::InterpolateOp::NearestMode::ROUND_PREFER_FLOOR },+ { data_types::i8, {1, 128, 26, 26}, {1, 128, 13, 13}, 1, resample::InterpolateOp::InterpolateMode::NEAREST, 1, format::b_fs_yx_fsv16, format::b_fs_yx_fsv16, {}, {},+ resample::InterpolateOp::CoordinateTransformMode::ALIGN_CORNERS, resample::InterpolateOp::NearestMode::ROUND_PREFER_FLOOR },+ { data_types::f16, {1, 128, 26, 26}, {1, 128, 13, 13}, 1, resample::InterpolateOp::InterpolateMode::NEAREST, 1, format::bs_fs_yx_bsv16_fsv16, format::bs_fs_yx_bsv16_fsv16, {}, {},+ resample::InterpolateOp::CoordinateTransformMode::ALIGN_CORNERS, resample::InterpolateOp::NearestMode::ROUND_PREFER_FLOOR },+ }+ ));++INSTANTIATE_TEST_SUITE_P(resample_opt_smoke_5d_nearest_modes,+ resample_opt_random_test,+ testing::ValuesIn(+ std::vector<resample_opt_random_test_params>{+ { data_types::i8, {1, 16, 13, 13, 13}, {1, 16, 26, 26, 26}, 1, resample::InterpolateOp::InterpolateMode::NEAREST, 1, format::b_fs_zyx_fsv16, format::b_fs_zyx_fsv16, {}, {},+ resample::InterpolateOp::CoordinateTransformMode::ALIGN_CORNERS, resample::InterpolateOp::NearestMode::ROUND_PREFER_FLOOR },+ { data_types::f16, {1, 16, 13, 13, 13}, {1, 16, 26, 26, 26}, 1, resample::InterpolateOp::InterpolateMode::NEAREST, 1, format::b_fs_zyx_fsv32, format::b_fs_zyx_fsv32, {}, {},+ resample::InterpolateOp::CoordinateTransformMode::HALF_PIXEL, resample::InterpolateOp::NearestMode::ROUND_PREFER_FLOOR },+ }+ ));+INSTANTIATE_TEST_SUITE_P(resample_opt_smoke_linear_onnx_4d_padding,resample_opt_random_test,testing::ValuesIn(