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 scatter_elements_update_ref data race (#29154)
Zaixing Wangd80ef2fbf75f
diff --git a/src/plugins/intel_gpu/src/kernel_selector/cl_kernels/scatter_elements_update_ref.cl b/src/plugins/intel_gpu/src/kernel_selector/cl_kernels/scatter_elements_update_ref.clindex 3d471bc0695..1b11e129787 100644--- a/src/plugins/intel_gpu/src/kernel_selector/cl_kernels/scatter_elements_update_ref.cl+++ b/src/plugins/intel_gpu/src/kernel_selector/cl_kernels/scatter_elements_update_ref.cl@@ -8,63 +8,129 @@#define GET_UPDATES_INDEX(idx_order) INPUT2_GET_INDEX(idx_order)#define GET_OUTPUT_INDEX(idx_order) OUTPUT_GET_INDEX(idx_order)#define GET_INPUT_INDEX(idx_order) INPUT0_GET_INDEX(idx_order)++#if AXIS_VALUE == 0+ #define SIZE INPUT0_BATCH_NUM+ #define ASSIGN_INDEX(index) b = index+#elif AXIS_VALUE == 1+ #define SIZE INPUT0_FEATURE_NUM+ #define ASSIGN_INDEX(index) f = index+#endif#if OUTPUT_DIMS == 4#define ORDER b,f,y,x- #define IDX_ORDER idx_b,idx_f,idx_y,idx_x+ #if AXIS_VALUE == 2+ #define SIZE INPUT0_SIZE_Y+ #define ASSIGN_INDEX(index) y = index+ #elif AXIS_VALUE == 3+ #define SIZE INPUT0_SIZE_X+ #define ASSIGN_INDEX(index) x = index+ #endif#elif OUTPUT_DIMS == 5#define ORDER b,f,z,y,x- #define IDX_ORDER idx_b,idx_f,idx_z,idx_y,idx_x+ #if AXIS_VALUE == 2+ #define SIZE INPUT0_SIZE_Z+ #define ASSIGN_INDEX(index) z = index+ #elif AXIS_VALUE == 3+ #define SIZE INPUT0_SIZE_Y+ #define ASSIGN_INDEX(index) y = index+ #elif AXIS_VALUE == 4+ #define SIZE INPUT0_SIZE_X+ #define ASSIGN_INDEX(index) x = index+ #endif#elif OUTPUT_DIMS == 6#define ORDER b,f,w,z,y,x- #define IDX_ORDER idx_b,idx_f,idx_w,idx_z,idx_y,idx_x+ #if AXIS_VALUE == 2+ #define SIZE INPUT0_SIZE_W+ #define ASSIGN_INDEX(index) w = index+ #elif AXIS_VALUE == 3+ #define SIZE INPUT0_SIZE_Z+ #define ASSIGN_INDEX(index) z = index+ #elif AXIS_VALUE == 4+ #define SIZE INPUT0_SIZE_Y+ #define ASSIGN_INDEX(index) y = index+ #elif AXIS_VALUE == 5+ #define SIZE INPUT0_SIZE_X+ #define ASSIGN_INDEX(index) x = index+ #endif#endif#if OUTPUT_DIMS != INPUT2_DIMS#error "OUTPUT_DIMS is supposed to be same as INPUT2_DIMS"#endif-#ifdef REDUCE_MODE- #define SUM_MODE 1- #define PROD_MODE 2- #define MIN_MODE 3- #define MAX_MODE 4- #define MEAN_MODE 5+#ifdef IS_SECOND_ITER // Socond kernel only+ #ifdef REDUCE_MODE+ #define SUM_MODE 1+ #define PROD_MODE 2+ #define MIN_MODE 3+ #define MAX_MODE 4+ #define MEAN_MODE 5++ #if USE_INIT_VAL == 0+ #if REDUCE_MODE == SUM_MODE+ #define REDUCTION_NEUTRAL_VALUE INPUT0_VAL_ZERO+ #elif REDUCE_MODE == PROD_MODE+ #define REDUCTION_NEUTRAL_VALUE INPUT0_VAL_ONE+ #elif REDUCE_MODE == MIN_MODE+ #define REDUCTION_NEUTRAL_VALUE INPUT0_VAL_MAX+ #elif REDUCE_MODE == MAX_MODE+ #define REDUCTION_NEUTRAL_VALUE INPUT0_VAL_MIN+ #elif REDUCE_MODE == MEAN_MODE+ #define REDUCTION_NEUTRAL_VALUE INPUT0_VAL_ZERO+ #else+ #error "Invalid REDUCE_MODE value"+ #endif+ #endif- #if USE_INIT_VAL == 0+ inline INPUT2_TYPE FUNC(reduce)(INPUT2_TYPE a, INPUT2_TYPE b)+ {#if REDUCE_MODE == SUM_MODE- #define REDUCTION_NEUTRAL_VALUE INPUT0_VAL_ZERO+ return a + b;#elif REDUCE_MODE == PROD_MODE- #define REDUCTION_NEUTRAL_VALUE INPUT0_VAL_ONE+ return a * b;#elif REDUCE_MODE == MIN_MODE- #define REDUCTION_NEUTRAL_VALUE INPUT0_VAL_MAX+ return MIN(a, b);#elif REDUCE_MODE == MAX_MODE- #define REDUCTION_NEUTRAL_VALUE INPUT0_VAL_MIN+ return MAX(a, b);#elif REDUCE_MODE == MEAN_MODE- #define REDUCTION_NEUTRAL_VALUE INPUT0_VAL_ZERO+ return a + b;#else#error "Invalid REDUCE_MODE value"#endif- #endif+ }- inline INPUT2_TYPE FUNC(reduce)(INPUT2_TYPE a, INPUT2_TYPE b)- {- #if REDUCE_MODE == SUM_MODE- return a + b;- #elif REDUCE_MODE == PROD_MODE- return a * b;- #elif REDUCE_MODE == MIN_MODE- return MIN(a, b);- #elif REDUCE_MODE == MAX_MODE- return MAX(a, b);- #elif REDUCE_MODE == MEAN_MODE- return (a + b) / (INPUT2_TYPE)(1 + USE_INIT_VAL);- #else- #error "Invalid REDUCE_MODE value"+ inline uint add_count(+ #if COUNT_LENGTH > COUNT_LIMIT+ __global int count_k[], __global int count_v[],+ #else+ __local int count_k[], __local int count_v[],+ #endif+ int idx, uint valid_count)+ {+ for (int i = 0; i < valid_count; ++i) {+ if (count_k[i] == idx) {+ count_v[i] += 1;+ return valid_count;+ }+ }+ count_k[valid_count] = idx;+ count_v[valid_count] += 1;+ return valid_count + 1;+ }++ inline int get_count(__local int count_k[], __local int count_v[], int it, int *idx)+ {+ if (count_k[it] != -1) {+ *idx = count_k[it];+ count_k[it] = -1;+ return count_v[it];+ }+ return -1;+ }#endif- }#endif-KERNEL(scatter_elements_update_ref)(OPTIONAL_SHAPE_INFO_ARG+KERNEL(scatter_elements_update_ref)(OPTIONAL_SHAPE_INFO_ARGconst __global INPUT0_TYPE* data,const __global INPUT1_TYPE* indices,const __global INPUT2_TYPE* updates,@@ -74,7 +140,6 @@ KERNEL(scatter_elements_update_ref)(OPTIONAL_SHAPE_INFO_ARG#endif){-const uint dim0 = get_global_id(0);const uint dim1 = get_global_id(1);const uint dim2 = get_global_id(2);@@ -107,99 +172,144 @@ KERNEL(scatter_elements_update_ref)(OPTIONAL_SHAPE_INFO_ARG#elseoutput[output_idx] = ACTIVATION(val, ACTIVATION_PARAMS);#endif-#else // Second kernel- #if OUTPUT_DIMS == 4- const uint idx_x = dim0;- const uint idx_y = dim1;- const uint idx_f = dim2 % INPUT2_FEATURE_NUM;- const uint idx_b = dim2 / INPUT2_FEATURE_NUM;- #elif OUTPUT_DIMS == 5- const uint idx_x = dim0 % INPUT2_SIZE_X;- const uint idx_y = dim0 / INPUT2_SIZE_X;- const uint idx_z = dim1;- const uint idx_f = dim2 % INPUT2_FEATURE_NUM;- const uint idx_b = dim2 / INPUT2_FEATURE_NUM;- #elif OUTPUT_DIMS == 6- const uint idx_x = dim0 % INPUT2_SIZE_X;- const uint idx_y = dim0 / INPUT2_SIZE_X;- const uint idx_z = dim1 % INPUT2_SIZE_Z;- const uint idx_w = dim1 / INPUT2_SIZE_Z;- const uint idx_f = dim2 % INPUT2_FEATURE_NUM;- const uint idx_b = dim2 / INPUT2_FEATURE_NUM;- #endif-- const uint indices_idx = GET_INDICES_INDEX(IDX_ORDER);- INPUT1_TYPE index = indices[(int)indices_idx];-- #if OUTPUT_DIMS == 4- #if AXIS_VALUE == 0- if (index < 0) { index += INPUT0_BATCH_NUM; }- const uint x = idx_x; const uint y = idx_y; const uint f = idx_f; const uint b = index;- #elif AXIS_VALUE == 1- if (index < 0) { index += INPUT0_FEATURE_NUM; }- const uint x = idx_x; const uint y = idx_y; const uint f = index; const uint b = idx_b;- #elif AXIS_VALUE == 2- if (index < 0) { index += INPUT0_SIZE_Y; }- const uint x = idx_x; const uint y = index; const uint f = idx_f; const uint b = idx_b;- #elif AXIS_VALUE == 3- if (index < 0) { index += INPUT0_SIZE_X; }- const uint x = index; const uint y = idx_y; const uint f = idx_f; const uint b = idx_b;- #endif // AXIS_VALUE- #elif OUTPUT_DIMS == 5- #if AXIS_VALUE == 0- if (index < 0) { index += INPUT0_BATCH_NUM; }- const uint x = idx_x; const uint y = idx_y; const uint z = idx_z; const uint f = idx_f; const uint b = index;- #elif AXIS_VALUE == 1- if (index < 0) { index += INPUT0_FEATURE_NUM; }- const uint x = idx_x; const uint y = idx_y; const uint z = idx_z; const uint f = index; const uint b = idx_b;- #elif AXIS_VALUE == 2- if (index < 0) { index += INPUT0_SIZE_Z; }- const uint x = idx_x; const uint y = idx_y; const uint z = index; const uint f = idx_f; const uint b = idx_b;- #elif AXIS_VALUE == 3- if (index < 0) { index += INPUT0_SIZE_Y; }- const uint x = idx_x; const uint y = index; const uint z = idx_z; const uint f = idx_f; const uint b = idx_b;- #elif AXIS_VALUE == 4- if (index < 0) { index += INPUT0_SIZE_X; }- const uint x = index; const uint y = idx_y; const uint z = idx_z; const uint f = idx_f; const uint b = idx_b;- #endif // AXIS_VALUE- #elif OUTPUT_DIMS == 6- #if AXIS_VALUE == 0- if (index < 0) { index += INPUT0_BATCH_NUM; }- const uint x = idx_x; const uint y = idx_y; const uint z = idx_z; const uint w = idx_w; const uint f = idx_f; const uint b = index;- #elif AXIS_VALUE == 1- if (index < 0) { index += INPUT0_FEATURE_NUM; }- const uint x = idx_x; const uint y = idx_y; const uint z = idx_z; const uint w = idx_w; const uint f = index; const uint b = idx_b;- #elif AXIS_VALUE == 2- if (index < 0) { index += INPUT0_SIZE_W; }- const uint x = idx_x; const uint y = idx_y; const uint z = idx_z; const uint w = index; const uint f = idx_f; const uint b = idx_b;- #elif AXIS_VALUE == 3- if (index < 0) { index += INPUT0_SIZE_Z; }- const uint x = idx_x; const uint y = idx_y; const uint z = index; const uint w = idx_w; const uint f = idx_f; const uint b = idx_b;- #elif AXIS_VALUE == 4- if (index < 0) { index += INPUT0_SIZE_Y; }- const uint x = idx_x; const uint y = index; const uint z = idx_z; const uint w = idx_w; const uint f = idx_f; const uint b = idx_b;- #elif AXIS_VALUE == 5- if (index < 0) { index += INPUT0_SIZE_X; }- const uint x = index; const uint y = idx_y; const uint z = idx_z; const uint w = idx_w; const uint f = idx_f; const uint b = idx_b;- #endif // AXIS_VALUE- #endif- const uint output_idx = GET_OUTPUT_INDEX(ORDER);-- const uint updates_idx = GET_UPDATES_INDEX(IDX_ORDER);- INPUT2_TYPE val = updates[(int)updates_idx];-+#else#ifdef REDUCE_MODE+ const uint tgz = INPUT2_FEATURE_NUM * INPUT2_BATCH_NUM;+ #if OUTPUT_DIMS == 4+ const uint tgx = INPUT2_SIZE_X;+ const uint tgy = INPUT2_SIZE_Y;+ #elif OUTPUT_DIMS == 5+ const uint tgx = INPUT2_SIZE_X * INPUT2_SIZE_Y;+ const uint tgy = INPUT2_SIZE_Z;+ #elif OUTPUT_DIMS == 6+ const uint tgx = INPUT2_SIZE_X * INPUT2_SIZE_Y;+ const uint tgy = INPUT2_SIZE_Z * INPUT2_SIZE_W;+ #endif+ #if COUNT_LENGTH > COUNT_LIMIT+ __global int count_k[COUNT_LENGTH];+ __global int count_v[COUNT_LENGTH];+ #elif COUNT_LENGTH == 0+ __local int count_k[1];+ __local int count_v[1];+ #else+ __local int count_k[COUNT_LENGTH];+ __local int count_v[COUNT_LENGTH];+ #endif+ for (int i = 0; i < COUNT_LENGTH; ++i) {+ count_k[i] = -1;+ count_v[i] = 0;+ }#if USE_INIT_VAL == 0- output[output_idx] = REDUCTION_NEUTRAL_VALUE;+ for (uint gz = 0; gz < tgz; gz++) {+ for (uint gy = 0; gy < tgy; gy++) {+ for (uint gx = 0; gx < tgx; gx++) {+ uint ORDER;+ #if OUTPUT_DIMS == 4+ x = gx;+ y = gy;+ #elif OUTPUT_DIMS == 5+ x = gx % INPUT2_SIZE_X;+ y = gx / INPUT2_SIZE_X;+ z = gy;+ #elif OUTPUT_DIMS == 6+ x = gx % INPUT2_SIZE_X;+ y = gx / INPUT2_SIZE_X;+ z = gy % INPUT2_SIZE_Z;+ w = gy / INPUT2_SIZE_Z;+ #endif+ f = gz % INPUT2_FEATURE_NUM;+ b = gz / INPUT2_FEATURE_NUM;+ const uint indices_idx = GET_INDICES_INDEX(ORDER);+ INPUT1_TYPE index = indices[(int)indices_idx];+ if (index < 0) { index += SIZE; }+ ASSIGN_INDEX(index);+ const uint output_idx = GET_OUTPUT_INDEX(ORDER);+ output[output_idx] = REDUCTION_NEUTRAL_VALUE;+ }+ }+ }+ #endif+ uint valid_count = 0;+ for (uint gz = 0; gz < tgz; gz++) {+ for (uint gy = 0; gy < tgy; gy++) {+ for (uint gx = 0; gx < tgx; gx++) {+ uint ORDER;+ #if OUTPUT_DIMS == 4+ x = gx;+ y = gy;+ #elif OUTPUT_DIMS == 5+ x = gx % INPUT2_SIZE_X;+ y = gx / INPUT2_SIZE_X;+ z = gy;+ #elif OUTPUT_DIMS == 6+ x = gx % INPUT2_SIZE_X;+ y = gx / INPUT2_SIZE_X;+ z = gy % INPUT2_SIZE_Z;+ w = gy / INPUT2_SIZE_Z;+ #endif+ f = gz % INPUT2_FEATURE_NUM;+ b = gz / INPUT2_FEATURE_NUM;+ const uint indices_idx = GET_INDICES_INDEX(ORDER);+ const uint updates_idx = GET_UPDATES_INDEX(ORDER);+ INPUT2_TYPE val = updates[(int)updates_idx];+ INPUT1_TYPE index = indices[(int)indices_idx];+ if (index < 0) {index += SIZE;}+ ASSIGN_INDEX(index);+ const uint output_idx = GET_OUTPUT_INDEX(ORDER);+ val = FUNC_CALL(reduce)(output[output_idx], val);+ output[output_idx] = val;+ valid_count = add_count(count_k, count_v, output_idx, valid_count);+ }+ }+ }+ for (int i = 0; i < valid_count; ++i) {+ int output_idx;+ const int count = get_count(count_k, count_v, i, &output_idx);+ #if REDUCE_MODE==MEAN_MODE+ output[output_idx] = output[output_idx] / (count + USE_INIT_VAL);+ #endif+ INPUT2_TYPE val = output[output_idx];+ #if HAS_FUSED_OPS+ FUSED_OPS_SECOND_KERNEL;+ output[output_idx] = TO_OUTPUT_TYPE(FUSED_OPS_RESULT_SECOND_KERNEL);+ #else+ output[output_idx] = ACTIVATION(val, ACTIVATION_PARAMS);+ #endif+ }+ #else // REDUCE_MODE==NONE.+ uint ORDER;+ #if OUTPUT_DIMS == 4+ x = dim0;+ y = dim1;+ f = dim2 % INPUT2_FEATURE_NUM;+ b = dim2 / INPUT2_FEATURE_NUM;+ #elif OUTPUT_DIMS == 5+ x = dim0 % INPUT2_SIZE_X;+ y = dim0 / INPUT2_SIZE_X;+ z = dim1;+ f = dim2 % INPUT2_FEATURE_NUM;+ b = dim2 / INPUT2_FEATURE_NUM;+ #elif OUTPUT_DIMS == 6+ x = dim0 % INPUT2_SIZE_X;+ y = dim0 / INPUT2_SIZE_X;+ z = dim1 % INPUT2_SIZE_Z;+ w = dim1 / INPUT2_SIZE_Z;+ f = dim2 % INPUT2_FEATURE_NUM;+ b = dim2 / INPUT2_FEATURE_NUM;+ #endif+ const uint indices_idx = GET_INDICES_INDEX(ORDER);+ const uint updates_idx = GET_UPDATES_INDEX(ORDER);+ INPUT2_TYPE val = updates[(int)updates_idx];+ INPUT1_TYPE index = indices[(int)indices_idx];+ if (index < 0) {index += SIZE;}+ ASSIGN_INDEX(index);+ const uint output_idx = GET_OUTPUT_INDEX(ORDER);+ #if HAS_FUSED_OPS+ FUSED_OPS_SECOND_KERNEL;+ output[output_idx] = TO_OUTPUT_TYPE(FUSED_OPS_RESULT_SECOND_KERNEL);+ #else+ output[output_idx] = ACTIVATION(val, ACTIVATION_PARAMS);#endif- val = FUNC_CALL(reduce)(output[output_idx], val);- #endif-- #if HAS_FUSED_OPS- FUSED_OPS_SECOND_KERNEL;- output[output_idx] = TO_OUTPUT_TYPE(FUSED_OPS_RESULT_SECOND_KERNEL);- #else- output[output_idx] = ACTIVATION(val, ACTIVATION_PARAMS);#endif#endif}@@ -216,5 +326,6 @@ KERNEL(scatter_elements_update_ref)(OPTIONAL_SHAPE_INFO_ARG#undef GET_INDICES_INDEX#undef GET_UPDATES_INDEX#undef GET_OUTPUT_INDEX-#undef IDX_ORDER#undef ORDER+#undef SIZE+#undef ASSIGN_INDEXdiff --git a/src/plugins/intel_gpu/src/kernel_selector/kernels/scatter_update/scatter_elements_update_kernel_ref.cpp b/src/plugins/intel_gpu/src/kernel_selector/kernels/scatter_update/scatter_elements_update_kernel_ref.cppindex 41f04063cbe..f4e77bc7c22 100644--- a/src/plugins/intel_gpu/src/kernel_selector/kernels/scatter_update/scatter_elements_update_kernel_ref.cpp+++ b/src/plugins/intel_gpu/src/kernel_selector/kernels/scatter_update/scatter_elements_update_kernel_ref.cpp@@ -93,11 +93,9 @@ CommonDispatchData ScatterElementsUpdateKernelRef::SetDefault(const scatter_elemconst auto& output = params.outputs[0];const auto& indices = params.inputs[1];-const auto& scope = is_second ? indices : output;const auto rank = params.inputs[0].GetDims().size();-switch (rank) {case 4:dispatchData.gws = {scope.X().v, scope.Y().v, scope.Feature().v * scope.Batch().v};@@ -125,7 +123,6 @@ CommonDispatchData ScatterElementsUpdateKernelRef::SetDefault(const scatter_elem}dispatchData.lws = GetOptimalLocalWorkGroupSizes(dispatchData.gws, params.engineInfo, in_layout, out_layout, dims_by_gws);-return dispatchData;}@@ -203,6 +200,12 @@ KernelsData ScatterElementsUpdateKernelRef::GetKernelsData(const Params& params)if (i == 1) {cldnn_jit.AddConstant(MakeJitConstant("IS_SECOND_ITER", "true"));+ cldnn_jit.AddConstant(MakeJitConstant("COUNT_LIMIT", params.engineInfo.maxLocalMemSize));+ cldnn_jit.AddConstant(MakeJitConstant("COUNT_LENGTH", dispatchData.gws[0] * dispatchData.gws[1] * dispatchData.gws[2]));+ if (newParams.mode != ScatterUpdateReduction::NONE) {+ dispatchData.gws = {1, 1, 1};+ dispatchData.lws = {1, 1, 1};+ }}auto jit = CreateJit(kernelName, cldnn_jit, entry_point);diff --git a/src/plugins/intel_gpu/tests/unit/test_cases/scatter_elements_update_gpu_test.cpp b/src/plugins/intel_gpu/tests/unit/test_cases/scatter_elements_update_gpu_test.cppindex ba97013aac7..d30dbf2f4e0 100644--- a/src/plugins/intel_gpu/tests/unit/test_cases/scatter_elements_update_gpu_test.cpp+++ b/src/plugins/intel_gpu/tests/unit/test_cases/scatter_elements_update_gpu_test.cpp@@ -107,7 +107,6 @@ struct ScatterElementsUpdateParams {tensor indices_tensor;std::vector<T_IND> indices;std::vector<T> updates;- std::vector<T> expected;};template<typename T, typename T_IND>@@ -162,7 +161,6 @@ std::vector<ScatterElementsUpdateParams<T, T_IND>> generateScatterElementsUpdatetensor{2, 2, 1, 1},getValues<T_IND>({ 0, 1, 2, 3 }),getValues<T>({ -10, -11, -12, -13 }),- getValues<T>({ -10, -11, 2, 3, 4, 5, -12, -13 })},{ 2,tensor{2, 1, 2, 2},@@ -170,7 +168,6 @@ std::vector<ScatterElementsUpdateParams<T, T_IND>> generateScatterElementsUpdatetensor{2, 1, 2, 1},getValues<T_IND>({ 0, 1, 0, 1 }),getValues<T>({ -10, -11, -12, -13 }),- getValues<T>({ -10, 1, 2, -11, -12, 5, 6, -13 })},{ 3,tensor{2, 1, 2, 2},@@ -178,14 +175,20 @@ std::vector<ScatterElementsUpdateParams<T, T_IND>> generateScatterElementsUpdatetensor{2, 1, 1, 2},getValues<T_IND>({ 0, 1, 0, 1 }),getValues<T>({ -10, -11, -12, -13 }),- getValues<T>({ -10, 1, 2, -11, -12, 5, 6, -13 })+ },+ {+ 1,+ tensor{1, 4, 1, 1},+ getValues<T>({10, 20, 30, 40}),+ tensor{1, 2, 1, 1},+ getValues<T_IND>({2, 3}),+ getValues<T>({99, 88}),},};return result;}-template<typename T, typename T_IND>std::vector<ScatterElementsUpdateParams<T, T_IND>> generateScatterElementsUpdateParams3D() {const std::vector<ScatterElementsUpdateParams<T, T_IND>> result = {@@ -195,7 +198,6 @@ std::vector<ScatterElementsUpdateParams<T, T_IND>> generateScatterElementsUpdatetensor{2, 1, 1, 1, 2},getValues<T_IND>({ 0, 3, 1, 2 }),getValues<T>({ -100, -110, -120, -130 }),- getValues<T>({ -100, 1, 2, 3, 4, 5, 6, 7, 8, 9, -110, 11, 12, 13, 14, -120, 16, 17, 18, -130, 20, 21, 22, 23 })},{ 4,tensor{2, 4, 1, 1, 3},@@ -203,8 +205,15 @@ std::vector<ScatterElementsUpdateParams<T, T_IND>> generateScatterElementsUpdatetensor{2, 1, 1, 1, 2},getValues<T_IND>({ 0, 1, 0, 1 }),getValues<T>({ -100, -110, -120, -130 }),- getValues<T>({ -100, 1, -110, 3, 4, 5, 6, 7, 8, 9, 10, 11, -120, 13, -130, 15, 16, 17, 18, 19, 20, 21, 22, 23 })},+ {+ 0,+ tensor{2, 2, 2, 1, 1},+ getValues<T>({1, 2, 3, 4, 5, 6, 7, 8}),+ tensor{2, 1, 2, 1, 1},+ getValues<T_IND>({1, 0, 0, 1}),+ getValues<T>({9, 8, 7, 6}),+ }};return result;@@ -220,9 +229,15 @@ std::vector<ScatterElementsUpdateParams<T, T_IND>> generateScatterElementsUpdatetensor{2, 1, 1, 1, 1, 2},getValues<T_IND>({2, 1, 1, 1}),getValues<T>({-100, -110, -120, -130}),- getValues<T>({0, 1, -100, -110, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23,- 24, -120, 26, -130, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47}),- }+ },+ {+ 5,+ tensor{1, 2, 2, 2, 1, 1},+ getValues<T>({1, 2, 3, 4, 5, 6, 7, 8}),+ tensor{1, 2, 1, 2, 1, 1},+ getValues<T_IND>({1, 0, 0, 1}),+ getValues<T>({10, 11, 12, 13}),+ },};return result;@@ -282,6 +297,7 @@ struct PrintToStringParamName {}};+template<typename T, typename T_IND>struct scatter_elements_update_gpu_formats_test: public ::testing::TestWithParam<ScatterElementsUpdateParamsWithFormat<T, T_IND> > {@@ -296,6 +312,7 @@ public:format::type target_updates_format;std::tie(params, plain_format, target_data_format, target_indices_format, target_updates_format) = this->GetParam();+ auto expected = generateReferenceOutput(plain_format, params, ov::op::v12::ScatterElementsUpdate::Reduction::NONE, false);if (target_indices_format == format::any) {target_indices_format = target_data_format;}@@ -336,12 +353,44 @@ public:const cldnn::mem_lock<T> output_ptr(output, get_test_stream());ASSERT_EQ(params.data.size(), output_ptr.size());- ASSERT_EQ(params.expected.size(), output_ptr.size());+ ASSERT_EQ(expected.size(), output_ptr.size());for (uint32_t i = 0; i < output_ptr.size(); i++) {- ASSERT_NEAR(output_ptr[i], params.expected[i], getError<T>())+ ASSERT_NEAR(output_ptr[i], expected[i], getError<T>())<< "format=" << fmt_to_str(target_data_format) << ", i=" << i;}}++private:+ static ov::Shape tensorToShape(const tensor &t, const format f) {+ std::vector<int> vec(cldnn::format::dimension(f));+ for (size_t i = 0; i < vec.size(); ++i) {+ vec[i] = t.sizes()[i];+ }+ std::reverse(vec.begin() + 2, vec.end());++ return ov::Shape(vec.begin(), vec.end());+ }+++ static std::vector<T> generateReferenceOutput(const format fmt,+ const ScatterElementsUpdateParams<T, T_IND>& p,+ const ScatterElementsUpdateOp::Reduction mode,+ const bool use_init_value) {+ std::vector<T> out(p.data_tensor.count());+ const auto data_shape = tensorToShape(p.data_tensor, fmt);+ const auto indices_shape = tensorToShape(p.indices_tensor, fmt);++ ov::reference::scatter_elem_update<T, T_IND>(p.data.data(),+ p.indices.data(),+ p.updates.data(),+ p.axis,+ out.data(),+ data_shape,+ indices_shape,+ mode,+ use_init_value);+ return out;+ }};using scatter_elements_update_gpu_formats_test_f32 = scatter_elements_update_gpu_formats_test<float, int32_t>;@@ -360,7 +409,7 @@ public:ScatterElementsUpdateOp::Reduction mode;bool use_init_value;std::tie(params, mode, use_init_value, plain_format) = this->GetParam();- params.expected = generateReferenceOutput(plain_format, params, mode, use_init_value);+ auto expected = generateReferenceOutput(plain_format, params, mode, use_init_value);auto& engine = get_test_engine();const auto data = engine.allocate_memory({data_type, plain_format, params.data_tensor});@@ -395,9 +444,9 @@ public:const cldnn::mem_lock<T> output_ptr(output, get_test_stream());ASSERT_EQ(params.data.size(), output_ptr.size());- ASSERT_EQ(params.expected.size(), output_ptr.size());+ ASSERT_EQ(expected.size(), output_ptr.size());for (uint32_t i = 0; i < output_ptr.size(); i++) {- ASSERT_NEAR(output_ptr[i], params.expected[i], getError<T>()) << ", i=" << i;+ ASSERT_NEAR(output_ptr[i], expected[i], getError<T>()) << ", i=" << i;}}private:@@ -627,4 +676,3 @@ TEST(scatter_elements_update_gpu_fp16, d2411_axisF_cached) {TEST_P(scatter_elements_update_gpu_reduction_test_f32, cached) {ASSERT_NO_FATAL_FAILURE(test(true));}-