Skip to content

Conversation

@daijh
Copy link
Contributor

@daijh daijh commented Dec 4, 2025

Description

The CeilDiv function, which is heavily used by operations to determine dispatch sizes, was duplicated in multiple files. This PR moves the implementation into the common WebGPU utils to ensure a single source and reduce code duplication.

Motivation and Context

See above.

@daijh
Copy link
Contributor Author

daijh commented Dec 4, 2025

@guschmue @fs-eire @qjia7 PTAL.

static_cast<uint32_t>(((new_output_shape[0] + TILE_SIZE - 1) / TILE_SIZE)));
} else {
program.SetWorkgroupSize(WORKGROUP_SIZE);
program.SetWorkgroupSize(64u);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: why not use WORKGROUP_SIZE?
In line 134, please help correct it to uint32_t output_size = onnxruntime::narrow<uint32_t>(input_shape.Size());

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reasons:

  1. Specify workgroup_size=64 explicitly improve readability.
  2. WORKGROUP_SIZE is defined as SafeInt<uint32_t>, it's not easy to cast back into uint32_t which is required by CeilDiv.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that it's not necessary to use SafeInt<uint32_t> for WORKGROUP_SIZE. WORKGROUP_SIZE is just a default value. If you are using 64 as the workgroup size, you can skip to call program.SetWorkgroupSize(64u); unless you are using a different value. Currently, a lot of ops are using the default WORKGROUP_SIZE. If you search, there should be many 'SetDispatchGroupSize((XXX + WORKGROUP_SIZE - 1) / WORKGROUP_SIZE). @fs-eire Do you think it's better to change the type of WORKGROUP_SIZE to uint32_t from SafeInt<uint32_t>? Or in all places, we explicitly specify the workgroup size.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I personally prefer to explicitly specify the workgroup_size. This practice improves code readability and saves time for developers read the source first time, as it eliminates the need to navigate to another file to figure out the default WORKGROUP_SIZE;

I have no objection if someone wishes to retain the implicit style.

@guschmue guschmue added the ep:WebGPU ort-web webgpu provider label Dec 4, 2025
@guschmue
Copy link
Contributor

guschmue commented Dec 5, 2025

/azp run Linux QNN CI Pipeline,Win_TRT_Minimal_CUDA_Test_CI,Windows ARM64 QNN CI Pipeline,Windows GPU Doc Gen CI Pipeline

@azure-pipelines
Copy link

Azure Pipelines successfully started running 4 pipeline(s).

namespace onnxruntime {
namespace webgpu {
template <typename T>

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove empty line here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for identifying it.

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.

4 participants