Skip to content

[ggml-webgpu] Implement 2D workgroups for scale, binary, and unary ops#24044

Merged
reeselevine merged 22 commits into
ggml-org:masterfrom
nikhilJain17:nikhilJain17/2d-subgroups-for-ops
Jun 8, 2026
Merged

[ggml-webgpu] Implement 2D workgroups for scale, binary, and unary ops#24044
reeselevine merged 22 commits into
ggml-org:masterfrom
nikhilJain17:nikhilJain17/2d-subgroups-for-ops

Conversation

@nikhilJain17

@nikhilJain17 nikhilJain17 commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

Overview

When running the WebGPU backend with stable-diffusion.cpp, it dispatched the following kernels with too many workgroups: scale, add, mul, silu.

Apply the same technique as #23750 to dispatch 2D workgroups to run these models.

Additional information

Tested with test-backend-ops -b WebGPU and CI suite locally.

Requirements

@github-actions github-actions Bot added ggml changes relating to the ggml tensor library for machine learning WebGPU labels Jun 2, 2026
@nikhilJain17 nikhilJain17 changed the title Nikhil jain17/2d subgroups for ops [ggml-webgpu] Implement 2D workgroups for scale, binary, and unary ops Jun 2, 2026
@nikhilJain17 nikhilJain17 marked this pull request as ready for review June 2, 2026 19:39
@nikhilJain17 nikhilJain17 requested a review from a team as a code owner June 2, 2026 19:39
let src1_i = params.offset_src1 + src1_index(gid.x);
update(params.offset_dst + gid.x, src0_i, src1_i);
fn main(@builtin(global_invocation_index) gindex: u32) {
if (gindex < params.ne) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It seems better to use global_invocation_id as is, because global_invocation_index is a wgsl extension (linear_indexing), and safari doesn't support it yet.
I reverted to using global_invocation_id in #23955.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good callout, thanks! I will update this.

@reeselevine reeselevine requested a review from CISC June 5, 2026 17:45
shader_lib_ctx.src1 = nullptr;
shader_lib_ctx.dst = dst;
shader_lib_ctx.max_wg_size = ctx->global_ctx->capabilities.limits.maxComputeInvocationsPerWorkgroup;
shader_lib_ctx.max_wg_size = ctx->global_ctx->capabilities.limits.maxComputeInvocationsPerWorkgroup;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Still conflicting versions of clang-format?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hmm, my environment (clangd 22.1.6) produces the same format changes as this PR, plus some additional format changes in this file.
@nikhilJain17 , what version of clang-format or clangd are you using? (see #23760 (comment))

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I'm on 21.1.8

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks! For reference, since the formatting output seems to differ slightly between versions 21 and 22, it might be good to use version 22 or later for future PRs.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Sounds good, will do

@reeselevine reeselevine merged commit 3b3da01 into ggml-org:master Jun 8, 2026
26 of 28 checks passed
turbo-tan pushed a commit to turbo-tan/llama.cpp-tq3 that referenced this pull request Jun 11, 2026
ggml-org#24044)

* Only run webgpu CI on my fork

* Add webgpu only workflow

* Implement 2d workgroups for more operations

* fix

* Fix type

* Move back to global_invocation_id

(cherry picked from commit 3b3da01)
adrianhoehne pushed a commit to adrianhoehne/llama.cpp that referenced this pull request Jul 5, 2026
ggml-org#24044)

* Only run webgpu CI on my fork

* Add webgpu only workflow

* Implement 2d workgroups for more operations

* fix

* Fix type

* Move back to global_invocation_id
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ggml changes relating to the ggml tensor library for machine learning WebGPU

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants