CUDA C++ LabGPU architecture

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.

Start with your first kernel →

From a C++ program to GPU threads and back The CPU launches one GPU thread on the compute chip. The thread writes 42 to separate device memory, then the CPU copies the result back. CPU · host C++ program main() Result 42 GPU · device Compute chip One GPU thread Device memory Write Launch Copy back

C++ launchhello<<<1, 1>>>(output)

A kernel is a function that GPU threads run. The first lesson launches one thread to write 42 to device memory, then copies the result back to the CPU. The browser simulates this hardware.

CUDA foundations

  1. Write your first GPU value

    Launch one thread, write one value, and read it back in main().

  2. One thread, one element

    Change a CUDA multiplier and follow each input to its output.

  3. More threads than elements

    Change the block size and see which threads skip the guarded array reads and writes.

  4. From CPU array to GPU result

    Change the input length and follow allocation, copies and the kernel launch.

GPU execution and AI workloads

  1. Same load, different addresses

    Change a warp’s input stride and predict which 32-byte sectors its reads touch.

  2. What runs while a warp waits?

    Follow a load dependency and compare what happens with one ready warp or two.

  3. When lanes take different branches

    Change the signs in a warp’s inputs and track which lanes execute each branch.

  4. Add values across a block

    Trace a block reduction and identify the barrier that makes each partial sum safe to read.

  5. When shared-memory addresses collide

    Change the stride of a shared-memory read and group the simultaneous requests by bank.

  6. Reuse inputs in a matrix tile

    Compare a direct CUDA matrix product with a tiled kernel and trace which loads the tile reuses.

  7. What changes when inputs use fewer bits?

    Round inputs through FP16 and compare the FP32 sum with and without that rounding.

  8. How a warp cooperates on a matrix tile

    Follow a CUDA warp-level matrix operation and distinguish its input fragments from its accumulator.

  9. Keep less intermediate data in attention

    Compare full score storage with a tiled calculation that carries an online softmax state.

  10. Follow the key-value cache during inference

    Change sequence length and account for the key-value data read and appended during decoding.

  11. Investigate a matrix multiplication

    Choose a tile width, predict its resource trade-off and decide what to measure on a GPU.

Parallel patterns

  1. Count token destinations safely

    Trace competing updates and compare global atomics with per-block partial counts.

  2. Build positions from prefix sums

    Step through shared-memory scan stages and convert inclusive totals to exclusive offsets.

  3. Pack surviving tokens in order

    Use selection flags and exclusive offsets to explain each surviving token’s write destination.

  4. Find a parallel program’s progress dependency

    Find which threads reach a block barrier and explain why the rest must also arrive.

  5. Overlap copies with computation

    Order copies, kernels and buffer reuse with explicit dependencies.

  6. Investigate stable token routing

    Combine counts, starts and ranks to place every token once, then design a performance measurement.

Practical GPU investigations

  1. Check every GPU result

    Compare every output with a CPU reference, then diagnose a safe indexing error.

  2. Process more inputs than the launch has threads

    Give each input one owner with a grid-stride loop, including tails and empty inputs.

  3. Carry a prefix across blocks

    Combine local scans, block totals and block starts in an ordered GPU pipeline.

  4. Explain an SM resource trade-off

    Calculate a residency limit and identify which hardware observation could test an optimisation.

  5. Measure a GPU kernel fairly

    Separate correctness, kernel timing and profiling, then interpret recorded evidence.

  6. Build and verify a stable softmax

    Implement a row-wise kernel, check additional shapes and propose a bottleneck to test on a GPU.

App status

Course status

Checking for updates

Version and download details

Downloads include all lessons, recordings, diagrams, examples, browser simulators and the CUDA compiler. Browser storage overhead is additional. External links need internet access.

Running examples outside the browser needs separate PyTorch or CUDA/GPGPU-Sim tools.

Add CUDA C++ Lab to your apps

Use your browser’s install option for an app icon and a separate window. Course status shows whether the course is downloaded and ready to use offline.