[WebGPU] Refactor subgroup matrix config selection - #32700
Yang Gu (gyagp) wants to merge 1 commit into
Conversation
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.
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
There was a problem hiding this comment.
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.
|
Intel Vulkan regression validation completed on
Passed three consecutive iterations of:
Also passed No Intel Vulkan regression was observed. |
|
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)) { |
There was a problem hiding this comment.
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)) { |
There was a problem hiding this comment.
NIT: Unrelated to the current PR.
context.HasFeature(wgpu::FeatureName::SubgroupSizeControl) is already checked inside SelectSubgroupMatrixConfig.
There was a problem hiding this comment.
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).
Description
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
onnxruntime_provider_testin Release with WebGPU/D3D12 enabled.SubgroupMatrixConfigTest.*.git diff --check.