What you will build, and the plan
Why an inference engineer should be able to write and read GPU kernels, what you will build in this course (from vector add to a decode-attention kernel), how the four parts fit together, and how to get a GPU for the labs for free or for a few dollars.
By Sandip Maity, Applied AI Engineer
Most of the time an LLM spends answering you, it's running inside a handful of GPU functions: matrix multiplies, attention, a few norms and activations. Those functions are called kernels. The rest of an inference engine (the scheduler, the KV cache manager, the HTTP server) exists to keep those kernels fed.
The Inference Engineering course teaches you to predict how fast those kernels should run. This course teaches you to open them up: write them, read them, profile them and make them faster. By the end, phrases like "this decode matmul only fills a quarter of the SMs" or "this norm isn't coalesced" will be things you can check and fix, not just repeat.
#Why bother, if libraries exist?
Fair question. cuBLAS, FlashAttention, FlashInfer and the kernels inside vLLM and SGLang are written by specialists. You'll rarely beat them at their own game. You need kernel skills anyway, for four reasons:
- Reading a profile. A profiler shows kernel names, durations and counters. If you don't know what a kernel does inside, those numbers don't tell you much.
- Fusion. The biggest wins in inference often come from merging small memory-bound operations into one kernel (fusion and launch overhead). Libraries can't fuse your model's particular sequence of operations for you; sometimes you have to.
- New shapes and formats. A new quantisation format, a new attention variant or a new GPU often runs on a slow generic path until someone writes a proper kernel. Sometimes that someone is you.
- Engine work. If you want to change how vLLM or SGLang works, you'll be reading their custom CUDA and Triton kernels.
#What you'll build
Every lesson has code you run and time yourself. The arc:
- 1Vector addyour first CUDA kernel, launched and timed
- 2Bandwidth-bound kernelscoalescing, copy and transpose at near-peak GB/s
- 3Tiled matmulshared memory, then tensor cores
- 4Reductionswarp shuffles, softmax and RMSNorm
- 5Tritonthe same kernels in Python, then a tuned matmul
- 6Fused opsRMSNorm and SwiGLU fused and plugged into PyTorch
- 7Decode attentiona split-KV attention kernel over a paged cache
- 8Profiling and capstoneNsight Systems, Nsight Compute, one real layer made faster
| Part | Lessons | What you can do afterwards |
|---|---|---|
| Start here | 2 | Explain threads, blocks, warps and SMs, and launch and time a kernel |
| CUDA | 6 | Write bandwidth-bound and compute-bound kernels, use shared memory, warp shuffles and tensor cores, and time and overlap work with streams and graphs |
| Triton | 4 | Write and autotune Triton kernels, fuse operations and register them with PyTorch, and write a decode-attention kernel |
| Profiling and capstone | 2 | Read Nsight Systems and Nsight Compute reports, and ship a measured speed-up |
Reading time is about 4 hours. Doing the labs properly takes about three times as long, and that's where the learning is.
#Getting a GPU
You need an NVIDIA GPU with the CUDA toolkit. Three ways in, cheapest first:
| Option | Cost | Good for | Limits |
|---|---|---|---|
| Google Colab, T4 runtime | Free (with usage limits) | Every lab in this course | Sessions time out; Nsight Compute counters may be blocked |
| A rented cloud GPU (an L4, A10, A100 or H100 by the hour) | Roughly a few dollars an hour for small GPUs; check current prices | Profiling with full counters, newer tensor-core features | You pay while it runs, so shut it down |
| Your own NVIDIA GPU | Already paid for | Everything, with no time limits | Driver and toolkit setup is on you |
The labs are written for the T4, because it's free and good enough. Its numbers, which we'll use all through the course:
| T4 (Turing, compute capability 7.5) | Value |
|---|---|
| Streaming multiprocessors (SMs) | 40 |
| Memory bandwidth (GDDR6) | 320 GB/s |
| FP32 throughput on ordinary cores | about 8.1 TFLOP/s |
| FP16 throughput on tensor cores | about 65 TFLOP/s |
| Max threads per SM | 1,024 (32 warps) |
| Registers per SM | 65,536 (32-bit) |
| Shared memory per SM | up to 64 KB |
| L2 cache | 4 MB |
Where it matters, lessons also show the numbers for an H100, so you can see how the same reasoning scales to a data-centre GPU.
#Setting up Colab
- Open a new notebook, then choose Runtime → Change runtime type → T4 GPU.
- Check the GPU and the compiler:
!nvidia-smi
!nvcc --version
!python -c "import torch, triton; print(torch.__version__, triton.__version__, torch.cuda.get_device_name())"- For CUDA lessons, you'll write a
.cufile from a cell and compile it:
%%writefile hello.cu
#include <cstdio>
__global__ void hello() { printf("block %d, thread %d\n", blockIdx.x, threadIdx.x); }
int main() { hello<<<2, 4>>>(); cudaDeviceSynchronize(); }!nvcc -arch=sm_75 -o hello hello.cu && ./helloYou should see eight lines, one per thread, in no particular order. That "no particular order" is your first lesson about GPUs. Threads run in parallel, and you don't get to choose who goes first.
A note on Triton and the T4: Triton's official support starts at Ampere (compute capability 8.0), one generation after the T4. The FP16 kernels in this course compile and run on a T4 in practice, which is also why torch.compile works on Colab. If you hit a compiler error that mentions the architecture, or you want BF16, rent an L4 or A10 for an hour.
#Debugging Triton without a GPU
Triton has an interpreter mode that runs kernels on the CPU with NumPy. Set TRITON_INTERPRET=1 before importing Triton, and use CPU tensors. It's slow and can't tell you anything about speed, but you can print inside a kernel and step through it, which is great for finding indexing bugs. Triton itself installs only on Linux, so on a Mac or Windows machine use Colab or WSL.
#How each lesson works
Every lesson follows the same rhythm:
- The idea, with an interactive diagram you can step through.
- The code, short enough to read in one go.
- What to expect: the speed the hardware limits predict, worked out from the specs above.
- What you measure: you run it and compare. Gaps between the two are where the interesting questions are.
- A quiz and an exercise, with answers you can reveal.
A word about the numbers. When a lesson predicts a speed, it's a calculation from published specs, not a measurement. Your measured numbers will be lower, sometimes a lot lower. That's normal, and working out why is the skill this course builds.
#Prerequisites
- C or C++ basics: pointers, arrays and loops. If you've written any C, you'll be fine. The C primer covers enough.
- Python and a little PyTorch: making tensors and calling functions.
- The roofline idea: memory-bound versus compute-bound. The roofline lesson and GPU architecture are the best preparation; skim them first if they're new to you.
#What you can now do
- Say why kernel skills matter for inference engineering even when libraries exist.
- Get a GPU runtime and compile and run a CUDA program.
- Use Triton's interpreter to debug a kernel on a CPU.
#Exercise
- Run the
helloprogram with<<<3, 5>>>. How many lines print? Run it three times: does the order change? - From the T4 table, what is the most data the T4 could possibly read from memory in one millisecond?
- A decode step of a 1B-parameter model in FP16 reads about 2 GB of weights. Using your answer to question 2, what is the fastest possible decode speed on a T4, in tokens per second?
Show answers
- 15 lines (3 blocks of 5 threads). The order can change between runs, especially between blocks. Within a warp, small printf outputs often appear grouped, but nothing guarantees an order.
- , so 320 MB.
- tokens per second at the very best. Real numbers will be lower; the next lessons show where the gap comes from.
#Going deeper
- Next: the CUDA programming model, where threads, blocks, warps and SMs fit together.
- Review the software stack from CUDA to engines to see where kernels sit in a serving engine.
Quick quiz
+10 XP per correct answer, +25 XP for a perfect score
1. Why does this course start with CUDA before Triton?
2. What is the main reason inference engineers need kernel skills?
3. Which free option runs every lab in this course?
4. What does the capstone ask you to produce?
Up next · 22 min · free
The CUDA programming model: threads, blocks, warps and SMs
How one kernel launch becomes thousands of threads, how they are grouped into blocks and warps, how blocks land on streaming multiprocessors, and how to write, launch, check and time your first real kernel: vector add, measured against the bandwidth limit.
Continue →Found this useful?
Send it to someone who is learning the same thing.
Articles that build on this lesson