| # Reference implementations — read for technique |
|
|
| These are the open-source kernels that demonstrate each technique best. In a graded KBench container |
| they are **deliberately absent** (offline, restricted toolchain), so this is a map of *ideas to |
| reproduce*, not dependencies to import. Knowing how FlashAttention-3 overlaps softmax with the next |
| MMA is what transfers; the import statement is worthless. |
|
|
| ## Attention |
|
|
| | repo | what to take from it | |
| |---|---| |
| | **Dao-AILab/flash-attention** | online softmax with running max/sum; the FA2 split over the query axis so each block keeps its accumulator in registers; FA3's warp specialization (producer warps issue TMA, consumer warps do MMA) and the ping-pong schedule that hides softmax under the next GEMM | |
| | **flashinfer-ai/flashinfer** | paged KV cache attention; JIT specialization per (head_dim, page_size, causal) instead of one general kernel; cascade attention sharing a common prefix across requests; prefill/decode split | |
| | **vLLM `csrc/attention`** | the paged-attention v1/v2 split; partitioning long contexts across blocks and reducing partial softmax states | |
| | **Colfax research posts** | the clearest written derivation of Hopper WGMMA + TMA attention | |
|
|
| ## GEMM and quantization |
|
|
| | repo | what to take from it | |
| |---|---| |
| | **NVIDIA/cutlass** | CuTe layout algebra — the thing to internalize is that a layout is a function from coordinate to offset, and swizzles are layout composition; collective mainloop; TMA multicast; epilogue fusion | |
| | **deepseek-ai/DeepGEMM** | FP8 GEMM with fine-grained (block/tile) scaling; persistent warp-specialized scheduling; grouped GEMM for MoE where each expert has a different M | |
| | **Marlin / Machete (vLLM)** | W4A16: weight layout repacking done *once* offline so the inner loop dequantizes with minimal ALU work; how to interleave nibbles so unpacking is a few shifts | |
| | **pytorch/ao** | reference semantics for int8/int4/fp8 scaling granularities — per-tensor vs per-row vs per-block | |
|
|
| ## Fusion and training kernels |
|
|
| | repo | what to take from it | |
| |---|---| |
| | **linkedin/Liger-Kernel** | chunked fused linear+cross-entropy: never materialize the full `[B*T, vocab]` logits — the single biggest memory win in LLM training; fused RMSNorm/SwiGLU/RoPE with recompute in backward | |
| | **triton-lang tutorials** | fused softmax, matmul with autotuning, persistent matmul — the idiomatic Triton patterns | |
| | **HazyResearch/ThunderKittens** | tile abstraction over registers and shared memory; shows how little code a Hopper kernel needs when tiles are the primitive | |
|
|
| ## Sequence models |
|
|
| | repo | what to take from it | |
| |---|---| |
| | **fla-org/flash-linear-attention** | chunked linear attention; the delta rule and gated variants (KDA, GatedDeltaNet) expressed as a chunk-parallel recurrence — sequential scan becomes a sequence of GEMMs via a WY-like representation | |
| | **state-spaces/mamba**, **causal-conv1d** | selective scan as a work-efficient parallel scan kept entirely in SRAM | |
|
|
| ## Distributed |
|
|
| | repo | what to take from it | |
| |---|---| |
| | **NVIDIA/TransformerEngine** | fp8 recipes and amax history; comm/compute overlap for TP | |
| | **NVSHMEM-based MoE dispatch (DeepEP)** | all-to-all expert dispatch/combine overlapped with expert compute | |
|
|
| ## How to read a kernel you have never seen |
|
|
| 1. Find the **inner loop** and ask what stays in registers across iterations. |
| 2. Find where data is **staged** (global → shared → register) and what overlaps that staging. |
| 3. Find the **layout/swizzle** — usually where the cleverness is. |
| 4. Only then read the setup and epilogue. |
|
|