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] convolution bfyx f16 fix & optimisation (#37769)
Mikołaj Roszczykb0086aa9c6c5
diff --git a/src/plugins/intel_gpu/src/kernel_selector/cl_kernels/convolution_gpu_bfyx_f16.cl b/src/plugins/intel_gpu/src/kernel_selector/cl_kernels/convolution_gpu_bfyx_f16.clindex a9b998d353b..f865e6730f8 100644--- a/src/plugins/intel_gpu/src/kernel_selector/cl_kernels/convolution_gpu_bfyx_f16.cl+++ b/src/plugins/intel_gpu/src/kernel_selector/cl_kernels/convolution_gpu_bfyx_f16.cl@@ -83,6 +83,12 @@ KERNEL(convolution_bfyx_f16)(const int input_x = x * STRIDE_SIZE_X - PADDING_SIZE_X;const int input_y = y * STRIDE_SIZE_Y - PADDING_SIZE_Y;+#if ENABLE_OOB_GUARD+ const int right_unreachable_count_x = min(max(0, input_x + INPUT_LINE_SIZE - INPUT0_SIZE_X),+ INPUT_LINE_SIZE);+ const int left_unreachable_count_x = min(max(0, -input_x), INPUT_LINE_SIZE);+#endif // ENABLE_OOB_GUARD+// Input offset calculations:const uint input_x_pitch = FEATURE_SLICE_SIZE;const uint input_y_pitch = input_x_pitch * (INPUT0_PAD_BEFORE_SIZE_X + INPUT0_SIZE_X + INPUT0_PAD_AFTER_SIZE_X);@@ -188,7 +194,8 @@ KERNEL(convolution_bfyx_f16)({for (int xb = 0; xb < INPUT_LINE_SIZE; xb++){- if (icb * FEATURE_SLICE_SIZE + sglid >= FILTER_IFM_NUM)+ const int in_x = input_x + xb;+ if (icb * FEATURE_SLICE_SIZE + sglid >= FILTER_IFM_NUM || in_x < 0 || in_x >= INPUT0_SIZE_X)line_cache[xb] = 0;elseline_cache[xb] = input[grouped_input_offset +@@ -199,10 +206,18 @@ KERNEL(convolution_bfyx_f16)(}}else-#endif // INPUT_LEFTOVERS+#endif // INPUT_LEFTOVERS{int xb = 0;+#if ENABLE_OOB_GUARD+ for (; xb < left_unreachable_count_x; xb++){+ line_cache[xb] = 0;+ }+ const int reachable_size = INPUT_LINE_SIZE - right_unreachable_count_x;+ for (; xb + 8 <= reachable_size; xb += 8) {+#else // ENABLE_OOB_GUARDfor (; xb + 8 <= INPUT_LINE_SIZE; xb += 8) {+#endif // ENABLE_OOB_GUARDINPUT_TYPE8 vv = DT_INPUT_BLOCK_READ8(input, grouped_input_offset +icb * input_fs_pitch +kh * DILATION_SIZE_Y * input_y_pitch +@@ -217,7 +232,11 @@ KERNEL(convolution_bfyx_f16)(line_cache[xb + 6] = vv[6];line_cache[xb + 7] = vv[7];}+#if ENABLE_OOB_GUARD+ for (; xb + 4 <= reachable_size; xb += 4) {+#else // ENABLE_OOB_GUARDfor (; xb + 4 <= INPUT_LINE_SIZE; xb += 4) {+#endifINPUT_TYPE4 vv = DT_INPUT_BLOCK_READ4(input, grouped_input_offset +icb * input_fs_pitch +kh * DILATION_SIZE_Y * input_y_pitch +@@ -228,12 +247,21 @@ KERNEL(convolution_bfyx_f16)(line_cache[xb + 2] = vv[2];line_cache[xb + 3] = vv[3];}+#if ENABLE_OOB_GUARD+ for (; xb < reachable_size; xb ++) {+#else // ENABLE_OOB_GUARDfor (; xb < INPUT_LINE_SIZE; xb++) {+#endifline_cache[xb] = DT_INPUT_BLOCK_READ(input, grouped_input_offset +icb * input_fs_pitch +kh * DILATION_SIZE_Y * input_y_pitch +xb * input_x_pitch);}+#if ENABLE_OOB_GUARD+ for (int i = 0; i < right_unreachable_count_x; i++){+ line_cache[xb + i] = 0;+ }+#endif}__attribute__((opencl_unroll_hint(FILTER_SIZE_X)))diff --git a/src/plugins/intel_gpu/src/kernel_selector/cl_kernels/convolution_gpu_bfyx_f16_1x1.cl b/src/plugins/intel_gpu/src/kernel_selector/cl_kernels/convolution_gpu_bfyx_f16_1x1.clindex f1a5da9b9ea..e3735f1c838 100644--- a/src/plugins/intel_gpu/src/kernel_selector/cl_kernels/convolution_gpu_bfyx_f16_1x1.cl+++ b/src/plugins/intel_gpu/src/kernel_selector/cl_kernels/convolution_gpu_bfyx_f16_1x1.cl@@ -162,7 +162,21 @@ KERNEL(convolution_b_fs_yx_fsv16_1x1)(#else // PADDED_INPUT#if X_BLOCK_SIZE > 1- src = UNIT_BLOCK_READ_VEC(input, input_offset + k * input_fs_pitch + input_y * input_y_pitch + input_x * input_x_pitch);+ if (xy * X_BLOCK_SIZE + X_BLOCK_SIZE <= INPUT0_SIZE_X * INPUT0_SIZE_Y) {+ src = UNIT_BLOCK_READ_VEC(input, input_offset + k * input_fs_pitch + input_y * input_y_pitch + input_x * input_x_pitch);+ } else {+ __attribute__((opencl_unroll_hint(X_BLOCK_SIZE)))+ for (int i = 0; i < X_BLOCK_SIZE; i++) {+ if (xy * X_BLOCK_SIZE + i >= INPUT0_SIZE_X * INPUT0_SIZE_Y)+ break;++ const uint xb = (input_x + i) % INPUT0_SIZE_X;+ const uint yb = input_y + (input_x + i) / INPUT0_SIZE_X;+ const uint input_idx = input_offset + k * input_fs_pitch + yb * input_y_pitch + xb * input_x_pitch;++ src[i] = UNIT_BLOCK_READ(input, input_idx);+ }+ }#elsesrc = UNIT_BLOCK_READ(input, input_offset + k * input_fs_pitch);#endif // X_BLOCK_SIZE > 1diff --git a/src/plugins/intel_gpu/src/kernel_selector/kernels/convolution/convolution_kernel_b_fs_yx_fsv16.cpp b/src/plugins/intel_gpu/src/kernel_selector/kernels/convolution/convolution_kernel_b_fs_yx_fsv16.cppindex 4eedd25d650..495c5cd7f69 100644--- a/src/plugins/intel_gpu/src/kernel_selector/kernels/convolution/convolution_kernel_b_fs_yx_fsv16.cpp+++ b/src/plugins/intel_gpu/src/kernel_selector/kernels/convolution/convolution_kernel_b_fs_yx_fsv16.cpp@@ -271,6 +271,12 @@ JitConstants ConvolutionKernel_b_fs_yx_fsv16::GetJitConstants(const convolution_jit.AddConstant(MakeJitConstant("MULTIPLE_GROUPS_INPUT_PRELOAD", 1));}+ // out-of-bound access causes fails starting with Xe2 platforms+ // additional guards prevent out-of-bound access but can significantly affect performance on older platforms+ // to avoid performance regression enable only for affected platforms+ const bool is_post_xe2 = params.engineInfo.arch >= gpu_arch::xe2;+ jit.AddConstant(MakeJitConstant("ENABLE_OOB_GUARD", is_post_xe2));+jit.AddConstant(MakeJitConstant("OUTPUT_X_BLOCK_SIZE", blockWidth));jit.AddConstant(MakeJitConstant("INPUT_LINE_SIZE", input_line_size));jit.AddConstant(MakeJitConstant("SUB_GROUP_SIZE", tuning_data.sub_group_size));