Phase 02/How a GPU executes work/CPU versus GPU architecture
PHASE 02 · How a GPU executes work

CPU versus GPU architecture

0%
5 h4 subtopics2 lessons · 1 required
In plain English

A CPU is like a small team of senior chefs. Each one can cook any dish, switch recipes instantly, and make smart guesses about what to prepare next. A GPU is like a factory canteen with thousands of junior cooks who all chop the same vegetable at the same time. One junior cook is slow, but if you have a mountain of identical chopping to do, the canteen wins by a huge margin. Running a language model is mostly identical arithmetic repeated millions of times, so it belongs in the canteen. The catch is that the canteen only pays off if you keep every cook busy and keep the ingredients arriving fast enough.

Why it matters

Inference performance questions always reduce to "is the GPU busy, and if not, why?". Knowing how a streaming multiprocessor schedules work and hides memory latency lets you predict whether a workload will saturate the chip before you run it.

Hiring signal

Skills this topic builds, with the number of the 46 analysed job postings that ask for each. Companies asking: Anthropic, Baseten, Cerebras, Cohere, CoreWeave, Crusoe, Databricks, Fireworks, Liquid AI, Modal, nvidia, OpenAI, Perplexity, Thinking Machines, Together AI, xAI.See all skills →

Learning objectives

  • Contrast CPU and GPU design goals in terms of latency versus throughput.
  • Describe the streaming multiprocessor (SM) and what resources it holds.
  • Explain how a GPU hides memory latency with massive parallelism instead of caches.
  • Read an NVIDIA spec sheet and extract SM count, peak FLOPS and memory bandwidth.

Key concepts

Latency-oriented versus throughput-oriented design
CPUs minimise time per instruction stream; GPUs maximise total work per second across many streams.
Streaming multiprocessor (SM)
The unit of a GPU that holds CUDA cores, tensor cores, registers, shared memory and warp schedulers; a GPU has tens to over a hundred of them.
SIMT
Single Instruction, Multiple Threads; groups of threads execute the same instruction in lockstep.
Latency hiding
Keeping enough threads resident that while some wait for memory, others compute.
Tensor core
A specialised unit inside an SM that performs small matrix multiply-accumulate operations in one step.
Occupancy
The fraction of the maximum resident warps on an SM that are actually active.

Subtopics

  1. 1. Design goals and die area

    Why CPUs spend transistors on caches, branch prediction and out-of-order logic while GPUs spend them on arithmetic units.

  2. 2. The GPU execution model

    Host launches kernels; the device scheduler distributes blocks of threads across SMs; SIMT execution within each SM.

  3. 3. Anatomy of a streaming multiprocessor

    CUDA cores, tensor cores, register file, shared memory, L1 cache, warp schedulers; how these numbers differ between T4, A100 and H100.

  4. 4. Reading a spec sheet

    Peak FP16 and FP32 TFLOPS, memory bandwidth, SM count, clock; how to compute them from each other.

Resources

documentation
course

Hands-on lessons

L1

Race a CPU against a T4 on the same vector operation

Colab T4 · freenotebook60 minrequired

Goal · Produce a plot of CPU versus GPU throughput for elementwise add and matmul as problem size grows, and identify the crossover point.

  1. 1Open a Colab notebook with a T4 runtime; run !nvidia-smi and record the GPU name and memory.
  2. 2In PyTorch, time a + b for float32 tensors of size 1e3 to 1e8 on CPU and on cuda; use torch.cuda.synchronize() before stopping the timer.
  3. 3Repeat for square matmul with N from 64 to 4096.
  4. 4Convert timings to GFLOP/s and GB/s and plot both devices on a log-log axis.
  5. 5Mark the size where the GPU overtakes the CPU and write one sentence on why small sizes lose.
  6. 6Compare your best matmul number to the T4 spec (8.1 TFLOPS FP32, 65 TFLOPS FP16 tensor core) and compute the percentage of peak reached.
Deliverable
Notebook with the two plots and a markdown cell containing the crossover sizes and percentage-of-peak figures.
Check
GPU matmul at N=4096 is at least 10x faster than CPU; elementwise add at N=1e3 is slower on GPU than CPU (launch overhead dominates).
Fallback
Kaggle notebooks with a T4 or P100 give the same experiment if Colab GPU quota is exhausted.
L2

Build a spec-sheet comparison table by hand

CPU · your Macdesign45 minoptional

Goal · A table of T4, A100 and H100 with SM count, cores per SM, clock, peak FLOPS and bandwidth, with the FLOPS figure re-derived from the other columns.

  1. 1Download the T4, A100 and H100 datasheets or whitepapers from nvidia.com.
  2. 2Record SM count, FP32 cores per SM, boost clock, memory type and bandwidth for each.
  3. 3Compute peak FP32 TFLOPS as SMs x cores_per_SM x 2 x clock_GHz and compare with the published number.
  4. 4Compute the ratio of FP16 tensor-core TFLOPS to memory bandwidth (FLOPs per byte) for each GPU.
  5. 5Write two sentences on what the growing FLOPs-per-byte ratio means for inference workloads.
Deliverable
A markdown table plus the two-sentence interpretation.
Check
Your derived FP32 TFLOPS is within 5 percent of each published figure.

Build your own

Build your own GPU simulator

PythonCPU · your Mac~6 h

A pure-Python model of SMs, warps and threads that executes a tiny kernel IR in lockstep and reports issue-slot utilisation, occupancy and memory sectors, so you can see latency hiding happen before you touch a real GPU.

The real thing: github.com/accel-sim/gpgpu-sim_distribution ↗

How you know a stage passes

Write tests/test_sim.py first. Every stage adds a test that runs a kernel written in your IR through the simulator, compares the output array with numpy, and asserts the utilisation or cycle numbers you computed by hand for a tiny configuration (2 SMs, 4 warp slots each). Run `pytest -q`; the CLI `python sim.py run kernels/vec_add.json --sms 2 --report` prints the same table. A stage is done when its test passes and all earlier tests still pass.

Stages, in order. Each one leaves you with something that runs.0/6
  1. 01a kernel IR and a one-thread interpreter
    A small instruction set (load, store, add, mul, cmp, branch_if, idx for threadIdx/blockIdx/blockDim) and an interpreter that executes one thread's program with its own registers.
    test · Running the vec_add IR once per thread id 0..n-1 produces an output array equal to numpy a + b exactly for n = 1000.
  2. 02warps in lockstep with an active mask
    32 threads form a warp that executes one instruction at a time under an active mask; a divergent branch_if runs both paths with complementary masks and reconverges.
    test · A kernel branching on tid % 2 reports 100 percent divergent warps and two passes per branch region; a kernel branching on tid < n/2 reports at most one divergent warp; outputs still match numpy.
  3. 03SMs, resident blocks and a cycle counter
    S SMs each hold up to W resident warps; blocks are assigned to free slots in order; every cycle each SM issues one instruction from one ready warp; the report prints waves and total cycles.
    test · 8 blocks of 64 threads on 2 SMs with 4 warp slots run in exactly 2 waves and the reported cycle count equals the number you derived by hand for a 10-instruction straight-line kernel.
  4. 04memory latency and latency hiding
    Loads stall their warp for L cycles (default 400) while the scheduler issues from other ready warps; the report shows per-SM issue-slot utilisation as issued cycles / total cycles.
    test · For a load-heavy kernel, utilisation is below 5 percent with 1 resident warp, above 30 percent with 8, and above 95 percent when L is set to 0.
  5. 05occupancy limits from registers and shared memory
    Kernels declare registers per thread and shared bytes per block; resident warps per SM become min(slot limit, 65536 / (32 x regs), smem_per_sm / smem_per_block) and the report prints occupancy percent.
    test · With a 32-warp slot limit, a kernel using 64 registers per thread reports 32 resident warps (100 percent occupancy) and one using 128 reports 16 (50 percent); utilisation in the s4 kernel drops when occupancy halves.
  6. 06a coalescing model and the final report
    A warp-level load touching 32 contiguous floats costs 4 sectors of 32 bytes; strided or scattered addresses cost up to 32; the CLI prints sectors per request, bytes moved and the utilisation table for any IR kernel and exits 0.
    test · Stride-1 copy reports 4 sectors per warp request and stride-32 reports 32; `python sim.py run kernels/copy_strided.json --report` exits 0 and the README places the simulated numbers next to the T4 numbers from lesson l1.

Knowledge check

QWhy does a GPU not need the large caches and branch predictors a CPU has?

It hides memory latency by switching among thousands of resident threads rather than by predicting or caching; the many ALUs keep working while some warps wait.

QWhat does one streaming multiprocessor contain?

CUDA cores, tensor cores, a register file, shared memory and L1 cache, and warp schedulers that issue instructions to resident warps.

QA kernel does 1e9 FLOPs and reads 1e9 bytes. On a T4 (about 8 TFLOPS FP32, 320 GB/s), is it compute-bound or memory-bound?

Memory-bound: compute takes about 0.125 ms but memory takes about 3.1 ms, so bandwidth is the limit.

QWhy can a tiny elementwise operation be slower on the GPU than the CPU?

Kernel launch and host-device synchronisation cost several microseconds, which exceeds the actual compute time for small inputs.

Completion

  • All 4 subtopics marked done
  • All 1 required lessons done
  • All four subtopics marked completed.
  • Lesson l1 notebook saved with both plots and the percentage-of-peak figure.
  • Can explain SIMT and latency hiding without notes.
Topic progress is derived; it reaches 100% when both checks above pass.Next recommended topic →