GPU kernels (simulated) practice problems
23 problems · 0 solved
GPU programming is about keeping thousands of small cores busy while moving as little data as possible. Most slow kernels are slow because they wait on memory, not because they run out of compute. These problems simulate GPU behaviour in plain Python, so you can learn the rules without needing a GPU. Picture a warp as a row of workers who must all do the same step at once; anything that splits them up wastes time. You will count memory transactions for a warp's loads, measure warp divergence from branch outcomes, count shared-memory bank conflicts, calculate SM occupancy from threads, registers and shared memory, predict attainable FLOPs with the roofline model, compare global loads for naive and tiled matmul, simulate a parallel tree reduction and a work-efficient prefix sum, and implement online softmax, the trick inside FlashAttention. Start with the Easy problems on the roofline model, reductions and memory transactions. Then do occupancy and tiled matmul, and finish with prefix sums, bank conflicts and online softmax. Kernel and inference optimisation skills are in high demand, and interviewers often test these exact concepts.
Easy 8
- Simulate a parallel tree reduction
- Count memory transactions for a warp's global loads
- Predict attainable FLOPs with the roofline model
- Measure warp divergence from branch outcomes
- Launch an elementwise kernel with the right grid size and bounds check
- Count the work each thread does in a grid-stride loop
- Measure wave quantization of a tiled kernel
- Estimate memory traffic saved by fusing elementwise kernels
Medium 10
- Count global memory loads for naive vs tiled matmulPro
- Calculate SM occupancy from threads, registers and shared memoryPro
- Reduce a warp with butterfly XOR shufflesPro
- Find the argmax with a parallel tree reduction and lowest-index tiesPro
- Simulate a warp-per-row matrix-vector kernelPro
- Merge split-KV partial attention resultsPro
- Compute a matmul with split-K partial sumsPro
- Count atomic serialization in a warp-level histogramPro
- Map program ids to tiles with grouped ordering for cache reusePro
- Merge per-thread mean and variance statistics in a blockPro