Repository navigation
Description
What problem does this solve?
cuTile has no way to sort or rank the values of a tile, so a radix sort written in cuTile has to rank keys within their digit with one tile-wide scan_sum per digit value. That makes sorting much slower than thread-level code, which uses warp intrinsics (match_any_sync) that tiles don't expose.
Measured on an RTX 3060 (sm_86), CUDA 13.3, cuda-rust ad0a42c, building a set from 100M shuffled u32 keys:
| Total | Sort passes | |
|---|---|---|
| cuda-oxide (8-bit digits, warp ranking, Onesweep look-back) | 154 ms | 4 |
cuTile (3-bit digits, 8 scan_sums per pass) |
264 ms | 11, about 20 ms each, of which moving the keys is about 2 ms |
So almost all of each cuTile pass goes to ranking, not to memory traffic. Wider digits don't help, because the scans per pass grow with the number of digit values: 4-bit digits were about 15% slower than 3-bit, and 2-bit about 20% slower.
Proposed API / behavior
Names and signatures are only illustrative:
// Stable sort of a tile by key, carrying a payload tile along.
let (sorted_keys, sorted_positions): (Tile<u32, { [1024] }>, Tile<i32, { [1024] }>) =
sort_by_key(keys, positions, order::Ascending);
// Or the building block under it: each element's rank among the
// earlier elements with the same (small) key, plus the per-key counts.
let (rank, counts): (Tile<i32, { [1024] }>, Tile<i32, { [256] }>) =
rank_by_key::<256>(digit);The compiler could implement these with match.any, warp ballots and shared memory, which kernel authors can't reach from cuTile. The same primitive would help stream compaction, partitioning, histograms and group-by, not just sorting.
Possibly later: a host-level device-wide sort (like CUB's DeviceRadixSort::SortPairs) built on it.
Alternatives considered
- One
scan_sumper digit value (what we use): correct, but bound by the scans as shown above. - A one-hot tile (1,024 × 16 for 4-bit digits) with a single
scan_sumdown the keys: about 40% slower than 16 separate scans. - Writing the sort in cuda-oxide instead: fast, but gives up the tile model, which is the reason to use cuTile.
Additional context
- Prior art: CUB's
BlockRadixSort/BlockRadixRankandDeviceRadixSort, and Triton'stl.sortfor tiles. - Both engines are in range-set-blaze's
gpu-on-simdbranch:src/gpu/cutile.rs(seescatter_digits) andsrc/gpu/cuda.rs(seeradix_scatter). A step-by-step comparison is inexperiments/CUDA_VS_CUTILE.md.
AI contribution: drafted with Claude Code (Anthropic); I reviewed it and the measurements before posting.
Activity
feat(cutile): add tile-level rank-by-key and stable sort-by-key kerne…