Skip to content

cuTile: tile-level sort / rank-by-key primitive (and maybe a device radix sort) #1658

Open

Description

@CarlKCarlK

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_sum per 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_sum down 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

AI contribution: drafted with Claude Code (Anthropic); I reviewed it and the measurements before posting.

Activity

  1. added
    enhancement
    TBD
    on Oct 27, 2026
  2. added
    cutile-rs
    on Nov 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    TBDcutile-rsenhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions