What is a GPU kernel?
Introduction
Project introduction
What is a GPU kernel?
A kernel is a function that runs on the GPU. Instead of calling it once, you launch many copies of it at the same time, and each copy, called a program, works on its own piece of the data. The only thing that tells programs apart is their program id.
Triton is a language for writing kernels in Python. Instead of thinking about single threads, each Triton program works on whole blocks of numbers at once. It loads a block from memory, does math on it, and stores a block back.
Why write a matrix multiply yourself?
A GPU can do math much faster than it can fetch numbers from its main memory. An NVIDIA A100 is rated at 312 trillion FP16 operations per second but about 2 trillion bytes per second of memory bandwidth, so a kernel that reads each number only once or twice spends most of its time waiting.
A good matrix multiply wins by reusing data: each program computes a tile of the output and reuses every number it loads many times. In this project you write that kernel, check it against PyTorch, and count exactly how much traffic tiling, launch order and fusion save. There is no GPU in the sandbox, so Triton runs your kernels on the CPU. The values match a GPU up to small rounding differences, but the speed does not, so the speedups are counted and estimated rather than timed.
One program, one tile of C
program 0A
B
C
Step 1 of 4 along K loads a block of A and a block of B and adds their product
What you will build
01
Tiles and program ids
Give every program its own tile of the output, in a cache-friendly order.
02
Masks for awkward sizes
Guard the edges so sizes that are not multiples of the block still come out right.
03
Counted speedups
Bytes moved, arithmetic intensity, a roofline estimate, and the traffic fusion removes.
Start with program ids
Map every program id to the tile of the output it computes.