Repository navigation
fix(cutile-compiler): emit the caller's scan dim and identity - #1809
Open
robertream wants to merge 2 commits into
Open
robertream wants to merge 2 commits into
robertream wants to merge 2 commits into
Conversation
robertream
force-pushed
the
fix/scan-dim-identity
branch
from
November 13, 2026 19:51
92b5544 to
739606f
Compare
Author
|
Added GPU execution tests on top: prefix-sum values along dim 0 and dim 1 of an [8, 16] tile, a dim-1 reverse (suffix-sum) scan, and reduce_sum along both axes, each checked against a host oracle. The whole gpu_execution_ops suite (the 8 existing tests plus these 2) passes on an A10G (sm_86) with this fix applied. The compile-level test pins the emitted attributes; these pin the executed values, which is the only way to catch a wrong-axis scan since scans preserve shape. |
compile_scan_op hardcoded dim=0 and identities=[0], silently ignoring the dim and identity arguments of scan_sum and scan. A scan along any non-leading dimension of a multi-dimensional tile therefore computed the wrong axis: scan_sum(onehot, 1, ...) on a [K, N] tile scanned down K and returned the operand effectively unscanned, with no compile-time signal since scans preserve shape. Parse the dim argument like the reduce intrinsics do (integer literals and const generics via parse_expr_as_i32), reject out-of-range dims with a JIT error, and carry the caller's numeric identity literal into the identities attribute with the element's type. The closure reduce form still reduces along dimension 0 only: honoring its dim needs a result-shape change to its public signature (it is declared -> Tile<E, S>), which is a separate change. The reduce_* intrinsics already honored dim and are unaffected. Test-first: compile_scan_sum_2d_dim1_test fails against the old lowering with "scan ... dim=0 ... identities=[0]" and passes with this fix. Signed-off-by: Robert Ream <[email protected]>
The scan dim fix so far had only a compile-level check that the right IR is emitted. Add GPU execution tests asserting values: prefix sums along dim 0 and dim 1 of an [8, 16] tile, a dim-1 reverse (suffix-sum) scan, and reduce_sum along both axes, each against a host oracle. Scans preserve shape, so only executed values can catch a wrong-axis scan. All pass on an A10G (sm_86) together with the existing execution suite. Signed-off-by: Robert Ream <[email protected]>
robertream
force-pushed
the
fix/scan-dim-identity
branch
from
November 17, 2026 17:59
962ca39 to
831c4a1
Compare
robertream
added a commit
to robertream/cuda-rust
that referenced
this pull request
Nov 17, 2026
…ls (NVIDIA#1658) Add cutile_kernels::sort with three single-tile-block kernels for [N] tiles of u32 keys in [0, K), N and K powers of two: - rank_by_key_probe: each element's rank among earlier elements with the same key, plus per-key counts, via a one-hot [N, K] matrix: one inclusive prefix sum down N yields within-key ranks, reductions yield counts and per-element selections. - rank_by_key_loop: the same contract computed with one [N] prefix sum per key value, the formulation NVIDIA#1658's radix sort shipped with. Kept for A/B timing and for K large enough that the one-hot working set fails Tile IR assembly (N * K = 32768 i32 elements on sm_86). - sort_by_key: a stable counting sort composing the one-hot core with an exclusive scan of the counts and a pointer-tile scatter, carrying an i32 payload. Each layer is tested against an independent host oracle (tests are written outside-in: a Rust stable sort for sort_by_key, an exact rank reference plus structural invariants for the probe), so a bug in one cannot be masked by the other. All five GPU tests pass on an A10G (sm_86). An opt-in paired benchmark (cutile::bench::do_bench_paired) measured the one-hot core 11-15% faster than per-key scans at 1024x8, 1024x16, and 512x32, which is why it backs the production entries. Both formulations are scan-bound baselines: the issue's intended fix is a compiler primitive on match.any and warp ballots that kernel code cannot express. These kernels pin down the API and the correctness oracles for it. Builds on the scan dim/identity fix (NVIDIA#1809): the one-hot core scans along dim 0 so it is correct under the pre-fix compiler too, but the kernels' tests exercise the fixed semantics. Signed-off-by: Robert Ream <[email protected]>
This branch has not been deployed
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.
compile_scan_ophardcodeddim=0andidentities=[0], silently ignoring thedimandidentityarguments ofscan_sumandscan. A scan along any non-leading dimension of a multi-dimensional tile therefore computed the wrong axis, with no compile-time signal since scans preserve shape. Found while building the #1658 rank-by-key kernels:scan_sum(onehot, 1, ...)on a[K, N]tile scanned down K, every within-key rank came back 0, and all equal keys scattered to the same slot. Confirmed on an A10G (sm_86) before the fix and re-verified green after it.This parses the
dimargument the way the reduce intrinsics do (integer literals and const generics, viaparse_expr_as_i32), rejects out-of-range dims with a JIT error instead of a panic, and carries the caller's numeric identity literal into theidentitiesattribute with the element's type. Non-literal identities report a clear error.Written test-first:
compile_scan_sum_2d_dim1_test(incutile/tests/reduce_scan_ops.rs) fails against the old lowering withscan ... dim=0 ... identities=[0]emitted for adim=1,identity=7call, and passes with this change. The fullreduce_scan_opssuite passes; existing in-tree scans all usedim=0with identity zero, so their emitted IR is unchanged.The closure
reduceform has the same hardcoded attributes plus a result-type problem and is tracked separately in #1808; thereduce_*intrinsics were never affected.