xlite-dev/LeetCUDA
An Open-source book with Modern CUDA learning Notes for Beginners - BF16/FP8/FP4, HGEMM, CuTe, Flash-Attention, etc.
What it solves
Writing fast GPU (CUDA) code is notoriously hard: modern tricks like Tensor Cores, MMA instructions, and memory tiling are poorly documented and intimidating. LeetCUDA is an open-source, structured learning book that walks you from simple kernels to advanced, near-production ones — so you can understand and write high-performance CUDA instead of just calling libraries.
How it works
It is a book-plus-repository of CUDA kernels organized by difficulty (Easy, Medium, Hard, Hard+, Hard++). Each topic follows a fixed workflow: write a custom CUDA kernel, wrap it with PyTorch Python bindings, then run tests. Easy and Medium sections cover basic operations (element-wise math, matrix transpose, reductions, activations like ReLU/GELU, layer-norm, embedding) for FP32/FP16/BF16/FP8 data types. Harder sections dive into GEMM (sgemm/hgemm) and FlashAttention, implemented with Tensor Cores using pure MMA PTX instructions. The HGEMM kernels reach 98–100% of cuBLAS performance on several NVIDIA GPUs, and the FlashAttention-2 variants (Split KV, Split Q, shared SMEM, fine-grained tiling) can beat FA2/SDPA on small-scale attention. The project also ships a "SKILL" that coding agents (GitHub Copilot, Claude Code, Open Code) can install to reuse the book's knowledge. Everything is available as a 600+ page PDF and online docs in Chinese and English.
Who it's for
Developers learning CUDA/GPU programming who want a step-by-step path from basics to advanced Tensor-Core kernels, plus anyone who wants to understand how high-performance GEMM and FlashAttention are actually built. It also helps people who use coding agents and want CUDA expertise injected into their agent's workflow.
Highlights
- 200+ CUDA kernels progressing from easy to very hard, each with tests and PyTorch bindings
- HGEMM kernels achieving 98–100% of cuBLAS TFLOPS on NVIDIA L20, RTX 4090, and RTX 3080 Laptop
- FlashAttention-2 built on Tensor Cores with pure MMA PTX, including Split KV/Q, shared SMEM, and fine-grained tiling variants
- FP8 and FP4 GEMM support
- Fine-grained tiling that extends the attention head dimension up to 1024
- 600+ page open-source book (PDF) plus online docs in Chinese and English
- Agentic workflow: a SKILL for coding agents (GitHub Copilot, Claude Code, Open Code)
- Production-ready ffpa-attn kernel library with 1.5x–15x speedup over standard PyTorch SDPA
Related
- Project
- Dispatch
- Project
- Project
- Project