Skip to content

[WebGPU] Refactor subgroup matrix config selection - #32700

Open
Yang Gu (gyagp) wants to merge 1 commit into
microsoft:mainfrom
gyagp:webgpu-subgroup-matrix-config-selection
Open

Yang Gu (gyagp) wants to merge 1 commit into
microsoft:mainfrom
gyagp:webgpu-subgroup-matrix-config-selection

Conversation

@gyagp

Copy link
Copy Markdown
Contributor

Description

  • Enumerate every capability-valid subgroup-matrix configuration before selection.
  • Let each WebGPU operation express an explicit configuration preference order.
  • Keep candidate discovery internal to the shared selector and add focused preference-order coverage.
  • Preserve the existing Apple MatMulNBits accuracy restriction as an operation eligibility check.

Motivation and Context

A device can report multiple subgroup-matrix configurations. Selecting the first match from the global supported-config table makes table order an implicit performance policy and prevents individual operations from choosing their best supported configuration. This change separates capability filtering from operation-specific ranking so future vendor- and workload-specific preferences can be added without relying on global array order.

Testing

  • Built onnxruntime_provider_test in Release with WebGPU/D3D12 enabled.
  • Passed SubgroupMatrixConfigTest.*.
  • Passed targeted subgroup-matrix MatMulNBits tests.
  • Passed lintrunner for the changed C++ files and git diff --check.

Enumerate every capability-valid subgroup matrix configuration and let each operation apply an explicit preference order. This keeps the global supported-config table from silently acting as performance policy.
Copilot AI balanced review requested due to automatic review settings September 20, 2026 02:31
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approval recommended

The refactor updates all callers consistently, preserves fallback behavior, and includes focused coverage.

Review effort: Balanced
Findings: None

What changed in this PR

Refactors WebGPU subgroup-matrix configuration selection to separate device capability discovery from operation-specific ranking.

Changes:

  • Enumerates all supported configurations before applying preferences.
  • Adds explicit preferences for MatMul, Gemm, and MatMulNBits.
  • Adds focused preference-order tests and preserves Apple restrictions.
File Description
onnxruntime/​core/​providers/​webgpu/​math/​subgroup_matrix_config.h Defines preference-based selection API.
onnxruntime/​core/​providers/​webgpu/​math/​subgroup_matrix_config.cc Implements candidate discovery and ranking.
onnxruntime/​core/​providers/​webgpu/​math/​subgroup_matrix_matmul.cc Selects the required MatMul configuration.
onnxruntime/​core/​providers/​webgpu/​math/​subgroup_matrix_gemm.cc Selects the required Gemm configuration.
onnxruntime/​contrib_ops/​webgpu/​quantization/​subgroup_matrix_matmul_nbits.cc Adds ordered MatMulNBits preferences and eligibility checks.
onnxruntime/​test/​providers/​cpu/​math/​matmul_test.cc Tests preference ordering and unavailable preferences.

💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@gyagp

Copy link
Copy Markdown
Contributor Author

Intel Vulkan regression validation completed on webgfx-32:

  • GPU: Intel Arc B390 (Panther Lake)
  • Driver: 32.0.101.8991
  • Vulkan API: 1.4.356
  • Capability: VK_KHR_cooperative_matrix revision 2, subgroup size 32, subgroup-size-control range 16–32
  • Build: PR commit a20eebedec, Vulkan-only Dawn configuration (D3D12 disabled, Vulkan enabled)

Passed three consecutive iterations of:

  • SubgroupMatrixConfigTest.*
  • MathOpTest.MatMulSubgroupMatrix
  • MatMulNBits.Float16_4b_Accuracy4
  • MatMulNBits.Float16_8b_AccuracyLevel4

Also passed Gemm_Large.DISABLED_SubgroupMatrixEdges with disabled tests explicitly enabled. Shader dumps contained enable chromium_experimental_subgroup_matrix and subgroupMatrixMultiplyAccumulate, confirming that subgroup-matrix kernels executed rather than falling back.

No Intel Vulkan regression was observed.

@gyagp

Copy link
Copy Markdown
Contributor Author

Jiajia Qin (@qjia7) Jie Chen (@jchen10) and Jianhui Dai (@daijh), the current global priority list is not flexible for selection with different operators. I'm refactoring it with this PR, and will introduce AMD specific support based on this. Please help to review, thanks!

!supported_subgroup_matrix_configs[config_index].Is(8, 16, 16) ||
!context.HasFeature(wgpu::FeatureName::SubgroupSizeControl)) {
const auto config_index = SelectSubgroupMatrixConfig(context, /*is_fp16=*/true, {{8, 16, 16, 32}});
if (!config_index || !context.HasFeature(wgpu::FeatureName::SubgroupSizeControl)) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT: Unrelated to the current PR.
context.HasFeature(wgpu::FeatureName::SubgroupSizeControl) is already checked inside SelectSubgroupMatrixConfig.

!supported_subgroup_matrix_configs[config_index].Is(8, 16, 16) ||
!context.HasFeature(wgpu::FeatureName::SubgroupSizeControl)) {
const auto config_index = SelectSubgroupMatrixConfig(context, /*is_fp16=*/true, {{8, 16, 16, 32}});
if (!config_index || !context.HasFeature(wgpu::FeatureName::SubgroupSizeControl)) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT: Unrelated to the current PR.
context.HasFeature(wgpu::FeatureName::SubgroupSizeControl) is already checked inside SelectSubgroupMatrixConfig.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Unrelated to the current PR.
The files subgroup_matrix_config.cc/h should be placed under the common WebGPU path (e.g., webgpu_context.h).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants