Skip to content
Merged
Show file tree
Hide file tree
Changes from 115 commits
Commits
Show all changes
138 commits
Select commit Hold shift + click to select a range
bbb8ace
fix: replace deprecated griddepcontrol PTX with CUDA PDL device APIs
ishovkun Jun 8, 2026
9a6c853
triton: add persistent IS_DYNAMIC kernel and update SSU checkpointing…
ishovkun Jun 8, 2026
14bb2c3
fix: restore runtime is_write gating in persistent SSU Triton reference
ishovkun Jun 9, 2026
165f3a4
feat: varlen support on the 5D persistent SSU path + migrate tests to 5D
ishovkun Jun 9, 2026
0285d1c
test: migrate M6-M8 (upstream-ported Triton-vs-PyTorch tests) to the …
ishovkun Jun 9, 2026
2eb0f7a
bench: add triton-replay row (5D persistent path) alongside increment…
ishovkun Jun 9, 2026
97fb2f8
bench: wire triton-replay (persistent_dynamic + persistent_main) to t…
ishovkun Jun 9, 2026
556dac6
feat: port varlen (IS_VARLEN) into the faithful TMA standalone + star…
ishovkun Jun 9, 2026
13f1b8c
test: parametrize checkpointing SSU tests across non_tma / tma_pd / t…
ishovkun Jun 10, 2026
ad8d233
bench: per-kernel CUPTI timeline + conv1d total-span; add conv1d/AL deps
ishovkun Jun 10, 2026
4601d89
feat(ssu): caller-provided scratch args (two-kernel dispatch) + xfail…
ishovkun Jun 10, 2026
1788fa9
feat(ssu): precompute-kernel prototype + fragA-native scratch contract
ishovkun Jun 10, 2026
16bdd13
refine: ssu precompute warp-per-head control flow
ishovkun Jun 10, 2026
1f5d8ae
feat(ssu): lean precompute SmemT + fp32 CB (precision fix)
ishovkun Jun 11, 2026
bbeb98c
feat(ssu): precompute raw C·B MMA (compute_cb_2warp)
ishovkun Jun 11, 2026
c42dcc0
fix(ssu): swizzle the fp32 precompute CB (SmemSwizzle<float>)
ishovkun Jun 11, 2026
a58ff62
feat(ssu): wire precompute loads + scale/decay store
ishovkun Jun 11, 2026
cec7591
refine(ssu): load_dt (drop _pw) + DT_SOFTPLUS as a template arg
ishovkun Jun 11, 2026
9d6627a
feat(ssu): precompute conditionally computes CB_old (C6, no-write)
ishovkun Jun 11, 2026
80ec866
refine(ssu): move WAR syncwarp inside has_head (after the reads)
ishovkun Jun 11, 2026
e546c4e
refine(ssu): WAR syncwarp inside scale_store, right after the reads
ishovkun Jun 11, 2026
f09066d
feat(ssu): precompute C6 gmem write (CB_old) + C7 tape + dedup old load
ishovkun Jun 11, 2026
3770266
feat(ssu): precompute owns old_B writeback + header
ishovkun Jun 11, 2026
9efb02c
refactor(ssu): scratch stores raw cumAdt (decay_vec -> cumAdt_vec)
ishovkun Jun 11, 2026
dd7e0c0
feat(ssu): parameterize output path on READ_PRECOMPUTED_CB + K-aware …
ishovkun Jun 11, 2026
2470cd5
feat(ssu): forward READ_PRECOMPUTED_CB through ssu_checkpoint/nocheck…
ishovkun Jun 11, 2026
7926238
feat(ssu): main kernel (S4) — consumer of precompute scratch
ishovkun Jun 11, 2026
17ab202
feat(ssu): S5 launcher + plumbing for the two-kernel path
ishovkun Jun 11, 2026
4212097
feat(ssu): two-kernel split passes T0 (bit-exact vs monolithic)
ishovkun Jun 11, 2026
fe90bb7
docs(ssu): drop PROTOTYPE header — precompute/main validated vs monol…
ishovkun Jun 11, 2026
d27fd12
feat(ssu): S7 bench --two-kernel (default on) for the cuda-incr path
ishovkun Jun 11, 2026
fbb70f2
refine(ssu): bench shows monolithic + two-kernel as separate rows (on…
ishovkun Jun 11, 2026
957f901
refine(ssu): bench skips cuda-incr-2k for non-2-byte state
ishovkun Jun 11, 2026
4bea7d4
perf(ssu): main runs load + state replay before gdc_wait (overlap pre…
ishovkun Jun 11, 2026
70db3ee
perf(ssu): head-tile precompute + gate/dedup main loads — two-kernel …
ishovkun Jun 12, 2026
4e73bfb
perf(ssu): ENABLE_PDL-gated PHASE-1 hoist + wire cuda-incr-2k into mi…
ishovkun Jun 12, 2026
16d9f4f
perf(ssu): precompute load pipeline — fire PDL first, hoist old_B pre…
ishovkun Jun 15, 2026
f768130
perf(ssu): co-residency-aware head-tiling heuristic (size precompute …
ishovkun Jun 15, 2026
34102e7
refine(ssu): bench --output-prefix "-" skips CSV/PNG write
ishovkun Jun 15, 2026
0b9d582
feat(ssu): head-tiled MAIN + tunable main/precompute heads-per-CTA ha…
ishovkun Jun 16, 2026
147892c
bench(mamba): add Nemotron Ultra SSU varlen benchmark + enable ratio=32
ishovkun Jun 16, 2026
aa52443
perf(ssu): lean MAIN smem storage + compile-time IS_FIRST peel + iden…
ishovkun Jun 16, 2026
fbf63eb
refine(ssu): bench_ssu_checkpoint_mixed --tag weaves a version into t…
ishovkun Jun 16, 2026
357a9f0
perf(ssu): cap MAIN at __maxnreg__(64) → 8 resident blocks/SM
ishovkun Jun 16, 2026
2e05ab6
refactor(ssu): extract precompute PHASE-1 into load_phase1_coeffs + _…
ishovkun Jun 17, 2026
e488413
perf(ssu): precompute 8 warps/CTA (hc=8 default) — 2x occupancy, half…
ishovkun Jun 22, 2026
d323567
fix(bench): finalize CUPTI once after the sweep, not per timing call
ishovkun Jun 22, 2026
022f094
refactor(ssu): make the main NUM_WARPS-generic + per-warp store_state…
ishovkun Jun 23, 2026
b42a931
perf(ssu): load conv1d C/x once (x->W0, C->W1) instead of per-warp re…
ishovkun Jun 23, 2026
94b9271
perf(ssu/main): hoist D/cumAdt loads, warp-0 cumAdt write, fix STAGES…
ishovkun Jun 24, 2026
c2508c2
perf(ssu/main): STAGES=2 bug fixes + MHC/DS heuristics for large-batc…
ishovkun Jun 24, 2026
7c8ef3a
perf(ssu/main): batch-prefetch cumAdt + cut per-head barriers (no-wri…
ishovkun Jun 25, 2026
a298e9a
perf(ssu/main): CTA-wide x load to balance warps (no-write 51.5->50.7µs)
ishovkun Jun 25, 2026
4e9127f
perf(ssu/main): CTA-wide old_x + z loads (finish warp rebalance)
ishovkun Jun 25, 2026
833db40
perf(ssu/main): predicate old_x to prev_k + split across warps (no-wr…
ishovkun Jun 25, 2026
9d2758c
bench(ssu): clamp prev_k to max_window, not mtp_len
ishovkun Jun 25, 2026
5f572f0
perf(ssu/main): persistent grid-stride main; ditch MHC/STAGES knobs
ishovkun Jun 25, 2026
9e1c5ac
perf(ssu/main): template NGROUPS for division-free unflatten (b1024 1…
ishovkun Jun 26, 2026
a0084b6
perf(ssu/main): register-resident meta ring over depth-2 state pipeli…
ishovkun Jun 27, 2026
e829c35
perf(ssu/main): prev_k in meta + CB A-operand via smem cp.async (b102…
ishovkun Jun 27, 2026
7a39bd3
perf(ssu/main): load_cumAdt_async (pipe=2 cumAdt off the synchronous …
ishovkun Jun 27, 2026
d6395f1
perf(ssu/main): hoist D_val into head_meta (off the synchronous outpu…
ishovkun Jun 29, 2026
56186ac
perf(ssu/main): cp.async the old_cumAdt β-tail (no-write barrier lagg…
ishovkun Jun 29, 2026
39540c3
docs(ssu/main): diagnose no-write gap as index-math, not matmuls (+ s…
ishovkun Jun 29, 2026
c5788dd
perf(ssu/main): hand-roll C@state A-operand LDSM with hoisted swizzle…
ishovkun Jun 29, 2026
1cb566e
perf(ssu/main): compute C@state byteoffA via explicit swizzle closed …
ishovkun Jun 30, 2026
f560035
perf(ssu/main): 2-way accumulator split in C@state k-loop
ishovkun Jun 30, 2026
754de9a
docs(ssu/main): record exact executed-instruction count vs triton (no…
ishovkun Jun 30, 2026
ba3539d
perf(ssu/main): hoist C@state byteoffA to head_loop + lift reg cap to…
ishovkun Jun 30, 2026
506cd1e
revert(ssu/main): drop byteoffA hoist (dead end), keep only reg-cap 128
ishovkun Jun 30, 2026
c4ca6b7
perf(ssu/main): fold inner address offsets to 32-bit (-1us no-write)
ishovkun Jun 30, 2026
f453785
perf(ssu): operand-swap C@state -> state=A operand, [DIM,NPRED] output
ishovkun Jul 2, 2026
33b4c75
bench(ssu): PNAT-absolute x-axis, prev_k->pnat rename, default d_split=1
ishovkun Jul 2, 2026
988d1b1
docs(ssu/main): operand-swap landing notes + bench/ncu run recipes
ishovkun Jul 2, 2026
512e9f1
perf(ssu/main): smem meta ring for per-unit metadata (-2.8% no-write)
ishovkun Jul 2, 2026
69cae8c
perf(ssu/main): register meta queue over the smem ring (-0.6us no-write)
ishovkun Jul 2, 2026
687032f
docs(ssu/main): meta-pipeline landing notes (smem ring + register que…
ishovkun Jul 2, 2026
e5e9dca
perf(ssu/main): hoist beta_extra above CB frag loads (wall-flat, -7 r…
ishovkun Jul 2, 2026
e19f05f
perf(ssu/main): NUM_STAGES=1 default — occupancy regime, triton-pm pa…
ishovkun Jul 2, 2026
7de75da
docs(ssu/main): v32 ncu results (63.4us, walls re-aligned) + split-pi…
ishovkun Jul 2, 2026
d877589
fix(ssu/main): f16 state in the two-kernel path (convert, not reinter…
ishovkun Jul 2, 2026
cc34d6e
test(ssu): two-kernel path under the real f16+philox validation suite
ishovkun Jul 2, 2026
6a953f7
feat(ssu/main): f32 state cache on the two-kernel path
ishovkun Jul 7, 2026
df8c797
bench(ssu): admit f32 state on the cuda-incr-2k rows
ishovkun Jul 7, 2026
7673207
docs(ssu/main): f32 LANDED entry + mio-throttle root-cause + STAGES=2…
ishovkun Jul 7, 2026
96067d7
test(ssu): mixed write/no-write batch on the f32 two-kernel path
ishovkun Jul 7, 2026
04504ba
docs(ssu/main): mixed-batch decomposition + REVERTED slot-order exper…
ishovkun Jul 7, 2026
fa12db9
perf(ssu): cp.async.cg for the read-once state prefetch
ishovkun Jul 7, 2026
db2c6ae
docs(ssu/main): wide-A handroll REJECTED (sliced-layout lesson) + .cg…
ishovkun Jul 7, 2026
9c8c131
docs(ssu): monolith operand-swap REJECTED + small-batch standings + j…
ishovkun Jul 7, 2026
cf9802c
test(ssu): session-scoped JIT pre-warm — one ninja graph for the URI …
ishovkun Jul 7, 2026
12e6592
perf(ssu): auto mono/2k dispatch + launcher {stages,cps} regime table
ishovkun Jul 9, 2026
95fa5a6
perf(ssu): SM-scale the precompute head-tiling boundary
ishovkun Jul 9, 2026
fc86fcc
perf(ssu): varlen row geometry through the packed meta ring
ishovkun Jul 9, 2026
33b0860
bench(ssu): varlen (cu_seqlens) A/B mode for the mixed bench
ishovkun Jul 9, 2026
6e3ca41
docs(ssu): varlen residual ncu attribution + precompute cu-hoist REJE…
ishovkun Jul 9, 2026
3691de5
bench(ssu): --varlen for the uniform bench CLI
ishovkun Jul 9, 2026
af8bf0e
docs(ssu): v34 write/no-write varlen ncu split — instruction-side mai…
ishovkun Jul 9, 2026
00e504b
bench(ssu): let --varlen compose with --with-conv1d
ishovkun Jul 9, 2026
5b810cd
fix(ssu): per-slot branch-mismatch early exit in the triton reference
ishovkun Jul 9, 2026
dae63c4
refactor(ssu): share the operand-swap output helpers in common.cuh
ishovkun Jul 9, 2026
6308c35
perf(ssu): monolith adopts the operand-swapped output ([DIM, t] fragm…
ishovkun Jul 9, 2026
d72c979
refactor(ssu): remove the old 4D checkpointing_state_update triton ke…
ishovkun Jul 10, 2026
b26f634
docs(ssu): B300 pre-ring baselines — 2k lead grows, SR anomaly backbu…
ishovkun Jul 10, 2026
2f16daf
refactor(ssu)!: triton reference speaks the ring-buffer cache contract
ishovkun Jul 10, 2026
9aba34d
refactor(ssu): rename ring_len -> ring_buffer_len in the ring reference
ishovkun Jul 10, 2026
333e827
fix(tests): prewarm builds each JIT spec through its own ninja db
ishovkun Jul 11, 2026
752194d
feat(ssu)!: CUDA kernels + API adopt the ring-buffer cache contract
ishovkun Jul 11, 2026
398213e
refactor(bench): checkpointing-SSU bench speaks the ring contract
ishovkun Jul 11, 2026
d95f489
docs(ssu): ring stage-5 parity — monolith clean, 2k regression attrib…
ishovkun Jul 11, 2026
4bb398f
perf(ssu): 2k ring path to parity — cumAdt_old scratch + zfill gather
ishovkun Jul 13, 2026
8c1a6bf
fix(mamba): enable hardware cvt.rs stochastic rounding on B300 (sm_103a)
ishovkun Jul 13, 2026
3d424a6
Remove verbose implementation comments from SSU kernel headers
ishovkun Jul 14, 2026
f31a5ba
Merge remote-tracking branch 'upstream/main' into ssu_replay_opt
ishovkun Jul 14, 2026
ab3a7c3
chore(ssu): drop lab notebooks + bench CSV (local-only, not for upstr…
ishovkun Jul 14, 2026
fe502a5
Fix Perron vector sign in markov_stationary
ishovkun Jul 14, 2026
080685c
Add shape/dtype validation for two-kernel scratch buffers
ishovkun Jul 14, 2026
54d24a1
Replace hardcoded benchmark output paths with env var
ishovkun Jul 14, 2026
5d16c98
Replace `.view()` with `.reshape()` for non-contiguous tensors
ishovkun Jul 14, 2026
5466277
Add conv and ring cache fields to `_build_tensors` docstring
ishovkun Jul 14, 2026
27b733f
Remove `main_heads_per_cta` knob from SSU checkpointing
ishovkun Jul 14, 2026
bca6867
Remove forward declaration of launchCheckpointingSsu
ishovkun Jul 14, 2026
f321288
Remove fi-replay kernel from mixed benchmark
ishovkun Jul 14, 2026
e7ff6c4
Revert "bench(mamba): add Nemotron Ultra SSU varlen benchmark + enabl…
ishovkun Jul 15, 2026
9a40ee6
Merge remote-tracking branch 'upstream/main' into ssu_replay_opt
ishovkun Jul 15, 2026
cd2859c
Add ngroups validation check in checkpointing SSU launcher
ishovkun Jul 15, 2026
099061d
Add CUDA error checking in launchCheckpointingSsuImpl
ishovkun Jul 15, 2026
0373d09
Skip fp16 Philox SR test when cvt.rs unsupported
ishovkun Jul 15, 2026
7e0d6d5
Fix benchmark output parsing to require 9 columns
ishovkun Jul 15, 2026
fe27f5e
Update `cb_scaled` and `cb_old` docstrings with layout details
ishovkun Jul 15, 2026
f60759e
Fix SM arch string: SM110a → SM103a in skip reasons
ishovkun Jul 15, 2026
26e0246
Read env vars per launch instead of once at static init
ishovkun Jul 15, 2026
1cbb557
Use current device for SM version detection
ishovkun Jul 15, 2026
6271eed
Remove unused `output_head` device function
ishovkun Jul 15, 2026
4ee5d0c
Refactor mamba conftest to use pytest collection hook
ishovkun Jul 16, 2026
072c934
Fix prewarm variant tuples missing num_groups field
ishovkun Jul 17, 2026
2663d82
Fix PDL race: load cumAdt_old scratch after gdc in persistent main
ishovkun Jul 20, 2026
a3b7224
Remove `cumAdt_old` scratch from two-kernel SSU split
ishovkun Jul 21, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,223 changes: 865 additions & 358 deletions benchmarks/bench_checkpointing_ssu.py

Large diffs are not rendered by default.

233 changes: 233 additions & 0 deletions benchmarks/bench_mamba_ssu.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,233 @@
#!/usr/bin/env python3
"""
Benchmark selective_state_update (varlen) for NVIDIA-Nemotron-3-Ultra-550B-A55B.

Model config (TP=8 slice of the full Ultra model):
mamba_num_heads=256 → nheads=32 per TP rank
mamba_head_dim=64
n_groups=8 → ngroups=1 per TP rank
ssm_state_size=128
mamba_ssm_cache_dtype=float32 (state is fp32)
io dtype: bfloat16

Usage:
uv run python benchmarks/bench_mamba_ssu.py
uv run python benchmarks/bench_mamba_ssu.py --backends flashinfer triton
uv run python benchmarks/bench_mamba_ssu.py --mtp-len 4
"""

import argparse
import sys
import os

import torch

# routines/ lives next to this file
sys.path.insert(0, os.path.dirname(__file__))

from routines.mamba import parse_mamba_args, run_mamba_test

# ---------------------------------------------------------------------------
# Nemotron Ultra full-model config
# ---------------------------------------------------------------------------
NHEADS_FULL = 256
NGROUPS_FULL = 8
HEADDIM = 64
DSTATE = 128

BATCH_SIZES = [1, 8, 16, 32, 64, 128, 256, 512]


def make_args(
batch_size,
mtp_len,
backends,
no_cuda_graph,
num_iters,
dry_run_iters,
nheads,
ngroups,
state_dtype="float32",
philox_rounds=0,
):
"""Build the args namespace expected by run_mamba_test."""
import argparse as _ap

shared_parser = _ap.ArgumentParser(add_help=False)
shared_parser.add_argument("--routine", type=str, default="selective_state_update")
shared_parser.add_argument("--verbose", "-v", action="count", default=0)

line = [
"--routine",
"selective_state_update",
"--batch_size",
str(batch_size),
"--nheads",
str(nheads),
"--dim",
str(HEADDIM),
"--dstate",
str(DSTATE),
"--ngroups",
str(ngroups),
"--cache_steps",
str(mtp_len),
"--input_dtype",
"bfloat16",
"--state_dtype",
state_dtype,
"--weight_dtype",
"float32",
"--dt_softplus",
"--varlen",
"--philox-rounds",
str(philox_rounds),
"--backends",
] + backends

args = parse_mamba_args(line, shared_parser)

# Shared benchmark knobs (normally set by flashinfer_benchmark.py)
args.no_cuda_graph = no_cuda_graph
args.use_cupti = False
args.use_cuda_events = True
args.refcheck = False
args.allow_output_mismatch = False
args.random_seed = 42
args.verbose = 0
args.output_path = (
"_collect" # non-None triggers result collection in run_mamba_test
)
args.num_iters = num_iters
args.dry_run_iters = dry_run_iters
args.autotune_cache = None
args.case_tag = f"nemotron_ultra_b{batch_size}_mtp{mtp_len}"
args.generate_repro_command = False
args.repro_command = ""

return args


def _print_table(results, backends):
"""Print a summary table: rows = batch sizes, columns = backends."""
# Gather: {batch -> {backend -> median_us}}
from collections import defaultdict

data = defaultdict(dict)
for r in results:
data[r["batch_size"]][r["backend"]] = r["median_time"] * 1e3 # ms → µs

has_both = "flashinfer" in backends and "triton" in backends

# Header
print("=" * 70)
print("Summary")
print("=" * 70)
header = f" {'batch':>6}"
for b in backends:
header += f" {b + ' (µs)':>16}"
if has_both:
header += f" {'speedup':>8}"
print(header)
print(" " + "-" * (len(header) - 2))

for batch in BATCH_SIZES:
if batch not in data:
continue
row = f" {batch:>6}"
for b in backends:
us = data[batch].get(b, float("nan"))
row += f" {us:>16.1f}"
if has_both:
fi = data[batch].get("flashinfer", float("nan"))
tr = data[batch].get("triton", float("nan"))
speedup = tr / fi if fi > 0 else float("nan")
row += f" {speedup:>7.2f}x"
print(row)
print()


def main():
parser = argparse.ArgumentParser(
description="Benchmark Mamba SSU for Nemotron Ultra"
)
parser.add_argument(
"--backends",
nargs="+",
default=["flashinfer", "triton"],
choices=["flashinfer", "triton"],
)
parser.add_argument(
"--tp",
type=int,
default=8,
help="Tensor parallel size (divides nheads and ngroups). Default: 8",
)
parser.add_argument(
"--mtp-len",
type=int,
default=1,
help="Tokens per sequence (max_seqlen / cache_steps). Default: 1",
)
parser.add_argument(
"--state-dtype",
default="float32",
choices=["float32", "float16", "bfloat16"],
help="State cache dtype. Default: float32",
)
parser.add_argument(
"--philox-rounds",
type=int,
default=0,
help="Philox stochastic rounding rounds (0=disabled, requires fp16 state)",
)
parser.add_argument(
"--cuda-graph",
action="store_true",
help="Enable CUDA graph timing (off by default: as_strided "
"tensors are incompatible with buffer rotation)",
)
parser.add_argument("-n", "--num-iters", type=int, default=30)
parser.add_argument("-d", "--dry-run-iters", type=int, default=5)
args = parser.parse_args()

nheads = NHEADS_FULL // args.tp
ngroups = max(1, NGROUPS_FULL // args.tp)

print("=" * 70)
print("Mamba selective_state_update — Nemotron Ultra")
print("=" * 70)
print(f" Device : {torch.cuda.get_device_name()}")
print(f" TP : {args.tp}")
print(
f" nheads : {nheads} headdim: {HEADDIM} dstate: {DSTATE} ngroups: {ngroups}"
)
print(f" mtp_len : {args.mtp_len} (tokens/seq)")
philox_str = f" + philox-{args.philox_rounds}" if args.philox_rounds > 0 else ""
print(f" state : {args.state_dtype}{philox_str} io: bfloat16 varlen: yes")
print(f" backends: {args.backends}")
print()

all_results = []
for batch in BATCH_SIZES:
bench_args = make_args(
batch_size=batch,
mtp_len=args.mtp_len,
backends=args.backends,
no_cuda_graph=not args.cuda_graph,
num_iters=args.num_iters,
dry_run_iters=args.dry_run_iters,
nheads=nheads,
ngroups=ngroups,
state_dtype=args.state_dtype,
philox_rounds=args.philox_rounds,
)
print(f"batch={batch}")
all_results.extend(run_mamba_test(bench_args))
print()

_print_table(all_results, args.backends)


if __name__ == "__main__":
main()
Loading
Loading