Skip to content

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

[GPU] Fix OOB read in gemm_tiled_opt input1 K-leftover (#36559)

David Nam993492c10f48
diff --git a/src/plugins/intel_gpu/src/kernel_selector/cl_kernels/gemm_tiled_opt.cl b/src/plugins/intel_gpu/src/kernel_selector/cl_kernels/gemm_tiled_opt.cl
index 297ab4e3abf..255df5e619e 100644
--- a/src/plugins/intel_gpu/src/kernel_selector/cl_kernels/gemm_tiled_opt.cl
+++ b/src/plugins/intel_gpu/src/kernel_selector/cl_kernels/gemm_tiled_opt.cl
@@ -583,12 +583,29 @@ KERNEL(gemm_tiled_opt)(
{
b_ptr = b_ptr + (input1_offset * sglid);
#if B_VEC_SIZE == 1
- b_tile = (N > b_raw_global_id) ? VLOAD(0, b_ptr) : 0;
+ if (N > b_raw_global_id + 1) {
+ b_tile = VLOAD(0, b_ptr);
+ } else if (N > b_raw_global_id) {
+ unroll_for (uint b_load_id = 0; b_load_id < SIMD_WIDTH; b_load_id++) {
+ b_tile[b_load_id] = ((K_FULL_ITERATIONS * TILE_K + b_load_id) < K) ? b_ptr[b_load_id] : 0;
+ }
+ } else {
+ b_tile = 0;
+ }
#else
- const __global INPUT1_TYPE* b_ptr_tmp = b_ptr;
- unroll_for (uint b_elem = 0; b_elem < B_VEC_SIZE; ++b_elem) {
- b_tile[b_elem] = (N > b_raw_global_id + SIMD_WIDTH * b_elem) ? VLOAD(0, b_ptr_tmp + input1_offset * SIMD_WIDTH * b_elem) : 0;
- }
+ const __global INPUT1_TYPE* b_ptr_tmp = b_ptr;
+ unroll_for (uint b_elem = 0; b_elem < B_VEC_SIZE; ++b_elem) {
+ if (N > b_raw_global_id + SIMD_WIDTH * b_elem + 1) {
+ b_tile[b_elem] = VLOAD(0, b_ptr_tmp + input1_offset * SIMD_WIDTH * b_elem);
+ } else if (N > b_raw_global_id + SIMD_WIDTH * b_elem) {
+ unroll_for (uint b_load_id = 0; b_load_id < SIMD_WIDTH; b_load_id++) {
+ b_tile[b_elem][b_load_id] = ((K_FULL_ITERATIONS * TILE_K + b_load_id) < K)
+ ? b_ptr_tmp[input1_offset * SIMD_WIDTH * b_elem + b_load_id] : 0;
+ }
+ } else {
+ b_tile[b_elem] = 0;
+ }
+ }
#endif
b_ptr = b_ptr + input1_offset1 - (input1_offset * sglid);
}
@@ -685,7 +702,15 @@ KERNEL(gemm_tiled_opt)(
#endif
{
b_ptr = b_ptr + (input1_offset * sglid);
- b_tile = (N > b_raw_global_id) ? VLOAD(0, b_ptr) : 0;
+ if (N > b_raw_global_id + 1) {
+ b_tile = VLOAD(0, b_ptr);
+ } else if (N > b_raw_global_id) {
+ unroll_for (uint b_load_id = 0; b_load_id < SIMD_WIDTH; b_load_id++) {
+ b_tile[b_load_id] = ((K_FULL_ITERATIONS * TILE_K + b_load_id) < K) ? b_ptr[b_load_id] : 0;
+ }
+ } else {
+ b_tile = 0;
+ }
}
#endif // TRANSPOSE_INPUT1 == TRANSPOSE_Y_LAST