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.
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.
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.
| Workload | Tokens | Keys per token | CUDA submission | Triton, faithful port | Triton, tuned | Triton, fused | Contest first place (Triton) |
|---|---|---|---|---|---|---|---|
| 0c23b10c | 1 | 2 | 3.6 | 8.3 | 5.8 | 3.9 | 4.8 |
| 9d4a5f21 | 2 | 14 | 4.4 | 14.3 | 5.6 | 4.2 | 5.0 |
| fc85411e | 2 | 15 | 4.4 | 14.5 | 5.7 | 4.2 | 4.9 |
| f77df5ce | 2 | 18 | 4.4 | 14.6 | 5.5 | 4.3 | 5.0 |
| 0a63b87b | 2 | 36 | 6.3 | 26.9 | 5.8 | 4.8 | 5.1 |
| b7668cfd | 2 | 42 | 6.3 | 26.8 | 5.6 | 4.9 | 5.1 |
| e6b849f2 | 2 | 70 | 8.1 | 38.6 | 8.4 | 6.5 | 7.3 |
| 9f3f891b | 2 | 146 | 19.2 | 113.1 | 17.1 | 8.0 | 14.3 |
| 05f6de65 | 2 | 171 | 23.0 | 135.1 | 19.8 | 8.1 | 16.4 |
| 68d6817d | 6 | 18 | 9.9 | 25.3 | 11.1 | 4.4 | 11.2 |
| ddfa9e34 | 6 | 291 | 50.1 | 42.3 | 14.8 | 11.0 | 11.6 |
| d57eb9e1 | 6 | 547 | 51.4 | 42.6 | 15.2 | 11.2 | 11.9 |
| 38389961 | 7 | 240 | 50.9 | 42.2 | 14.7 | 10.9 | 11.7 |
| ae4219a9 | 7 | 329 | 51.6 | 43.0 | 15.0 | 11.1 | 11.8 |
| 2207f0fd | 7 | 514 | 51.0 | 42.8 | 15.3 | 11.2 | 12.2 |
| 4c46a94b | 8 | 177 | 36.1 | 201.8 | 14.8 | 9.3 | 11.8 |
| 385742b2 | 8 | 207 | 38.2 | 204.2 | 14.8 | 10.9 | 12.0 |
| 232ed014 | 8 | 212 | 50.9 | 42.6 | 15.0 | 11.0 | 11.9 |
| 7a389715 | 8 | 220 | 51.0 | 42.5 | 14.9 | 11.2 | 11.9 |
| 02d6ae9c | 8 | 303 | 52.0 | 44.0 | 15.2 | 11.1 | 12.0 |
| 78b2e11c | 8 | 328 | 51.3 | 216.7 | 15.2 | 11.1 | 12.3 |
| 5096e459 | 8 | 564 | 51.6 | 43.1 | 15.6 | 11.6 | 12.5 |
| 564007ac | 8 | 594 | 51.9 | 43.6 | 15.7 | 11.8 | 12.5 |
| Mean | 31.6 | 63.9 | 12.5 | 8.6 | 10.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
- 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 feedtl.dot, and this kernel's dot products are element-wise sums, sonum_stageshas no effect on it. - 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 >= 8takes the per-token kernel); that shape rule was measured slightly faster than the index count. - 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.
- 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.
- 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.
- 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.
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:
- Short token (last valid position below 128): each program scores every key and accumulates 32 of the 512 output columns. Nothing is shared between programs.
- Long token: each program takes every 16th key and publishes a partial softmax. A per-token atomic counter is the barrier. When all 16 partials are in, each program merges its 32 columns from them. This replaces the second launch of split-K, so there is no gap to hide and no CUDA graph to keep.
Three things account for the gain over the tuned version:
- The path is chosen per token, not per call. Workload
68d6817dhas 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. - 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).
- 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:
- The barrier only opens if every program of the launch is on the GPU at the same time. The kernel therefore uses
16 programs per token up to 9 tokens and 8 up to 18 (a B200 has 148 SMs), and
run_fusedhands larger calls torun_tuned. The first-place kernel uses the same kind of barrier with 16 programs per token at any token count. On a synthetic 12-token call (192 programs) it did not return before the run's time limit, which is consistent with this constraint. The contest workloads stop at 8 tokens. - The partials live in one workspace per call shape, so concurrent calls from several streams would collide. The port's split-K workspace has the same property.
- The benchmark repeats one input, which would hide a merge that read partials left over from the previous call.
A separate check runs 180 synthetic calls with new contents each time, 1 to 20 tokens, padding at the
tail or scattered through the row: the largest output error is 0.0067 and the largest
lseerror is 7.6e-06.
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 release | Faithful port | Per-head kernel only | Per-token, 16-key tiles | Per-token, 64-key tiles, 3 stages | Same, graph replay |
|---|---|---|---|---|---|
| 3.4.0 | fails | fails | fails | fails | fails |
| 3.5.1 | 1.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.1 | 1.89× | 7.38× | 1.49× | 0.70× | 0.62× |
| 3.8.0 | 1.34× | 3.50× | 1.49× | 0.71× | 0.62× |
| 3.9.0 | 1.27× | 3.03× | 1.50× | 0.72× | 0.61× |
- 3.4.0 refuses to compile for CUDA 13.2, so it cannot run in the contest image.
- 3.8.0 and 3.9.0 generate a per-head kernel that is 2.2–2.6× faster. The per-token kernel takes the same GPU time in every release.
- 3.7.0, the release in the benchmark image, spends about twice as long in its Python launcher as the other releases (about 50 µs per launch against 21 µs). That widens the idle gap between the two split-K launches, so the 64-key configuration without graph replay is slower than CUDA on 3.7.0 only.
How this was measured
- One NVIDIA B200 on Modal, image
flashinfer/flashinfer-ci-cu132, CUDA 13.2, torch 2.12.0.dev20260408+cu132, Triton 3.7.0. The contest evaluated Triton 3.6.0. - The headline numbers come from the official flashinfer-bench evaluator, all solutions in one container run. Latency is the span from the first kernel's start to the last kernel's end, so Python time before the first launch is not counted and time between launches is.
- The CUDA kernel is the submission with its source split into readable headers; the algorithm and thresholds are unchanged.
- Both the CUDA kernel and the faithful port cache their dispatch decision on the address of the index tensor. When
a new workload's tensor reuses a freed address, the previous decision is applied. This sent workload
78b2e11cthrough the port's per-head kernel in the official run. The tuned entry point decides on shape only, and the fused kernel decides inside the kernel from the index row itself.
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