SuperAPI AI Directory

LeetCUDA

An open-source educational repository and question bank for CUDA programming and deep learning operator optimization. Includes 200+ kernels ranging from basic to advanced (e.g., FlashAttention-2) with PyTorch bindings.

Open website

About this tool

LeetCUDA is an open-source project positioned as modern CUDA study notes and a problem set for beginners, covering topics such as BF16/FP8/FP4, HGEMM, CuTe, and Flash-Attention.

Purpose

This project is mainly used for learning and practicing CUDA programming and deep learning operator optimization. It provides a systematic learning path from basics to advanced topics, helping readers understand how to use Tensor/CUDA Cores and how to write high-performance operators.

Main Capabilities

  • 200+ CUDA kernels: The content is divided by difficulty into levels such as Easy, Medium, Hard, Hard+, and Hard++, covering operations such as element-wise, mat_trans, warp/block reduce, nms, relu, gelu, swish, layer-norm, rms-norm, online-softmax, dot-prod, and embedding, as well as advanced topics such as sgemv, sgemm, hgemv, hgemm, and flash-attention.
  • Tensor Cores implementations: Includes FlashAttention-2 implemented using pure MMA PTX instructions, supporting features such as Multi-Stages, Tile MMA, Tile Warp, Shared KV SMEM, Fully Shared QKV SMEM, Prefetch, QKV Fine-grained Tiling, and Collective Store.
  • HGEMM performance: On NVIDIA L20, RTX 4090, and RTX 3080 Laptop, the HGEMM in the repository (WMMA/MMA/CuTe) can achieve 98%~100% of the performance of cuBLAS default Tensor Cores algorithms.
  • FA2-MMA performance: For small-scale attention (B<=4, H<=48, SeqLen<=8192, D<=64), it can be faster than FA2/SDPA on some devices. For example, on RTX 3080 Laptop, the Split Q + Fully Shared QKV SMEM method can achieve 55 TFLOPS (D=64), about 1.5 times faster than FA2 ; on NVIDIA L20, the ffpa-attn method can achieve 104 TFLOPS (D=512), about 1.8 times faster than SDPA (EFFICIENT ATTENTION). For large-scale attention, there is still a performance gap, and the author says updates will continue.
  • Open-source book and documentation: Provides LeetCUDA.pdf of more than 600 pages as well as online documentation (Chinese, English).
  • Technical blogs: Includes 100+ technical blogs and recommended articles related to high-performance computing and distributed systems.
  • Agentic workflow: Provides the leetcuda-cpp-kernel SKILL, which can reuse knowledge and examples from the open-source book and repository for Coding Agents, such as GitHub Copilot, Claude Code, and Open Code.
  • Related project: ffpa-attn is a production-oriented Kernel Library that provides fast and memory-efficient exact attention for large Headdim (BF16/FP16/FP8/FP4), and is claimed to be 1.5x~15x faster than standard PyTorch SDPA.

Usage

The workflow for each topic is: custom CUDA kernel implementation -> PyTorch Python binding -> run tests. Readers can learn step by step in the order from Easy to Hard++. In the repository, * indicates Tensor Cores (WMMA, MMA, CuTe), otherwise it is CUDA Cores; / indicates not supported, ✔️ indicates supported, and ❔ indicates TODO.

Applicable Scenarios

Suitable for developers, students, and researchers who want to systematically learn CUDA programming, deep learning operator optimization, the use of Tensor Cores, and the implementation details of FlashAttention. It is also suitable as reference material for knowledge related to high-performance computing and distributed systems.

Limitations

Some content is still TODO (❔). For large-scale attention, the current implementation still has a performance gap compared with FA2/SDPA. The project uses the GNU General Public License v3.0. Other specific limitations (such as the range of hardware compatibility and complete dependency versions) are not yet provided.