CUDA Kernels
Write CUDA C++ kernels and run them against correctness tests on real GPU hardware.
What you will learn
CUDA is NVIDIA's platform for writing programs that run on the GPU. In this plan you write 35 CUDA C++ kernels in six sections, from element-wise operations to matrix operations, reductions, convolutions and ML building blocks, ending with a tiled matrix multiply.
Prerequisites
Basic C or C++ syntax and comfort with arrays and loops. No GPU experience is needed: the first section introduces threads and blocks with simple element-wise kernels.
The sections, in order
- Kernel foundations: vector addition and subtraction, and activations such as ReLU, sigmoid, tanh, softmax, GELU and Swish.
- Matrix operations: addition, transpose, multiplication, outer and Hadamard products, matrix-vector products, LayerNorm and RMSNorm.
- Reductions: dot product, sum, L1 and L2 normalization, mean and variance, min, max, argmin and argmax.
- Convolutions: 1D, 2D and 3D convolution and 2D max pooling.
- ML primitives: cross-entropy loss, dropout, scaled dot-product attention and cosine similarity.
- Performance: tiled matrix multiplication using shared memory.
How the GPU tests work
Each kernel runs on real GPU hardware and is checked against correctness tests. Each section ends with a short quiz on the concepts behind the kernels.
Where to go next
Write the same kernels at a higher level with the Triton study plan, then apply them to model serving in the Inference Engineering study plan.