From eb409669f6b97a0276f5b150c013eb4b32a2a3ce Mon Sep 17 00:00:00 2001 From: Xinghua Cao Date: Thu, 5 Nov 2026 14:45:46 +0800 Subject: [PATCH] [WebGPU] Disable automatic subgroup MatMul selection on gen-12hp --- .../providers/webgpu/vendor/intel/math/gemm_subgroup.cc | 7 ++++++- .../webgpu/vendor/intel/math/gemm_subgroup_utils.h | 4 ++++ .../webgpu/vendor/intel/math/matmul_execution_planner.cc | 3 +++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/onnxruntime/core/providers/webgpu/vendor/intel/math/gemm_subgroup.cc b/onnxruntime/core/providers/webgpu/vendor/intel/math/gemm_subgroup.cc index 1e32fefde8d6a..773fca7b1b009 100644 --- a/onnxruntime/core/providers/webgpu/vendor/intel/math/gemm_subgroup.cc +++ b/onnxruntime/core/providers/webgpu/vendor/intel/math/gemm_subgroup.cc @@ -154,9 +154,14 @@ std::string CalculateAccStr(const ShaderIndicesHelper* batch_dims, int64_t eleme } // namespace +bool CanAutoSelectSubgroupGemm(std::string_view architecture) { + return architecture != gpu_arch::kGen12Hp; +} + bool CanApplySubgroup(const ComputeContext& context, int64_t M, int64_t N, int64_t K, bool transA, bool transB) { if (context.AdapterInfo().vendor == std::string_view{"intel"}) { - bool use_subgroup = context.HasFeature(wgpu::FeatureName::Subgroups) && + bool use_subgroup = CanAutoSelectSubgroupGemm(context.AdapterInfo().architecture) && + context.HasFeature(wgpu::FeatureName::Subgroups) && M >= 64 && N >= 512 && K >= 32 && !transA && !transB; return use_subgroup; } diff --git a/onnxruntime/core/providers/webgpu/vendor/intel/math/gemm_subgroup_utils.h b/onnxruntime/core/providers/webgpu/vendor/intel/math/gemm_subgroup_utils.h index 5d78f9feff4cb..9f97999c55bbb 100644 --- a/onnxruntime/core/providers/webgpu/vendor/intel/math/gemm_subgroup_utils.h +++ b/onnxruntime/core/providers/webgpu/vendor/intel/math/gemm_subgroup_utils.h @@ -12,10 +12,14 @@ namespace webgpu { namespace intel { namespace gpu_arch { +inline constexpr std::string_view kGen12Hp = "gen-12hp"; inline constexpr std::string_view kXeLpg = "xe-lpg"; inline constexpr std::string_view kXe3Lpg = "xe-3lpg"; } // namespace gpu_arch +// Whether automatic algorithm selection may choose the subgroup GEMM/MatMul kernel on `architecture`. +bool CanAutoSelectSubgroupGemm(std::string_view architecture); + bool ShouldFoldMatMulSubgroupBatch(std::string_view architecture, int64_t m, bool can_fold_batch_into_m); diff --git a/onnxruntime/core/providers/webgpu/vendor/intel/math/matmul_execution_planner.cc b/onnxruntime/core/providers/webgpu/vendor/intel/math/matmul_execution_planner.cc index 30f9757948847..779b5e46b9fd6 100644 --- a/onnxruntime/core/providers/webgpu/vendor/intel/math/matmul_execution_planner.cc +++ b/onnxruntime/core/providers/webgpu/vendor/intel/math/matmul_execution_planner.cc @@ -5,6 +5,8 @@ #include +#include "core/providers/webgpu/vendor/intel/math/gemm_subgroup_utils.h" + namespace onnxruntime { namespace webgpu { namespace intel { @@ -18,6 +20,7 @@ std::optional IntelMatMulExecutionPlanner::SelectVendorAlgorith return MatMulAlgorithm::SubgroupMatrix; } if (params.has_subgroup_capability && + CanAutoSelectSubgroupGemm(params.adapter_architecture) && params.m >= 64 && params.n >= 512 && params.k >= 32) { return MatMulAlgorithm::Subgroup; }