Fix workgroup reordering for large shapes#1063
Merged
Conversation
Signed-off-by: xintin <gaurav.verma@amd.com>
Signed-off-by: xintin <gaurav.verma@amd.com>
Signed-off-by: xintin <gaurav.verma@amd.com>
Collaborator
|
Could you add some lit test for this that shows the IR? |
Signed-off-by: xintin <gaurav.verma@amd.com>
harsh-nod
approved these changes
Mar 6, 2026
4047564 to
0bd999d
Compare
Signed-off-by: xintin <gaurav.verma@amd.com>
06a9196 to
1705b86
Compare
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.
In read_write.py, the split_index function splits an index expression into workgroup-independent (wg) and thread-dependent (th) parts for linearize_memref. The wg part becomes the reinterpret_cast base offset, while the th part becomes the store index.
When reorder_workgroups=True with dynamic dimensions, the output index contains Piecewise(tail_new_wg0, main_new_wg0) expressions.
After substituting WORKGROUP_0/1=0, the difference diff = src - thread_dependent_index still contains dynamic symbols (M, N, K).
The guard detects these residual symbols and falls back:
This makes the full linear address (
M_row * N + N_col) the store index, which overflows 32-bit when the output buffer exceeds ~4 GB in bytes (M*N*4 > 2**32).In the reorder_workgroups=False case, diff = block_id_x * 64 has no residual symbols (block_id_x is a wg symbol), so the split works correctly, embedding the large wg offset into the reinterpret_cast base and keeping only a small thread offset.