r/MachineLearning • • 27m ago

Project PTX Puzzles: 12 GPU synchronization bugs from real LLM megakernels and solvers, graded by a race detector [P]

I made a set of 12 puzzles while learning the PTX memory model. Each is a small kernel where blocks hand data to each other through global memory (a flag, a counter, a grid barrier, a TMA store, a spinlock), and each has a synchronization bug. Most of the bugs come from real code: Hazy Research's Llama-1B megakernel, SuperLU_DIST's triangular solve, CUTLASS Stream-K, Mirage MPK, Lucebox, and CUDA's own threadFenceReduction sample.

The catch is that most of the starters give the right answer when you run them. Your GPU doesn't reorder enough to show the bug, but the memory model allows it. So the grader runs each kernel under a race detector I wrote (syncsan, on NVBit), which reports racing accesses and, in an adversarial mode, hands racy loads the stale values the model allows. A fix passes only if it has no races and the output stays correct with stale values. It's scored by how many fences, acquires, releases and barriers you add, against a par.

It runs on Colab's free T4, no setup: https://colab.research.google.com/github/ShreshthRajan/ptx-puzzles/blob/main/puzzles.ipynb

Repo, with solutions and a paragraph on why each works: https://github.com/ShreshthRajan/ptx-puzzles

The format is borrowed from Sasha Rush's GPU Puzzles. Puzzle 8 (TMA) needs an H100 and is skipped on the T4. Feedback on puzzles that are unclear or too easy is very welcome.

1 Upvotes

0 comments sorted by