Skip to content

nki(radix_sort): NKI (Trainium) implementation - #296

Open
bowencui123 wants to merge 5 commits into
mainfrom
bowen/nki/radix_sort
Open

bowencui123 wants to merge 5 commits into
mainfrom
bowen/nki/radix_sort

Conversation

@bowencui123

@bowencui123 bowencui123 commented Aug 29, 2026

Copy link
Copy Markdown
Collaborator

NKI (AWS Trainium) implementation of radix_sort, split out of the consolidated NKI branch cecilia/feature/nki-vector-add (nki-all-operators, #259) so each operator can be reviewed independently. Supersedes #226 (older per-operator branch: legacy neuronxcc.nki imports; this is the migrated import nki version).

Files: A benchmarks/operators/radix_sort/impl_nki.py, M benchmarks/operators/radix_sort/impl_torch.py

Status: imports and exposes run()/get_last_config() on trn2 (nki 0.6.0); not individually re-benchmarked in this split

Implementation by @Cecilia123li. Timing/identity infrastructure: #261; Trainium peak/roofline infra: #262.

🤖 Generated with Claude Code

https://claude.ai/code/session_012Q38kGmXvyoeM1qtCbheSL

Autotune (11f19c5)

NKI tunables Triton counterpart note
block_size (elements per partition block S) BLOCK_SIZE timing proxy: one radix pass; end-to-end profiling of this multi-graph operator is a framework follow-up

autotune=False keeps the previous constants (default numbers unchanged). Validation on trn2, case 0 (default run + autotune code path with the candidate timer stubbed — no sweep; --autotune runs a real sweep):

# initial run
[radix_sort] default : verify=OK (283s) 
[radix_sort] autotune: verify=OK (1020s) last_config={'block_size': 256} trace_records=1 
STUB_EXIT=0
  NKI FAILED: profile worker failed: NkiArtifactIdentityError: 2 valid NKI (marker-bearing) NEFF/HLO pairs found — artifact identity is ambiguous
Params      |    Dtype |  Torch(ms) |      NKI(ms) |  Speedup(N)
n=1000000   | int32    |        nan |          nan |        0.00

Split out of the consolidated NKI branch cecilia/feature/nki-vector-add
(nki-all-operators, PR #259) so each operator can be reviewed on its own.
Supersedes PR #226 (older per-operator branch).
- run() calls mark_step() per radix pass -> several compiled graphs; the exact-identity profiler (PR #261) refuses to time a fragment (nki_ms=nan) until multi-graph aggregation lands
- also carries the operator's `impl_torch.py` change from the NKI branch

Co-Authored-By: Cecilia123li <68335867+Cecilia123li@users.noreply.github.com>
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012Q38kGmXvyoeM1qtCbheSL
bowencui123 and others added 2 commits August 29, 2026 08:37
Tunables mirror the Triton search space (`BLOCK_SIZE`); defaults are the previous constants,
so autotune=False is unchanged. timing proxy: one radix pass; end-to-end profiling of this multi-graph operator is a framework follow-up

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012Q38kGmXvyoeM1qtCbheSL
…ming note

- impl_torch replaced torch.sort globally with a bitonic where-network,
  which would have silently changed the B200 GPU baseline too. Now only
  the XLA device (where XLA `sort` is NCC_EVRF029-unsupported on trn2)
  takes the network; CPU/CUDA keep torch.sort — the CPU reference and the
  frozen GPU numbers are untouched.
- impl_nki still carried the pre-#309 note that the profiler times a
  single pass; the runtime-trace framework sums every graph a timed run()
  executes, so NKI(ms) covers the whole 16-pass sort.

Validated on trn2 (runtime-trace framework, n=1e6 int32, warmup 2 /
repeat 10): NKI default 327.85 ms and autotune 327.72 ms (winner
block_size=1024 = default; per-pass proxy timed 3 candidates), 17 graphs
per iteration summed; the torch-on-Neuron baseline now verifies and times
(2625.4 ms, one graph) instead of nan -> speedup 8.01x.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011Wvs1tztZTGQFD78YdZaha
@bowencui123

Copy link
Copy Markdown
Collaborator Author

Review pass (Bowen's assignment): Triton/cuTile alignment + scaffold removal + real autotune & default runs on trn2 (post-#309 runtime-trace timing framework, case 0, --warmup 2 --repeat 10; autotune numbers come from a real selector sweep replayed by the profile worker).

#296 radix_sort — CHANGES PUSHED

🤖 Generated with Claude Code

https://claude.ai/code/session_011Wvs1tztZTGQFD78YdZaha

bowencui123 and others added 2 commits August 31, 2026 04:39
Code is AST-identical to the previous commit (verified); the design notes
live in the PR review comments and git history.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011Wvs1tztZTGQFD78YdZaha
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants