Skip to content

fix: use y-first approach in Compute.calcDispatchSize to minimize wasted workgroups#8538

Merged
mvaligursky merged 1 commit intomainfrom
mv-compute-dispatch-y-first
Mar 19, 2026
Merged

fix: use y-first approach in Compute.calcDispatchSize to minimize wasted workgroups#8538
mvaligursky merged 1 commit intomainfrom
mv-compute-dispatch-y-first

Conversation

@mvaligursky
Copy link
Contributor

@mvaligursky mvaligursky commented Mar 19, 2026

Summary

  • Replace sqrt-based 2D dispatch calculation in Compute.calcDispatchSize with a y-first approach: y = ceil(count / maxDimension), x = ceil(count / y).
  • The previous sqrt approach (x = floor(sqrt(count))) balanced dimensions but didn't account for maxDimension, potentially producing x > maxDimension when count is large.
  • The new approach wastes at most y - 1 workgroups while guaranteeing both dimensions stay within maxDimension.

…ted workgroups

Replace sqrt-based 2D dispatch calculation with y-first approach:
y = ceil(count / maxDimension), x = ceil(count / y). This wastes at most
y-1 workgroups (typically 0-1) instead of potentially many more with the
sqrt approach which doesn't account for the maxDimension limit.

Made-with: Cursor
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

Updates Compute.calcDispatchSize to avoid exceeding the per-dimension workgroup limit by switching from a sqrt-based 2D dispatch size calculation to a y-first calculation based on maxDimension.

Changes:

  • Replaced sqrt-based x/y sizing with y = ceil(count / maxDimension), x = ceil(count / y)
  • Aims to reduce wasted workgroups while staying within the device’s max workgroup dimension

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

@mvaligursky mvaligursky merged commit d7f5710 into main Mar 19, 2026
12 checks passed
@mvaligursky mvaligursky deleted the mv-compute-dispatch-y-first branch March 19, 2026 15:14
mvaligursky added a commit that referenced this pull request Mar 19, 2026
…ted workgroups (#8538)

Replace sqrt-based 2D dispatch calculation with y-first approach:
y = ceil(count / maxDimension), x = ceil(count / y). This wastes at most
y-1 workgroups (typically 0-1) instead of potentially many more with the
sqrt approach which doesn't account for the maxDimension limit.

Made-with: Cursor

Co-authored-by: Martin Valigursky <mvaligursky@snapchat.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants