Skip to content

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

[GPU] Add optimized cubic interpolation kernel for bfyx layout (#34945)

Andrew Kwangwoong Park468f32a646ae
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
new file mode 100644
index 00000000000..ffdfdaee49d
--- /dev/null
+++ b/src/plugins/intel_gpu/src/kernel_selector/cl_kernels/resample_bfyx_cubic_opt.cl
@@ -0,0 +1,124 @@
+// Copyright (C) 2018-2026 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#include "include/fetch_utils.cl"
+
+#ifdef RTE_OUTPUT
+ #define TO_OUTPUT_TYPE(x) CAT(CAT(convert_, OUTPUT_TYPE), _rte)(x)
+#else
+ #define TO_OUTPUT_TYPE(x) CAT(convert_, OUTPUT_TYPE)(x)
+#endif
+
+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;
+#elif defined(COORD_TRANS_MODE_PYTORCH_HALF_PIXEL)
+ return (length_resized > 1) ? (num + 0.5f) * scale - 0.5f : 0.f;
+#elif defined(COORD_TRANS_MODE_ASYMMETRIC)
+ return num * scale;
+#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;
+#else
+#error [clDNN resample_bfyx_cubic_opt.cl]: coordinate transformation mode - not supported
+#endif
+}
+
+inline void FUNC(get_cubic_coeff)(float* cubic_coef, float coord, float coef)
+{
+ 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);
+}
+
+KERNEL (resample_bfyx_cubic_opt)(
+ __global INPUT0_TYPE* input,
+ __global OUTPUT_TYPE* output
+#if HAS_FUSED_OPS_DECLS
+ , FUSED_OPS_DECLS
+#endif
+)
+{
+ const int xy = get_global_id(0);
+ const int out_x = (xy % X_BLOCKS) * OUTPUT_X_BLOCK_SIZE;
+ const int out_y = xy / X_BLOCKS;
+ const int out_f = get_global_id(1);
+ const int out_b = get_global_id(2);
+
+ if (out_f >= OUTPUT_FEATURE_NUM || out_b >= OUTPUT_BATCH_NUM)
+ return;
+
+ // 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];
+ const int iy = (int)floor(orig_y);
+ const float y_frac = orig_y - (float)iy;
+ float cy[4];
+ FUNC_CALL(get_cubic_coeff)(cy, y_frac, CUBE_COEFF);
+
+ // Pre-clamp Y indices
+ int y_idx[4];
+ unroll_for (int j = 0; j < 4; ++j) {
+ y_idx[j] = clamp(iy + j - 1, -PADS_BEGIN[3], INPUT0_SIZE_Y + PADS_END[3] - 1);
+ }
+
+ unroll_for (uint bx = 0; bx < OUTPUT_X_BLOCK_SIZE; ++bx) {
+ const int ox = out_x + bx;
+ if (ox >= OUTPUT_SIZE_X)
+ break;
+
+ // 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];
+ const int ix = (int)floor(orig_x);
+ const float x_frac = orig_x - (float)ix;
+ float cx[4];
+ FUNC_CALL(get_cubic_coeff)(cx, x_frac, CUBE_COEFF);
+
+ // Pre-clamp X indices
+ int x_idx[4];
+ unroll_for (int k = 0; k < 4; ++k) {
+ x_idx[k] = clamp(ix + k - 1, -PADS_BEGIN[4], INPUT0_SIZE_X + PADS_END[4] - 1);
+ }
+
+ ACCUMULATOR_TYPE interp_val = ACCUMULATOR_VAL_ZERO;
+
+ // 4x4 bicubic interpolation with fused cy*cx coefficients
+ unroll_for (int dy = 0; dy < 4; ++dy) {
+ unroll_for (int dx = 0; dx < 4; ++dx) {
+#if PADDING_USED == 1
+ if (y_idx[dy] >= 0 && y_idx[dy] < INPUT0_SIZE_Y &&
+ x_idx[dx] >= 0 && x_idx[dx] < INPUT0_SIZE_X)
+#endif
+ {
+ interp_val = fma((ACCUMULATOR_TYPE)(cy[dy] * cx[dx]),
+ (ACCUMULATOR_TYPE)input[INPUT0_GET_INDEX(out_b, out_f, y_idx[dy], x_idx[dx])],
+ interp_val);
+ }
+ }
+ }
+
+#if HAS_FUSED_OPS
+ #define batch (out_b)
+ #define OF_ID (out_f)
+ #define oy (out_y)
+ FUSED_OPS;
+ OUTPUT_TYPE res = FUSED_OPS_RESULT;
+ #undef batch
+ #undef OF_ID
+ #undef oy
+#else
+ OUTPUT_TYPE res = ACTIVATION(TO_OUTPUT_TYPE(interp_val), ACTIVATION_PARAMS);
+#endif
+ output[OUTPUT_GET_INDEX(out_b, out_f, out_y, ox)] = res;
+ }
+}
+
+#undef TO_OUTPUT_TYPE
diff --git a/src/plugins/intel_gpu/src/kernel_selector/kernel_selector_params.cpp b/src/plugins/intel_gpu/src/kernel_selector/kernel_selector_params.cpp
index 094a65bdbd6..ae255a0a9b8 100644
--- a/src/plugins/intel_gpu/src/kernel_selector/kernel_selector_params.cpp
+++ b/src/plugins/intel_gpu/src/kernel_selector/kernel_selector_params.cpp
@@ -344,7 +344,7 @@ void ParamsKey::EnableConcatAxis(ConcatAxis a) {
}
}
-void ParamsKey::EnableReampleType(ResampleType a) {
+void ParamsKey::EnableResampleType(ResampleType a) {
switch (a) {
case ResampleType::NEAREST_NEIGHBOR:
key.restrict.val.dedicated.resample.nearest_neighbor = 1;
diff --git a/src/plugins/intel_gpu/src/kernel_selector/kernel_selector_params.h b/src/plugins/intel_gpu/src/kernel_selector/kernel_selector_params.h
index 79c8869ab15..ef37c3759ed 100644
--- a/src/plugins/intel_gpu/src/kernel_selector/kernel_selector_params.h
+++ b/src/plugins/intel_gpu/src/kernel_selector/kernel_selector_params.h
@@ -328,7 +328,7 @@ public:
void EnableSurfaceInputSupport() { key.restrict.val.dedicated.reorder.surface_input = 1; }
void EnableSoftmaxDim(SoftmaxDim d);
void EnableConcatAxis(ConcatAxis a);
- void EnableReampleType(ResampleType a);
+ void EnableResampleType(ResampleType a);
void EnableEltwiseStride();
void EnableEltwiseBroadcast() { key.restrict.val.dedicated.eltwise.broadcast = 1; }
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 f727fb107de..5db4fad0b99 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
@@ -29,7 +29,7 @@ struct resample_params : public base_params {
ParamsKey GetParamsKey() const override {
auto k = base_params::GetParamsKey();
- k.EnableReampleType(resampleType);
+ k.EnableResampleType(resampleType);
return k;
}
};
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
new file mode 100644
index 00000000000..048d9958f81
--- /dev/null
+++ b/src/plugins/intel_gpu/src/kernel_selector/kernels/resample/resample_kernel_bfyx_cubic_opt.cpp
@@ -0,0 +1,108 @@
+// Copyright (C) 2018-2026 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#include "resample_kernel_bfyx_cubic_opt.h"
+#include <vector>
+#include <kernel_selector_utils.h>
+
+namespace kernel_selector {
+
+size_t ResampleKernelBfyxCubicOpt::GetOptimalBlockSize(const resample_params& params) const {
+ std::vector<size_t> block_width = {16, 8, 4, 2, 1};
+ for (auto& w : block_width) {
+ if (params.outputs[0].X().v % w == 0) {
+ return w;
+ }
+ }
+ return 1;
+}
+
+ParamsKey ResampleKernelBfyxCubicOpt::GetSupportedKey() const {
+ ParamsKey k;
+ k.EnableInputDataType(Datatype::F16);
+ k.EnableInputDataType(Datatype::F32);
+ k.EnableOutputDataType(Datatype::F16);
+ k.EnableOutputDataType(Datatype::F32);
+ k.EnableInputLayout(DataLayout::bfyx);
+ k.EnableOutputLayout(DataLayout::bfyx);
+ k.EnableDifferentTypes();
+ k.EnableTensorOffset();
+ k.EnableTensorPitches();
+ k.EnableBatching();
+ k.EnableResampleType(ResampleType::CUBIC);
+ return k;
+}
+
+ResampleKernelBase::DispatchData ResampleKernelBfyxCubicOpt::SetDefault(const resample_params& arg) const {
+ DispatchData dispatchData;
+ auto in_layout = arg.inputs[0].GetLayout();
+ auto out_layout = arg.outputs[0].GetLayout();
+
+ const auto& out = arg.outputs[0];
+ auto opt_x_block_size = GetOptimalBlockSize(arg);
+
+ dispatchData.gws[0] = CeilDiv(out.X().v, opt_x_block_size) * out.Y().v;
+ dispatchData.gws[1] = out.Feature().v;
+ dispatchData.gws[2] = out.Batch().v;
+
+ std::vector<std::vector<Tensor::DataChannelName>> dims_by_gws = {
+ {Tensor::DataChannelName::X, Tensor::DataChannelName::Y},
+ {Tensor::DataChannelName::FEATURE},
+ {Tensor::DataChannelName::BATCH}};
+
+ dispatchData.lws = GetOptimalLocalWorkGroupSizes(dispatchData.gws, arg.engineInfo, in_layout, out_layout, dims_by_gws);
+
+ return dispatchData;
+}
+
+KernelsPriority ResampleKernelBfyxCubicOpt::GetKernelsPriority(const Params& /*params*/) const {
+ return FORCE_PRIORITY_3;
+}
+
+bool ResampleKernelBfyxCubicOpt::Validate(const Params& p) const {
+ if (!Parent::Validate(p))
+ DO_NOT_USE_THIS_KERNEL(p.layerID);
+
+ const resample_params& params = static_cast<const resample_params&>(p);
+
+ // Only 4D tensors (no Z axis).
+ if (params.inputs[0].Dimentions() != 4)
+ DO_NOT_USE_THIS_KERNEL(p.layerID);
+
+ // Only spatial axes (Y, X) may be resized.
+ for (const auto& axis : params.axes) {
+ if (axis != InterpolateAxis::Y && axis != InterpolateAxis::X)
+ DO_NOT_USE_THIS_KERNEL(p.layerID);
+ }
+
+ // Non-spatial dimensions (batch and feature) must not be resized.
+ const auto& in = params.inputs[0];
+ const auto& out = params.outputs[0];
+ if (in.Batch().v != out.Batch().v || in.Feature().v != out.Feature().v)
+ DO_NOT_USE_THIS_KERNEL(p.layerID);
+
+ return true;
+}
+
+JitConstants ResampleKernelBfyxCubicOpt::GetJitConstants(const resample_params& params) const {
+ auto jit = Parent::GetJitConstants(params);
+
+ auto opt_x_block_size = GetOptimalBlockSize(params);
+ jit.AddConstant(MakeJitConstant("OUTPUT_X_BLOCK_SIZE", opt_x_block_size));
+ jit.AddConstant(MakeJitConstant("X_BLOCKS", CeilDiv(params.outputs[0].X().v, opt_x_block_size)));
+
+ if (!params.fused_ops.empty()) {
+ std::vector<std::string> idx_order = {"batch", "OF_ID", "oy", "ox"};
+ FusedOpsConfiguration conf = {"", idx_order, "interp_val", GetAccumulatorType(params), 1};
+ jit.Merge(MakeFusedOpsJitConstants(params, {conf}));
+ }
+
+ return jit;
+}
+
+KernelsData ResampleKernelBfyxCubicOpt::GetKernelsData(const Params& params) const {
+ return GetCommonKernelsData(params);
+}
+
+} // namespace kernel_selector
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
new file mode 100644
index 00000000000..b2026e7b87e
--- /dev/null
+++ b/src/plugins/intel_gpu/src/kernel_selector/kernels/resample/resample_kernel_bfyx_cubic_opt.h
@@ -0,0 +1,33 @@
+// Copyright (C) 2018-2026 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#pragma once
+
+#include "resample_kernel_base.h"
+
+namespace kernel_selector {
+class ResampleKernelBfyxCubicOpt : public ResampleKernelBase {
+public:
+ using Parent = ResampleKernelBase;
+ ResampleKernelBfyxCubicOpt() : ResampleKernelBase("resample_bfyx_cubic_opt") {}
+ virtual ~ResampleKernelBfyxCubicOpt() = default;
+
+ KernelsData GetKernelsData(const Params& params) const override;
+ KernelsPriority GetKernelsPriority(const Params& params) const override;
+ ParamsKey GetSupportedKey() const override;
+
+protected:
+ bool Validate(const Params& p) const override;
+ JitConstants GetJitConstants(const resample_params& params) const override;
+ DispatchData SetDefault(const resample_params& arg) const override;
+ std::vector<FusedOpType> GetSupportedFusedOps() const override {
+ return { FusedOpType::QUANTIZE,
+ FusedOpType::ELTWISE,
+ FusedOpType::ACTIVATION };
+ }
+
+private:
+ size_t GetOptimalBlockSize(const resample_params& params) const;
+};
+} // namespace kernel_selector
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 a4898535958..2aa309cda9f 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
@@ -76,7 +76,7 @@ ParamsKey ResampleKernelOnnx::GetSupportedKey() const {
k.EnableTensorOffset();
k.EnableTensorPitches();
k.EnableBatching();
- k.EnableReampleType(ResampleType::LINEAR_ONNX);
+ k.EnableResampleType(ResampleType::LINEAR_ONNX);
return k;
}
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 a27bc766adc..1317bb44eb1 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
@@ -71,9 +71,9 @@ ParamsKey ResampleKernelOpt::GetSupportedKey() const {
k.EnableTensorOffset();
k.EnableTensorPitches();
k.EnableBatching();
- k.EnableReampleType(ResampleType::BILINEAR_INTERP);
- k.EnableReampleType(ResampleType::NEAREST_NEIGHBOR);
- k.EnableReampleType(ResampleType::CAFFE_BILINEAR_INTERP);
+ k.EnableResampleType(ResampleType::BILINEAR_INTERP);
+ k.EnableResampleType(ResampleType::NEAREST_NEIGHBOR);
+ k.EnableResampleType(ResampleType::CAFFE_BILINEAR_INTERP);
return k;
}
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 70a93a6d958..d47a9dc01e7 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
@@ -142,8 +142,8 @@ ParamsKey ResampleKernelPilRef::GetSupportedKey() const {
k.EnableTensorOffset();
k.EnableTensorPitches();
k.EnableBatching();
- k.EnableReampleType(ResampleType::BILINEAR_PILLOW);
- k.EnableReampleType(ResampleType::BICUBIC_PILLOW);
+ k.EnableResampleType(ResampleType::BILINEAR_PILLOW);
+ k.EnableResampleType(ResampleType::BICUBIC_PILLOW);
return k;
}
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 775c90d6446..557390094a1 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
@@ -27,11 +27,11 @@ ParamsKey ResampleKernelRef::GetSupportedKey() const {
k.EnableTensorOffset();
k.EnableTensorPitches();
k.EnableBatching();
- k.EnableReampleType(ResampleType::NEAREST_NEIGHBOR);
- k.EnableReampleType(ResampleType::CAFFE_BILINEAR_INTERP);
- k.EnableReampleType(ResampleType::BILINEAR_INTERP);
- k.EnableReampleType(ResampleType::CUBIC);
- k.EnableReampleType(ResampleType::LINEAR_ONNX);
+ k.EnableResampleType(ResampleType::NEAREST_NEIGHBOR);
+ k.EnableResampleType(ResampleType::CAFFE_BILINEAR_INTERP);
+ k.EnableResampleType(ResampleType::BILINEAR_INTERP);
+ k.EnableResampleType(ResampleType::CUBIC);
+ k.EnableResampleType(ResampleType::LINEAR_ONNX);
return k;
}
diff --git a/src/plugins/intel_gpu/src/kernel_selector/kernels/resample/resample_kernel_selector.cpp b/src/plugins/intel_gpu/src/kernel_selector/kernels/resample/resample_kernel_selector.cpp
index 617336d3a95..0b025dde484 100644
--- a/src/plugins/intel_gpu/src/kernel_selector/kernels/resample/resample_kernel_selector.cpp
+++ b/src/plugins/intel_gpu/src/kernel_selector/kernels/resample/resample_kernel_selector.cpp
@@ -7,6 +7,7 @@
#include "resample_kernel_opt.h"
#include "resample_kernel_onnx.h"
#include "resample_kernel_pil_ref.h"
+#include "resample_kernel_bfyx_cubic_opt.h"
namespace kernel_selector {
resample_kernel_selector::resample_kernel_selector() {
@@ -14,6 +15,7 @@ resample_kernel_selector::resample_kernel_selector() {
Attach<ResampleKernelOpt>();
Attach<ResampleKernelOnnx>();
Attach<ResampleKernelPilRef>();
+ Attach<ResampleKernelBfyxCubicOpt>();
}
KernelsData resample_kernel_selector::GetBestKernels(const Params& params) const {
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.cpp
index a31794fca75..8fb601edbaa 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
@@ -2486,6 +2486,299 @@ TEST_P(resample_opt_random_test, random_cached) {
execute_compare(param, true, true);
}
#endif
+
+TEST(resample_gpu, interpolate_in2x2x3x2_cubic_opt) {
+ // Verify optimized cubic kernel produces same results as reference
+ // Input : 2x2x3x2 (b=2, f=2, y=3, x=2)
+ // Output : 2x2x2x3
+
+ auto& engine = get_test_engine();
+ ov::intel_gpu::ExecutionConfig config = get_test_default_config(engine);
+ config.set_property(ov::intel_gpu::allow_new_shape_infer(true));
+ config.set_property(ov::intel_gpu::force_implementations(
+ ov::intel_gpu::ImplForcingMap{{"interpolate", {format::bfyx, "resample_bfyx_cubic_opt"}}}));
+
+ int b = 2;
+ int f = 2;
+ int y = 3;
+ int x = 2;
+ tensor shape = tensor{batch(b), feature(f), spatial(x, y)};
+ auto input = engine.allocate_memory({ data_types::f32, format::bfyx, shape });
+
+ y = 2;
+ x = 3;
+ std::vector<int64_t> output_pattern {b, f, y, x};
+
+ topology topology;
+ topology.add(input_layout("input", input->get_layout()));
+ int32_t antialias = 0;
+ float cube_coeff = -0.75f;
+ auto mode = resample::InterpolateOp::InterpolateMode::CUBIC;
+ auto shapeCalcMode = resample::InterpolateOp::ShapeCalcMode::SIZES;
+ topology.add(resample("interpolate", input_info("input"), output_pattern, std::vector<float>{}, {}, {0, 0, 0, 0}, {0, 0, 0, 0}, antialias, cube_coeff, mode, shapeCalcMode));
+
+ set_values(input, {
+ 0.f, 1.f, 2.f,
+ 3.f, 4.f, 5.f,
+ 6.f, 7.f, 8.f,
+ 9.f, 10.f, 11.f,
+ 12.f, 13.f, 14.f,
+ 15.f, 16.f, 17.f,
+ 18.f, 19.f, 20.f,
+ 21.f, 22.f, 23.f,
+ });
+
+ cldnn::network net{ engine, topology, config };
+ net.set_input_data("input", input);
+
+ auto outputs = net.execute();
+ auto output = outputs.at("interpolate").get_memory();
+ cldnn::mem_lock<float> output_ptr(output, get_test_stream());
+
+ std::vector<float> answers = {
+ 0.29600694f, 0.8828125f, 1.46961806f,
+ 3.53038194f, 4.1171875f, 4.70399306f,
+
+ 6.29600694f, 6.8828125f, 7.46961806f,
+ 9.53038194f, 10.1171875f, 10.70399306f,
+
+ 12.29600694f, 12.8828125f, 13.46961806f,
+ 15.53038194f, 16.1171875f, 16.70399306f,
+
+ 18.29600694f, 18.8828125f, 19.46961806f,
+ 21.53038194f, 22.1171875f, 22.70399306f,
+ };
+
+ ASSERT_EQ(answers.size(), output_ptr.size());
+ for (size_t i = 0; i < answers.size(); ++i) {
+ ASSERT_TRUE(are_equal(answers[i], output_ptr[i])) << i;
+ }
+}
+
+TEST(resample_gpu, interpolate_in1x1x3x2_cubic_opt) {
+ // Single batch/feature cubic test
+ // Input : 1x1x3x2 (b=1, f=1, y=3, x=2)
+ // Output : 1x1x3x3
+
+ auto& engine = get_test_engine();
+ ov::intel_gpu::ExecutionConfig config = get_test_default_config(engine);
+ config.set_property(ov::intel_gpu::allow_new_shape_infer(true));
+ config.set_property(ov::intel_gpu::force_implementations(
+ ov::intel_gpu::ImplForcingMap{{"interpolate", {format::bfyx, "resample_bfyx_cubic_opt"}}}));
+
+ int b = 1;
+ int f = 1;
+ int y = 3;
+ int x = 2;
+ tensor shape = tensor{batch(b), feature(f), spatial(x, y)};
+ auto input = engine.allocate_memory({ data_types::f32, format::bfyx, shape });
+
+ x = 3;
+ std::vector<int64_t> output_pattern {b, f, y, x};
+
+ topology topology;
+ topology.add(input_layout("input", input->get_layout()));
+ int32_t antialias = 0;
+ float cube_coeff = -0.75f;
+ auto mode = resample::InterpolateOp::InterpolateMode::CUBIC;
+ auto shapeCalcMode = resample::InterpolateOp::ShapeCalcMode::SIZES;
+ topology.add(resample("interpolate", input_info("input"), output_pattern, std::vector<float>{}, {}, {0, 0, 0, 0}, {0, 0, 0, 0}, antialias, cube_coeff, mode, shapeCalcMode));
+
+ set_values(input, {
+ 5.f, 1.f, 2.f,
+ 3.f, 4.f, 5.f,
+ });
+
+ cldnn::network net{ engine, topology, config };
+ net.set_input_data("input", input);
+
+ auto outputs = net.execute();
+ auto output = outputs.at("interpolate").get_memory();
+ cldnn::mem_lock<float> output_ptr(output, get_test_stream());
+
+ std::vector<float> answers = {
+ 5.34722222f, 3.f, 0.65277778f,
+ 1.91319444f, 2.5f, 3.08680556f,
+ 3.91319444f, 4.5f, 5.08680556f,
+ };
+
+ ASSERT_EQ(answers.size(), output_ptr.size());
+ for (size_t i = 0; i < answers.size(); ++i) {
+ ASSERT_TRUE(are_equal(answers[i], output_ptr[i])) << i;
+ }
+}
+
+// Parametrized random test: compare optimized cubic bfyx kernel against reference
+struct resample_cubic_random_test_params {
+ data_types input_type;
+ tensor input_size;
+ tensor output_size;
+};
+
+struct resample_cubic_random_test : testing::TestWithParam<resample_cubic_random_test_params> {
+ tests::random_generator rg;
+
+ void SetUp() override {
+ rg.set_seed(GET_SUITE_NAME);
+ }
+
+ template <typename T>
+ void fill_random_typed(memory::ptr mem, int min, int max, int k) {
+ auto l = mem->get_layout();
+ size_t b = l.batch();
+ size_t f = l.feature();
+ size_t x = l.spatial(0);
+ size_t y = l.spatial(1);
+
+ auto data = rg.generate_random_4d<T>(b, f, y, x, min, max, k);
+ mem_lock<T> ptr{mem, get_test_stream()};
+ for (size_t bi = 0; bi < b; ++bi) {
+ for (size_t fi = 0; fi < f; ++fi) {
+ for (size_t yi = 0; yi < y; ++yi) {
+ for (size_t xi = 0; xi < x; ++xi) {
+ auto coords = tensor(batch(bi), feature(fi), spatial(xi, yi, 0, 0));
+ auto offset = mem->get_layout().get_linear_offset(coords);
+ ptr[offset] = data[bi][fi][yi][xi];
+ }
+ }
+ }
+ }
+ }
+
+ void fill_random(memory::ptr mem) {
+ auto dt = mem->get_layout().data_type;
+ switch (dt) {
+ case data_types::f32:
+ fill_random_typed<float>(mem, -127, 127, 2);
+ break;
+ case data_types::f16:
+ fill_random_typed<ov::float16>(mem, -127, 127, 2);
+ break;
+ default:
+ break;
+ }
+ }
+
+ template <typename T>
+ void compare_outputs(const memory::ptr out_ref, const memory::ptr out_opt, float tolerance) {
+ auto ref_lay = out_ref->get_layout();
+ auto opt_lay = out_opt->get_layout();
+
+ size_t b = ref_lay.batch();
+ size_t f = ref_lay.feature();
+ size_t x = ref_lay.spatial(0);
+ size_t y = ref_lay.spatial(1);
+ mem_lock<T> ref_ptr{out_ref, get_test_stream()};
+ mem_lock<T> opt_ptr{out_opt, get_test_stream()};
+ for (size_t bi = 0; bi < b; ++bi) {
+ for (size_t fi = 0; fi < f; ++fi) {
+ for (size_t yi = 0; yi < y; ++yi) {
+ for (size_t xi = 0; xi < x; ++xi) {
+ auto coords = tensor(batch(bi), feature(fi), spatial(xi, yi, 0, 0));
+ auto ref_offset = ref_lay.get_linear_offset(coords);
+ auto opt_offset = opt_lay.get_linear_offset(coords);
+ auto ref_val = static_cast<float>(ref_ptr[ref_offset]);
+ auto opt_val = static_cast<float>(opt_ptr[opt_offset]);
+ ASSERT_NEAR(opt_val, ref_val, tolerance)
+ << " at b=" << bi << ", f=" << fi << ", y=" << yi << ", x=" << xi;
+ }
+ }
+ }
+ }
+ }
+
+ void execute_compare(const resample_cubic_random_test_params& params) {
+ auto& engine = get_test_engine();
+
+ auto in_layout = layout(params.input_type, format::bfyx, params.input_size);
+ auto in_mem = engine.allocate_memory(in_layout);
+ fill_random(in_mem);
+
+ int b = params.output_size.batch[0];
+ int f = params.output_size.feature[0];
+ int y = params.output_size.spatial[1];
+ int x = params.output_size.spatial[0];
+ std::vector<int64_t> output_pattern {b, f, y, x};
+
+ // Reference network (uses resample_ref kernel)
+ cldnn::topology topo_ref;
+ topo_ref.add(input_layout("in", in_layout));
+ auto prim_ref = resample("resample", input_info("in"), output_pattern, std::vector<float>{}, {},
+ {0, 0, 0, 0}, {0, 0, 0, 0}, 0, -0.75f,
+ resample::InterpolateOp::InterpolateMode::CUBIC,
+ resample::InterpolateOp::ShapeCalcMode::SIZES);
+ topo_ref.add(prim_ref);
+
+ ExecutionConfig config_ref = get_test_default_config(engine);
+ config_ref.set_property(ov::intel_gpu::allow_new_shape_infer(true));
+ config_ref.set_property(ov::intel_gpu::force_implementations(
+ ov::intel_gpu::ImplForcingMap{{"resample", {format::bfyx, "resample_ref"}}}));
+
+ network net_ref(engine, topo_ref, config_ref);
+ net_ref.set_input_data("in", in_mem);
+ auto result_ref = net_ref.execute();
+ auto output_ref = result_ref.at("resample").get_memory();
+
+ // Optimized network (uses resample_cubic kernel)
+ cldnn::topology topo_opt;
+ topo_opt.add(input_layout("in", in_layout));
+ auto prim_opt = resample("resample", input_info("in"), output_pattern, std::vector<float>{}, {},
+ {0, 0, 0, 0}, {0, 0, 0, 0}, 0, -0.75f,
+ resample::InterpolateOp::InterpolateMode::CUBIC,
+ resample::InterpolateOp::ShapeCalcMode::SIZES);
+ topo_opt.add(prim_opt);
+
+ ExecutionConfig config_opt = get_test_default_config(engine);
+ config_opt.set_property(ov::intel_gpu::allow_new_shape_infer(true));
+ config_opt.set_property(ov::intel_gpu::force_implementations(
+ ov::intel_gpu::ImplForcingMap{{"resample", {format::bfyx, "resample_bfyx_cubic_opt"}}}));
+
+ network net_opt(engine, topo_opt, config_opt);
+ net_opt.set_input_data("in", in_mem);
+ auto result_opt = net_opt.execute();
+ auto output_opt = result_opt.at("resample").get_memory();
+
+ // Compare results
+ // Bicubic overshoot from [-127,127] inputs can reach ~179 (FP16 ULP=0.125 in [128,256)).
+ // 16 fma accumulations in different order between ref/opt can diverge by 2-3 ULPs.
+ float tolerance = (params.input_type == data_types::f16) ? 5.e-1f : 1.e-4f;
+ if (params.input_type == data_types::f32) {
+ compare_outputs<float>(output_ref, output_opt, tolerance);
+ } else if (params.input_type == data_types::f16) {
+ compare_outputs<ov::float16>(output_ref, output_opt, tolerance);
+ }
+ }
+};
+
+TEST_P(resample_cubic_random_test, random) {
+ execute_compare(GetParam());
+}
+
+INSTANTIATE_TEST_SUITE_P(resample_cubic_bfyx_smoke,
+ resample_cubic_random_test,
+ testing::ValuesIn(
+ std::vector<resample_cubic_random_test_params>{
+ // Upscale cases
+ { data_types::f32, {1, 1, 3, 2}, {1, 1, 6, 4} },
+ { data_types::f32, {1, 1, 5, 5}, {1, 1, 10, 10} },
+ { data_types::f32, {2, 3, 4, 4}, {2, 3, 8, 8} },
+ { data_types::f32, {1, 16, 7, 7}, {1, 16, 14, 14} },
+ { data_types::f32, {1, 32, 16, 16}, {1, 32, 32, 32} },
+ // Downscale cases
+ { data_types::f32, {1, 1, 8, 8}, {1, 1, 4, 4} },
+ { data_types::f32, {2, 3, 16, 16}, {2, 3, 8, 8} },
+ // Non-power-of-2 sizes
+ { data_types::f32, {1, 3, 13, 13}, {1, 3, 26, 26} },
+ { data_types::f32, {1, 3, 7, 11}, {1, 3, 21, 33} },
+ { data_types::f32, {1, 1, 3, 2}, {1, 1, 2, 3} },
+ // f16 cases
+ { data_types::f16, {1, 1, 5, 5}, {1, 1, 10, 10} },
+ { data_types::f16, {2, 3, 4, 4}, {2, 3, 8, 8} },
+ { data_types::f16, {1, 16, 7, 7}, {1, 16, 14, 14} },
+ { data_types::f16, {1, 3, 13, 13}, {1, 3, 26, 26} },
+ }
+ ));
+
TEST(resample_gpu, basic_in2x3x2x2_nearest_cached) {
test_basic_in2x3x2x2_nearest<float>(true);
}