COURSE / LESSONS
CUDA from day 0 to day 100
00
Day 0
Before you start
1 lessons
01
Days 1-10
First kernels
9 lessons
- 1Your first CUDA kernel (and why it prints nothing)Why does my CUDA hello world print nothing?run logged
- 2How a GPU differs from a CPUHow is a GPU different from a CPU?run logged
- 4CUDA grid, block and thread indexing explainedHow do blockIdx, blockDim and threadIdx map a thread to an array element?run logged
- 5CUDA vector addition, end to end with error checkingHow do I write a CUDA vector addition, and why does mine run without reporting an error?run logged
- 6How to check for errors in CUDAHow do I check for errors in CUDA, and why is the error reported at the wrong line?run logged
- 7Two-dimensional grids and image kernelsHow do I launch a 2D grid in CUDA, and does x map to the row or the column?run logged
- 8Bounds checks and CUDA grid-stride loopsHow do I write a CUDA kernel that is correct for any N?run logged
- 9Why your GPU code looks slower than your CPUWhy is my CUDA code slower than my CPU?run logged
- 10How to choose threads per block and blocks per gridHow do I choose the number of threads per block and blocks per grid for a CUDA kernel?run logged
02
Days 11-20
The memory hierarchy
10 lessons
- 11CUDA memory coalescing, measuredWhat is memory coalescing in CUDA, and when does it actually matter?run logged
- 12Why transposing a matrix is slowWhy is my CUDA matrix transpose so much slower than a copy?run logged
- 13CUDA shared memory and tiling, measured on a transposeHow do I use shared memory in CUDA, and how much does tiling actually buy?run logged
- 14What __syncthreads() guaranteesWhat does __syncthreads() actually guarantee, and why does my kernel work without it?run logged
- 15Shared memory bank conflicts explainedWhat is a shared memory bank conflict, and why does adding one column fix it?run logged
- 16CUDA tiled matrix multiplication, measuredHow does tiling speed up matrix multiplication in CUDA?run logged
- 17Registers, local memory and spillsHow do I tell whether my CUDA kernel is spilling registers?run logged
- 18CUDA constant memory, measured against globalIs CUDA constant memory faster than global memory?run logged
- 19Unified memory and what it costsIs cudaMallocManaged slower than cudaMalloc?run logged
- 20CUDA image convolution and edge detectionHow do I write a fast 2D convolution in CUDA?run logged
03
Days 21-30
Warps, reductions, atomics
10 lessons
- 21What is a warp in CUDA (and why warp size is 32)What is a warp in CUDA, and why does a 48-thread block cost two warp slots?run logged
- 22Warp divergence and what it costsWhat is warp divergence in CUDA, and what does it cost?run logged
- 23__shfl_down_sync and the mask argumentWhat does the mask argument in __shfl_down_sync actually do?run logged
- 24Parallel reduction, versions 1 to 4How much is each step of the CUDA reduction ladder actually worth?run logged
- 25Optimizing a CUDA reduction to the memory ceilingHow do I make a CUDA reduction faster?run logged
- 26CUDA atomicAdd and what contention costsHow slow is atomicAdd in CUDA, and when is a reduction faster?run logged
- 27The CUDA memory model: fences, scopes and atomicsWhat does __threadfence() do in CUDA, and when do I need one?run logged
- 28CUDA cooperative groups and grid-wide syncHow do I synchronize every block in a CUDA grid?run logged
- 29CUDA histograms, privatized and measuredWhy is a CUDA histogram slow, and how does privatization fix it?run logged
- 30Arithmetic intensity and the memory-bound mindsetIs my CUDA kernel memory bound or compute bound, and how do I tell before I profile?run logged
04
Days 31-40
Parallel patterns
10 lessons
- 31CUDA prefix sum, the Hillis-Steele scanHow do I write a prefix sum in CUDA, and why does it need two shared arrays?run logged
- 32The CUDA scan algorithm: the tree and the three kernelsHow does a work-efficient CUDA scan work, and why three kernels?run logged
- 33CUDA stream compaction with a prefix sumHow do I remove elements from an array on a GPU?run logged
- 34CUDA stencils and the heat equationHow do I write a 2D stencil in CUDA, and why does my heat simulation blow up?run logged
- 35CUDA radix sort, built from the scan you already wroteHow does a radix sort work on a GPU, and why is it the sort GPUs use?run logged
- 36CUDA merge path: merging sorted arrays in parallelHow do you merge two sorted arrays in parallel on a GPU?run logged
- 37Sparse matrices in CUDA: COO, CSR and SpMVWhat is CSR, and why is my CUDA SpMV slow on some matrices?run logged
- 38Graph traversal on a GPUHow do you run a breadth-first search on a GPU, and why is one thread per vertex slow?run logged
- 39When to stop hand-writing: Thrust, CUB and libcu++Should I use Thrust and CUB or write the CUDA kernel myself?run logged
- 40PageRank on a real graph in CUDAHow do I implement PageRank in CUDA?run logged
05
Days 41-50
Profiling and optimization
10 lessons
- 41Reading an Nsight Systems timelineHow do I read an Nsight Systems timeline?run logged
- 42Reading an Nsight Compute reportHow do I read an Nsight Compute report?run logged
- 43Optimizing CUDA matmul, steps 1 to 3How do I optimize a CUDA matrix multiplication kernel?run logged
- 44Optimizing CUDA matmul, steps 4 to 6How do I get a CUDA matmul close to cuBLAS speed?run logged
- 45Occupancy is not the goalDoes higher occupancy make a CUDA kernel faster?run logged
- 46Reading PTX and SASS, and which one runsWhat is the difference between PTX and SASS in CUDA?run logged
- 47Fast math, FMA and precision, one flag at a timeWhat does -use_fast_math actually do in CUDA, and what does it cost?run logged
- 48CUDA kernel fusion and what a launch really costsWhen does fusing CUDA kernels actually make them faster?run logged
- 49Building a roofline for your GPUHow do I build a roofline model for my own GPU?run logged
- 50The CUDA performance checklist, in diagnostic orderMy CUDA kernel is slow. What do I check first?run logged
06
Days 51-60
Concurrency
10 lessons
- 51CUDA streams and overlapHow do CUDA streams overlap two kernels?run logged
- 52Events and cross-stream dependenciesHow do I make one CUDA stream wait on another?run logged
- 53Pinned memory and async copiesWhy is cudaMemcpyAsync not asynchronous?run logged
- 54Double bufferingHow does double buffering overlap CUDA copies and kernels?run logged
- 55Stream-ordered allocation and memory poolsWhat does cudaMallocAsync actually do?run logged
- 56CUDA graphsWhen do CUDA graphs actually make a program faster?run logged
- 57Graph updates and conditional nodesHow do I change a CUDA graph's parameters, and can a graph loop until convergence without the host?run logged
- 58Programmatic dependent launchWhat is programmatic dependent launch in CUDA?lesson
- 59Host threads and the GPUCan multiple CPU threads use CUDA at the same time?run logged
- 60Capstone 3: a real-time frame pipelineHow do I build a real-time video pipeline in CUDA?run logged
07
Days 61-70
Correctness and debugging
9 lessons
- 61Finding memory bugs with compute-sanitizerHow do I find out-of-bounds accesses and memory leaks in a CUDA kernel?run logged
- 62Finding races with racecheck and synccheckHow do I find a data race in a CUDA kernel?run logged
- 63Debugging a kernel with cuda-gdbHow do I debug a CUDA kernel with cuda-gdb?run logged
- 64printf, assert and when printf liesWhy does printf in my CUDA kernel print nothing?run logged
- 65Deadlocks and hangsWhy does my CUDA kernel hang, and how do I find out where?run logged
- 66Testing GPU kernelsHow do I test CUDA kernels?run logged
- 68Floating point and reproducibilityWhy does my CUDA reduction give a slightly different result every run?run logged
- 69One CUDA binary across GPU generationsHow do I build one CUDA binary that runs on every GPU generation?run logged
- 70Checkpoint: the CUDA bug catalogWhich tool catches which CUDA bug, and which bugs does no tool see?run logged
08
Days 71-80
Tensor cores and modern hardware
10 lessons
- 71Mixed precision: FP16, BF16, TF32, FP8, FP4What is mixed precision in CUDA, and why accumulate in FP32?run logged
- 72Tensor cores with WMMAHow do I use tensor cores from CUDA C++ with the WMMA API?run logged
- 73mma.sync and ldmatrixHow do I use mma.sync and ldmatrix, and do they need an Ampere GPU?run logged
- 74Async copies and pipelinesWhat is cp.async, and how does cuda::pipeline use it?lesson
- 75Asynchronous barriersWhat is cuda::barrier and how is it different from __syncthreads?lesson
- 76The Tensor Memory Accelerator (TMA)How do I load a tile with TMA in CUDA?lesson
- 77Thread block clusters and distributed shared memoryWhat are thread block clusters and distributed shared memory in CUDA?lesson
- 78Which Blackwell do you have: wgmma, tcgen05 and what your card cannot doDoes an RTX 5090 support wgmma or tcgen05?lesson
- 79Tile programming with cuTileWhat is cuTile and how do I write a tile kernel?lesson
- 80Capstone 4: a tensor-core GEMMHow do I write a CUDA GEMM that uses tensor cores?run logged
09
Days 81-90
Libraries, Python and the ML bridge
9 lessons
- 81cuBLAS and cuBLASLtHow do I call cuBLAS from C++ when my matrices are row major?run logged
- 82cuFFT, cuRAND, cuSPARSE and cuSOLVERWhich CUDA math library replaces the kernel I was about to write?run logged
- 83cuDNN with the graph APIHow do I call cuDNN's graph API for a Conv2D forward?run logged
- 84CUTLASS and CuTe layoutsWhat is CuTe, and does CUTLASS need an Ampere GPU?run logged
- 85CUDA from Python: cuda.core, CuPy, Numba and PyCUDAHow do I launch a CUDA kernel from Python?run logged
- 86Writing kernels in TritonHow do I write a CUDA kernel in Triton, and will it run on my GPU?lesson
- 87Custom PyTorch operatorsHow do I call my own CUDA kernel from PyTorch with a backward pass?run logged
- 88Profiling a PyTorch model down to the kernelHow do I profile a PyTorch model and find the slowest CUDA kernel?run logged
- 90Checkpoint: library or kernel?When should I write a custom CUDA kernel instead of calling a library?run logged
10
Days 91-100
Scale and the final capstone
10 lessons
- 91Using more than one GPUHow do I use two GPUs in one CUDA program?lesson
- 92NCCL and collective operationsHow does an NCCL all-reduce work, and why does adding GPUs not make it worse?lesson
- 93Unified memory, second passWhat does cudaMemAdvise actually do, and when does it beat a prefetch?run logged
- 94Sharing a GPU: green contexts, MPS and MIGHow do I run two CUDA workloads on one GPU without them fighting?run logged
- 95LLM kernels 1: softmax, layer norm, RMS normHow do you write a fast softmax, layer norm and RMS norm kernel in CUDA?run logged
- 96LLM kernels 2: RoPE, GELU and elementwise fusionHow do you write a RoPE and a GELU kernel in CUDA, and what does fusing them save?run logged
- 97LLM kernels 3: attention and online softmaxHow does FlashAttention compute attention without storing the N by N matrix?run logged
- 98Quantization and sparsityHow do you write an INT8 matmul in CUDA, and where does the scale go?run logged
- 99Assembling a forward and a backward passHow do you write and check a neural-network backward pass in CUDA?run logged
- 100Capstone 5: your own llm.c-liteHow do I train a neural network with CUDA kernels I wrote myself?run logged