Skip to content

OpenVINO™ is an open source toolkit for optimizing and deploying AI inference

[GPU] Fix for Interpolate func tests on PTL (#36752)

Nikolay Shchegolev5c5d8e7f642c
diff --git a/src/plugins/intel_gpu/src/graph/impls/ocl/kernel_selector_helper.cpp b/src/plugins/intel_gpu/src/graph/impls/ocl/kernel_selector_helper.cpp
index 7c7bec3d6d5..176716f4b94 100644
--- a/src/plugins/intel_gpu/src/graph/impls/ocl/kernel_selector_helper.cpp
+++ b/src/plugins/intel_gpu/src/graph/impls/ocl/kernel_selector_helper.cpp
@@ -306,6 +306,8 @@ data_types from_data_type(kernel_selector::data_type dt) {
return cldnn::data_types::f16;
case kernel_selector::data_type::F32:
return cldnn::data_types::f32;
+ case kernel_selector::data_type::BF16:
+ return cldnn::data_types::bf16;
case kernel_selector::data_type::F4E2M1:
return cldnn::data_types::f4e2m1;
case kernel_selector::data_type::F8E4M3:
diff --git a/src/plugins/intel_gpu/src/kernel_selector/cl_kernels/resample_bfyx_cubic_opt.cl b/src/plugins/intel_gpu/src/kernel_selector/cl_kernels/resample_bfyx_cubic_opt.cl
index f2b81d9009e..bafb5a483b6 100644
--- a/src/plugins/intel_gpu/src/kernel_selector/cl_kernels/resample_bfyx_cubic_opt.cl
+++ b/src/plugins/intel_gpu/src/kernel_selector/cl_kernels/resample_bfyx_cubic_opt.cl
@@ -8,20 +8,33 @@
#define TO_OUTPUT_COMPUTE_TYPE(x) CAT(CAT(convert_, OUTPUT_TYPE), _rte)(x)
#endif
+inline float FUNC(ref_divide)(float numerator, float denominator)
+{
+ volatile float numerator_value = numerator;
+ volatile float denominator_value = denominator;
+ volatile float quotient = numerator_value / denominator_value;
+ volatile float residual = numerator_value - quotient * denominator_value;
+ return quotient + residual / denominator_value;
+}
+
inline float FUNC(get_original_coordinate)(float num, float scale, int length_resized, int length_original)
{
if (scale == 1.0f)
return num;
#if defined(COORD_TRANS_MODE_HALF_PIXEL)
- return (num + 0.5f) * scale - 0.5f;
+ return FUNC_CALL(ref_divide)(num + 0.5f, scale) - 0.5f;
#elif defined(COORD_TRANS_MODE_PYTORCH_HALF_PIXEL)
- return (length_resized > 1) ? (num + 0.5f) * scale - 0.5f : 0.f;
+ return (length_resized > 1) ? FUNC_CALL(ref_divide)(num + 0.5f, scale) - 0.5f : 0.f;
#elif defined(COORD_TRANS_MODE_ASYMMETRIC)
- return num * scale;
+ return FUNC_CALL(ref_divide)(num, scale);
#elif defined(COORD_TRANS_MODE_TF_HALF_PIXEL_FOR_NN)
- return (num + 0.5f) * scale;
+ return FUNC_CALL(ref_divide)(num + 0.5f, scale);
#elif defined(COORD_TRANS_MODE_ALIGN_CORNERS)
- return (length_resized != 1) ? num * (length_original - 1) / (length_resized - 1) : 0.f;
+ if (length_resized == 1)
+ return 0.f;
+ if (num == 0.f || num == (float)(length_resized - 1))
+ return num == 0.f ? 0.f : (float)(length_original - 1);
+ return FUNC_CALL(ref_divide)((float)((int)num * (length_original - 1)), (float)(length_resized - 1));
#else
#error [clDNN resample_bfyx_cubic_opt.cl]: coordinate transformation mode - not supported
#endif
@@ -29,11 +42,54 @@ inline float FUNC(get_original_coordinate)(float num, float scale, int length_re
inline void FUNC(get_cubic_coeff)(float* cubic_coef, float coord, float coef)
{
+ // NOTE: The multiply-then-add/sub sequences below (e.g. "coef * x0 - 5.0f * coef")
+ // must be evaluated with separate rounding steps (as-if FP_CONTRACT/mad were OFF)
+ // to match the reference implementation bit-for-bit. Instead of disabling
+ // FP_CONTRACT/"-cl-mad-enable" for the whole translation unit (which would also
+ // block FMA/mad fusion for unrelated, perf-sensitive code), we locally block
+ // fusion only for these specific multiplications by routing *both* operands of
+ // every add/sub whose left- or right-hand side is itself a multiplication
+ // through a volatile temporary. This forces each multiplication to be
+ // rounded/stored (single rounding step) before it is combined with the
+ // following add/sub, regardless of which operand the compiler would have
+ // otherwise chosen to fuse.
float abs_num = fabs(coord);
- cubic_coef[0] = coef * (abs_num - 1.0f) * (abs_num - 1.0f) * abs_num;
- cubic_coef[1] = ((coef + 2.0f) * abs_num - (coef + 3.0f)) * abs_num * abs_num + 1.0f;
- cubic_coef[2] = (((-coef - 2.0f) * abs_num + (2.0f * coef + 3.0f)) * abs_num - coef) * abs_num;
- cubic_coef[3] = -coef * abs_num * abs_num * (abs_num - 1.0f);
+ float x0 = abs_num + 1.0f;
+ float x1 = abs_num;
+ float x2 = 1.0f - abs_num;
+ float x3 = 2.0f - abs_num;
+
+ volatile float t0_m1 = coef * x0;
+ volatile float t0_c1 = 5.0f * coef;
+ float t0 = t0_m1 - t0_c1;
+ volatile float t0_m2 = t0 * x0;
+ volatile float t0_c2 = 8.0f * coef;
+ t0 = t0_m2 + t0_c2;
+ volatile float t0_m3 = t0 * x0;
+ volatile float t0_c3 = 4.0f * coef;
+ cubic_coef[0] = t0_m3 - t0_c3;
+
+ volatile float t1_m1 = (coef + 2.0f) * x1;
+ float t1 = t1_m1 - (coef + 3.0f);
+ t1 = t1 * x1;
+ volatile float t1_m2 = t1 * x1;
+ cubic_coef[1] = t1_m2 + 1.0f;
+
+ volatile float t2_m1 = (coef + 2.0f) * x2;
+ float t2 = t2_m1 - (coef + 3.0f);
+ t2 = t2 * x2;
+ volatile float t2_m2 = t2 * x2;
+ cubic_coef[2] = t2_m2 + 1.0f;
+
+ volatile float t3_m1 = coef * x3;
+ volatile float t3_c1 = 5.0f * coef;
+ float t3 = t3_m1 - t3_c1;
+ volatile float t3_m2 = t3 * x3;
+ volatile float t3_c2 = 8.0f * coef;
+ t3 = t3_m2 + t3_c2;
+ volatile float t3_m3 = t3 * x3;
+ volatile float t3_c3 = 4.0f * coef;
+ cubic_coef[3] = t3_m3 - t3_c3;
}
KERNEL (resample_bfyx_cubic_opt)(
@@ -55,7 +111,7 @@ KERNEL (resample_bfyx_cubic_opt)(
// Compute Y coordinate mapping once (shared for all X in the block)
const float orig_y = FUNC_CALL(get_original_coordinate)((float)out_y, SCALES[3], OUTPUT_SIZE_Y,
- INPUT0_SIZE_Y + PADS_BEGIN[3] + PADS_END[3]) - PADS_BEGIN[3];
+ INPUT0_SIZE_Y + PADS_BEGIN[3] + PADS_END[3]) - PADS_BEGIN[3];
const int iy = (int)floor(orig_y);
const float y_frac = orig_y - (float)iy;
float cy[4];
@@ -74,7 +130,7 @@ KERNEL (resample_bfyx_cubic_opt)(
// Compute X coordinate mapping
const float orig_x = FUNC_CALL(get_original_coordinate)((float)ox, SCALES[4], OUTPUT_SIZE_X,
- INPUT0_SIZE_X + PADS_BEGIN[4] + PADS_END[4]) - PADS_BEGIN[4];
+ INPUT0_SIZE_X + PADS_BEGIN[4] + PADS_END[4]) - PADS_BEGIN[4];
const int ix = (int)floor(orig_x);
const float x_frac = orig_x - (float)ix;
float cx[4];
@@ -96,9 +152,8 @@ KERNEL (resample_bfyx_cubic_opt)(
x_idx[dx] >= 0 && x_idx[dx] < INPUT0_SIZE_X)
#endif
{
- interp_val = fma((ACCUMULATOR_TYPE)(cy[dy] * cx[dx]),
- (ACCUMULATOR_TYPE)DECODE_INPUT0_COMPUTE_TYPE(input[INPUT0_GET_INDEX(out_b, out_f, y_idx[dy], x_idx[dx])]),
- interp_val);
+ const float term = cy[dy] * cx[dx] * (float)DECODE_INPUT0_COMPUTE_TYPE(input[INPUT0_GET_INDEX(out_b, out_f, y_idx[dy], x_idx[dx])]);
+ interp_val = interp_val + (ACCUMULATOR_TYPE)term;
}
}
}
diff --git a/src/plugins/intel_gpu/src/kernel_selector/cl_kernels/resample_onnx.cl b/src/plugins/intel_gpu/src/kernel_selector/cl_kernels/resample_onnx.cl
index 178221e3349..0fdae94a191 100644
--- a/src/plugins/intel_gpu/src/kernel_selector/cl_kernels/resample_onnx.cl
+++ b/src/plugins/intel_gpu/src/kernel_selector/cl_kernels/resample_onnx.cl
@@ -22,20 +22,33 @@
#define TO_OUT_VEC_TYPE(x) TO_OUTPUT_VECTOR_TYPE(x, VEC_SIZE)
#endif
+inline float FUNC(ref_divide)(float numerator, float denominator)
+{
+ volatile float numerator_value = numerator;
+ volatile float denominator_value = denominator;
+ volatile float quotient = numerator_value / denominator_value;
+ volatile float residual = numerator_value - quotient * denominator_value;
+ return quotient + residual / denominator_value;
+}
+
inline float FUNC(get_original_coordinate)(float num, float scale, int length_resized, int length_original)
{
if (scale == 1.0f)
return num;
#if defined(COORD_TRANS_MODE_HALF_PIXEL)
- return (num + 0.5f) * scale - 0.5f;
+ return FUNC_CALL(ref_divide)(num + 0.5f, scale) - 0.5f;
#elif defined(COORD_TRANS_MODE_PYTORCH_HALF_PIXEL)
- return (length_resized > 1) ? (num + 0.5f) * scale - 0.5f : 0.f;
+ return (length_resized > 1) ? FUNC_CALL(ref_divide)(num + 0.5f, scale) - 0.5f : 0.f;
#elif defined(COORD_TRANS_MODE_ASYMMETRIC)
- return num * scale;
+ return FUNC_CALL(ref_divide)(num, scale);
#elif defined(COORD_TRANS_MODE_TF_HALF_PIXEL_FOR_NN)
- return (num + 0.5f) * scale;
+ return FUNC_CALL(ref_divide)(num + 0.5f, scale);
#elif defined(COORD_TRANS_MODE_ALIGN_CORNERS)
- return (length_resized != 1) ? num * (length_original - 1) / (length_resized - 1) : 0.f;
+ if (length_resized == 1)
+ return 0.f;
+ if (num == 0.f || num == (float)(length_resized - 1))
+ return num == 0.f ? 0.f : (float)(length_original - 1);
+ return FUNC_CALL(ref_divide)((float)((int)num * (length_original - 1)), (float)(length_resized - 1));
#else
#error [clDNN resample_onnx.cl]: coordinate transformation 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.cl
index 396f35579f1..dde5e3678a7 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
@@ -42,7 +42,11 @@ inline float FUNC(get_original_coordinate)(float num, float scale, int length_re
#elif defined(COORD_TRANS_MODE_TF_HALF_PIXEL_FOR_NN)
return (num + 0.5f) * scale;
#elif defined(COORD_TRANS_MODE_ALIGN_CORNERS)
- return (length_resized != 1) ? num * (length_original - 1) / (length_resized - 1) : 0.f;
+ if (length_resized == 1)
+ return 0.f;
+ if (num == 0.f || num == (float)(length_resized - 1))
+ return num == 0.f ? 0.f : (float)(length_original - 1);
+ return (float)((int)num * (length_original - 1)) / (float)(length_resized - 1);
#else
#error [clDNN resample_opt.cl]: coordinate transformation mode - not supported
#endif
diff --git a/src/plugins/intel_gpu/src/kernel_selector/cl_kernels/resample_pil_ref.cl b/src/plugins/intel_gpu/src/kernel_selector/cl_kernels/resample_pil_ref.cl
index 7c8caf7a2c0..7e1d2df7965 100644
--- a/src/plugins/intel_gpu/src/kernel_selector/cl_kernels/resample_pil_ref.cl
+++ b/src/plugins/intel_gpu/src/kernel_selector/cl_kernels/resample_pil_ref.cl
@@ -153,6 +153,7 @@ KERNEL (resample_horizontal_gpu_ref)( __global INPUT0_TYPE* input
int out_idx = OUTPUT_GET_INDEX(b, f, y, x);
#endif
#if HAS_FUSED_OPS
+ INPUT0_TYPE resample_result = TO_INPUT0_TYPE(ACTIVATION(ss, ACTIVATION_PARAMS));
FUSED_OPS;
output[out_idx] = FUSED_OPS_RESULT;
#else
@@ -259,6 +260,7 @@ KERNEL (resample_vertical_gpu_ref)( __global RESAMPLE_VERTICAL_INPUT_TYPE* inpu
}
int out_idx = OUTPUT_GET_INDEX(b, f, y, x);
#if HAS_FUSED_OPS
+ INPUT0_TYPE resample_result = TO_INPUT0_TYPE(ACTIVATION(ss, ACTIVATION_PARAMS));
FUSED_OPS;
output[out_idx] = FUSED_OPS_RESULT;
#else
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.cl
index 15eb546bc8d..0948978bca4 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
@@ -25,20 +25,49 @@ inline int FUNC(get_nearest_val)(float num, bool is_downsample)
#endif
}
+inline float FUNC(ref_divide)(float numerator, float denominator)
+{
+ volatile float numerator_value = numerator;
+ volatile float denominator_value = denominator;
+ volatile float quotient = numerator_value / denominator_value;
+ volatile float residual = numerator_value - quotient * denominator_value;
+ return quotient + residual / denominator_value;
+}
+
inline float FUNC(get_original_coordinate)(float num, float scale, int length_resized, int length_original)
{
if (scale == 1.0f)
return num;
#if defined(COORD_TRANS_MODE_HALF_PIXEL)
+#if RESAMPLE_USE_LEGACY_SCALE == 1
return (num + 0.5f) * scale - 0.5f;
+#else
+ return FUNC_CALL(ref_divide)(num + 0.5f, scale) - 0.5f;
+#endif
#elif defined(COORD_TRANS_MODE_PYTORCH_HALF_PIXEL)
+#if RESAMPLE_USE_LEGACY_SCALE == 1
return (length_resized > 1) ? (num + 0.5f) * scale - 0.5f : 0.f;
+#else
+ return (length_resized > 1) ? FUNC_CALL(ref_divide)(num + 0.5f, scale) - 0.5f : 0.f;
+#endif
#elif defined(COORD_TRANS_MODE_ASYMMETRIC)
+#if RESAMPLE_USE_LEGACY_SCALE == 1
return num * scale;
+#else
+ return FUNC_CALL(ref_divide)(num, scale);
+#endif
#elif defined(COORD_TRANS_MODE_TF_HALF_PIXEL_FOR_NN)
+#if RESAMPLE_USE_LEGACY_SCALE == 1
return (num + 0.5f) * scale;
+#else
+ return FUNC_CALL(ref_divide)(num + 0.5f, scale);
+#endif
#elif defined(COORD_TRANS_MODE_ALIGN_CORNERS)
- return (length_resized != 1) ? num * (length_original - 1) / (length_resized - 1) : 0.f;
+ if (length_resized == 1)
+ return 0.f;
+ if (num == 0.f || num == (float)(length_resized - 1))
+ return num == 0.f ? 0.f : (float)(length_original - 1);
+ return FUNC_CALL(ref_divide)((float)((int)num * (length_original - 1)), (float)(length_resized - 1));
#else
#error [clDNN resample_ref.cl]: coordinate transformation mode - not supported
#endif
@@ -46,11 +75,54 @@ inline float FUNC(get_original_coordinate)(float num, float scale, int length_re
inline void FUNC(get_cubic_coeff)(float* cubic_coef, float coord, float coef)
{
+ // NOTE: The multiply-then-add/sub sequences below (e.g. "coef * x0 - 5.0f * coef")
+ // must be evaluated with separate rounding steps (as-if FP_CONTRACT/mad were OFF)
+ // to match the reference implementation bit-for-bit. Instead of disabling
+ // FP_CONTRACT/"-cl-mad-enable" for the whole translation unit (which would also
+ // block FMA/mad fusion for unrelated, perf-sensitive code), we locally block
+ // fusion only for these specific multiplications by routing *both* operands of
+ // every add/sub whose left- or right-hand side is itself a multiplication
+ // through a volatile temporary. This forces each multiplication to be
+ // rounded/stored (single rounding step) before it is combined with the
+ // following add/sub, regardless of which operand the compiler would have
+ // otherwise chosen to fuse.
float abs_num = fabs(coord);
- cubic_coef[0] = coef * (abs_num - 1.0) * (abs_num - 1.0) * abs_num;
- cubic_coef[1] = ((coef + 2.0) * abs_num - (coef + 3.0)) * abs_num * abs_num + 1.0;
- cubic_coef[2] = (((-coef - 2.0) * abs_num + (2.0 * coef + 3.0)) * abs_num - coef) * abs_num;
- cubic_coef[3] = -coef * abs_num * abs_num * (abs_num - 1.0);
+ float x0 = abs_num + 1.0f;
+ float x1 = abs_num;
+ float x2 = 1.0f - abs_num;
+ float x3 = 2.0f - abs_num;
+
+ volatile float t0_m1 = coef * x0;
+ volatile float t0_c1 = 5.0f * coef;
+ float t0 = t0_m1 - t0_c1;
+ volatile float t0_m2 = t0 * x0;
+ volatile float t0_c2 = 8.0f * coef;
+ t0 = t0_m2 + t0_c2;
+ volatile float t0_m3 = t0 * x0;
+ volatile float t0_c3 = 4.0f * coef;
+ cubic_coef[0] = t0_m3 - t0_c3;
+
+ volatile float t1_m1 = (coef + 2.0f) * x1;
+ float t1 = t1_m1 - (coef + 3.0f);
+ t1 = t1 * x1;
+ volatile float t1_m2 = t1 * x1;
+ cubic_coef[1] = t1_m2 + 1.0f;
+
+ volatile float t2_m1 = (coef + 2.0f) * x2;
+ float t2 = t2_m1 - (coef + 3.0f);
+ t2 = t2 * x2;
+ volatile float t2_m2 = t2 * x2;
+ cubic_coef[2] = t2_m2 + 1.0f;
+
+ volatile float t3_m1 = coef * x3;
+ volatile float t3_c1 = 5.0f * coef;
+ float t3 = t3_m1 - t3_c1;
+ volatile float t3_m2 = t3 * x3;
+ volatile float t3_c2 = 8.0f * coef;
+ t3 = t3_m2 + t3_c2;
+ volatile float t3_m3 = t3 * x3;
+ volatile float t3_c3 = 4.0f * coef;
+ cubic_coef[3] = t3_m3 - t3_c3;
}
#define TRIANGLE_COEFF(x) (ACCUMULATOR_MAX_FUNC(ACCUMULATOR_VAL_ZERO, ACCUMULATOR_VAL_ONE - ACCUMULATOR_ABS_FUNC(x)))
@@ -80,18 +152,28 @@ KERNEL (resample_gpu_ref)(__global INPUT0_TYPE* input,
out_coords[1] = ((int)get_global_id(2) * PACK_SIZE) % OUTPUT_FEATURE_NUM;
out_coords[0] = ((int)get_global_id(2) * PACK_SIZE) / OUTPUT_FEATURE_NUM;
int in_coords[5];
+ int safe_in_coords[5];
bool isOutOfBounds = false;
+#if RESAMPLE_FAST_NEAREST == 1
+ safe_in_coords[4] = (int)floor(out_coords[4] * SCALES[4]);
+ safe_in_coords[3] = (int)floor(out_coords[3] * SCALES[3]);
+ safe_in_coords[2] = (int)floor(out_coords[2] * SCALES[2]);
+ safe_in_coords[1] = out_coords[1];
+ safe_in_coords[0] = out_coords[0];
+#else
unroll_for (int i = 0; i < 5; ++i) {
const float orig_coord = FUNC_CALL(get_original_coordinate)(out_coords[i], SCALES[i], out_size[i], in_size[i] + PADS_BEGIN[i] + PADS_END[i]);
- const int nearest_pixel = FUNC_CALL(get_nearest_val)(orig_coord, SCALES[i] > 1) - PADS_BEGIN[i];
- in_coords[i] = max(-PADS_BEGIN[0], min(nearest_pixel, in_size[i] + PADS_END[i] - 1));
+ const int nearest_pixel = FUNC_CALL(get_nearest_val)(orig_coord, SCALES[i] < 1) - PADS_BEGIN[i];
+ in_coords[i] = max(-PADS_BEGIN[i], min(nearest_pixel, in_size[i] + PADS_END[i] - 1));
+ safe_in_coords[i] = clamp(in_coords[i], 0, in_size[i] - 1);
#if PADDING_USED == 1
if (in_coords[i] < 0 || in_coords[i] >= in_size[i])
isOutOfBounds = true;
#endif
}
+#endif
- uint input_idx = FUNC_CALL(get_input_index)(in_coords[0], in_coords[1], 0, in_coords[2], in_coords[3], in_coords[4]);
+ uint input_idx = FUNC_CALL(get_input_index)(safe_in_coords[0], safe_in_coords[1], 0, safe_in_coords[2], safe_in_coords[3], safe_in_coords[4]);
uint output_idx = FUNC_CALL(get_output_index)(out_coords[0], out_coords[1], 0, out_coords[2], out_coords[3], out_coords[4]);
in_pack_t interp_val_pack = ((const __global in_pack_t*)(input + input_idx))[0];
@@ -134,17 +216,27 @@ KERNEL (resample_gpu_ref)(__global INPUT0_TYPE* input,
out_coords[1] = (int)get_global_id(2) % OUTPUT_FEATURE_NUM;
out_coords[0] = (int)get_global_id(2) / OUTPUT_FEATURE_NUM;
int in_coords[5];
+ int safe_in_coords[5];
bool isOutOfBounds = false;
+#if RESAMPLE_FAST_NEAREST == 1
+ safe_in_coords[4] = (int)floor(out_coords[4] * SCALES[4]);
+ safe_in_coords[3] = (int)floor(out_coords[3] * SCALES[3]);
+ safe_in_coords[2] = (int)floor(out_coords[2] * SCALES[2]);
+ safe_in_coords[1] = out_coords[1];
+ safe_in_coords[0] = out_coords[0];
+#else
unroll_for (int i = 0; i < 5; ++i) {
const float orig_coord = FUNC_CALL(get_original_coordinate)(out_coords[i], SCALES[i], out_size[i], in_size[i] + PADS_BEGIN[i] + PADS_END[i]);
- int nearest_pixel = FUNC_CALL(get_nearest_val)(orig_coord, SCALES[i] > 1) - PADS_BEGIN[i];
+ int nearest_pixel = FUNC_CALL(get_nearest_val)(orig_coord, SCALES[i] < 1) - PADS_BEGIN[i];
in_coords[i] = max(-PADS_BEGIN[i], min(nearest_pixel, in_size[i] + PADS_END[i] - 1));
+ safe_in_coords[i] = clamp(in_coords[i], 0, in_size[i] - 1);
#if PADDING_USED == 1
if (in_coords[i] < 0 || in_coords[i] >= in_size[i])
isOutOfBounds = true;
#endif
}
- INPUT0_TYPE interp_val = input[FUNC_CALL(get_input_index)(in_coords[0], in_coords[1], 0, in_coords[2], in_coords[3], in_coords[4])];
+#endif
+ INPUT0_TYPE interp_val = input[FUNC_CALL(get_input_index)(safe_in_coords[0], safe_in_coords[1], 0, safe_in_coords[2], safe_in_coords[3], safe_in_coords[4])];
#if PADDING_USED == 1
if (isOutOfBounds)
interp_val = TO_INPUT0_TYPE(INPUT0_VAL_ZERO);
@@ -182,12 +274,38 @@ KERNEL (resample_gpu_ref)(__global INPUT0_TYPE* input,
float cubic_coeff[5][4];
unroll_for (int i = 0; i < 5; ++i) {
float orig_coord = FUNC_CALL(get_original_coordinate)(out_coords[i], SCALES[i], out_size[i], in_size[i] + PADS_BEGIN[i] + PADS_END[i]) - PADS_BEGIN[i];
+ #if SHAPE_CALC_MODE_SIZES && PADDING_USED == 1 && defined(COORD_TRANS_MODE_TF_HALF_PIXEL_FOR_NN)
+ // Only re-derive the coordinate when the axis is actually being resized
+ // (SCALES[i] != 1.0f). get_original_coordinate() has its own early-out
+ // for unit scale (returns "num" as-is); axes that are only padded but not
+ // resized (e.g. explicit sizes matching the padded input size) must keep
+ // that behavior, otherwise an incorrect half-pixel shift would be applied.
+ if (SCALES[i] != 1.0f) {
+ if ((PADS_BEGIN[i] == 0) != (PADS_END[i] == 0)) {
+ // Split into separate statements (with a volatile intermediate)
+ // so the final "- PADS_BEGIN[i]" is not fused by the compiler
+ // with the preceding multiplication into a single FMA, which
+ // would change rounding relative to the reference.
+ volatile float scaled = ((float)out_coords[i] + 0.5f) / (float)out_size[i] * (float)(in_size[i] + PADS_BEGIN[i] + PADS_END[i]);
+ orig_coord = scaled - PADS_BEGIN[i];
+ } else if (PADS_BEGIN[i] != 0 && PADS_END[i] != 0) {
+ volatile float inv_scale = 1.0f / SCALES[i];
+ volatile float scaled = ((float)out_coords[i] + 0.5f) * inv_scale;
+ orig_coord = scaled - PADS_BEGIN[i];
+ }
+ }
+ #elif SHAPE_CALC_MODE_SIZES && PADDING_USED == 1 && defined(COORD_TRANS_MODE_ASYMMETRIC)
+ if (SCALES[i] != 1.0f) {
+ volatile float scaled = (float)out_coords[i] / (float)out_size[i] * (float)(in_size[i] + PADS_BEGIN[i] + PADS_END[i]);
+ orig_coord = scaled - PADS_BEGIN[i];
+ }
+ #endif
in_coords[i] = floor(orig_coord);
orig_coord = (orig_coord - in_coords[i]) * AXES_USED[i];
FUNC_CALL(get_cubic_coeff)(cubic_coeff[i], orig_coord, CUBE_COEFF);
}
- INPUT0_COMPUTE_TYPE interp_val = INPUT0_VAL_ZERO;
+ ACCUMULATOR_TYPE interp_val = ACCUMULATOR_VAL_ZERO;
int index[5];
unroll_for (index[0] = 0; index[0] <= 3; ++index[0]) {
unroll_for (index[1] = 0; index[1] <= 3; ++index[1]) {
@@ -208,7 +326,11 @@ KERNEL (resample_gpu_ref)(__global INPUT0_TYPE* input,
#if PADDING_USED == 1
if (!isOutOfBounds)
#endif
- interp_val += coeff_prod * DECODE_INPUT0_COMPUTE_TYPE(input[FUNC_CALL(get_input_index)(coords_sum[0], coords_sum[1], 0, coords_sum[2], coords_sum[3], coords_sum[4])]);
+ {
+ interp_val = fma((ACCUMULATOR_TYPE)coeff_prod,
+ (ACCUMULATOR_TYPE)DECODE_INPUT0_COMPUTE_TYPE(input[FUNC_CALL(get_input_index)(coords_sum[0], coords_sum[1], 0, coords_sum[2], coords_sum[3], coords_sum[4])]),
+ interp_val);
+ }
}
}
}
@@ -499,11 +621,11 @@ KERNEL (resample_gpu_ref)(__global INPUT0_TYPE* input,
ACCUMULATOR_TYPE sum[fp_max] = {0};
ACCUMULATOR_TYPE wsum[fp_max] = {0};
- unroll_for(int b = b_init; b < b_max; b++) {
- unroll_for(int f = f_init; f < f_max; f++) {
- unroll_for(int z = z_init; z < z_max; z++) {
- unroll_for(int y = y_init; y < y_max; y++) {
- unroll_for(int x = x_init; x < x_max; x++) {
+ for (int b = b_init; b < b_max; b++) {
+ for (int f = f_init; f < f_max; f++) {
+ for (int z = z_init; z < z_max; z++) {
+ for (int y = y_init; y < y_max; y++) {
+ for (int x = x_init; x < x_max; x++) {
unroll_for(int fp = 0; fp < fp_max; fp++) {
#if PADDING_USED == 1
bool isOutOfBounds = b < 0 || f < 0 || z < 0 || y < 0 || x < 0 ||
diff --git a/src/plugins/intel_gpu/src/kernel_selector/kernels/resample/resample_kernel_base.cpp b/src/plugins/intel_gpu/src/kernel_selector/kernels/resample/resample_kernel_base.cpp
index 3a8bf453f15..3cbf861bbdf 100644
--- a/src/plugins/intel_gpu/src/kernel_selector/kernels/resample/resample_kernel_base.cpp
+++ b/src/plugins/intel_gpu/src/kernel_selector/kernels/resample/resample_kernel_base.cpp
@@ -13,7 +13,7 @@
#include "kernel_selector_utils.h"
namespace {
-int getAxisIndex(kernel_selector::InterpolateAxis axis) {
+int get_axis_index(kernel_selector::InterpolateAxis axis) {
switch (axis) {
case kernel_selector::InterpolateAxis::BATCH:
return 0;
@@ -33,6 +33,11 @@ int getAxisIndex(kernel_selector::InterpolateAxis axis) {
namespace kernel_selector {
+bool ResampleKernelBase::has_padding(const resample_params& params) {
+ return std::any_of(params.pads_begin.begin(), params.pads_begin.end(), [](const auto pad) { return pad != 0; }) ||
+ std::any_of(params.pads_end.begin(), params.pads_end.end(), [](const auto pad) { return pad != 0; });
+}
+
size_t ResampleKernelBase::GetFeatureBlockSize(const resample_params& params) const {
const size_t max_size = 32;
const size_t min_size = 4;
@@ -120,7 +125,7 @@ bool ResampleKernelBase::Validate(const Params& p) const {
return true;
}
-JitConstants ResampleKernelBase::GetJitConstants(const resample_params& params) const {
+JitConstants ResampleKernelBase::GetJitConstants(const resample_params& params, bool legacy_scale) const {
JitConstants jit = MakeBaseParamsJitConstants(params);
const auto& input = params.inputs[0];
@@ -128,10 +133,10 @@ JitConstants ResampleKernelBase::GetJitConstants(const resample_params& params)
auto pads_begin = params.pads_begin;
auto pads_end = params.pads_end;
if (pads_begin.size() == 4) {
- pads_begin.insert(std::next(pads_begin.begin(), 2), 0);
+ pads_begin.insert(pads_begin.begin() + 2, 0);
}
if (pads_end.size() == 4) {
- pads_end.insert(std::next(pads_end.begin(), 2), 0);
+ pads_end.insert(pads_end.begin() + 2, 0);
}
const auto b_size_padded = pads_begin[0] + input.Batch().v + pads_end[0];
@@ -151,19 +156,35 @@ JitConstants ResampleKernelBase::GetJitConstants(const resample_params& params)
paddingUsed |= (pads_begin[i] != 0 || pads_end[i] != 0);
}
- scales[0] = static_cast<float>(b_size_padded) / static_cast<float>(out_b_size_padded);
- scales[1] = static_cast<float>(f_size_padded) / static_cast<float>(out_f_size_padded);
- scales[4] = static_cast<float>(x_size_padded) / static_cast<float>(out_x_size_padded);
- scales[3] = static_cast<float>(y_size_padded) / static_cast<float>(out_y_size_padded);
- scales[2] = static_cast<float>(z_size_padded) / static_cast<float>(out_z_size_padded);
-
- for (std::size_t i = 0; i < params.axes.size(); i++) {
- int idx = getAxisIndex(params.axes[i]);
- axesUsed[idx] = 1;
- if (params.shapeCalculationMode == kernel_selector::ShapeCalculationMode::SCALES) {
- scales[idx] = 1.f / params.scales[i];
+ if (legacy_scale) {
+ scales[0] = static_cast<float>(b_size_padded) / static_cast<float>(out_b_size_padded);
+ scales[1] = static_cast<float>(f_size_padded) / static_cast<float>(out_f_size_padded);
+ scales[4] = static_cast<float>(x_size_padded) / static_cast<float>(out_x_size_padded);
+ scales[3] = static_cast<float>(y_size_padded) / static_cast<float>(out_y_size_padded);
+ scales[2] = static_cast<float>(z_size_padded) / static_cast<float>(out_z_size_padded);
+
+ for (std::size_t i = 0; i < params.axes.size(); i++) {
+ const int idx = get_axis_index(params.axes[i]);
+ if (params.shapeCalculationMode == kernel_selector::ShapeCalculationMode::SCALES) {
+ scales[idx] = 1.f / params.scales[i];
+ }
+ }
+ } else {
+ scales[0] = static_cast<float>(out_b_size_padded) / static_cast<float>(b_size_padded);
+ scales[1] = static_cast<float>(out_f_size_padded) / static_cast<float>(f_size_padded);
+ scales[4] = static_cast<float>(out_x_size_padded) / static_cast<float>(x_size_padded);
+ scales[3] = static_cast<float>(out_y_size_padded) / static_cast<float>(y_size_padded);
+ scales[2] = static_cast<float>(out_z_size_padded) / static_cast<float>(z_size_padded);
+
+ for (std::size_t i = 0; i < params.axes.size(); i++) {
+ int idx = get_axis_index(params.axes[i]);
+ axesUsed[idx] = 1;
+ if (params.shapeCalculationMode == kernel_selector::ShapeCalculationMode::SCALES) {
+ scales[idx] = params.scales[i];
+ }
}
}
+
for (size_t i = 0; i < scales.size(); ++i) {
if (scales[i] != 1.f) {
axesUsed[i] = 1;
@@ -174,6 +195,7 @@ JitConstants ResampleKernelBase::GetJitConstants(const resample_params& params)
MakeJitConstant(toString(params.resampleType), ""),
MakeJitConstant(toString(params.nearestMode), ""),
MakeJitConstant(toString(params.coordTransMode), ""),
+ MakeJitConstant("SHAPE_CALC_MODE_SIZES", params.shapeCalculationMode == ShapeCalculationMode::SIZES),
MakeJitConstant("SCALES", scales),
MakeJitConstant("PADS_BEGIN", pads_begin),
MakeJitConstant("PADS_END", pads_end),
diff --git a/src/plugins/intel_gpu/src/kernel_selector/kernels/resample/resample_kernel_base.h b/src/plugins/intel_gpu/src/kernel_selector/kernels/resample/resample_kernel_base.h
index af4c9a5c4ee..865b9f9a8c1 100644
--- a/src/plugins/intel_gpu/src/kernel_selector/kernels/resample/resample_kernel_base.h
+++ b/src/plugins/intel_gpu/src/kernel_selector/kernels/resample/resample_kernel_base.h
@@ -44,10 +44,12 @@ public:
~ResampleKernelBase() override = default;
+ static bool has_padding(const resample_params& params);
+
protected:
bool Validate(const Params& p) const override;
virtual DispatchData SetDefault(const resample_params& arg) const;
- virtual JitConstants GetJitConstants(const resample_params& params) const;
+ virtual JitConstants GetJitConstants(const resample_params& params, bool legacy_scale = false) const;
KernelsData GetCommonKernelsData(const Params& params) const;
size_t GetFeatureBlockSize(const resample_params& params) const;
virtual Datatype GetAccumulatorType(const resample_params& params) const;
diff --git a/src/plugins/intel_gpu/src/kernel_selector/kernels/resample/resample_kernel_bfyx_cubic_opt.cpp b/src/plugins/intel_gpu/src/kernel_selector/kernels/resample/resample_kernel_bfyx_cubic_opt.cpp
index 510ebce08f4..9cc65ead91a 100644
--- a/src/plugins/intel_gpu/src/kernel_selector/kernels/resample/resample_kernel_bfyx_cubic_opt.cpp
+++ b/src/plugins/intel_gpu/src/kernel_selector/kernels/resample/resample_kernel_bfyx_cubic_opt.cpp
@@ -3,6 +3,7 @@
//
#include "resample_kernel_bfyx_cubic_opt.h"
+#include <algorithm>
#include <vector>
#include <kernel_selector_utils.h>
@@ -74,9 +75,15 @@ bool ResampleKernelBfyxCubicOpt::Validate(const Params& p) const {
DO_NOT_USE_THIS_KERNEL(p.layerID);
}
- // Only spatial axes (Y, X) may be resized.
+ if (ResampleKernelBase::has_padding(params)) {
+ DO_NOT_USE_THIS_KERNEL(p.layerID);
+ }
+
+ // Explicit axes may include B/F with unit scale. The optimized kernel is still valid
+ // as long as only spatial dimensions actually change.
for (const auto& axis : params.axes) {
- if (axis != InterpolateAxis::Y && axis != InterpolateAxis::X) {
+ if (axis != InterpolateAxis::BATCH && axis != InterpolateAxis::FEATURE &&
+ axis != InterpolateAxis::Y && axis != InterpolateAxis::X) {
DO_NOT_USE_THIS_KERNEL(p.layerID);
}
}
@@ -91,7 +98,7 @@ bool ResampleKernelBfyxCubicOpt::Validate(const Params& p) const {
return true;
}
-JitConstants ResampleKernelBfyxCubicOpt::GetJitConstants(const resample_params& params) const {
+JitConstants ResampleKernelBfyxCubicOpt::GetJitConstants(const resample_params& params, bool legacy_scale) const {
auto jit = Parent::GetJitConstants(params);
auto opt_x_block_size = GetOptimalBlockSize(params);
diff --git a/src/plugins/intel_gpu/src/kernel_selector/kernels/resample/resample_kernel_bfyx_cubic_opt.h b/src/plugins/intel_gpu/src/kernel_selector/kernels/resample/resample_kernel_bfyx_cubic_opt.h
index 88d5b2ce30c..3bb5e282fa2 100644
--- a/src/plugins/intel_gpu/src/kernel_selector/kernels/resample/resample_kernel_bfyx_cubic_opt.h
+++ b/src/plugins/intel_gpu/src/kernel_selector/kernels/resample/resample_kernel_bfyx_cubic_opt.h
@@ -19,7 +19,7 @@ public:
protected:
bool Validate(const Params& p) const override;
- JitConstants GetJitConstants(const resample_params& params) const override;
+ JitConstants GetJitConstants(const resample_params& params, bool legacy_scale = false) const override;
DispatchData SetDefault(const resample_params& arg) const override;
std::vector<FusedOpType> GetSupportedFusedOps() const override {
return { FusedOpType::QUANTIZE,
diff --git a/src/plugins/intel_gpu/src/kernel_selector/kernels/resample/resample_kernel_onnx.cpp b/src/plugins/intel_gpu/src/kernel_selector/kernels/resample/resample_kernel_onnx.cpp
index 54e81eb26df..1c7f04e72b1 100644
--- a/src/plugins/intel_gpu/src/kernel_selector/kernels/resample/resample_kernel_onnx.cpp
+++ b/src/plugins/intel_gpu/src/kernel_selector/kernels/resample/resample_kernel_onnx.cpp
@@ -147,7 +147,7 @@ static bool IsThreeSpatialResample(const resample_params& params) {
return input.Dimentions() == 5 && input.Z().v != output.Z().v;
}
-JitConstants ResampleKernelOnnx::GetJitConstants(const resample_params& params) const {
+JitConstants ResampleKernelOnnx::GetJitConstants(const resample_params& params, bool legacy_scale) const {
auto jit = Parent::GetJitConstants(params);
auto opt_x_block_size = GetOptimalBlockSize(params);
diff --git a/src/plugins/intel_gpu/src/kernel_selector/kernels/resample/resample_kernel_onnx.h b/src/plugins/intel_gpu/src/kernel_selector/kernels/resample/resample_kernel_onnx.h
index 5f4bde6b3c9..ade82471fdd 100644
--- a/src/plugins/intel_gpu/src/kernel_selector/kernels/resample/resample_kernel_onnx.h
+++ b/src/plugins/intel_gpu/src/kernel_selector/kernels/resample/resample_kernel_onnx.h
@@ -20,7 +20,7 @@ public:
protected:
bool Validate(const Params& p) const override;
- JitConstants GetJitConstants(const resample_params& params) const override;
+ JitConstants GetJitConstants(const resample_params& params, bool legacy_scale = false) const override;
DispatchData SetDefault(const resample_params& arg) const override;
std::vector<FusedOpType> GetSupportedFusedOps() const override {
return {FusedOpType::QUANTIZE, FusedOpType::ELTWISE, FusedOpType::ACTIVATION};
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.cpp
index 722502cde5c..8bc443f35ae 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
@@ -3,8 +3,11 @@
//
#include "resample_kernel_opt.h"
+
+#include <algorithm>
#include <vector>
#include <kernel_selector_utils.h>
+#include "resample/utils.hpp"
namespace kernel_selector {
@@ -97,6 +100,55 @@ static int get_feature_slice_size(const resample_params &params) {
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();
@@ -157,6 +209,9 @@ bool ResampleKernelOpt::Validate(const Params& p) const {
}
const auto& input = params.inputs[0];
+ const auto& output = params.outputs[0];
+
+ const auto has_padding = ResampleKernelBase::has_padding(params);
if ((input.GetDType() == Datatype::UINT8 || input.GetDType() == Datatype::INT8) &&
params.resampleType != ResampleType::NEAREST_NEIGHBOR &&
@@ -173,7 +228,6 @@ bool ResampleKernelOpt::Validate(const Params& p) const {
// LINEAR_ONNX in resample_opt does not implement OOB-to-zero for padded
// coordinates; let resample_onnx (which does) handle those cases.
if (params.resampleType == ResampleType::LINEAR_ONNX) {
- const auto& output = params.outputs[0];
if (input.Batch().v != output.Batch().v || input.Feature().v != output.Feature().v) {
DO_NOT_USE_THIS_KERNEL(p.layerID);
}
@@ -185,11 +239,35 @@ 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);
+
+ 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);
+ }
+ }
+
+ if (params.resampleType == ResampleType::BILINEAR_INTERP) {
+ if (has_padding ||
+ params.coordTransMode != CoordinateTransformationMode::ASYMMETRIC ||
+ input.Batch().v != output.Batch().v ||
+ input.Feature().v != output.Feature().v) {
+ DO_NOT_USE_THIS_KERNEL(p.layerID);
+ }
+ }
+
return true;
}
-JitConstants ResampleKernelOpt::GetJitConstants(const resample_params &params) const {
- auto jit = Parent::GetJitConstants(params);
+JitConstants ResampleKernelOpt::GetJitConstants(const resample_params &params, bool legacy_scale) const {
+ auto jit = Parent::GetJitConstants(params, true);
auto opt_x_block_size = GetOptimalBlockSize(params);
if (params.outputs[0].X().v > 32 && opt_x_block_size == 1) {
diff --git a/src/plugins/intel_gpu/src/kernel_selector/kernels/resample/resample_kernel_opt.h b/src/plugins/intel_gpu/src/kernel_selector/kernels/resample/resample_kernel_opt.h
index 9415ebbe587..9892b99c038 100644
--- a/src/plugins/intel_gpu/src/kernel_selector/kernels/resample/resample_kernel_opt.h
+++ b/src/plugins/intel_gpu/src/kernel_selector/kernels/resample/resample_kernel_opt.h
@@ -20,7 +20,7 @@ public:
protected:
bool Validate(const Params& p) const override;
- JitConstants GetJitConstants(const resample_params& params) const override;
+ JitConstants GetJitConstants(const resample_params& params, bool legacy_scale = false) const override;
DispatchData SetDefault(const resample_params& arg) const override;
Datatype GetUnitType(const base_params& params) const override;
std::vector<FusedOpType> GetSupportedFusedOps() const override {
diff --git a/src/plugins/intel_gpu/src/kernel_selector/kernels/resample/resample_kernel_pil_ref.cpp b/src/plugins/intel_gpu/src/kernel_selector/kernels/resample/resample_kernel_pil_ref.cpp
index 1b7e3cc54bb..d2ded1505c5 100644
--- a/src/plugins/intel_gpu/src/kernel_selector/kernels/resample/resample_kernel_pil_ref.cpp
+++ b/src/plugins/intel_gpu/src/kernel_selector/kernels/resample/resample_kernel_pil_ref.cpp
@@ -129,7 +129,7 @@ DataTensor GetIntermediateBufferSize(const resample_params& params) {
OPENVINO_ASSERT(channelIndex >= 0, "Invalid layout channel index");
dims[channelIndex] = ybox_last - ybox_first;
- DataTensor result{dims, Datatype::F16, layout};
+ DataTensor result{dims, params.inputs[0].GetDType(), layout};
return result;
}
@@ -412,7 +412,7 @@ JitConstants ResampleKernelPilRef::GetJitConstantsForKernel(KernelId id, const r
} else if (DataTensor::ChannelsCount(params.outputs[0].GetLayout()) == 6) {
idx_order = {"b", "f", "w", "z", "y", "x"};
}
- FusedOpsConfiguration conf = {"", idx_order, "ss", GetAccumulatorType(params), 1};
+ FusedOpsConfiguration conf = {"", idx_order, "resample_result", params.inputs[0].GetDType(), 1};
jit_constants.Merge(MakeFusedOpsJitConstants(params, {conf}));
}
}
@@ -423,7 +423,7 @@ JitConstants ResampleKernelPilRef::GetJitConstantsForKernel(KernelId id, const r
KernelsData ResampleKernelPilRef::GetKernelsData(const Params &params) const {
const resample_params& resample_parameters = static_cast<const resample_params&>(params);
KernelData kd = KernelData::Default<resample_params>(params, GetKernelsNum(resample_parameters));
- kd.internalBufferDataType = Datatype::F16;
+ kd.internalBufferDataType = resample_parameters.inputs[0].GetDType();
int i = 0;
for (ResampleKernelPilRef::KernelId id = eCalcHorizontalCoefficients; id < eEnd; ++id) {
if (!NeedHorizontalPass(resample_parameters) &&
diff --git a/src/plugins/intel_gpu/src/kernel_selector/kernels/resample/resample_kernel_ref.cpp b/src/plugins/intel_gpu/src/kernel_selector/kernels/resample/resample_kernel_ref.cpp
index dd908bd14f5..9cc1ffa74ec 100644
--- a/src/plugins/intel_gpu/src/kernel_selector/kernels/resample/resample_kernel_ref.cpp
+++ b/src/plugins/intel_gpu/src/kernel_selector/kernels/resample/resample_kernel_ref.cpp
@@ -4,6 +4,7 @@
#include <kernel_selector_utils.h>
#include "resample_kernel_ref.h"
+#include "resample/utils.hpp"
#include <algorithm>
#include <vector>
@@ -95,8 +96,82 @@ static bool use_packing(const resample_params& params) {
return packed_work_items >= minimum_work_items;
}
-JitConstants ResampleKernelRef::GetJitConstants(const resample_params& params) const {
- JitConstants jit = ResampleKernelBase::GetJitConstants(params);
+static bool is_fast_nearest_case(const resample_params& params) {
+ const auto& input = params.inputs[0];
+ const auto& output = params.outputs[0];
+
+ if (params.resampleType != ResampleType::NEAREST_NEIGHBOR || ResampleKernelBase::has_padding(params) ||
+ input.Batch().v != output.Batch().v || input.Feature().v != output.Feature().v) {
+ return false;
+ }
+
+ const auto asymmetric_floor = params.coordTransMode == CoordinateTransformationMode::ASYMMETRIC &&
+ params.nearestMode == NearestMode::FLOOR;
+ const auto asymmetric_simple_upsampling =
+ params.coordTransMode == CoordinateTransformationMode::ASYMMETRIC &&
+ params.nearestMode == NearestMode::SIMPLE &&
+ is_integral_upsampling_ratio(output.X().v, input.X().v) &&
+ is_integral_upsampling_ratio(output.Y().v, input.Y().v) &&
+ (input.Dimentions() != 5 || is_integral_upsampling_ratio(output.Z().v, input.Z().v));
+ const auto tf_half_pixel_for_nn_floor_upsampling =
+ params.coordTransMode == CoordinateTransformationMode::TF_HALF_PIXEL_FOR_NN &&
+ params.nearestMode == NearestMode::FLOOR &&
+ is_integral_upsampling_ratio(output.X().v, input.X().v) &&
+ is_integral_upsampling_ratio(output.Y().v, input.Y().v) &&
+ (input.Dimentions() != 5 || is_integral_upsampling_ratio(output.Z().v, input.Z().v));
+ const auto half_pixel_round_prefer_floor =
+ params.coordTransMode == CoordinateTransformationMode::HALF_PIXEL &&
+ params.nearestMode == NearestMode::ROUND_PREFER_FLOOR &&
+ is_integral_ratio(output.X().v, input.X().v) &&
+ is_integral_ratio(output.Y().v, input.Y().v) &&
+ (input.Dimentions() != 5 || is_integral_ratio(output.Z().v, input.Z().v));
+
+ return asymmetric_floor || asymmetric_simple_upsampling || tf_half_pixel_for_nn_floor_upsampling ||
+ half_pixel_round_prefer_floor;
+}
+
+static bool is_fast_linear_onnx_case(const resample_params& params) {
+ const auto& input = params.inputs[0];
+ const auto& output = params.outputs[0];
+
+ if (params.resampleType != ResampleType::LINEAR_ONNX || ResampleKernelBase::has_padding(params) ||
+ params.coordTransMode != CoordinateTransformationMode::HALF_PIXEL ||
+ input.Batch().v != output.Batch().v || input.Feature().v != output.Feature().v) {
+ 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_fast_caffe_bilinear_interp_case(const resample_params& params) {
+ const auto& input = params.inputs[0];
+ const auto& output = params.outputs[0];
+
+ return params.resampleType == ResampleType::CAFFE_BILINEAR_INTERP &&
+ !ResampleKernelBase::has_padding(params) &&
+ input.Batch().v == output.Batch().v &&
+ input.Feature().v == output.Feature().v;
+}
+
+JitConstants ResampleKernelRef::GetJitConstants(const resample_params& params, bool legacy_scale) const {
+ const auto fast_nearest_case = is_fast_nearest_case(params);
+ const auto fast_linear_onnx_case = is_fast_linear_onnx_case(params);
+ const auto fast_caffe_bilinear_interp_case = is_fast_caffe_bilinear_interp_case(params);
+
+ JitConstants jit = ResampleKernelBase::GetJitConstants(params, fast_nearest_case || fast_linear_onnx_case || fast_caffe_bilinear_interp_case);
+
+ if (fast_nearest_case) {
+ jit.AddConstant(MakeJitConstant("RESAMPLE_FAST_NEAREST", 1));
+ }
+
+ if (fast_linear_onnx_case || fast_caffe_bilinear_interp_case) {
+ jit.AddConstant(MakeJitConstant("RESAMPLE_USE_LEGACY_SCALE", 1));
+ }
if (use_packing(params)) {
jit.AddConstant(MakeJitConstant("PACK_SIZE", packing_factor(params)));
diff --git a/src/plugins/intel_gpu/src/kernel_selector/kernels/resample/resample_kernel_ref.h b/src/plugins/intel_gpu/src/kernel_selector/kernels/resample/resample_kernel_ref.h
index 9eeee329bbe..b93cdf3e105 100644
--- a/src/plugins/intel_gpu/src/kernel_selector/kernels/resample/resample_kernel_ref.h
+++ b/src/plugins/intel_gpu/src/kernel_selector/kernels/resample/resample_kernel_ref.h
@@ -16,7 +16,7 @@ public:
KernelsData GetKernelsData(const Params& params) const override;
KernelsPriority GetKernelsPriority(const Params& params) const override;
ParamsKey GetSupportedKey() const override;
- JitConstants GetJitConstants(const resample_params& params) const override;
+ JitConstants GetJitConstants(const resample_params& params, bool legacy_scale = false) const override;
std::vector<FusedOpType> GetSupportedFusedOps() const override {
return { FusedOpType::QUANTIZE,
FusedOpType::ELTWISE,
diff --git a/src/plugins/intel_gpu/src/kernel_selector/kernels/resample/utils.hpp b/src/plugins/intel_gpu/src/kernel_selector/kernels/resample/utils.hpp
new file mode 100644
index 00000000000..86653e622c2
--- /dev/null
+++ b/src/plugins/intel_gpu/src/kernel_selector/kernels/resample/utils.hpp
@@ -0,0 +1,18 @@
+// Copyright (C) 2018-2026 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#pragma once
+#include <cstddef>
+
+namespace kernel_selector {
+
+inline bool is_integral_ratio(size_t lhs, size_t rhs) {
+ return lhs != 0 && rhs != 0 && (lhs % rhs == 0 || rhs % lhs == 0);
+}
+
+inline bool is_integral_upsampling_ratio(size_t output, size_t input) {
+ return input != 0 && output >= input && output % input == 0;
+}
+
+} // namespace kernel_selector
diff --git a/src/plugins/intel_gpu/src/plugin/ops/interpolate.cpp b/src/plugins/intel_gpu/src/plugin/ops/interpolate.cpp
index b9f61bc10e8..45a4513f022 100644
--- a/src/plugins/intel_gpu/src/plugin/ops/interpolate.cpp
+++ b/src/plugins/intel_gpu/src/plugin/ops/interpolate.cpp
@@ -21,11 +21,14 @@ static std::vector<int64_t> ExtractAxes(const std::shared_ptr<ov::op::util::Inte
OPENVINO_ASSERT(axes_constant, "Unsupported parameter node type in ", op->get_friendly_name(), " (", op->get_type_name(), ")");
axes = axes_constant->cast_vector<int64_t>();
- ov::util::try_normalize_axes(axes, inputRank, *op);
- } else {
+ }
+
+ if (axes.empty()) {
for (size_t i = 0; i < inputRank; ++i) {
axes.push_back(ov::util::try_normalize_axis(i, inputRank, *op));
}
+ } else {
+ ov::util::try_normalize_axes(axes, inputRank, *op);
}
return axes;
}
diff --git a/src/plugins/intel_gpu/tests/functional/shared_tests_instances/single_layer_tests/interpolate.cpp b/src/plugins/intel_gpu/tests/functional/shared_tests_instances/single_layer_tests/interpolate.cpp
index 642c9b20ba8..7e4c2648a37 100644
--- a/src/plugins/intel_gpu/tests/functional/shared_tests_instances/single_layer_tests/interpolate.cpp
+++ b/src/plugins/intel_gpu/tests/functional/shared_tests_instances/single_layer_tests/interpolate.cpp
@@ -20,10 +20,10 @@ protected:
// Some rounding float to integer types on GPU may differ from CPU, and as result,
// the actual values may differ from reference ones on 1 when the float is very close to an integer,
// e.g 6,0000023 calculated on CPU may be cast to 5 by OpenCL convert_uchar function.
- // That is why the threshold is set 1.f for integer types.
+ // That is why the absolute threshold is set 1.f for integer types.
if (targetDevice == "GPU" &&
(model_type == ov::element::u8 || model_type == ov::element::i8)) {
- rel_threshold = 1.f;
+ abs_threshold = 1.f;
}
}
};
diff --git a/src/plugins/intel_gpu/tests/functional/single_layer_tests/dynamic/interpolate.cpp b/src/plugins/intel_gpu/tests/functional/single_layer_tests/dynamic/interpolate.cpp
index 271f09338f4..a98ebe2546b 100644
--- a/src/plugins/intel_gpu/tests/functional/single_layer_tests/dynamic/interpolate.cpp
+++ b/src/plugins/intel_gpu/tests/functional/single_layer_tests/dynamic/interpolate.cpp
@@ -152,6 +152,10 @@ protected:
const auto& [mode, transfMode, nearMode, antiAlias, padBegin, padEnd, cubeCoef] = specificParams;
+ if (mode == ov::op::v4::Interpolate::InterpolateMode::CUBIC && ngPrc == ov::element::f32) {
+ abs_threshold = 1e-3;
+ }
+
const auto& [_shapeCalcMode, dataShape, sizesInputType, scalesInputType, shapeDataForInput, axes] = shapeParams;
shapeCalcMode = _shapeCalcMode;
diff --git a/src/tests/functional/plugin/shared/src/single_op/interpolate.cpp b/src/tests/functional/plugin/shared/src/single_op/interpolate.cpp
index 9f82aa396b7..d3cdfa81d9b 100644
--- a/src/tests/functional/plugin/shared/src/single_op/interpolate.cpp
+++ b/src/tests/functional/plugin/shared/src/single_op/interpolate.cpp
@@ -144,7 +144,15 @@ void Interpolate11LayerTest::SetUp() {
auto param = std::make_shared<ov::op::v0::Parameter>(model_type, inputDynamicShapes.front());
- auto scales_orsizes_input = make_scales_or_sizes_input(shape_calc_mode, target_shape, scales);
+ auto target_sizes = target_shape;
+ if (!axes.empty()) {
+ target_sizes.clear();
+ for (const auto axis : axes) {
+ target_sizes.push_back(target_shape[axis]);
+ }
+ }
+
+ auto scales_orsizes_input = make_scales_or_sizes_input(shape_calc_mode, target_sizes, scales);
ov::op::util::InterpolateBase::InterpolateAttrs interpolate_attributes{mode, shape_calc_mode, pad_begin,
pad_end, coordinate_transform_mode, nearest_mode, antialias, cube_coef};
@@ -165,6 +173,10 @@ void Interpolate11LayerTest::SetUp() {
auto result = std::make_shared<ov::op::v0::Result>(interpolate);
function = std::make_shared<ov::Model>(result, ov::ParameterVector{param}, "interpolate");
+
+ if (model_type == ov::element::f32) {
+ abs_threshold = 1e-6;
+ }
}
} // namespace test
} // namespace ov