Skip to content

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

[GPU] Fixed the issue with incorrect Gather+Eltwise results. (#31139)

Xiping Yanb85c4bc559ca
diff --git a/src/plugins/intel_gpu/src/kernel_selector/kernels/gather/gather_kernel_ref.cpp b/src/plugins/intel_gpu/src/kernel_selector/kernels/gather/gather_kernel_ref.cpp
index cbb55451fb9..5702d1db383 100644
--- a/src/plugins/intel_gpu/src/kernel_selector/kernels/gather/gather_kernel_ref.cpp
+++ b/src/plugins/intel_gpu/src/kernel_selector/kernels/gather/gather_kernel_ref.cpp
@@ -212,6 +212,12 @@ static std::string GetIndicesIdxOrder(const gather_params& params, size_t axis,
return GetOrderString(idx_order);
}
+static bool OutputBiasPositionCompatible(const gather_params& params) {
+ auto out = params.outputs[0];
+ auto bias = params.fused_ops[0].output_tensor;
+ return out.SameDims(bias);
+}
+
CommonDispatchData GatherKernelRef::SetDefault(const gather_params& params) const {
CommonDispatchData dispatchData;
const auto& output = params.outputs[0];
@@ -272,10 +278,14 @@ JitConstants GatherKernelRef::GetJitConstants(const gather_params& params) const
std::vector<std::string> idx_order;
if (params.inputs[0].GetDims().size() == 4 && GetGatherIndexDim(params).v == 0 && !params.inputs[1].is_dynamic() &&
params.inputs[1].LogicalSize() == 1) {
- idx_order = idx_order = {"(f)", "(y)", "(x)", "(1)"};
+ idx_order = {"(f)", "(y)", "(x)", "(1)"};
+ } else if (params.inputs[0].GetDims().size() == 4 && GetGatherChannelIndex(params) == 1 && !params.inputs[1].is_dynamic() &&
+ params.inputs[1].LogicalSize() == 1 && !OutputBiasPositionCompatible(params)) {
+ idx_order = {"(b)", "(y)", "(x)", "(1)"};
} else {
idx_order = GetOrder(params.inputs[0].GetDims().size());
}
+
FusedOpsConfiguration conf = { "", idx_order, "val", params.inputs[0].GetDType() };
jit.Merge(MakeFusedOpsJitConstants(params, {conf}));
}
diff --git a/src/plugins/intel_gpu/tests/functional/subgraph_tests/dynamic/eltwise_fusion.cpp b/src/plugins/intel_gpu/tests/functional/subgraph_tests/dynamic/eltwise_fusion.cpp
index fd625ed3e57..c97ac0a278a 100644
--- a/src/plugins/intel_gpu/tests/functional/subgraph_tests/dynamic/eltwise_fusion.cpp
+++ b/src/plugins/intel_gpu/tests/functional/subgraph_tests/dynamic/eltwise_fusion.cpp
@@ -10,6 +10,7 @@
#include "openvino/op/constant.hpp"
#include "openvino/op/multiply.hpp"
#include "openvino/op/add.hpp"
+#include "openvino/op/gather.hpp"
namespace {
@@ -89,4 +90,97 @@ INSTANTIATE_TEST_SUITE_P(StaticEltwiseDynamicFusions_basic,
::testing::Combine(::testing::ValuesIn(input_shapes_dyn2),
::testing::ValuesIn(input_precisions2)),
StaticEltwiseDynamicFusions::getTestCaseName);
+
+// Gather+Add
+/****************************************
+ * input[?,2,3]
+ * |
+ * Gather[?,3] bias[1,3]
+ * \ /
+ * Add
+ * |
+ * Output
+ * **************************************/
+
+using GatherEltwiseFusionsParams = std::tuple<std::vector<InputShape>, // input shapes
+ ov::element::Type, // input precision
+ bool>; // gather indices is scalor or not.
+class GatherEltwiseFusion : public testing::WithParamInterface<GatherEltwiseFusionsParams>, virtual public ov::test::SubgraphBaseTest {
+public:
+ static std::string getTestCaseName(testing::TestParamInfo<GatherEltwiseFusionsParams> obj) {
+ std::vector<InputShape> input_shapes;
+ ov::element::Type input_precision;
+ bool input_scalar_indices;
+
+ std::tie(input_shapes, input_precision, input_scalar_indices) = obj.param;
+
+ std::ostringstream result;
+ result << "IS=(";
+ for (const auto& shape : input_shapes) {
+ result << ov::test::utils::partialShape2str({shape.first}) << "_";
+ }
+ result << ")_TS=";
+ for (const auto& shape : input_shapes) {
+ result << "(";
+ if (!shape.second.empty()) {
+ auto itr = shape.second.begin();
+ do {
+ result << ov::test::utils::vec2str(*itr);
+ } while (++itr != shape.second.end() && result << "_");
+ }
+ result << ")_";
+ }
+ result << "input_precision=" << input_precision;
+ result << "_input_scalar_indices=" << input_scalar_indices;
+ return result.str();
+ }
+
+protected:
+ std::shared_ptr<ov::Model> init_subgraph(std::vector<ov::PartialShape>& input_shapes,
+ const ov::element::Type input_precision,
+ const bool input_scalar_indices) {
+ auto input = std::make_shared<ov::op::v0::Parameter>(input_precision, input_shapes[0]);
+
+ auto indices = std::make_shared<ov::op::v0::Constant>(ov::element::i32, input_scalar_indices ? ov::Shape{} : ov::Shape{1}, std::vector<int>{0});
+ auto axis = std::make_shared<ov::op::v0::Constant>(ov::element::i32, input_scalar_indices ? ov::Shape{} : ov::Shape{1}, std::vector<int>{1});
+ auto gather = std::make_shared<ov::op::v8::Gather>(input, indices, axis);
+
+ auto bias = std::make_shared<ov::op::v0::Constant>(input_precision, ov::Shape{1, 3}, std::vector<float>{1.0, 2.0 , 3.0});
+ auto add = std::make_shared<ov::op::v1::Add>(gather, bias);
+
+ return std::make_shared<ov::Model>(ov::OutputVector{add}, ov::ParameterVector{input}, "GatherEltwiseFusion");
+ }
+
+ void SetUp() override {
+ targetDevice = ov::test::utils::DEVICE_GPU;
+
+ std::vector<InputShape> input_shapes;
+ ov::element::Type input_precision;
+ bool input_scalar_indices;
+
+ std::tie(input_shapes, input_precision, input_scalar_indices) = GetParam();
+
+ init_input_shapes(input_shapes);
+
+ inType = outType = input_precision;
+ function = init_subgraph(inputDynamicShapes, input_precision, input_scalar_indices);
+ }
+};
+
+TEST_P(GatherEltwiseFusion, Inference) {
+ run();
+}
+
+const std::vector<std::vector<InputShape>> input_shapes_dyn = {
+ {{{-1, 2, 3}, {{3, 2, 3}}}},
+};
+
+const std::vector<bool> input_scalar_indices = {false, true};
+
+INSTANTIATE_TEST_SUITE_P(GatherEltwiseFusion_basic,
+ GatherEltwiseFusion,
+ ::testing::Combine(::testing::ValuesIn(input_shapes_dyn),
+ ::testing::ValuesIn(input_precisions2),
+ ::testing::ValuesIn(input_scalar_indices)),
+ GatherEltwiseFusion::getTestCaseName);
} // namespace