-
Notifications
You must be signed in to change notification settings - Fork 3.6k
[webgpu] Remove global_id and workgroup_id in gemm_utils.cc
#26662
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
[webgpu] Remove global_id and workgroup_id in gemm_utils.cc
#26662
Conversation
This patch replaces `global_id` and `workgroup_id` with `logical_global_id` and `logical_workgroup_id` which are computed from `workgroup_idx` and the dispatch workgroup sizes set in `ProgramBase::SetDispatchGroupSize()` because the dispatch workgroup sizes may be normalized in `ProgramManager::NormalizeDispatchGroupSize()`.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR replaces direct usage of global_id and workgroup_id WebGPU built-in variables with computed logical_global_id and logical_workgroup_id values in GEMM-related shader generation code. This change is necessary because the dispatch workgroup sizes set via ProgramBase::SetDispatchGroupSize() may be normalized by ProgramManager::NormalizeDispatchGroupSize() to fit within WebGPU device limits.
Key changes:
- Added
logical_dispatch_x/y/zuniform variables to multiple program classes (MatMulProgram, GemmProgram, Conv2dMMProgram) - Implemented logical workgroup ID computation from
workgroup_idxusing the logical dispatch dimensions - Updated all references from
global_idandworkgroup_idto their logical counterparts in shader code generation - Removed outdated TODO comment in matmul.cc that referenced avoiding
global_id/workgroup_id
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| onnxruntime/core/providers/webgpu/nn/conv2d_mm.h | Added logical_dispatch_x/y/z uniform variable declarations to Conv2dMMProgram |
| onnxruntime/core/providers/webgpu/nn/conv2d_mm.cc | Pass dispatch dimensions as uniform variables to Conv2dMMProgram |
| onnxruntime/core/providers/webgpu/math/matmul_packed.h | Added logical_dispatch_x/y/z uniform variable declarations to MatMulProgram |
| onnxruntime/core/providers/webgpu/math/matmul.cc | Removed outdated TODO comment and pass dispatch dimensions as uniform variables to MatMulProgram |
| onnxruntime/core/providers/webgpu/math/gemm_utils.cc | Implemented logical workgroup/global ID computation and replaced all usage of global_id/workgroup_id with logical equivalents in shader generation |
| onnxruntime/core/providers/webgpu/math/gemm_packed.h | Added logical_dispatch_x/y/z uniform variable declarations to GemmProgram |
| onnxruntime/core/providers/webgpu/math/gemm_packed.cc | Pass dispatch dimensions as uniform variables to GemmProgram |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 7 out of 7 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Hi reviewers, The failed test is PTAL, thanks! |
Description
This patch replaces
global_idandworkgroup_idwithlogical_global_idandlogical_workgroup_idwhich are computed fromworkgroup_idxand the dispatch workgroup sizes set inProgramBase::SetDispatchGroupSize().Motivation and Context
We shouldn't use
global_idorworkgroup_iddirectly because the dispatch workgroup sizes may be normalized inProgramManager::NormalizeDispatchGroupSize().