webgpu: merge batchA into M dimension when batchB==1#28197
Merged
guschmue merged 2 commits intomicrosoft:mainfrom Apr 29, 2026
Merged
webgpu: merge batchA into M dimension when batchB==1#28197guschmue merged 2 commits intomicrosoft:mainfrom
guschmue merged 2 commits intomicrosoft:mainfrom
Conversation
When M is small and batchA is large, there are some invalid elements in each tile, merge batchA into M dimesion would reduce the workgroup count.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the WebGPU MatMul implementation to flatten A’s batch dimensions into the effective M dimension when B has no batching (batchB==1), aiming to reduce workgroup overhead for cases with small M and large batchA. It also adds WebGPU-specific regression tests for additional 3D batched MatMul shapes.
Changes:
- WebGPU MatMul: reshape A/B and treat output as
{1, batchA*M, N}whenbatchA != 1 && batchB == 1(applies to both the generic and Intel subgroup paths). - Add WebGPU-only MatMul test cases covering 3D inputs with
batchA=3, M=2andN in {3,4}.
Reviewed changes
Copilot reviewed 2 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| onnxruntime/test/providers/cpu/math/matmul_test.cc | Adds WebGPU-only test cases for 3D batched MatMul with batchA>1 and M>1. |
| onnxruntime/core/providers/webgpu/vendor/intel/math/matmul.cc | Extends the Intel subgroup MatMul reshape optimization from M==1 to all batchA!=1 && batchB==1 cases. |
| onnxruntime/core/providers/webgpu/math/matmul.cc | Extends the generic WebGPU MatMul reshape optimization similarly, flattening batch dims into M when batchB==1. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Contributor
Author
qjia7
reviewed
Apr 24, 2026
Contributor
qjia7
approved these changes
Apr 29, 2026
Contributor
qjia7
left a comment
There was a problem hiding this comment.
LGTM. Please also update your PR description. Thanks.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When M is small and batchA is large, there are some invalid elements in each tile, merge batchA into M dimesion would reduce the workgroup count.
Description
Motivation and Context