[WebGPU] Intel SubgroupMatrix MatMul: batched-B support - #29749
Conversation
Jie Chen (jchen10)
commented
Jul 17, 2026
- Create the Intel subgroup-matrix impl lazily in ComputeInternal (via std::call_once) instead of PrePackInternal, which only fires for constant initializers and so skipped the subgroup-matrix path for runtime/dynamic B (batched matmul).
- Fall back to the generic MatMul path when N is odd: Intel's f16 subgroup-matrix B load requires an even row stride (4-byte-aligned K-rows); an odd N corrupts odd output columns.
- Add batched f16 MatMul tests (matmul_large_test.cc).
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
|
Jiajia Qin (@qjia7) PTAL |
There was a problem hiding this comment.
Pull request overview
This PR updates the WebGPU MatMul implementation to better utilize Intel’s subgroup-matrix path for batched (true-BMM) workloads by (1) initializing the optimized implementation lazily at first compute, (2) extending the subgroup-matrix kernel to dispatch batch slices on z, and (3) tuning the Intel tiling selector to account for batch-driven occupancy while falling back for unsupported odd N cases.
Changes:
- Lazily initialize the subgroup-matrix optimized MatMul path in
ComputeInternalusingstd::call_onceso it can apply even whenBis not a constant initializer. - Add batched-
Bsupport to the subgroup-matrix MatMul path by dispatching slices onzand applying per-slice A/B/output offsets in WGSL. - Extend Intel tiling selection to incorporate batch as an occupancy multiplier and clamp split-K accordingly.
Reviewed changes
Copilot reviewed 6 out of 7 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| onnxruntime/test/providers/webgpu/matmul_large_test.cc | Adds disabled large tests covering true batched-B MatMul, unaligned shapes, and 4D batching. |
| onnxruntime/core/providers/webgpu/vendor/intel/math/subgroup_matrix_tiling_selector.cc | Adds batch-aware heuristic tiling and split-K clamping for batched dispatch. |
| onnxruntime/core/providers/webgpu/math/subgroup_matrix_matmul.h | Updates the tiling-selector callback signature to include batch. |
| onnxruntime/core/providers/webgpu/math/subgroup_matrix_matmul.cc | Implements true batched-B handling (z-dispatch), odd-N fallback, and passes batch into the tiling selector. |
| onnxruntime/core/providers/webgpu/math/subgroup_matrix_matmul_8x16x16.wgsl.template | Adds batch-id recovery from flattened workgroup_idx and per-slice offsets for A/B/output addressing. |
| onnxruntime/core/providers/webgpu/math/matmul.h | Adds std::once_flag and removes PrePackInternal override to support lazy optimized-path creation. |
| onnxruntime/core/providers/webgpu/math/matmul.cc | Performs lazy subgroup-matrix impl creation in ComputeInternal via std::call_once; removes PrePackInternal implementation. |
|
Jiajia Qin (@qjia7) Thanks for reviewing. Hariharan Seshadri (@hariharans29) Could you please take a look, thanks! |
Review: PR #29749 —
|
|
Approving as Jiajia Qin (@qjia7) is OOF and her comments have been resolved. |
- Create the Intel subgroup-matrix impl lazily in ComputeInternal (via std::call_once) instead of PrePackInternal, which only fires for constant initializers and so skipped the subgroup-matrix path for runtime/dynamic B (batched matmul). - Fall back to the generic MatMul path when N is odd: Intel's f16 subgroup-matrix B load requires an even row stride (4-byte-aligned K-rows); an odd N corrupts odd output columns. - Add batched f16 MatMul tests (matmul_large_test.cc).
Head branch was pushed to by a user without write access
ee2794a to
1857812
Compare
|
Thanks, Hariharan Seshadri (@hariharans29)! Just rebased and squashed the commits. |
|
The failing checks look like a CI infra issue. |
Yeah we have some CI issues. I ll follow up on this PR and merge once they are resolved. |
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
137dbef
into
microsoft:main