[Codegen] Apply bounds to subgroup_id#23768
Open
krzysz00 wants to merge 1 commit intoiree-org:mainfrom
Open
Conversation
Since we're fixing to start using subgroup_id more often with PCF, apply bounds to it based on the subgroup size (or sizes) and the number of threads in the workgroup. Also extend subgroup_size handling to account for known subgroup sizes instead of giving up completely when there isn't a fixed choice made yet. Co-Authored-By: Claude Opus 4.6 <[email protected]>
2a4b225 to
ad04bc3
Compare
amd-eochoalo
approved these changes
Mar 13, 2026
Contributor
amd-eochoalo
left a comment
There was a problem hiding this comment.
I think this looks good, but you may want to wait for other reviewers. Just one comment about the for-loop.
Comment on lines
+215
to
+229
| for (std::optional<int64_t> size : workgroupSizes) { | ||
| if (size) { | ||
| maxTotalThreads *= *size; | ||
| // Cap at the hardware thread-per-workgroup limit inside the loop | ||
| // to avoid overflow from multiplying per-dimension maximums. | ||
| if (target) { | ||
| maxTotalThreads = | ||
| std::min(maxTotalThreads, | ||
| static_cast<int64_t>( | ||
| target.getWgp().getMaxThreadCountPerWorkgroup())); | ||
| } | ||
| } else { | ||
| allSizesKnown = false; | ||
| break; | ||
| } |
Contributor
There was a problem hiding this comment.
Nit: I think this is a little bit more difficult to parse than it should be. Could we remove one level of nesting by moving the break earlier and then the else should not be necessary, right? Maybe changing the logic slightly too for calculating the maxTotalThreads when target is known and avoid overflow somehow or adding variables?
// pseudocode
Suggested change
| for (std::optional<int64_t> size : workgroupSizes) { | |
| if (size) { | |
| maxTotalThreads *= *size; | |
| // Cap at the hardware thread-per-workgroup limit inside the loop | |
| // to avoid overflow from multiplying per-dimension maximums. | |
| if (target) { | |
| maxTotalThreads = | |
| std::min(maxTotalThreads, | |
| static_cast<int64_t>( | |
| target.getWgp().getMaxThreadCountPerWorkgroup())); | |
| } | |
| } else { | |
| allSizesKnown = false; | |
| break; | |
| } | |
| // if target is available | |
| std::optional<int64_t> maxThreadCountPerWg = static_cast<int64_t> (target.getWgp().getMaxThreadCountPerWorkgroup())); | |
| for (std::optional<int64_t> size : workgroupSizes) { | |
| if (!size) { | |
| allSizesKnown = false; | |
| break; | |
| } | |
| maxTotalThreads *= *size; | |
| // Cap at the hardware thread-per-workgroup limit inside the loop | |
| // to avoid overflow from multiplying per-dimension maximums. | |
| if (maxThreadCountPerWg) { | |
| maxTotalThreads = std::min(maxTotalThreads, maxThreadCountPerWg) | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Since we're fixing to start using subgroup_id more often with PCF, apply bounds to it based on the subgroup size (or sizes) and the number of threads in the workgroup. Also extend subgroup_size handling to account for known subgroup sizes instead of giving up completely when there isn't a fixed choice made yet.
Also fix up some double-spaces in test attributes.