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 select-kernel indexing mismatch for lower-rank inputs (#34537)
David Nam42264ee3c0bd
diff --git a/src/plugins/intel_gpu/src/graph/impls/ocl/select.cpp b/src/plugins/intel_gpu/src/graph/impls/ocl/select.cppindex 0c5979f18cf..a53de7a01c5 100644--- a/src/plugins/intel_gpu/src/graph/impls/ocl/select.cpp+++ b/src/plugins/intel_gpu/src/graph/impls/ocl/select.cpp@@ -46,12 +46,19 @@ struct select_impl : typed_primitive_impl_ocl<select> {static kernel_impl_params static_canonicalize_shapes(const kernel_impl_params& impl_params) {auto updated_impl_params = canonicalize_fused_shapes(impl_params);+ auto& output_layout = updated_impl_params.output_layouts[0];+ auto out_pshape = output_layout.get_partial_shape();+ size_t target_rank = std::max<size_t>(4, out_pshape.size());+for (auto& input_layout : updated_impl_params.input_layouts) {- input_layout.set_partial_shape(extend_shape_to_rank_from_begin(input_layout.get_partial_shape()));+ auto input_pshape = input_layout.get_partial_shape();+ input_pshape = extend_shape_to_rank_from_begin(input_pshape, target_rank);+ input_layout.set_partial_shape(input_pshape);+ input_layout.format = format::adjust_to_rank(input_layout.format, input_pshape.size());}- auto& output_layout = updated_impl_params.output_layouts[0];- output_layout.set_partial_shape(extend_shape_to_rank_from_begin(output_layout.get_partial_shape()));+ output_layout.set_partial_shape(extend_shape_to_rank_from_begin(out_pshape, target_rank));+ output_layout.format = format::adjust_to_rank(output_layout.format, target_rank);return updated_impl_params;}diff --git a/src/plugins/intel_gpu/src/kernel_selector/cl_kernels/select_gpu_ref.cl b/src/plugins/intel_gpu/src/kernel_selector/cl_kernels/select_gpu_ref.clindex 40111769920..d90f46057ca 100644--- a/src/plugins/intel_gpu/src/kernel_selector/cl_kernels/select_gpu_ref.cl+++ b/src/plugins/intel_gpu/src/kernel_selector/cl_kernels/select_gpu_ref.cl@@ -6,16 +6,8 @@#if OUTPUT_DIMS == 5#define INPUT_0 input0[INPUT0_GET_INDEX_SAFE(b, f, z, y, x)]- #if INPUT1_DIMS == 4- #define INPUT_1 input1[INPUT1_GET_INDEX_SAFE(b, f, y, x)]- #else- #define INPUT_1 input1[INPUT1_GET_INDEX_SAFE(b, f, z, y, x)]- #endif- #if INPUT2_DIMS == 4- #define INPUT_2 input2[INPUT2_GET_INDEX_SAFE(b, f, y, x)]- #else- #define INPUT_2 input2[INPUT2_GET_INDEX_SAFE(b, f, z, y, x)]- #endif+ #define INPUT_1 input1[INPUT1_GET_INDEX_SAFE(b, f, z, y, x)]+ #define INPUT_2 input2[INPUT2_GET_INDEX_SAFE(b, f, z, y, x)]#elif OUTPUT_DIMS == 4#define INPUT_0 input0[INPUT0_GET_INDEX_SAFE(b, f, y, x)]#define INPUT_1 input1[INPUT1_GET_INDEX_SAFE(b, f, y, x)]diff --git a/src/plugins/intel_gpu/tests/functional/shared_tests_instances/single_layer_tests/select.cpp b/src/plugins/intel_gpu/tests/functional/shared_tests_instances/single_layer_tests/select.cppindex ed92ed59422..4e2033f438f 100644--- a/src/plugins/intel_gpu/tests/functional/shared_tests_instances/single_layer_tests/select.cpp+++ b/src/plugins/intel_gpu/tests/functional/shared_tests_instances/single_layer_tests/select.cpp@@ -47,7 +47,28 @@ const std::vector<std::vector<ov::Shape>> numpyShapes = {{{5, 1, 1, 1}, {5, 7, 8, 6}, {1, 8, 6}},{{1, 1, 3}, {1, 3, 1}, {3, 1, 1}},{{2, 2, 2, 2, 2}, {2, 2, 2, 2}, {2, 2, 2, 2, 2}},- {{2, 2, 2, 2, 2}, {2, 2, 2, 2, 2}, {2, 2, 2, 2}}+ {{2, 2, 2, 2, 2}, {2, 2, 2, 2, 2}, {2, 2, 2, 2}},+};++const std::vector<std::vector<ov::test::InputShape>> numpyDynShapesMask4d = {+ // mask 4D, then 5D, else 5D → output 5D+ {+ {{-1, -1, -1, -1}, {{2, 2, 2, 2}}},+ {{-1, -1, -1, -1, -1}, {{2, 2, 2, 2, 2}}},+ {{-1, -1, -1, -1, -1}, {{2, 2, 2, 2, 2}}},+ },+ // mask 4D, then 5D, else 4D → output 5D+ {+ {{-1, -1, -1, -1}, {{2, 2, 2, 2}}},+ {{-1, -1, -1, -1, -1}, {{2, 2, 2, 2, 2}}},+ {{-1, -1, -1, -1}, {{2, 2, 2, 2}}},+ },+ // mask 4D, then 4D, else 5D → output 5D+ {+ {{-1, -1, -1, -1}, {{2, 2, 2, 2}}},+ {{-1, -1, -1, -1}, {{2, 2, 2, 2}}},+ {{-1, -1, -1, -1, -1}, {{2, 2, 2, 2, 2}}},+ },};const std::vector<std::vector<ov::Shape>> pdpdShapes = {@@ -84,6 +105,14 @@ INSTANTIATE_TEST_SUITE_P(smoke_CLDNN_TestsSelect_numpy,::testing::Values(ov::test::utils::DEVICE_GPU)),SelectLayerTest::getTestCaseName);+INSTANTIATE_TEST_SUITE_P(smoke_CLDNN_TestsSelect_numpy_broadcast_mask4d,+ SelectLayerTest,+ ::testing::Combine(::testing::ValuesIn(numpyDynShapesMask4d),+ ::testing::ValuesIn(inputPrecision),+ ::testing::Values(ov::op::AutoBroadcastType::NUMPY),+ ::testing::Values(ov::test::utils::DEVICE_GPU)),+ SelectLayerTest::getTestCaseName);+INSTANTIATE_TEST_SUITE_P(smoke_CLDNN_TestsSelect_pdpd,SelectLayerTest,::testing::Combine(::testing::ValuesIn(ov::test::static_shapes_to_test_representation(pdpdShapes)),