Learn the GPU through CUDA C++
Run a small CUDA C++ program, predict what one edit will change and compare the results. Later lessons trace memory, synchronisation and the parallel patterns behind AI workloads.
Before you start, be comfortable with basic programming, reading Python and array indexing. The course introduces CUDA and GPU architecture.
No installation or GPU required. The browser compiles CUDA C++ and runs the examples in a functional GPU simulator. The teaching models calculate specific details such as memory addresses and possible instruction schedules.
C++ launchhello<<<1, 1>>>(output)
CUDA foundations
-
Write your first GPU value
Launch one thread, write one value, and read it back in main().
-
One thread, one element
Change a CUDA multiplier and follow each input to its output.
-
More threads than elements
Change the block size and see which threads skip the guarded array reads and writes.
-
From CPU array to GPU result
Change the input length and follow allocation, copies and the kernel launch.
GPU execution and AI workloads
-
Same load, different addresses
Change a warp’s input stride and predict which 32-byte sectors its reads touch.
-
What runs while a warp waits?
Follow a load dependency and compare what happens with one ready warp or two.
-
When lanes take different branches
Change the signs in a warp’s inputs and track which lanes execute each branch.
-
Add values across a block
Trace a block reduction and identify the barrier that makes each partial sum safe to read.
-
When shared-memory addresses collide
Change the stride of a shared-memory read and group the simultaneous requests by bank.
-
Reuse inputs in a matrix tile
Compare a direct CUDA matrix product with a tiled kernel and trace which loads the tile reuses.
-
What changes when inputs use fewer bits?
Round inputs through FP16 and compare the FP32 sum with and without that rounding.
-
How a warp cooperates on a matrix tile
Follow a CUDA warp-level matrix operation and distinguish its input fragments from its accumulator.
-
Keep less intermediate data in attention
Compare full score storage with a tiled calculation that carries an online softmax state.
-
Follow the key-value cache during inference
Change sequence length and account for the key-value data read and appended during decoding.
-
Investigate a matrix multiplication
Choose a tile width, predict its resource trade-off and decide what to measure on a GPU.
Parallel patterns
-
Count token destinations safely
Trace competing updates and compare global atomics with per-block partial counts.
-
Build positions from prefix sums
Step through shared-memory scan stages and convert inclusive totals to exclusive offsets.
-
Pack surviving tokens in order
Use selection flags and exclusive offsets to explain each surviving token’s write destination.
-
Find a parallel program’s progress dependency
Find which threads reach a block barrier and explain why the rest must also arrive.
-
Overlap copies with computation
Order copies, kernels and buffer reuse with explicit dependencies.
-
Investigate stable token routing
Combine counts, starts and ranks to place every token once, then design a performance measurement.
Practical GPU investigations
-
Check every GPU result
Compare every output with a CPU reference, then diagnose a safe indexing error.
-
Process more inputs than the launch has threads
Give each input one owner with a grid-stride loop, including tails and empty inputs.
-
Carry a prefix across blocks
Combine local scans, block totals and block starts in an ordered GPU pipeline.
-
Explain an SM resource trade-off
Calculate a residency limit and identify which hardware observation could test an optimisation.
-
Measure a GPU kernel fairly
Separate correctness, kernel timing and profiling, then interpret recorded evidence.
-
Build and verify a stable softmax
Implement a row-wise kernel, check additional shapes and propose a bottleneck to test on a GPU.