Skip to content

Optimize RMSNorm with block-parallel kernels - #20

Merged
feitreim merged 1 commit into
mainfrom
perf/block-parallel-rmsnorm
Jul 17, 2026
Merged

feitreim merged 1 commit into
mainfrom
perf/block-parallel-rmsnorm

Conversation

@feitreim

Copy link
Copy Markdown
Owner

Summary

  • replace the model's per-element RMSNorm forward and input-backward kernels with 256-thread block-per-row reductions
  • fuse row inverse-factor generation into input backward, removing three standalone kernel launches
  • tile the weight-gradient reduction over 256-row chunks and atomically accumulate one partial per column/chunk
  • retain the naive kernels as parity oracles and test partial row/column tiles
  • record the completed optimization and same-container result in SPEC.md

Root cause

The old forward and input-backward kernels launched one thread per output element, but every thread rescanned all D features. At N=32,768, D=1,536, this made both paths O(N*D^2) and consumed about 252 ms of the step before weight-gradient time.

The optimized kernels cooperatively calculate each row's reductions once and then write strided columns, reducing the work to O(N*D).

Performance

B200, same-container baseline/candidate comparison at B=32, T=1024, D=1536:

Area Baseline Candidate Speedup
Three norm forwards 88.34 ms 0.38 ms 232.8x
Input backward + inverse 163.77 ms 0.45 ms 367.2x
Weight backward 15.88 ms 0.25 ms 62.7x
All norm rows 267.99 ms 1.08 ms 248.4x
Full step 751.93 ms 485.19 ms 1.55x (-35.5%)

Non-norm rows were essentially unchanged.

Validation

  • ./run.sh llama-ops: CPU -> naive GPU -> optimized GPU parity passed on B200
    • test shape N=259, D=261 crosses both 256-wide row and column boundaries
  • ./run.sh llama-model: full forward/backward and AdamW CPU parity passed
  • tiny-batch GPU overfit passed (1.540382 -> 0.000002)
  • BASELINE_REF=acc8ce4a7e39b9e6e501e597f74b9949da1538c6 ./run.sh llama-model profile: same-container performance gate passed
  • git diff --check passed

SANITIZE=synccheck ./run.sh llama-ops cannot build because cuda-oxide's legacy NVVM sanitizer target rejects the pre-existing atomic embedding kernel (atomic read-modify-write operations); normal Blackwell PTX builds and execution pass.

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.

1 participant