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] Support b_fs_yx_fsv16 in the optimized GridSample bilinear/zeros kernel (#37191)
da3dsoulb496e7800cd0
diff --git a/src/plugins/intel_gpu/src/kernel_selector/cl_kernels/grid_sample_opt_bilinear_zeros.cl b/src/plugins/intel_gpu/src/kernel_selector/cl_kernels/grid_sample_opt_bilinear_zeros.clindex 9f8ea16c461..58f0a995b2a 100644--- a/src/plugins/intel_gpu/src/kernel_selector/cl_kernels/grid_sample_opt_bilinear_zeros.cl+++ b/src/plugins/intel_gpu/src/kernel_selector/cl_kernels/grid_sample_opt_bilinear_zeros.cl@@ -1,5 +1,5 @@// Copyright (C) 2018-2026 Intel Corporation-// SPdx_1-License-Identifier: Apache-2.0+// SPDX-License-Identifier: Apache-2.0//typedef INPUT0_TYPE data_t;@@ -28,31 +28,31 @@ inline const bool FUNC(is_between)(int val, int min, int max) {}#define is_between FUNC_CALL(is_between)-#define PRE_CALC_VALID_OFFSETS_FOR_INPUT_LOAD(x_n, x_y, GLOBAL_OFFSET) \- const grid_et y_d = denormalize(y_n, INPUT0_SIZE_Y); \- const grid_et x_d = denormalize(x_n, INPUT0_SIZE_X); \- const int y_topleft = (int)floor(y_d); \- const int x_topleft = (int)floor(x_d); \- const grid_et dy = y_d - y_topleft; \- const grid_et dx = x_d - x_topleft; \- \- const bool y_topleft_valid = is_between(y_topleft, 0, INPUT0_SIZE_Y); \- const bool y_topleft_plus_valid = is_between(y_topleft + 1, 0, INPUT0_SIZE_Y); \- const bool x_topleft_valid = is_between(x_topleft, 0, INPUT0_SIZE_X); \- const bool x_topleft_plus_valid = is_between(x_topleft + 1, 0, INPUT0_SIZE_X); \- \- const bool v00_valid = y_topleft_valid && x_topleft_valid; \- const bool v01_valid = y_topleft_valid && x_topleft_plus_valid; \- const bool v10_valid = y_topleft_plus_valid && x_topleft_valid; \- const bool v11_valid = y_topleft_plus_valid && x_topleft_plus_valid; \- \- const int v00_OFFSET = v00_valid ? (GLOBAL_OFFSET + y_topleft * INPUT0_SIZE_X + x_topleft) : 0; \- const int v01_OFFSET = v01_valid ? (GLOBAL_OFFSET + y_topleft * INPUT0_SIZE_X + x_topleft + 1) : 0; \- const int v10_OFFSET = v10_valid ? (GLOBAL_OFFSET + (y_topleft + 1) * INPUT0_SIZE_X + x_topleft) : 0; \- const int v11_OFFSET = v11_valid ? (GLOBAL_OFFSET + (y_topleft + 1) * INPUT0_SIZE_X + x_topleft + 1) : 0;+#define PRE_CALC_VALID_OFFSETS_FOR_INPUT_LOAD(x_n, y_n) \+ const grid_et y_d = denormalize(y_n, INPUT0_SIZE_Y); \+ const grid_et x_d = denormalize(x_n, INPUT0_SIZE_X); \+ const int y_topleft = (int)floor(y_d); \+ const int x_topleft = (int)floor(x_d); \+ const grid_et dy = y_d - y_topleft; \+ const grid_et dx = x_d - x_topleft; \+ \+ const bool y0_valid = is_between(y_topleft, 0, INPUT0_SIZE_Y); \+ const bool y1_valid = is_between(y_topleft + 1, 0, INPUT0_SIZE_Y); \+ const bool x0_valid = is_between(x_topleft, 0, INPUT0_SIZE_X); \+ const bool x1_valid = is_between(x_topleft + 1, 0, INPUT0_SIZE_X); \+ \+ const bool v00_valid = y0_valid && x0_valid; \+ const bool v01_valid = y0_valid && x1_valid; \+ const bool v10_valid = y1_valid && x0_valid; \+ const bool v11_valid = y1_valid && x1_valid; \+ \+ const int y0c = y0_valid ? y_topleft : 0; \+ const int y1c = y1_valid ? (y_topleft + 1) : 0; \+ const int x0c = x0_valid ? x_topleft : 0; \+ const int x1c = x1_valid ? (x_topleft + 1) : 0;// WARNING: This loads may read from 'wrong' location-// (in sense that is has nothing to do with+// (in sense that is has nothing to do with// sampling point being calculated) - this is done// intentianally to keep warp without need to sync// and allows for having multiple such loads on the fly - if@@ -60,23 +60,23 @@ inline const bool FUNC(is_between)(int val, int min, int max) {// Otherwise, if load is done conditionally, software pipelinging// is hindered by having warp sync due to warp divergence.// Tested on a770 GPU with ocl 3.0-#define LOAD_INPUT(c, C_STRIDE) \- const data_et v00_d = data[v00_OFFSET + c * C_STRIDE]; \- const data_et v01_d = data[v01_OFFSET + c * C_STRIDE]; \- const data_et v10_d = data[v10_OFFSET + c * C_STRIDE]; \- const data_et v11_d = data[v11_OFFSET + c * C_STRIDE];--#define INTERPOLATE() \- const data_et v00 = v00_valid ? v00_d * (1 - dx) : 0; \- const data_et v01 = v01_valid ? v01_d * dx : 0; \- const data_et v10 = v10_valid ? v10_d * (1 - dx) : 0; \- const data_et v11 = v11_valid ? v11_d * dx : 0; \- \- const data_et q0 = v00 + v01; \- const data_et q1 = v10 + v11; \+#define LOAD_INPUT(c) \+ const data_et v00_d = data[INPUT0_GET_INDEX(n, c, y0c, x0c)]; \+ const data_et v01_d = data[INPUT0_GET_INDEX(n, c, y0c, x1c)]; \+ const data_et v10_d = data[INPUT0_GET_INDEX(n, c, y1c, x0c)]; \+ const data_et v11_d = data[INPUT0_GET_INDEX(n, c, y1c, x1c)];++#define INTERPOLATE() \+ const data_et v00 = v00_valid ? v00_d * (1 - dx) : 0; \+ const data_et v01 = v01_valid ? v01_d * dx : 0; \+ const data_et v10 = v10_valid ? v10_d * (1 - dx) : 0; \+ const data_et v11 = v11_valid ? v11_d * dx : 0; \+ \+ const data_et q0 = v00 + v01; \+ const data_et q1 = v10 + v11; \const data_et out = dy * q1 + (1 - dy) * q0;-#define STORE(c, GLOBAL_OFFSET, C_STRIDE) output[GLOBAL_OFFSET + c * C_STRIDE] = out;+#define STORE(c) output[OUTPUT_GET_INDEX(n, c, h, w)] = out;// ====================================================================//@@ -97,43 +97,35 @@ KERNEL(grid_sample_opt_bilinear_zeros)(const __global data_t* restrict data,const int n = get_global_id(0);- const int LOCAL_GRID_OFFSET_FOR_THI_BLOCK = GRID_ITEMS_PER_BLOCK * 2 * get_group_id(1);const int OUTPUT_C_STRIDE = OUTPUT_SIZE_Y * OUTPUT_SIZE_X;- const int GLOBAL_GRID_OFFSET_FOR_THIS_BLOCK = n * OUTPUT_C_STRIDE * 2 + LOCAL_GRID_OFFSET_FOR_THI_BLOCK;+ const int LOCAL_GRID_OFFSET_FOR_THIS_BLOCK = GRID_ITEMS_PER_BLOCK * 2 * get_group_id(1);const int BLOCK_SIZE = get_local_size(1);- const grid_t* restrict grid_for_this_block = grid + GLOBAL_GRID_OFFSET_FOR_THIS_BLOCK;const int GRID_ITEMS_FOR_THIS_BLOCK =- min(OUTPUT_C_STRIDE * 2 - LOCAL_GRID_OFFSET_FOR_THI_BLOCK, GRID_ITEMS_PER_BLOCK * 2);+ min(OUTPUT_C_STRIDE * 2 - LOCAL_GRID_OFFSET_FOR_THIS_BLOCK, GRID_ITEMS_PER_BLOCK * 2);- const int INPUT_C_STRIDE = INPUT0_SIZE_Y * INPUT0_SIZE_X;- const int GLOBAL_INPUT_OFFSET_THIS_THREAD = n * INPUT0_FEATURE_NUM * INPUT_C_STRIDE;-- // The basic idea is to cache and reuse grid vals for getting close to- // optimal numer of loads(and stores).for (int thisThreadHW = get_local_linear_id() * 2; thisThreadHW < GRID_ITEMS_FOR_THIS_BLOCK;thisThreadHW += 2 * BLOCK_SIZE) {- const int globalThisThreadHW = (thisThreadHW + LOCAL_GRID_OFFSET_FOR_THI_BLOCK) / 2;+ const int globalThisThreadHW = (thisThreadHW + LOCAL_GRID_OFFSET_FOR_THIS_BLOCK) / 2;const int h = globalThisThreadHW / OUTPUT_SIZE_X;const int w = globalThisThreadHW % OUTPUT_SIZE_X;- const int GLOBAL_OUTPUT_OFFSET_THIS_THREAD =- n * OUTPUT_FEATURE_NUM * OUTPUT_SIZE_Y * OUTPUT_SIZE_X + h * OUTPUT_SIZE_X + w;- const grid_et x_n = grid_for_this_block[thisThreadHW];- const grid_et y_n = grid_for_this_block[thisThreadHW + 1];+ const grid_et x_n = grid[INPUT1_GET_INDEX(n, h, w, 0)];+ const grid_et y_n = grid[INPUT1_GET_INDEX(n, h, w, 1)];- PRE_CALC_VALID_OFFSETS_FOR_INPUT_LOAD(x_n, y_n, GLOBAL_INPUT_OFFSET_THIS_THREAD);+ PRE_CALC_VALID_OFFSETS_FOR_INPUT_LOAD(x_n, y_n);#pragma unrollfor (int c = 0; c < OUTPUT_FEATURE_NUM; ++c) {- LOAD_INPUT(c, INPUT_C_STRIDE);+ LOAD_INPUT(c);INTERPOLATE();- STORE(c, GLOBAL_OUTPUT_OFFSET_THIS_THREAD, OUTPUT_C_STRIDE);+ STORE(c);}}}#undef denormalize+#undef is_between#undef STORE#undef INTERPOLATE-#undef PRE_CALC_VALID_OFFSETS_FOR_INPUT_LOAD#undef LOAD_INPUT+#undef PRE_CALC_VALID_OFFSETS_FOR_INPUT_LOADdiff --git a/src/plugins/intel_gpu/src/kernel_selector/kernels/grid_sample/grid_sample_kernel_opt_bilinear_zeros.cpp b/src/plugins/intel_gpu/src/kernel_selector/kernels/grid_sample/grid_sample_kernel_opt_bilinear_zeros.cppindex d4cabe986ec..aba38a2963a 100644--- a/src/plugins/intel_gpu/src/kernel_selector/kernels/grid_sample/grid_sample_kernel_opt_bilinear_zeros.cpp+++ b/src/plugins/intel_gpu/src/kernel_selector/kernels/grid_sample/grid_sample_kernel_opt_bilinear_zeros.cpp@@ -71,6 +71,8 @@ ParamsKey GridSampleKernelOpt_BilinearZeros::GetSupportedKey() const {key.EnableDifferentTypes();key.EnableInputLayout(DataLayout::bfyx);key.EnableOutputLayout(DataLayout::bfyx);+ key.EnableInputLayout(DataLayout::b_fs_yx_fsv16);+ key.EnableOutputLayout(DataLayout::b_fs_yx_fsv16);key.EnableTensorOffset();key.EnableTensorPitches();key.EnableBatching();diff --git a/src/plugins/intel_gpu/tests/unit/test_cases/grid_sample_gpu_test.cpp b/src/plugins/intel_gpu/tests/unit/test_cases/grid_sample_gpu_test.cppindex e5539d65480..c06833eb2e4 100644--- a/src/plugins/intel_gpu/tests/unit/test_cases/grid_sample_gpu_test.cpp+++ b/src/plugins/intel_gpu/tests/unit/test_cases/grid_sample_gpu_test.cpp@@ -687,6 +687,13 @@ INSTANTIATE_TEST_SUITE_P(smoke_grid_sample_gpu_test_FLOAT16_FLOAT16,testing::Values(RUN_CACHING_TEST)),grid_sample_gpu_test_FLOAT16_FLOAT16::PrintToStringParamName);+INSTANTIATE_TEST_SUITE_P(smoke_grid_sample_gpu_test_FLOAT16_FLOAT16_layouts,+ grid_sample_gpu_test_FLOAT16_FLOAT16,+ testing::Combine(testing::ValuesIn(getParamsToCheckLayouts<ov::float16, ov::float16>()),+ testing::ValuesIn(layout_formats),+ testing::Values(RUN_CACHING_TEST)),+ grid_sample_gpu_test_FLOAT16_FLOAT16::PrintToStringParamName);+#ifndef RUN_ALL_MODEL_CACHING_TESTSINSTANTIATE_TEST_SUITE_P(smoke_grid_sample_gpu_test_FLOAT16_FLOAT16_cached,grid_sample_gpu_test_FLOAT16_FLOAT16,