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] Fix ScatterNDUpdate negative index normalization (#37789)
Wilson Seok172e4e57202a
diff --git a/src/plugins/intel_gpu/src/graph/impls/ocl_v2/scatter_nd_update_opt.cl b/src/plugins/intel_gpu/src/graph/impls/ocl_v2/scatter_nd_update_opt.clindex c8a82a40b7b..89b16d5fb37 100644--- a/src/plugins/intel_gpu/src/graph/impls/ocl_v2/scatter_nd_update_opt.cl+++ b/src/plugins/intel_gpu/src/graph/impls/ocl_v2/scatter_nd_update_opt.cl@@ -78,6 +78,14 @@ KERNEL(scatter_nd_update_opt)(OPTIONAL_SHAPE_INFO_ARGuint target_coord[INDICES_MAX_DIM];uint g_coord[INDICES_MAX_DIM] = { INPUT2_ORDER };+#if INPUT0_DIMS <= 4+ const uint data_dim[INPUT0_DIMS] = {INPUT0_BATCH_NUM, INPUT0_FEATURE_NUM, INPUT0_SIZE_Y, INPUT0_SIZE_X};+#elif INPUT0_DIMS == 5+ const uint data_dim[INPUT0_DIMS] = {INPUT0_BATCH_NUM, INPUT0_FEATURE_NUM, INPUT0_SIZE_Z, INPUT0_SIZE_Y, INPUT0_SIZE_X};+#elif INPUT0_DIMS == 6+ const uint data_dim[INPUT0_DIMS] = {INPUT0_BATCH_NUM, INPUT0_FEATURE_NUM, INPUT0_SIZE_W, INPUT0_SIZE_Z, INPUT0_SIZE_Y, INPUT0_SIZE_X};+#endif+#if INPUT1_LENGTH == 1 && INDICES_RANK == 1for (uint i = 0; i < OUTPUT_DIMS; ++i) {target_coord[i] = g_coord[i];@@ -90,7 +98,7 @@ KERNEL(scatter_nd_update_opt)(OPTIONAL_SHAPE_INFO_ARGfor (uint i = 0; i < INDICES_LAST_DIM; ++i) {indices_coord[INDICES_RANK - 1] = i;int indices_val = indices[GET_INDICES_INDEX(INPUT1_ORDER)];- target_coord[i] = indices_val + (INPUT0_DIMS * (indices_val < 0));+ target_coord[i] = indices_val < 0 ? indices_val + (int)data_dim[i] : indices_val;}for (uint i = INDICES_LAST_DIM; i < OUTPUT_DIMS; ++i) {diff --git a/src/plugins/intel_gpu/tests/unit/test_cases/scatter_nd_update_gpu_test.cpp b/src/plugins/intel_gpu/tests/unit/test_cases/scatter_nd_update_gpu_test.cppindex 905e3b9bc39..2636e47a716 100644--- a/src/plugins/intel_gpu/tests/unit/test_cases/scatter_nd_update_gpu_test.cpp+++ b/src/plugins/intel_gpu/tests/unit/test_cases/scatter_nd_update_gpu_test.cpp@@ -507,7 +507,7 @@ TEST(scatter_nd_update_gpu_fp16_test16, data3_indice4_update3_dynamic) {auto input2_layout = layout{ ov::PartialShape::dynamic(4), data_types::i32, format::bfyx };auto input3_layout = layout{ ov::PartialShape::dynamic(3), data_types::f16, format::bfyx };- auto input1 = engine.allocate_memory({ { 2, 3, 3 }, data_types::f16, format::bfyx }); // data+ auto input1 = engine.allocate_memory({ { 2, 2, 3 }, data_types::f16, format::bfyx }); // dataauto input2 = engine.allocate_memory({ { 2, 1, 1, 3 }, data_types::i32, format::bfyx }); // Indexesauto input3 = engine.allocate_memory({ { 2, 1, 1 }, data_types::f16, format::bfyx }); // Updates@@ -515,11 +515,9 @@ TEST(scatter_nd_update_gpu_fp16_test16, data3_indice4_update3_dynamic) {// 0ov::float16(1.f), ov::float16(2.f), ov::float16(3.f),ov::float16(1.f), ov::float16(2.f), ov::float16(3.f),- ov::float16(1.f), ov::float16(2.f), ov::float16(3.f),// 1ov::float16(1.f), ov::float16(2.f), ov::float16(3.f),ov::float16(1.f), ov::float16(2.f), ov::float16(3.f),- ov::float16(1.f), ov::float16(2.f), ov::float16(3.f),});set_values(input2, {@@ -533,11 +531,9 @@ TEST(scatter_nd_update_gpu_fp16_test16, data3_indice4_update3_dynamic) {std::vector<float> expected_results = {// 0ov::float16(1.f), ov::float16(2.f), ov::float16(3.f),- ov::float16(1.f), ov::float16(2.f), ov::float16(3.f),ov::float16(1.f), ov::float16(2.f), ov::float16(1.f),// 1ov::float16(1.f), ov::float16(2.f), ov::float16(3.f),- ov::float16(1.f), ov::float16(2.f), ov::float16(3.f),ov::float16(1.f), ov::float16(2.f), ov::float16(-1.f),};