Skip to content

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

[GPU] Fix assert on unfoldable fused eltwise peer (#38300)

David Nam3f018837ad4a
diff --git a/src/plugins/intel_gpu/src/graph/impls/ocl/kernel_selector_helper.h b/src/plugins/intel_gpu/src/graph/impls/ocl/kernel_selector_helper.h
index cdabdaef4e8..f618e5bf2e8 100644
--- a/src/plugins/intel_gpu/src/graph/impls/ocl/kernel_selector_helper.h
+++ b/src/plugins/intel_gpu/src/graph/impls/ocl/kernel_selector_helper.h
@@ -346,13 +346,18 @@ inline kernel_impl_params canonicalize_fused_shapes(const kernel_impl_params& im
// broadcastable() only compares the first out_pshape.size() axes, so a peer whose leading
// axes are all 1 can be misreported as compatible while its rank still mismatches the host's
// iteration space, causing the fused-op kernel to index the peer incorrectly.
- auto folded = fold_higher_rank_fused_peer(dep_layout, out_layout);
- // can_fuse_reorder_to_prev() must have already declined fusion for any non-foldable peer.
- OPENVINO_ASSERT(folded.has_value(),
- "Unfoldable higher-rank fused eltwise peer reached canonicalization; "
- "can_fuse_reorder_to_prev guard was expected to prevent this.");
- dep_layout.set_partial_shape(*folded);
- dep_layout.format = format::adjust_to_rank(dep_layout.format, out_pshape.size());
+ if (auto folded = fold_higher_rank_fused_peer(dep_layout, out_layout)) {
+ dep_layout.set_partial_shape(*folded);
+ dep_layout.format = format::adjust_to_rank(dep_layout.format, out_pshape.size());
+ } else {
+ OPENVINO_ASSERT(dep_layout.is_static() && out_layout.is_static() &&
+ broadcastable(ov::PartialShape(dep_layout.get_tensor().sizes()),
+ ov::PartialShape(out_layout.get_tensor().sizes()),
+ /*use_new_shape_infer=*/false,
+ /*first_to_second_only=*/true),
+ "Fused eltwise peer ", dep_layout.to_short_string(),
+ " cannot broadcast into host ", out_layout.to_short_string());
+ }
} else if (!broadcastable(dep_shape, out_pshape, use_new_shape_infer)) {
dep_layout.set_partial_shape(extend_shape_to_rank_from_begin(dep_shape, out_pshape.size()));
}
diff --git a/src/plugins/intel_gpu/tests/unit/module_tests/canonicalize_fused_shapes_test.cpp b/src/plugins/intel_gpu/tests/unit/module_tests/canonicalize_fused_shapes_test.cpp
index 5d45cd552a4..4ceefc7458f 100644
--- a/src/plugins/intel_gpu/tests/unit/module_tests/canonicalize_fused_shapes_test.cpp
+++ b/src/plugins/intel_gpu/tests/unit/module_tests/canonicalize_fused_shapes_test.cpp
@@ -5,6 +5,8 @@
#include <limits>
#include "impls/ocl/kernel_selector_helper.h"
+#include "intel_gpu/graph/program.hpp"
+#include "intel_gpu/primitives/eltwise.hpp"
#include "intel_gpu/runtime/layout.hpp"
#include "test_utils.h"
@@ -147,3 +149,27 @@ TEST(canonicalize_fused_peer_fold, overflow_rejected) {
auto host = make_layout({1, 1, big, big}, format::bfyx);
ASSERT_FALSE(fold_higher_rank_fused_peer(peer, host).has_value());
}
+
+// When the peer cannot fold, keep it as-is instead of failing.
+TEST(canonicalize_fused_peer_fold, unfoldable_higher_rank_peer_is_left_untouched) {
+ auto& engine = tests::get_test_engine();
+ program prog(engine, tests::get_test_default_config(engine));
+
+ const auto host = make_layout(ov::PartialShape{}, format::bfyx); // host rank < 3: no fold exists
+ const auto peer = make_layout({1}, format::bfyx);
+
+ fused_primitive_desc fused(
+ std::make_shared<eltwise>("add", std::vector<input_info>{input_info("host"), input_info("peer")}, eltwise_mode::sum));
+ fused.total_num_deps = 2;
+ fused.outer_dep_start_idx = 1;
+ fused.output_layout = host;
+
+ kernel_impl_params params;
+ params.prog = &prog;
+ params.input_layouts = {host, peer};
+ params.output_layouts = {host};
+ params.fused_desc = {fused};
+
+ const auto updated = canonicalize_fused_shapes(params);
+ EXPECT_EQ(updated.input_layouts[1], peer);
+}