Level 0: Foundation
★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.A stadium full of calculators
A CPU is a handful of very clever workers; a GPU is a stadium of tens of thousands of simple ones who all follow the same instructions together, in squads of 32. When one squad waits for data, another squad immediately takes over, so the stadium never idles. It works brilliantly when every worker does the same thing to different data (pixels, matrix entries, particles), and when the squad’s members ask for data that sits side by side in memory.
GPUs train every modern neural network and accelerate radiative transfer, CFD, Monte Carlo trajectory dispersions and SAR image formation. Embedded GPUs (Jetson-class) run perception on drones and rovers. Knowing warps, coalescing and occupancy is the difference between a kernel at 5% and at 80% of the hardware.
- 1. How many threads are in a warp on NVIDIA GPUs?
- 2. GPUs hide memory waits by…
- 3. In the demo, which access pattern moves the fewest bytes?
Level 1: Beginner
★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.The hardware
An NVIDIA GPU has many streaming multiprocessors (A100: 108 SMs; H100 SXM: 132). Each SM has integer and FP32/FP64 units, tensor cores, a large register file (64 K 32-bit registers), shared memory/L1 (up to 228 KB on H100), and warp schedulers. Threads are grouped into blocks (up to 1024 threads) that run on one SM and can cooperate through shared memory; blocks form a grid. The SM executes warps of 32 threads that share one instruction stream (SIMT).
| Memory | Scope | Latency (approx.) | Notes |
|---|---|---|---|
| registers | thread | ~1 cycle | spills go to slow “local” memory |
| shared memory / L1 | block / SM | ~30 cycles | 32 banks of 4 bytes |
| L2 | whole GPU | ~200 cycles | 40–50 MB on A100/H100 |
| global (HBM) | whole GPU | ~400–600 cycles | 1.6–2 TB/s (A100), 3.35 TB/s (H100 SXM) |
- 1. Threads of one block can share data through…
- 2. SIMT means…
- 3. Roughly how much faster is A100 HBM than a desktop DDR4 channel (~25 GB/s)?
Level 2: Intermediate
★★★☆☆ Intermediate⏱ 35 minUndergraduate students and practising engineers.Occupancy and latency hiding
Each SM can hold a limited number of resident warps (64 on A100), blocks (32) and threads (2048). Registers and shared memory are split among resident blocks, so a kernel using many registers per thread fits fewer warps. Occupancy = resident warps / maximum warps. More resident warps give the scheduler more independent work to switch to while others wait on memory (by Little’s law, bytes in flight = bandwidth × latency: about 0.8 MB across an A100). High occupancy is a means, not a goal: kernels that keep data in registers can be fast at 25–50%.
Memory access rules
- Coalescing: global memory is served in 32-byte sectors (128-byte cache lines). If thread t of a warp reads element t, 128 bytes arrive in 4 sectors; strides or misalignment waste bandwidth.
- Bank conflicts: shared memory has 32 banks of 4-byte words; threads of a warp hitting different words in one bank are serialized (the same word is broadcast). Padding a 32-wide tile to 33 columns makes column accesses conflict-free.
- Divergence: if threads of a warp take different branches, the warp executes each path in turn with inactive lanes masked.
- 1. 256-thread blocks using 64 registers per thread on A100: occupancy?
- 2. A warp reads float32 with stride 2 elements. Efficiency?
- 3. 32 threads read the same shared-memory word. Conflict degree?
Level 3: Advanced
★★★★☆ Advanced⏱ 30 minGraduate level, with full derivations and proofs.Tensor cores
Tensor cores execute small matrix multiply-accumulates (for example a 16×8×16 FP16 MMA per instruction per warp) at a rate far beyond the scalar units: A100 reaches 312 TFLOPS dense FP16/BF16 versus 19.5 TFLOPS FP32 on its CUDA cores; TF32 (FP32 range, 10-bit mantissa) gives 156 TFLOPS for FP32 code; H100 adds FP8. Using them needs matrix shapes that are multiples of 8 or 16, low-precision inputs (C5.5) and data staged through shared memory, which is what cuBLAS, cuDNN, CUTLASS, Triton and torch.compile arrange.
Putting it together: matrix transpose
A transpose reads rows and writes columns. Naively one side is coalesced and the other strided. Staging a 32×32 tile in shared memory makes both global accesses coalesced, but reading a column of the tile hits one bank 32 times; padding the tile to 33 columns removes the conflict. This three-step progression (NVIDIA’s classic transpose example) captures most of GPU memory optimization.
- 1. A100 dense FP16 tensor-core peak is roughly how many times its FP32 CUDA-core peak?
- 2. Why pad a shared-memory tile to 33 columns?
- 3. Tensor cores require…
Level 4: Expert
★★★★★ Expert⏱ 35 minResearchers: original papers and open problems.GPU memory behaviour, measured
Exercise 1. On sm_80 limits: 256 threads at 32 registers gives 8 blocks and 100% occupancy; at 64 registers, 4 blocks (50%, register-limited); 128 threads with 48 KB of shared memory, 3 blocks (shared-memory-limited); 32-thread blocks stop at the 32-block limit (50%); 1024 threads at 255 registers cannot launch. A coalesced float32 warp load uses 4 sectors, stride 2 uses 8 (50%), stride 32 uses 32 (12.5%), and a 4-byte misalignment adds one sector. Reading a column of a 32-word-wide shared tile is a 32-way conflict; a 33-word-wide tile is conflict-free.
Exercise 2: access patterns, transpose and occupancy.
| Pattern (float32, one warp) | efficiency |
|---|---|
| stride 1 / 2 / 4 / 8 / 16 / 32 | 100% / 50% / 25% / 12.5% / 12.5% / 12.5% |
| array of structures (3 floats), read x | 33% |
| structure of arrays, read x | 100% |
| Transpose kernel, 256×256 float32 | global sectors | shared-memory passes |
|---|---|---|
| naive | 73 728 (4.5× ideal) | 0 |
| 32×32 shared tile | 16 384 (ideal) | 67 584 |
| 32×33 padded shared tile | 16 384 | 4 096 |
All three produce the correct transpose. Occupancy of 256-thread blocks with 32 / 40 / 48 / 64 / 96 / 128 / 255 registers: 100 / 75 / 62.5 / 50 / 25 / 25 / 12.5% (register allocation in units of 256 per warp makes 96 and 128 equal).
GPUs in AI, robotics and aerospace
- Training and inference of neural networks: tensor cores for GEMMs and convolutions, memory-bound kernels for everything else.
- Simulation: Monte Carlo dispersions with millions of independent trajectories, particle methods, lattice-Boltzmann CFD, ray tracing for radiation and sensor simulation.
- Embedded: Jetson Orin-class modules run perception on robots and drones within tens of watts.
- Ground processing: SAR focusing and hyperspectral pipelines on GPU clusters.
References
- NVIDIA (2024). CUDA C++ Programming Guide and CUDA C++ Best Practices Guide (docs.nvidia.com/cuda).
- NVIDIA (2020). NVIDIA A100 Tensor Core GPU Architecture (whitepaper); NVIDIA (2022). NVIDIA H100 Tensor Core GPU Architecture.
- M. Harris (2013). “An efficient matrix transpose in CUDA C/C++.” NVIDIA Technical Blog.
- V. Volkov (2010). “Better performance at lower occupancy.” GPU Technology Conference.
- D. B. Kirk, W. W. Hwu, I. El Hajj (2022). Programming Massively Parallel Processors, 4th ed. Morgan Kaufmann.