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] out-of-bound access of convolution kernel (#26326)
Mingyu Kim4655dd0f2806
diff --git a/src/plugins/intel_gpu/src/kernel_selector/cl_kernels/convolution_gpu_bfyx_os_iyx_osv16.cl b/src/plugins/intel_gpu/src/kernel_selector/cl_kernels/convolution_gpu_bfyx_os_iyx_osv16.clindex 1abaefa8f3d..d259aa98c3b 100644--- a/src/plugins/intel_gpu/src/kernel_selector/cl_kernels/convolution_gpu_bfyx_os_iyx_osv16.cl+++ b/src/plugins/intel_gpu/src/kernel_selector/cl_kernels/convolution_gpu_bfyx_os_iyx_osv16.cl@@ -72,6 +72,8 @@ KERNEL(convolution_gpu_bfyx_os_iyx_osv16)(const uint or = (uint)get_global_id(1) * OUTPUT_BLOCK_HEIGHT; // or = Output Rowconst uint fm = get_global_id(2); // fm = Feature Map = od = Output Depthconst uint lid = get_sub_group_local_id();+ const uint filter_physical_len = FILTER_GROUPS_NUM * FILTER_SIZE_X * FILTER_SIZE_Y * FILTER_SIZE_Z * FILTER_IFM_NUM * ALIGN(FILTER_OFM_NUM, OSV_SIZE);+ const uint input0_physical_len = INPUT0_OFFSET_WITH_PADDING + INPUT0_BATCH_PITCH * INPUT0_BATCH_NUM; // bfyx format#if GROUPEDuint batch_idx = fm / (FEATURES_THREADS_PER_BATCH * FILTER_GROUPS_NUM);@@ -113,8 +115,10 @@ KERNEL(convolution_gpu_bfyx_os_iyx_osv16)(for(uint in_block_pos = 0; in_block_pos < IN_BLOCK_ARRAY_SIZE * SUB_GROUP_SIZE; in_block_pos += SUB_GROUP_SIZE) {// Horizontal position in input block after read.const uint in_block_next_x_pos = in_block_pos % IN_BLOCK_WIDTH + SUB_GROUP_SIZE;-- in[in_block_pos / SUB_GROUP_SIZE] = input[tmp_in_addr + (in_block_pos % IN_BLOCK_WIDTH) * INPUT0_X_PITCH];+ uint idx = tmp_in_addr + (in_block_pos % IN_BLOCK_WIDTH) * INPUT0_X_PITCH;+ // index clipping to avoid out-of-bound memory access. Such data is not supposed to be used in actual computation.+ idx = min(idx, input0_physical_len - 1);+ in[in_block_pos / SUB_GROUP_SIZE] = input[idx];// If we have row break, move to the next row.if (in_block_next_x_pos == IN_BLOCK_WIDTH)@@ -126,8 +130,10 @@ KERNEL(convolution_gpu_bfyx_os_iyx_osv16)(// Horizontal position in input block after read.const uint in_block_next_x_pos = in_block_pos % IN_BLOCK_WIDTH + SUB_GROUP_SIZE;- if (in_block_next_x_pos <= IN_BLOCK_WIDTH) { //- in[in_block_pos / SUB_GROUP_SIZE] = input[tmp_in_addr + (in_block_pos % IN_BLOCK_WIDTH) * INPUT0_X_PITCH];+ if (in_block_next_x_pos <= IN_BLOCK_WIDTH) {+ uint idx = tmp_in_addr + (in_block_pos % IN_BLOCK_WIDTH) * INPUT0_X_PITCH;+ idx = min(idx, input0_physical_len - 1);+ in[in_block_pos / SUB_GROUP_SIZE] = input[idx];// If we have row break, move to the next row.if (in_block_next_x_pos == IN_BLOCK_WIDTH)@@ -158,7 +164,9 @@ KERNEL(convolution_gpu_bfyx_os_iyx_osv16)(in_addr += INPUT0_FEATURE_PITCH;for(int pf=0; pf<PREFETCH; pf++) {- w[pf] = weights[weight_addr]; weight_addr += OSV_SIZE;+ uint weight_addr_safe = min(weight_addr, filter_physical_len - 1);+ w[pf] = weights[weight_addr_safe];+ weight_addr += OSV_SIZE;}uint wi = 0;@@ -168,7 +176,6 @@ KERNEL(convolution_gpu_bfyx_os_iyx_osv16)(uint kc = 0; // kc = Kernel ColumnLOOP(FILTER_SIZE_X, kc,{- //w = weights[weight_addr];for(uint br=0; br<OUTPUT_BLOCK_HEIGHT; br++) {for(uint bc=0; bc<OUTPUT_BLOCK_WIDTH; bc++) {@@ -179,11 +186,11 @@ KERNEL(convolution_gpu_bfyx_os_iyx_osv16)(#elseUNIT_TYPE val = _sub_group_shuffle( in[br * STRIDE_SIZE_Y + kr * DILATION_SIZE_Y], bc * STRIDE_SIZE_X + kc * DILATION_SIZE_X);#endif-out[br * OUTPUT_BLOCK_WIDTH + bc] = mad(w[wi % PREFETCH], val, out[br * OUTPUT_BLOCK_WIDTH + bc]);}}- w[wi % PREFETCH] = weights[weight_addr];+ uint weight_addr_safe = min(weight_addr, filter_physical_len - 1);+ w[wi % PREFETCH] = weights[weight_addr_safe];weight_addr += OSV_SIZE; // weights must be stored in just the right SIMD swizzled format for this to work, see host code for details.wi++;});diff --git a/src/plugins/intel_gpu/tests/unit/test_cases/convolution_gpu_test.cpp b/src/plugins/intel_gpu/tests/unit/test_cases/convolution_gpu_test.cppindex 9b9ac3ed01c..9602168b892 100644--- a/src/plugins/intel_gpu/tests/unit/test_cases/convolution_gpu_test.cpp+++ b/src/plugins/intel_gpu/tests/unit/test_cases/convolution_gpu_test.cpp@@ -10465,6 +10465,8 @@ TEST_P(conv_dyn_test, convolution_gpu_bfyx_os_iyx_osv16_no_bias) {auto outputs = network.execute();auto output_memory = outputs.at("conv").get_memory();+ ov::intel_gpu::ImplementationDesc conv_impl_ref = { format::bfyx, "convolution_gpu_ref", impl_types::ocl };+ config.set_property(ov::intel_gpu::force_implementations(ov::intel_gpu::ImplForcingMap{ { "conv", conv_impl_ref } }));auto output_memory_ref = calculate_ref(input, weights, config);cldnn::mem_lock<float> output_ptr(output_memory, get_test_stream());