Articles How a GPU works

Masterclass · Part 2AI Systems, explained for everyone

How a GPU works, and why AI can't live without it

Your computer's main chip, the CPU, is brilliant. So why does every AI model run on a different chip, the GPU? This masterclass opens one up and shows you, step by step, what it does that a CPU cannot.

No hardware background needed. We will use one picture all the way through: a few brilliant professors versus a stadium full of students. Every number is checked against NVIDIA's own documentation and the original papers, listed at the end.

Your reading ticket

TIMEabout 35 minutes
BEFOREnone needed (Part 1 helps)
YOU LEAVE KNOWINGlatency vs throughput, SMs, warps, memory bandwidth, Tensor Cores
NOT IN THIS ONEwriting CUDA code (its own article)
Chapter 01

Why this one chip matters so much

Every time an AI model answers you, millions of small multiplications happen in a fraction of a second. In Part 1 we saw that a model produces its answer one token (a word or piece of a word) at a time, and that each token needs the model's billions of numbers, its weights. Something has to do all that arithmetic, fast, for millions of people.

That something is almost always a GPU, a graphics processing unit. It was built to draw video game graphics. Today it is the engine of AI: training models, and running them.

To see why, we first need to understand the chip you already know, the CPU (central processing unit), and what it was designed for.

In the stadium

Picture two ways to mark a mountain of exam papers. Hire a few brilliant professors, or fill a stadium with thousands of students who each know a little arithmetic.

In the silicon

A CPU has a few very powerful cores. A GPU has thousands of simpler ones. Which is better depends entirely on the kind of work.

Remember thisAI is mostly a huge pile of simple multiplications that can be done at the same time. GPUs are built for exactly that shape of work.
Chapter 02

What a CPU is brilliant at

A CPU is designed to finish one task, as fast as possible. The time it takes to finish one task is called latency, and CPUs are latency champions. They get there with a few tricks, all of which take up a lot of the chip:

  • Big caches. A cache is a small, very fast memory right next to the core that keeps recently used data close, so the core rarely waits for the slower main memory.
  • Branch prediction. Programs are full of "if this, then that". The CPU guesses which way each "if" will go and starts work early. When it guesses right, which is most of the time, no time is lost.
  • Out-of-order execution. If one instruction is stuck waiting, the CPU looks ahead and runs later instructions that do not depend on it.
  • High clock speeds. Each core does each step very quickly.

This is why your laptop feels snappy: opening apps, running a web browser, an operating system juggling many small different jobs. Each job is different, full of decisions, and needs answering now.

In the stadium

A professor can solve a hard, twisty problem quickly, keeps their favourite notes on their own desk, and can guess which page you will ask about next. But there are only a handful of professors.

In the silicon

A CPU core spends most of its transistors on caches and control logic that make one stream of instructions fast. Even the biggest server CPUs have a couple of hundred cores: AMD's newest EPYC tops out at 256. Not thousands.

Now give the professors a different job: add 1 to each of 8 million numbers. No decisions, no twists, just the same tiny step, millions of times. The professors' clever tricks do not help much here. What would help is more hands.

Remember thisA CPU is built for latency: one complicated task, finished quickly. That is the opposite of what AI needs most.
Chapter 03

The GPU's big bet: throughput

A GPU makes a different bet. Instead of finishing one task fast, it tries to finish as many tasks as possible per second. That is called throughput.

NVIDIA's own programming guide puts it plainly: the GPU is designed so that more transistors are devoted to data processing rather than data caching and flow control. Fewer clever tricks per core, many more cores.

Each GPU core is slower and simpler than a CPU core. But when the work is thousands of identical little jobs, being wide beats being fast. Try it:

The race: a few fast workers vs many slow ones

CPU 8 fast cores · 1 tick per job

0 ticks

GPU 1,024 slow lanes · 4 ticks per job

0 ticks

4,096 independent jobs, like 4,096 pixels. Press Play.

Toy numbers, real idea. With many independent jobs, the GPU finishes in 16 ticks while the CPU needs 512, even though each GPU lane is 4 times slower. Switch to "1 long chain", where every step needs the previous result: now only one worker can help, and the fast CPU core wins easily.

In the stadium

Ask the stadium to add up 4,096 separate receipts and they finish in moments, each student doing one. Ask them one long riddle where every clue depends on the last, and the professor wins.

In the silicon

GPUs win on data-parallel work: the same operation on lots of independent data. CPUs win on sequential work, where each step depends on the one before.

Remember thisLatency is how fast one job finishes. Throughput is how many jobs finish per second. CPUs optimise latency, GPUs optimise throughput.
Chapter 04

From pixels to AI

Why did anyone build such a chip? Graphics. A modern screen has millions of pixels, and a game redraws all of them many times a second. Each pixel's colour can be worked out mostly on its own, with the same steps as its neighbours. That is the perfect stadium job.

For years GPUs could only do graphics. Researchers who wanted their raw arithmetic power had to disguise their maths as pictures. In 2006, NVIDIA introduced CUDA, a way to program its GPUs for general computing in a C-like language, starting with the GeForce 8800 generation. Suddenly the stadium could be hired for any job that looked like "the same step on lots of data".

In 2012, a neural network called AlexNet won the ImageNet image-recognition challenge by a wide margin. Its authors trained it on two NVIDIA GTX 580 GPUs with 3 GB of memory each, over five to six days. That result is widely seen as the moment deep learning took off, and GPUs came with it.

Why AI is "stadium work"

A neural network layer does one main thing: it multiplies a list of input numbers by a big grid of weights. That is called a matrix multiplication. And a matrix multiplication is just a huge number of small multiply-then-add steps, most of which do not depend on each other.

For example, one output number of a layer might be: 0.2×w1 + 0.7×w2 + 0.1×w3 + … for thousands of inputs. Every output number can be computed at the same time as every other one. Large language models are mostly stacks of these multiplications, repeated layer after layer.

In the stadium

Marking a million multiple-choice answers against an answer key. Every paper can be marked by a different student, at the same time.

In the silicon

Matrix multiplication: millions of independent multiply-adds. Exactly the work GPUs were built to spread across thousands of cores.

Remember thisGPUs were built for pixels. AI turned out to be the same shape of problem: the same simple maths on huge amounts of data.
Chapter 05

Inside the chip

Let's open up a real data-centre GPU: NVIDIA's H100 (the SXM5 version, launched in 2022 and widely used for AI). Click the parts.

Explore an H100 GPU

1 square = 1 SM (132 in total)memory

The whole chip

The H100 SXM5 has 132 Streaming Multiprocessors (SMs). An SM is a self-contained block that runs groups of threads. Think of each SM as one section of the stadium, with its own supervisors, desks and whiteboard.

132SMs
16,896FP32 CUDA cores
528Tensor Cores
80 GBHBM3 memory
Simplified drawing. The real chip is not a neat grid, and the full GH100 design has 144 SMs, of which 132 are switched on in the H100 SXM5. Numbers are from NVIDIA's H100 architecture whitepaper and datasheet.
Careful with "cores". A "CUDA core" is not the same as a CPU core. It is a simple arithmetic unit that does one ordinary maths operation per step for one thread. A CPU core is a complete, independent worker with its own control logic. So "16,896 cores vs 256 cores" is not an apples-to-apples comparison. The point is the shape: a GPU has vastly more simple units doing arithmetic side by side.

In the stadium

The stadium is divided into 132 sections. Each section has four rows of students, a supervisor for each row, a few times-table machines and a shared whiteboard. The library across the road holds all the books.

In the silicon

132 SMs. Each has 4 warp schedulers, 128 FP32 cores, 4 Tensor Cores and shared memory. The L2 cache is shared by all SMs. HBM holds the model.

Remember thisA GPU is built from many identical blocks called SMs. Each SM runs lots of threads at once using many simple arithmetic units.
Chapter 06

Warps: 32 threads in lockstep

A thread is one small stream of work, like "compute output number 4,217". A GPU program launches thousands or millions of threads. But an SM does not manage them one by one. It handles them in groups of 32, called a warp.

All 32 threads of a warp run the same instruction at the same time, each on its own data. NVIDIA calls this SIMT: single instruction, multiple threads. It is cheap: one instruction is fetched and decoded once, and 32 threads use it.

But there is a catch. What if threads in the same warp disagree at an "if"? Step through it:

One warp of 32 threads

A warp of 32 threads. Half will take the "if", half the "else". Press Step.

Simplified. When threads in a warp take different paths, the warp runs each path in turn while the other threads wait. This is called divergence, and it wastes part of the warp. Newer NVIDIA GPUs give each thread more independence in scheduling, but the cost of divergence is still real.

In the stadium

Each row of 32 students reads the same instruction from one board. If the board says "students with even numbers, double it; others, add one", the even half works while the odd half waits, then they swap.

In the silicon

A warp issues one instruction for 32 threads. Branches that split a warp are run one path after the other, with the inactive threads masked off.

Remember thisGPUs are fastest when all 32 threads in a warp do exactly the same thing. Branchy, decision-heavy code is where they struggle, and where CPUs shine.
Chapter 07

Hiding the wait

Fetching data from main memory is slow compared with doing maths: hundreds of clock cycles. A CPU fights this with big caches and clever prediction, so it rarely has to wait.

A GPU uses a different trick. Each SM keeps many warps loaded at once, each with its own registers already in place. When one warp has to wait for memory, the scheduler simply switches to another warp that is ready, with no setup cost. With enough warps, someone is always doing maths. This is called latency hiding.

One warp alone vs a scheduler juggling four
One warp: compute, then wait for memory
Four warps: while one waits, another computes

doing mathswaiting for memory (another warp can run)SM idle: nobody readyready, waiting for its turn

Toy timings (2 steps of maths, then 6 steps of waiting). With one warp the SM sits idle most of the time. With four, the scheduler fills the gaps and the SM stays busy. Real GPUs keep up to dozens of warps per SM for exactly this reason.

In the stadium

When one row sends a runner to the library, the supervisor doesn't wait. They turn to the next row and give them work. Each row's notes stay on their desks, so switching costs nothing.

In the silicon

Warps that stall on memory are set aside, and the warp scheduler issues instructions from ready warps. Because every warp's registers stay on the SM, switching is essentially free.

This is also why GPUs need lots of work to be fast. Give a GPU only a few threads and there is nobody to switch to: it waits, just like the lonely warp above.

Remember thisCPUs avoid waiting with big caches. GPUs accept waiting and hide it by always having another warp ready to run.
Chapter 08

Memory is often the real limit

A GPU has a ladder of memories. The closer to the cores, the faster and smaller:

MemoryWhere it isSize on H100Stadium version
RegistersInside each SM, private to each thread256 KB per SMA student's scrap paper
Shared memory / L1Inside each SM; shared by the threads of one thread block256 KB per SM (combined)The section's whiteboard
L2 cacheOn the chip, shared by all SMs50 MBThe stadium's reading room
HBM3Stacked next to the chip80 GB, about 3.35 TB/sThe library across the road

Here is the key idea. For every job, ask: how much maths do I do for each byte I read from memory? That ratio is called arithmetic intensity.

  • If you do lots of maths per byte, the cores are the bottleneck. The job is math-bound.
  • If you do little maths per byte, the cores finish quickly and then wait for data. The job is memory-bound, no matter how many cores you have.

The tipping point is the chip's peak maths speed divided by its memory speed. Drag the slider, or pick a preset:

Math-bound or memory-bound? (H100 SXM5, 16-bit Tensor Core maths)

A simplified "roofline" model. Peak: about 989 TFLOPS of dense 16-bit Tensor Core maths and 3.35 TB/s of memory bandwidth (NVIDIA H100 SXM5 figures), so the tipping point is about 295 operations per byte (989 ÷ 3.35). Presets are rough estimates. NVIDIA's own performance guide puts a layer processing one input at a time at about 1 operation per byte: each 16-bit weight (2 bytes) is read once and used for about 2 operations (a multiply and an add). Batching 64 users reuses each weight 64 times. A large square matrix multiply of size 4,096 reaches about 1,365.

This explains something from Part 1. When a chatbot writes an answer for one person, every new token needs the entire model read from HBM, but does only a little maths with each weight. So token generation is memory-bound: the speed of the library corridor, not the number of students, sets the pace. That is why serving systems like vLLM batch many users together: each weight read from memory is reused for many users at once.

In the stadium

If every student needs a new library book for each sum, it doesn't matter how many students you have: the corridor to the library is jammed. If each book is used for hundreds of sums, the students become the limit.

In the silicon

Low arithmetic intensity means memory-bound; high means math-bound. Batching, caching and smaller number formats all raise the useful work per byte moved.

Remember thisA GPU is only as fast as it can be fed. For chatbots, memory bandwidth (how fast weights can be read) usually matters more than raw maths speed.
Chapter 09

Tensor Cores and smaller numbers

Ordinary GPU cores do one multiply-add for one thread per step. In 2017, NVIDIA's Volta generation (the V100) added a new kind of unit: the Tensor Core. A Tensor Core multiplies and adds a whole small block of numbers (a matrix tile) in one operation.

Multiply two 4×4 tiles
–
steps on a plain core (one multiply-add each)
–
operations on a Tensor Core (the whole tile)

Pick a way to multiply the two tiles.

Simplified. A 4×4 times 4×4 tile needs 64 multiply-adds. A plain core does them one by one; a Tensor Core does the whole tile at once. This is exactly the size of the first Tensor Cores: on Volta, each one did a 4×4×4 block, 64 multiply-adds per clock. Newer generations work on larger tiles and more number formats.

Smaller numbers, more speed

Numbers in a computer have a precision: how many bits are used to store each one. Classic scientific computing uses 64 or 32 bits. AI models turned out to work well with far fewer, and fewer bits mean less memory to read and more maths per second. Each GPU generation has added new, mostly smaller formats to its Tensor Cores:

Volta2017 · V100

First Tensor Cores, 16-bit (FP16) inputs

Turing2018 · T4, RTX 20

Adds 8-bit and 4-bit integers (INT8, INT4) for inference

Ampere2020 · A100

Adds TF32 (speeds up 32-bit work) and BF16 (32-bit range in 16 bits)

Hopper2022 · H100

Adds 8-bit floating point (FP8)

Blackwell2024 · B200

Adds 4-bit floating point (FP4)

Halve the bits and you halve the bytes read from memory for the same model, which matters a lot when you are memory-bound. The trade-off is accuracy, which is why choosing a format is a careful engineering decision. We will cover it properly in the quantization part of this series.

In the stadium

Each section gets a few times-table machines that fill in a whole small grid at once. And answers rounded to fewer decimal places are faster to write down and carry.

In the silicon

Tensor Cores do matrix multiply-accumulate on tiles, and support lower-precision formats (FP16, BF16, FP8, FP4) for more speed and less memory traffic.

Remember thisMost of a modern GPU's AI speed comes from Tensor Cores doing whole tiles at once, in small number formats.
Chapter 10

When the CPU still wins, and how they work together

GPUs are not "better CPUs". They are a different tool. Here is the honest comparison:

QuestionCPUGPU
Built to optimiseLatency: one task, fastThroughput: many tasks per second
CoresFew, powerful, independentThousands of simple units, grouped in SMs
Best atBranchy logic, operating systems, databases, web serversThe same maths on lots of data: graphics, AI, simulations
Handles waiting byBig caches, prediction, out-of-order executionSwitching between many warps
Weak atMassive parallel arithmeticSequential steps, heavy branching, small jobs
Main memoryLarge and flexible (often hundreds of GB or more)Smaller but very fast (tens to hundreds of GB of HBM)
Memory speed (top chips, 2026)AMD EPYC 9996 (announced 2026): up to about 1.6 TB/s per socket, with the fastest supported memoryH100: 3.35 TB/s · B200: up to 8 TB/s

In practice they always work as a team. The CPU is the host: it runs the operating system and your program, loads data, and decides what to do. The GPU is the device: the CPU sends it big blocks of maths to do, and it sends results back. Data travels between them over a connection such as PCIe, and between GPUs over faster links such as NVIDIA's NVLink.

In the stadium

The professor plans the exam, decides what needs marking and checks the tricky cases. The stadium does the bulk marking.

In the silicon

The CPU (host) runs the program and schedules work; the GPU (device) runs the massively parallel parts. Moving data between them has a cost, so good programs keep data on the GPU as long as possible.

Remember thisCPU for decisions, GPU for bulk maths. Every AI server has both.
Chapter 11

Try it yourself

If you have a computer with an NVIDIA GPU and its driver installed, or a free GPU notebook such as Google Colab, you can look at a real GPU in seconds.

See your GPU, its memory and how busy it is
nvidia-smi
Ask for specific fields, in CSV
nvidia-smi --query-gpu=name,memory.total,memory.used,utilization.gpu --format=csv
From Python with PyTorch: is a GPU available, and which one?
import torch
print(torch.cuda.is_available())
print(torch.cuda.get_device_name(0))

Watch utilization.gpu while a model runs. If it is low, the GPU is often waiting: for data from the CPU, or for memory. That is the memory wall from Chapter 8, showing up on your own screen.

Coming next: CUDA. How you actually write code for a GPU (kernels, threads, blocks, grids) gets its own article. Everything in this masterclass is the foundation for it.
Remember thisnvidia-smi is the first command every GPU engineer runs: what GPU is this, how much memory is used, and is it busy?
Chapter 12

Cheat sheet and quiz

Glossary

CPU
Central processing unit. Few powerful cores, built for latency: finishing one task fast.
GPU
Graphics processing unit. Thousands of simple arithmetic units, built for throughput.
Latency
How long one task takes from start to finish.
Throughput
How many tasks are finished per second.
SM
Streaming Multiprocessor: one of the identical blocks a GPU is built from. Runs many warps.
Thread
One small stream of work, like computing one output number.
Warp
A group of 32 threads that run the same instruction together (SIMT).
Divergence
When threads in a warp take different branches, so the paths run one after another.
Latency hiding
Keeping many warps ready, so the SM switches to another one while a warp waits for memory.
HBM
High Bandwidth Memory: the GPU's main memory, stacked beside the chip.
Memory bandwidth
How many bytes per second can move between memory and the chip.
Arithmetic intensity
Maths operations per byte read. Low means memory-bound, high means math-bound.
Tensor Core
A unit that multiplies and adds whole small matrix tiles in one operation.
Precision
How many bits store each number (FP32, FP16, BF16, FP8, FP4). Fewer bits: faster, less exact.
Host and device
The CPU (host) runs the program and sends bulk maths to the GPU (device).
CUDA
NVIDIA's platform for programming its GPUs. Its own article is coming next.

Quick quiz

1. Why is a CPU still the right chip for running a web server or database?

That work is full of different, branchy, sequential decisions that need fast answers. CPUs are built for latency on exactly that kind of work.

2. What is a warp, and why does an "if" inside it cost time?

A group of 32 threads running the same instruction. If they disagree at an "if", each path runs in turn while the other threads wait (divergence).

3. How does a GPU deal with slow memory, compared with a CPU?

A CPU avoids waiting with big caches and prediction. A GPU keeps many warps loaded and switches to a ready one whenever a warp waits (latency hiding).

4. Why is chatbot token generation usually memory-bound?

Each new token needs every weight read from memory, but only a little maths is done per weight. Batching many users reuses each weight and raises the maths per byte.

5. What does a Tensor Core do differently from an ordinary core?

It multiplies and adds a whole small matrix tile in one operation, usually in smaller number formats such as FP16, BF16 or FP8.

Next in this series

Part 1 · doneInference engineering & vLLM
Part 2 · you are hereHow a GPU works
Part 3 · nextTokens & embeddings
Part 4Transformers & attention
Coming soonCUDA: programming the GPU

Sources

  1. NVIDIA, CUDA C++ Programming Guide (12.9 archive): "The Benefits of Using GPUs", SIMT architecture, hardware multithreading. Current guide: docs.nvidia.com/cuda/cuda-programming-guide.
  2. NVIDIA, GPU Performance Background User's Guide: SMs, arithmetic intensity, math-limited vs memory-limited.
  3. NVIDIA, Matrix Multiplication Background User's Guide.
  4. NVIDIA, H100 Tensor Core GPU Architecture whitepaper and NVIDIA Hopper Architecture In-Depth.
  5. NVIDIA, H100 product page and datasheet: memory, bandwidth, TFLOPS (sparsity figures halved for dense).
  6. NVIDIA, Hopper Tuning Guide: registers and shared memory per SM.
  7. NVIDIA, Programming Tensor Cores in CUDA 9 and Inside Volta.
  8. NVIDIA, Ampere Architecture In-Depth (TF32, BF16) and Introducing NVFP4 (Blackwell FP4).
  9. NVIDIA, Blackwell architecture and DGX B200 (up to 8 TB/s per GPU).
  10. NVIDIA, Fermi Compute Architecture whitepaper: G80 / GeForce 8800 and the introduction of CUDA in 2006.
  11. Krizhevsky, Sutskever, Hinton, ImageNet Classification with Deep Convolutional Neural Networks (AlexNet), NeurIPS 2012.
  12. Zhong et al., DistServe (2024): decode is limited by memory bandwidth; batching raises arithmetic intensity.
  13. AMD, EPYC 9996 product page and 6th Gen EPYC (Venice) announcement, 2026.
  14. NVIDIA, nvidia-smi documentation; PyTorch, torch.cuda.

Written for supraj.dev. Every number in this article comes from the sources above and was checked on 11 October 2026. Simplified drawings and toy numbers are labelled as such.