Skip to content

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

[GPU] Do not pad 2-4 row int4 fully connected to 16 rows (#38795)

seungwoo kim4e9742d72bf5
diff --git a/src/plugins/intel_gpu/src/graph/fully_connected.cpp b/src/plugins/intel_gpu/src/graph/fully_connected.cpp
index cae0a7bf7eb..5c686159ada 100644
--- a/src/plugins/intel_gpu/src/graph/fully_connected.cpp
+++ b/src/plugins/intel_gpu/src/graph/fully_connected.cpp
@@ -345,6 +345,17 @@ kernel_impl_params fully_connected_inst::get_fake_aligned_params(kernel_impl_par
return std::move(orig_impl_param);
}
+ // A 4-bit FC with 2..4 rows has a 128-register gemm kernel (4 columns); padding the rows to 16 sends it
+ // to the 256-register systolic kernel, which runs half the hardware threads per EU. Both are oneDNN
+ // kernels, and oneDNN runs the FC only on GPUs with XMX (immad).
+ if (orig_impl_param.dev_type == cldnn::device_type::integrated_gpu && orig_impl_param.get_device_info().supports_immad && batch_size >= 2 &&
+ batch_size <= 4 && orig_impl_param.weights_layout.has_value()) {
+ const auto small_row_wdt = orig_impl_param.weights_layout.value().data_type;
+ if (small_row_wdt == data_types::i4 || small_row_wdt == data_types::u4) {
+ return std::move(orig_impl_param);
+ }
+ }
+
size_t fake_align_base = 8;
if (orig_impl_param.dev_type == cldnn::device_type::integrated_gpu) {
auto weights_layout_dt = orig_impl_param.weights_layout.value().data_type;
diff --git a/src/plugins/intel_gpu/tests/unit/fake_alignment/fc_fake_alignment_test.cpp b/src/plugins/intel_gpu/tests/unit/fake_alignment/fc_fake_alignment_test.cpp
index a6edb2deb8b..acd6e57c7c6 100644
--- a/src/plugins/intel_gpu/tests/unit/fake_alignment/fc_fake_alignment_test.cpp
+++ b/src/plugins/intel_gpu/tests/unit/fake_alignment/fc_fake_alignment_test.cpp
@@ -218,6 +218,60 @@ INSTANTIATE_TEST_SUITE_P(smoke, fully_connected_fake_align_test,
},
}));
+struct fc_fake_align_int4_small_batch_params {
+ int64_t rows;
+ int64_t aligned_rows_xmx_igpu;
+ int64_t aligned_rows_igpu; // integrated GPU without XMX
+ int64_t aligned_rows_dgpu;
+};
+
+class fully_connected_fake_align_int4_small_batch_test : public testing::TestWithParam<fc_fake_align_int4_small_batch_params> {};
+
+// 4-bit weights with 2..4 rows are not padded on integrated GPUs with XMX: the padded shape would select the
+// 256-GRF systolic gemm instead of the 128-GRF dot kernel that covers 2..4 rows. Integrated GPUs without XMX
+// do not run the FC on oneDNN and keep the padding. 512 input features keep the 1-row case away from the
+// vector-by-matrix early return, so it reaches the 2..4 row check.
+TEST_P(fully_connected_fake_align_int4_small_batch_test, fake_alignment) {
+ auto p = GetParam();
+
+ auto& engine = get_test_engine();
+
+ auto input_layout_prim = std::make_shared<input_layout>("input", layout{ov::PartialShape{p.rows, 512}, data_types::f16, format::bfyx});
+ auto weight_layout_prim = std::make_shared<input_layout>("weight", layout{ov::PartialShape{1000, 512}, data_types::i4, format::bfyx});
+ auto fully_connected_prim = std::make_shared<fully_connected>("output", input_info("input"), "weight", "", data_types::f16, 2);
+
+ cldnn::program prog(engine);
+
+ auto& input_node = prog.get_or_create(input_layout_prim);
+ auto& weight_node = prog.get_or_create(weight_layout_prim);
+ auto& fully_connected_node = prog.get_or_create(fully_connected_prim);
+ program_wrapper::add_connection(prog, input_node, fully_connected_node);
+ program_wrapper::add_connection(prog, weight_node, fully_connected_node);
+
+ auto impl_param = fully_connected_node.get_kernel_impl_params();
+ impl_param->output_layouts[0] = fully_connected_inst::calc_output_layouts<ov::PartialShape>(fully_connected_node, *impl_param)[0];
+
+ auto updated_param = fully_connected_inst::get_fake_aligned_params(*impl_param);
+
+ const auto& device_info = engine.get_device_info();
+ auto aligned_rows = p.aligned_rows_dgpu;
+ if (device_info.dev_type == cldnn::device_type::integrated_gpu) {
+ aligned_rows = device_info.supports_immad ? p.aligned_rows_xmx_igpu : p.aligned_rows_igpu;
+ }
+ ASSERT_EQ(updated_param.get_input_layout(), (layout{ov::PartialShape{aligned_rows, 512}, data_types::f16, format::bfyx}));
+ ASSERT_EQ(updated_param.get_output_layout(), (layout{ov::PartialShape{aligned_rows, 1000}, data_types::f16, format::bfyx}));
+}
+
+INSTANTIATE_TEST_SUITE_P(smoke, fully_connected_fake_align_int4_small_batch_test,
+ testing::ValuesIn(std::vector<fc_fake_align_int4_small_batch_params>{
+ // rows, aligned rows on an XMX iGPU, on an iGPU without XMX, on a dGPU
+ {1, 16, 16, 8},
+ {2, 2, 16, 8},
+ {3, 3, 16, 8},
+ {4, 4, 16, 8},
+ {5, 16, 16, 8},
+ }));
+
class fully_connected_skip_fake_align_test : public testing::TestWithParam<fc_fake_align_params> {};
// Skip fake alignment when fused desc has full tensor dependency