DSA sparse attention on B200: CUDA vs Triton

MLSys 2026 FlashInfer contest kernel dsa_sparse_attention_h16_ckv512_kpe64_topk2048_ps64 · 23 contest workloads · NVIDIA B200 · Triton 3.7.0

Translating the CUDA submission to Triton line for line makes it 2.04× slower. Keeping the same Triton kernels and changing four settings makes it 1.86× faster than the CUDA submission (0.54× its latency). A new Triton kernel that splits and merges inside a single launch is 2.70× faster (0.37×). For scale, the kernel that won the contest track is also Triton and runs at 0.45× in the same run. Every version passes all 23 workloads. The same kernel in TileLang and ThunderKittens is timed on the same workloads in four frameworks, side by side, and that page sets the fused kernel next to the contest winner.

CUDA submission
31.6 µs
mean latency, the baseline
The contest kernel: hand-written CUDA with WMMA, cp.async and a CUDA-graph cache.
Triton, faithful port
2.04×
CUDA latency (geomean) · 63.9 µs mean · faster on 10 of 23
The same dispatcher and the same two kernels, translated one to one.
Triton, tuned
0.54×
CUDA latency (geomean) · 12.5 µs mean · faster on 17 of 23
The port's per-token kernel with larger tiles, pipelined loads and graph replay.
Triton, fused
0.37×
CUDA latency (geomean) · 8.6 µs mean · faster on 22 of 23
A new kernel: one launch, the programs of a token split its keys and merge at a barrier.
Contest first place (Triton)
0.45×
CUDA latency (geomean) · 10.2 µs mean · faster on 18 of 23
Doğaç Eldenk's winning kernel, run here as a reference.

Latency on every workload

Each row is one contest workload, ordered by token count and by the average number of valid keys per token (the rest of the 2,048 top-k slots are padding). Further left is faster; the axis is logarithmic.

CUDA submissionTriton, faithful portTriton, tunedTriton, fusedContest first place (Triton)
2 µs4 µs8 µs16 µs32 µs64 µs128 µs256 µsworkloadtokenskeys0c23b10c12CUDA submission: 3.6 µsTriton, faithful port: 8.3 µsTriton, tuned: 5.8 µsTriton, fused: 3.9 µsContest first place (Triton): 4.8 µs9d4a5f21214CUDA submission: 4.4 µsTriton, faithful port: 14.3 µsTriton, tuned: 5.6 µsTriton, fused: 4.2 µsContest first place (Triton): 5.0 µsfc85411e215CUDA submission: 4.4 µsTriton, faithful port: 14.5 µsTriton, tuned: 5.7 µsTriton, fused: 4.2 µsContest first place (Triton): 4.9 µsf77df5ce218CUDA submission: 4.4 µsTriton, faithful port: 14.6 µsTriton, tuned: 5.5 µsTriton, fused: 4.3 µsContest first place (Triton): 5.0 µs0a63b87b236CUDA submission: 6.3 µsTriton, faithful port: 26.9 µsTriton, tuned: 5.8 µsTriton, fused: 4.8 µsContest first place (Triton): 5.1 µsb7668cfd242CUDA submission: 6.3 µsTriton, faithful port: 26.8 µsTriton, tuned: 5.6 µsTriton, fused: 4.9 µsContest first place (Triton): 5.1 µse6b849f2270CUDA submission: 8.1 µsTriton, faithful port: 38.6 µsTriton, tuned: 8.4 µsTriton, fused: 6.5 µsContest first place (Triton): 7.3 µs9f3f891b2146CUDA submission: 19.2 µsTriton, faithful port: 113.1 µsTriton, tuned: 17.1 µsTriton, fused: 8.0 µsContest first place (Triton): 14.3 µs05f6de652171CUDA submission: 23.0 µsTriton, faithful port: 135.1 µsTriton, tuned: 19.8 µsTriton, fused: 8.1 µsContest first place (Triton): 16.4 µs68d6817d618CUDA submission: 9.9 µsTriton, faithful port: 25.3 µsTriton, tuned: 11.1 µsTriton, fused: 4.4 µsContest first place (Triton): 11.2 µsddfa9e346291CUDA submission: 50.1 µsTriton, faithful port: 42.3 µsTriton, tuned: 14.8 µsTriton, fused: 11.0 µsContest first place (Triton): 11.6 µsd57eb9e16547CUDA submission: 51.4 µsTriton, faithful port: 42.6 µsTriton, tuned: 15.2 µsTriton, fused: 11.2 µsContest first place (Triton): 11.9 µs383899617240CUDA submission: 50.9 µsTriton, faithful port: 42.2 µsTriton, tuned: 14.7 µsTriton, fused: 10.9 µsContest first place (Triton): 11.7 µsae4219a97329CUDA submission: 51.6 µsTriton, faithful port: 43.0 µsTriton, tuned: 15.0 µsTriton, fused: 11.1 µsContest first place (Triton): 11.8 µs2207f0fd7514CUDA submission: 51.0 µsTriton, faithful port: 42.8 µsTriton, tuned: 15.3 µsTriton, fused: 11.2 µsContest first place (Triton): 12.2 µs4c46a94b8177CUDA submission: 36.1 µsTriton, faithful port: 201.8 µsTriton, tuned: 14.8 µsTriton, fused: 9.3 µsContest first place (Triton): 11.8 µs385742b28207CUDA submission: 38.2 µsTriton, faithful port: 204.2 µsTriton, tuned: 14.8 µsTriton, fused: 10.9 µsContest first place (Triton): 12.0 µs232ed0148212CUDA submission: 50.9 µsTriton, faithful port: 42.6 µsTriton, tuned: 15.0 µsTriton, fused: 11.0 µsContest first place (Triton): 11.9 µs7a3897158220CUDA submission: 51.0 µsTriton, faithful port: 42.5 µsTriton, tuned: 14.9 µsTriton, fused: 11.2 µsContest first place (Triton): 11.9 µs02d6ae9c8303CUDA submission: 52.0 µsTriton, faithful port: 44.0 µsTriton, tuned: 15.2 µsTriton, fused: 11.1 µsContest first place (Triton): 12.0 µs78b2e11c8328CUDA submission: 51.3 µsTriton, faithful port: 216.7 µsTriton, tuned: 15.2 µsTriton, fused: 11.1 µsContest first place (Triton): 12.3 µs5096e4598564CUDA submission: 51.6 µsTriton, faithful port: 43.1 µsTriton, tuned: 15.6 µsTriton, fused: 11.6 µsContest first place (Triton): 12.5 µs564007ac8594CUDA submission: 51.9 µsTriton, faithful port: 43.6 µsTriton, tuned: 15.7 µsTriton, fused: 11.8 µsContest first place (Triton): 12.5 µs
Median latency per call from the official flashinfer-bench timing (CUPTI kernel span, L2 cache flushed before each call, 5 warm-up and 50 timed calls).

On the smallest calls the CUDA kernel and the fused Triton kernel are level (3.6–6.3 µs against 3.9–4.9 µs; tuned Triton takes 5.5–5.8 µs). On the dense workloads, where most of the time goes, the CUDA kernel averages 51.2 µs, tuned Triton 15.2 µs and fused Triton 11.2 µs.

WorkloadTokensKeys per tokenCUDA submissionTriton, faithful portTriton, tunedTriton, fusedContest first place (Triton)
0c23b10c123.68.35.83.94.8
9d4a5f212144.414.35.64.25.0
fc85411e2154.414.55.74.24.9
f77df5ce2184.414.65.54.35.0
0a63b87b2366.326.95.84.85.1
b7668cfd2426.326.85.64.95.1
e6b849f22708.138.68.46.57.3
9f3f891b214619.2113.117.18.014.3
05f6de65217123.0135.119.88.116.4
68d6817d6189.925.311.14.411.2
ddfa9e34629150.142.314.811.011.6
d57eb9e1654751.442.615.211.211.9
38389961724050.942.214.710.911.7
ae4219a9732951.643.015.011.111.8
2207f0fd751451.042.815.311.212.2
4c46a94b817736.1201.814.89.311.8
385742b2820738.2204.214.810.912.0
232ed014821250.942.615.011.011.9
7a389715822051.042.514.911.211.9
02d6ae9c830352.044.015.211.112.0
78b2e11c832851.3216.715.211.112.3
5096e459856451.643.115.611.612.5
564007ac859451.943.615.711.812.5
Mean31.663.912.58.610.2

Latency in µs; the fastest entry in each row is bold. Largest absolute output error over all workloads: CUDA submission 0.0156, Triton, faithful port 0.0156, Triton, tuned 0.0156, Triton, fused 0.0156, Contest first place (Triton) 0.0156 (tolerance 0.05). Passed: 23/23, 23/23, 23/23, 23/23, 23/23.

Why the line-for-line port is slower

  1. The per-head kernel is 3–6× slower in Triton. It costs about 6.2 µs per 16-key tile against about 0.9 µs in CUDA. The CUDA kernel double-buffers its gather loads with cp.async; Triton only pipelines loads that feed tl.dot, and this kernel's dot products are element-wise sums, so num_stages has no effect on it.
  2. The dispatch thresholds are tuned for CUDA. In this run, workloads averaging fewer than 210 valid keys per token go to the per-head kernel. That is 12 of the 23 workloads: CUDA's cheapest path and Triton's most expensive one. The CUDA source now uses the token count instead (T >= 8 takes the per-token kernel); that shape rule was measured slightly faster than the index count.
  3. The per-token kernel is already faster in Triton. The 10 dense workloads that reach it take 42.2–44.0 µs in the port against 50.1–52.0 µs in CUDA.
  4. 16-key tiles are the wrong size for Triton. One loop iteration costs 4–5 µs almost regardless of how many keys it holds, so 64-key tiles with pipelined loads cut the cost per key several times over.
  5. Split-K is two Python launches. The GPU idles between the partial kernel and the merge kernel while Python prepares the second launch. The CUDA submission replays both from one CUDA graph.
  6. Small calls have a higher floor. The smallest call takes 5.3–6.9 µs in Triton against 3.6 µs in CUDA.

From the port to the tuned version

Each bar is one configuration of the same Triton file used for every workload, as geomean latency relative to the CUDA kernel. Left of the dashed line is faster than CUDA.

0.5×CUDA = 1.0×1.5×2×Per-head kernel for every workload7.38×Faithful port: CUDA dispatch, 16-key tiles1.89×Per-token kernel for every workload, 16-way split1.64×+ 64-key tiles1.15×+ pipelined loads (num_stages=2)1.13×+ both launches replayed from one CUDA graph0.62×Same with 128-key tiles0.59×Fused kernel: split and merge in one launch0.37×
Configuration sweep on one B200 with the same timing method (10–20 timed calls per point). The first bar is off the scale at 7.38×.

The tuned entry point, run_tuned, uses the per-token kernel for every workload with 64-key tiles and num_stages=3. One or two tokens run as a single kernel with no split. More tokens split the top-k axis 16 ways and replay the two launches from a CUDA graph.

One launch: the fused kernel

run_fused is a different kernel, not a setting of the port. It launches once, with 16 programs per token. Every program first scans its token's index row for the last valid position, and all 16 then take the same path:

Three things account for the gain over the tuned version:

  1. The path is chosen per token, not per call. Workload 68d6817d has 6 tokens with at most 32 keys each. The tuned version and the first-place kernel both split it because of its token count and take 11.1 µs and 11.2 µs. The fused kernel takes 4.4 µs.
  2. The tile is sized to the work. A tile costs about as much as its size whether its slots hold keys or padding: the smallest call takes 4.2 µs with a 32-slot tile, 5.1 µs with 64 slots and 6.0 µs with 128. Both paths therefore pick the smallest of the three that covers the token. The 2 two-token workloads whose longer token has 288–337 keys went from 10.5 µs to 8.0–8.1 µs this way (19.2–23.0 µs in CUDA, 14.3–16.4 µs for first place).
  3. Every tile is written as a loop, even a single one. Triton pipelines loads only inside a loop. The same 64-slot tile as straight-line code took 7.2 µs instead of 5.2 µs.

On a dense workload the fused kernel takes about 11 µs. Runs with parts of the kernel switched off put roughly 3 µs in the launch, the query load and the row scan, 4 µs in the 128-key tile, 2 µs in publishing and merging the partials, and 1.5 µs in the barrier. These are estimates from differences between runs.

Limits:

Triton releases

The port and tuned configurations on seven Triton releases, as geomean latency relative to the CUDA kernel (the CUDA medians are taken from the sweep run on the same GPU model). The fused kernel was only run on 3.7.0.

Triton releaseFaithful portPer-head kernel onlyPer-token, 16-key tilesPer-token, 64-key tiles, 3 stagesSame, graph replay
3.4.0failsfailsfailsfailsfails
3.5.11.85×7.14×1.52×0.76×0.64×
3.6.0 (contest)1.86×7.32×1.48×0.69×0.61×
3.7.0 (benchmark image)1.89×7.38×1.64×1.15×0.62×
3.7.11.89×7.38×1.49×0.70×0.62×
3.8.01.34×3.50×1.49×0.71×0.62×
3.9.01.27×3.03×1.50×0.72×0.61×

How this was measured

modal run scripts/compare_cuda_triton.py      # official benchmark, all solutions
modal run scripts/profile_triton.py           # configuration sweep
modal run scripts/profile_triton.py --configs "fn=run_fused" --stress 180   # fused kernel, with synthetic checks
modal run scripts/profile_triton.py --versions "3.6.0,3.9.0" --configs "auto;token,16,8,64,3,graph"
python scripts/build_triton_report.py         # rebuild this page