syncsan
Finds data races in GPU megakernels and shows what each one does to your output.
Downloads & Community Adoption
Health & Engineering Analysis (5 Pillars)
1. Governance & Community100 / 200 ▾
2. PEP Metadata & Packaging200 / 200 ▾
3. Security & Supply Chain150 / 200 ▾
4. Documentation, SEO & Ecosystem105 / 200 ▾
5. Engineering, CI & Quality165 / 200 ▾
Official Documentation & Usage Guide — syncsan
Show full original documentation (English README) ▾
syncsan
syncsan finds data races in GPU megakernels. It runs your CUDA program unchanged under
NVBit and reports every pair of memory accesses that no barrier, fence,
release/acquire or async-copy wait puts in order. With SYNCSAN_ADVERSARIAL=1 it also hands each racy load the stale
value the PTX memory model allows, so you can see what the race does to your output.
Megakernels need this more than most code. They run a whole model in one launch and pass activations between SMs through counters in global memory. A missing fence in one of those handoffs rarely fails on today's GPUs, so it survives testing.
Quick start
You need Linux, an NVIDIA GPU from the A100 onward, and CUDA 12.
pip install syncsan
syncsan build --arch 90 # once; use 100 for B200, 120 for RTX 50xx, 80 for A100
syncsan run -- python generate.py
To see it work before pointing it at your own code, try examples/handoff.cu. It is the most common megakernel bug in 30 lines: one block writes data, fences and bumps a counter, and another block spins on the counter and reads the data with no fence after the spin.
$ nvcc -arch=sm_90 -lineinfo -o handoff examples/handoff.cu
$ ./handoff
sum = 32896 (expected 32896): correct
$ syncsan run -- ./handoff
syncsan: RACE (write then read) at 0x7ef8ffe00300
block 1 warp 2: STG.E desc[UR6][R2.64], R5 ; [handoff(unsigned int*, int*, int*)+0x1e0 handoff.cu:15]
block 0 warp 2: LDG.E R2, desc[UR6][R2.64] ; [handoff(unsigned int*, int*, int*)+0x120 handoff.cu:26]
sum = 32896 (expected 32896): correct
$ SYNCSAN_ADVERSARIAL=1 syncsan run -- ./handoff
sum = 0 (expected 32896): WRONG
The kernel gives the right sum on the GPU, syncsan points at the write on line 15 and the read on line 26, and
adversarial mode shows the wrong sum the memory model allows. Rebuild with -DFIXED, which adds the fence after the
spin, and syncsan reports nothing. Build your own kernels with -lineinfo so the reports name source lines.
--kernel NAME checks only the kernels whose name contains NAME, --exitcode 1 makes a race fail your CI
(example workflow), and --sample k checks one in k plain accesses when the full
check is too slow. syncsan run --help lists the rest.
What it has found
The clearest case is SuperLU_DIST. A commit that fixed a dropped fence in its GPU triangular solve restored the consumer's acquire but left out the producer's release. syncsan flagged the producer's decrement, and in adversarial mode the solve came back with an error of 0.7. On the fixed commit the error is 6e-15. The maintainers confirmed it and fixed it the same day (xiaoyeli/superlu_dist#261).
In Hazy Research's Llama-1B megakernel, activations move between SMs
through a TMA store, a relaxed atomicAdd on a counter and a volatile spin, with no gpu-scope fence. syncsan
reports 25 racing pairs, and in adversarial mode the model stops making sense (H100, 8 tokens):
| Build | Mode | Output |
|---|---|---|
| original | native | "Why did the cookie go to the" |
| original | adversarial | "iteriteriter abstractجرineronde" |
| original | control | "Why did the cookie go to the" |
| release/acquire counters | adversarial | "Why did the cookie go to the" |
The control run redirects the same loads but hands them their current values, so the redirection itself is not what
breaks the output. This race also fails on real hardware. When silu_out is filled with NaN before each step, the
original megakernel reads the NaN in all 1,000 generations and the fixed one in none. Making the counters
release/acquire fixes it at a 9% latency cost
(HazyResearch/Megakernels#16).
The other finds:
- AutoMegaKernel waits with
atomicAdd(c, 0), which a comment calls an acquire but PTX treats as relaxed. In adversarial mode its own--verifycheck fails (RightNow-AI/AutoMegaKernel#6). - megakernel-zoo and Lucebox
release correctly but spin on a
volatileload with no fence after it. In both, the adversarial output is garbage and a fence after the spin fixes it (dangxingyu/megakernel-zoo#3, Luce-Org/lucebox#1075). - Mirage MPK's argmax reduction has no barrier between warp 0 reading the per-warp maxima and the other warps writing the next row's (mirage-project/mirage#843).
- Magni VM had an admission race that 3,200 passing test runs never hit (Bobliuuu/mvm#97).
- On CUTLASS 3.6.0, syncsan finds the known Stream-K race from issue #2027, and it finds nothing in the fixed 3.7.0.
Each one has a write-up in docs/findings and a script in reproduce that reruns it on a rented GPU. The summary of every run is in results.
What it checks
syncsan follows the PTX memory model for global memory between thread blocks and for shared memory between warps,
including mbarriers and the Hopper and Blackwell copy engine (TMA, cp.async.bulk, cp.async). It does not check
races between lanes of one warp, distributed shared memory, or ordering across kernels and streams. It is slow: a
4-token decode of the Hazy megakernel takes 54 s under syncsan and 14 s without it.
docs/how-it-works.md describes the model and its limits, and
docs/prior-work.md compares syncsan with Barracuda, iGUARD, SuperCollider and compute-sanitizer.
Tests
tests/run_tests.sh sm_90 runs 51 cases with known answers on a local GPU. tests/cuhadron adds six
cross-block synchronization tests to NVIDIA's cuHadron race benchmark.
License
Apache 2.0. To cite syncsan, see CITATION.cff.