Skip to content

Conversation

@Jiawei-Shao
Copy link
Contributor

Description

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().

Motivation and Context

We shouldn't use global_id or workgroup_id directly because the dispatch workgroup sizes may be normalized in ProgramManager::NormalizeDispatchGroupSize().

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()`.
@Jiawei-Shao Jiawei-Shao marked this pull request as ready for review November 26, 2025 08:38
@qjia7 qjia7 requested a review from Copilot November 26, 2025 08:43
Copilot finished reviewing on behalf of qjia7 November 26, 2025 08:45
Copy link
Contributor

Copilot AI left a 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/z uniform variables to multiple program classes (MatMulProgram, GemmProgram, Conv2dMMProgram)
  • Implemented logical workgroup ID computation from workgroup_idx using the logical dispatch dimensions
  • Updated all references from global_id and workgroup_id to 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.

@Jiawei-Shao Jiawei-Shao requested a review from Copilot November 26, 2025 13:27
Copy link
Contributor

Copilot AI left a 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.

@Jiawei-Shao Jiawei-Shao requested a review from Copilot November 26, 2025 13:34
Copy link
Contributor

Copilot AI left a 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.

@guschmue guschmue added the ep:WebGPU ort-web webgpu provider label Nov 26, 2025
@Jiawei-Shao
Copy link
Contributor Author

Hi reviewers,

The failed test is CudaNhwcTypedTest/0.ConvNhwcBias which should not be related to my PR.

PTAL, thanks!

qjia7
qjia7 previously approved these changes Nov 27, 2025
@qjia7 qjia7 requested review from fs-eire and guschmue November 27, 2025 06:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ep:WebGPU ort-web webgpu provider

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants