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: Disable non-transposed MatMul→FC path on Intel GPUs without XMX (#36812)
Chon Ming Lee4e3fe42add7b
diff --git a/src/plugins/intel_gpu/src/plugin/transformations/convert_matmul_to_fc.cpp b/src/plugins/intel_gpu/src/plugin/transformations/convert_matmul_to_fc.cppindex 715d51fd58c..47b2766044e 100644--- a/src/plugins/intel_gpu/src/plugin/transformations/convert_matmul_to_fc.cpp+++ b/src/plugins/intel_gpu/src/plugin/transformations/convert_matmul_to_fc.cpp@@ -232,9 +232,9 @@ ConvertMatMulToFullyConnected::ConvertMatMulToFullyConnected(bool supports_immad// dimension. When both M and N are large the GEMM becomes// compute-bound and the transposed layout (acb) is faster (the// non-transposed kernel can regress by up to ~1.3x there). Restrict- // the non-transposed path to K >= 8192 and (M <= 512 or N <= 4096)- // to keep the wins while avoiding those regressions.- if (k >= 8192 && (m <= 512 || n <= 4096) &&+ // the non-transposed path to XMX-capable GPUs (supports_immad) with+ // K >= 8192 and (M <= 512 or N <= 4096) to keep the wins while avoiding those regressions.+ if (supports_immad && k >= 8192 && (m <= 512 || n <= 4096) &&matmul->get_input_element_type(0) == ov::element::f16 && !is_compressed_weight) {is_small_matmul = false;}diff --git a/src/plugins/intel_gpu/tests/unit/transformations/convert_matmul_to_fc_test.cpp b/src/plugins/intel_gpu/tests/unit/transformations/convert_matmul_to_fc_test.cppindex a12ec42865c..82c8a600d1c 100644--- a/src/plugins/intel_gpu/tests/unit/transformations/convert_matmul_to_fc_test.cpp+++ b/src/plugins/intel_gpu/tests/unit/transformations/convert_matmul_to_fc_test.cpp@@ -856,7 +856,7 @@ TEST_F(TransformationTestsF, ConvertMatMulToFullyConnected_LargeF16_NonTransposeauto matmul = std::make_shared<ov::opset1::MatMul>(input, weights, false, false);model = std::make_shared<ov::Model>(ov::OutputVector{matmul}, ov::ParameterVector{input});- manager.register_pass<ConvertMatMulToFullyConnected>();+ manager.register_pass<ConvertMatMulToFullyConnected>(true); // supports_immad=true (XMX available)}{auto input = std::make_shared<ov::opset1::Parameter>(ov::element::f16, ov::Shape{512, 8192});@@ -876,7 +876,7 @@ TEST_F(TransformationTestsF, ConvertMatMulToFullyConnected_LargeF16_NonTransposeauto matmul = std::make_shared<ov::opset1::MatMul>(input, weights, false, false);model = std::make_shared<ov::Model>(ov::OutputVector{matmul}, ov::ParameterVector{input});- manager.register_pass<ConvertMatMulToFullyConnected>();+ manager.register_pass<ConvertMatMulToFullyConnected>(true); // supports_immad=true (XMX available)}{auto input = std::make_shared<ov::opset1::Parameter>(ov::element::f16, ov::Shape{4096, 8192});@@ -940,7 +940,7 @@ TEST_F(TransformationTestsF, ConvertMatMulToFullyConnected_LargeF16_MatMulTranspauto matmul = std::make_shared<ov::opset1::MatMul>(input, weights, false, true);model = std::make_shared<ov::Model>(ov::OutputVector{matmul}, ov::ParameterVector{input});- manager.register_pass<ConvertMatMulToFullyConnected>();+ manager.register_pass<ConvertMatMulToFullyConnected>(true); // supports_immad=true (XMX available)}{auto input = std::make_shared<ov::opset1::Parameter>(ov::element::f16, ov::Shape{256, 8192});@@ -975,3 +975,28 @@ TEST_F(TransformationTestsF, ConvertMatMulToFullyConnected_LargeF32_Transposed)model_ref = std::make_shared<ov::Model>(ov::OutputVector{fc}, ov::ParameterVector{input});}}++// Large f16 matmul on non-XMX hardware (supports_immad=false):+// K>=8192 and M<=512 would normally enable the non-transposed path, but without XMX+// the non-transposed path is unavailable, so the transposed path is used instead.+TEST_F(TransformationTestsF, ConvertMatMulToFullyConnected_LargeF16_NoXMX_Transposed) {+ {+ auto input = std::make_shared<ov::opset1::Parameter>(ov::element::f16, ov::Shape{512, 8192});+ auto weights = ov::opset1::Constant::create(ov::element::f16, ov::Shape{8192, 4096}, {1});+ auto matmul = std::make_shared<ov::opset1::MatMul>(input, weights, false, false);++ model = std::make_shared<ov::Model>(ov::OutputVector{matmul}, ov::ParameterVector{input});+ manager.register_pass<ConvertMatMulToFullyConnected>(); // supports_immad=false (no XMX)+ }+ {+ // Expected: weights transposed + FC with transpose_b=true+ auto input = std::make_shared<ov::opset1::Parameter>(ov::element::f16, ov::Shape{512, 8192});+ auto weights = ov::opset1::Constant::create(ov::element::f16, ov::Shape{8192, 4096}, {1});+ auto transpose_constant = ov::opset1::Constant::create(ov::element::i32, ov::Shape{2}, {1, 0});+ auto transpose = std::make_shared<ov::opset1::Transpose>(weights, transpose_constant);+ auto no_bias = std::make_shared<ov::intel_gpu::op::Placeholder>();+ auto fc = std::make_shared<op::FullyConnected>(input, transpose, no_bias, ov::element::f16, true);++ model_ref = std::make_shared<ov::Model>(ov::OutputVector{fc}, ov::ParameterVector{input});+ }+}