Skip to content

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

[GPU] Fix rank-1 GatherElements with a constant input (always returned element 0) (#39432)

Randy Smits-Schreuder Goedheijt4ce8badb5c60
diff --git a/src/plugins/intel_gpu/src/plugin/ops/constant.cpp b/src/plugins/intel_gpu/src/plugin/ops/constant.cpp
index d6b083ce79b..e67342fa396 100644
--- a/src/plugins/intel_gpu/src/plugin/ops/constant.cpp
+++ b/src/plugins/intel_gpu/src/plugin/ops/constant.cpp
@@ -23,6 +23,7 @@
#include "openvino/op/convolution.hpp"
#include "openvino/op/deformable_convolution.hpp"
#include "openvino/op/gather.hpp"
+#include "openvino/op/gather_elements.hpp"
#include "openvino/op/gather_nd.hpp"
#include "openvino/op/group_conv.hpp"
#include "openvino/op/loop.hpp"
@@ -287,10 +288,13 @@ static void CreateConstantOp(ProgramBuilder& p, const std::shared_ptr<ov::op::v0
} else if (((is_binary_eltwise(outOp) || ov::is_type<ov::op::v0::SquaredDifference>(outOp)) && is_all_inputs_1d(outOp)) ||
is_convert_into_binary_eltwise(outOp)) {
consts[op].needsBatchInterpretation = constDims.size() == 1;
- } else if (ov::is_type<ov::op::v1::Gather>(outOp) || ov::is_type<ov::op::v7::Gather>(outOp) || ov::is_type<ov::op::v8::Gather>(outOp) ||
- ov::is_type<ov::op::v5::GatherND>(outOp) || ov::is_type<ov::op::v8::GatherND>(outOp) || ov::is_type<ov::op::v1::Split>(outOp) ||
- ov::is_type<ov::op::v1::VariadicSplit>(outOp) || ov::is_type<ov::op::util::ScatterBase>(outOp) ||
- ov::is_type<ov::op::util::ScatterElementsUpdateBase>(outOp) || ov::is_type<ov::op::util::ScatterNDBase>(outOp)) {
+ } else if (ov::is_type<ov::op::v1::Gather>(outOp) || ov::is_type<ov::op::v7::Gather>(outOp) ||
+ ov::is_type<ov::op::v8::Gather>(outOp) || ov::is_type<ov::op::v5::GatherND>(outOp) ||
+ ov::is_type<ov::op::v8::GatherND>(outOp) || ov::is_type<ov::op::v6::GatherElements>(outOp) ||
+ ov::is_type<ov::op::v1::Split>(outOp) || ov::is_type<ov::op::v1::VariadicSplit>(outOp) ||
+ ov::is_type<ov::op::util::ScatterBase>(outOp) ||
+ ov::is_type<ov::op::util::ScatterElementsUpdateBase>(outOp) ||
+ ov::is_type<ov::op::util::ScatterNDBase>(outOp)) {
consts[op].needsBatchInterpretation = constDims.size() == 1;
} else if (ov::is_type<ov::op::v0::PRelu>(outOp) && node.get_index() == 1) {
// PReLU slope tensor reshape policy
diff --git a/src/plugins/intel_gpu/tests/functional/shared_tests_instances/single_layer_tests/gather_elements.cpp b/src/plugins/intel_gpu/tests/functional/shared_tests_instances/single_layer_tests/gather_elements.cpp
index 372e077ae67..efcc1509cf2 100644
--- a/src/plugins/intel_gpu/tests/functional/shared_tests_instances/single_layer_tests/gather_elements.cpp
+++ b/src/plugins/intel_gpu/tests/functional/shared_tests_instances/single_layer_tests/gather_elements.cpp
@@ -221,4 +221,17 @@ INSTANTIATE_TEST_SUITE_P(smoke_GatherElements_rank6axis5, GatherElementsLayerTes
::testing::Values(ov::test::utils::DEVICE_GPU)),
GatherElementsLayerTest::getTestCaseName);
+// Rank-1 data with rank-1 constant indices: the plugin stores a rank-1 constant in
+// the feature slot while rank-1 parameters and the output use batch, so this read
+// the wrong indices before the constant.cpp batch-interpretation fix.
+INSTANTIATE_TEST_SUITE_P(smoke_GatherElements_rank1, GatherElementsLayerTest,
+ ::testing::Combine(
+ ::testing::Values(ov::test::static_shapes_to_test_representation({ov::Shape{100}})),
+ ::testing::Values(ov::Shape{4}),
+ ::testing::Values(0, -1),
+ ::testing::ValuesIn(model_types),
+ ::testing::ValuesIn(indices_types),
+ ::testing::Values(ov::test::utils::DEVICE_GPU)),
+ GatherElementsLayerTest::getTestCaseName);
+
} // namespace