Repository navigation
feat(dialect): add warp shuffle words - #150
Merged
Merged
Conversation
SHFL-DOWN, SHFL-UP, SHFL-XOR, and SHFL-IDX move one i64 stack cell across a warp. The memref pass emits gpu.shuffle of that cell at width 32, and the NVVM pass splits it into two shfl.sync instructions with a full mask. LANE-ID reads %laneid. WARP-SIZE is the constant 32.
A shuffle fold of the same partials was correct and not faster. On one RTX 2070, 50 paired samples, noise floor 2%: reduce_sum_f64 moved 1140 us to 1137 us (no change), and attention_f32 moved 1188 us to 1222 us (slower). The trees stay. Comments no longer say the word set has no warp shuffle.
Bench compare against
|
| case | verdict | ratio | mad | base | head | gap |
|---|---|---|---|---|---|---|
| scale_i64 | no change | 1.000 | 0.000 | 272.4 us | 272.4 us | 1.01x |
| axpy_f64 | no change | 1.000 | 0.000 | 403.1 us | 403.1 us | 1.01x |
| reduce_sum_f64 | no change | 1.000 | 0.000 | 448.5 us | 448.5 us | 1.64x |
| matmul_f64_naive | no change | 1.000 | 0.000 | 43.1 us | 43.1 us | 1.49x |
| matmul_f64_tiled | no change | 1.000 | 0.000 | 343.0 us | 343.0 us | 1.61x |
| attention_f32 | no change | 1.000 | 0.000 | 1189.5 us | 1189.5 us | 9.31x |
- Base:
5a239604c9262f265372be8b60b5ef02995c2ead - Head:
86c7e5e25ad5c77a98b298916ac73a2d6ebf7913 - Rental:
6e076ac49014a41d64330330f0e48900, driver 13.2, SM clock 2460 MHz, memory clock 8501 MHz,sm_89
cursor
Bot
force-pushed
the
cursor/warp-shuffle-words-7f40
branch
from
November 9, 2026 12:40
b56e26f to
f8ef969
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.
Why
Forth kernels need to move one stack cell between lanes of a warp without a shared-memory round trip. Issue #10 asks for
SHFL-DOWN,SHFL-UP,SHFL-XOR,SHFL-IDX, plusLANE-IDandWARP-SIZE.What
forth.shufflecarries the mode. The memref pass emitsgpu.shuffleof the i64 cell at width 32, and the selector is masked to the low five bits.convert-gpu-to-nvvmsplits that into twoshfl.syncinstructions with mask0xFFFFFFFF.LANE-IDisgpu.lane_id.WARP-SIZEis the constant 32.A colon word that only shuffles inlines. The pipeline test pins the four modes,
%laneid, and no leftover.func.Benchmarks
The shared trees in
reduce_sum_f64andattention_f32were rewritten to warp folds, compiled with the samewarpforthc, and timed on one RTX 2070 (50 paired samples, harness noise floor 2%). Head is the shuffle fold, base is the tree.reduce_sum_f64attention_f32Both rewrites matched the case reference. They are not in the tree. The reduce kernel reads 8 MiB in 1.14 ms, about 7.4 GB/s, so the grid-stride loop dominates the fold. Comments no longer say the word set has no warp shuffle.
Checked
check-warpforth: 142 tests.check-clang-tidyafter the dialect change.SHFL-IDXbroadcast, partial-warp max and sum, block reduce at 64 and 256, andLANE-IDon a 16×4 block. The rental was destroyed on exit.Open
gpu.shuffleis Pure, and the optimize window runs ongpu.func. No current pass moves a Pure op across a branch. A later one could hoist a shuffle out of a divergent region, which is undefined. The op itself stays trait-free so a Forth pass will not speculate it. The full mask on a partial warp was measured on this one GPU, where an 8-thread block returned the right cells.