Please enable JavaScript to use CodeHS

AI · Computer hardware

What Is a GPU? Why AI runs on graphics chips

A GPU (graphics processing unit) is a chip packed with thousands of tiny workers that all do math at the same time. It was built to paint video game worlds. It turned out to be exactly what AI needs, too. Here is why, plus a race between a CPU and a GPU that you control.

AI literacy ~20 min 4 hands-on labs
CACHE + CONTROL CPU 8 big cores GPU thousands of tiny cores
CH 01 / The basics

What does a processor do?

A processor is the part of a computer that actually does the work. It follows instructions, one tiny step at a time: add these two numbers, compare these two values, move this number over there. Everything you see a computer do, from a text message to a 3D game, is built out of billions of these tiny steps.

Inside a processor are cores. A core is one worker that can follow its own list of instructions. A chip with 8 cores can work on 8 things at once. How fast each core works is set by its clock speed, measured in gigahertz (GHz). One gigahertz means about a billion ticks every second.

Every computer, phone, and game console has two main kinds of processor:

  • The CPU (central processing unit), the general boss that runs apps and the operating system.
  • The GPU (graphics processing unit), the specialist that does huge amounts of the same math at once.

They are good at different kinds of work. To see why, picture a kitchen.

CH 02 / Two kinds of kitchen

CPU vs. GPU: expert chefs vs. a cupcake army

Imagine you run a bakery and get two very different orders.

Order 1: make one fancy wedding cake. Bake the layers, let them cool, stack them, then decorate. Each step needs the step before it to be finished. You cannot frost a cake that is not baked yet.

Order 2: frost 10,000 cupcakes, all exactly the same. No cupcake depends on any other cupcake.

CPU = a few expert chefs

  • Usually 4 to 24 big, smart cores
  • Each core is very fast and can handle any task
  • Great at step-by-step work where each step depends on the last
  • Perfect for Order 1: the wedding cake

GPU = a huge team of helpers

  • Thousands of small, simple cores
  • Each core is slower and only does simple math
  • Great at doing the same small job on lots of data at once
  • Perfect for Order 2: each helper frosts one cupcake

This gives us two big ideas:

  • Serial work happens in a line, one step after another. Adding more workers does not help, because everyone is waiting on the step before.
  • Parallel work can be split into many pieces that happen at the same time. More workers means it finishes faster.
SERIAL: each step waits for the last Mix Bake Cool Stack Decorate 5 rounds PARALLEL: every job at the same time 1 round 16 cupcakes, 16 helpers: each helper frosts one cupcake.
Serial work is a chain. Parallel work is a crowd. GPUs are built for crowds.

A GPU does not replace the CPU. They work as a team. The CPU runs the program and decides what needs to happen. When a big pile of identical math shows up, it hands that pile to the GPU.

CH 03 / Lab 1

Race a CPU against a GPU

Time to test it. In this race, the CPU has 8 fast cores. Each one finishes a job in 1 tick. The GPU has 256 simpler cores. Each one needs 4 ticks per job, because each GPU core is slower. Pick a task, press Race, and watch the cores light up as they work.

CPU vs. GPU race

Lab 1 · Serial vs. parallel

1,024 pixels. Each pixel's color can be worked out on its own, so every job is independent.

WINNER
CPU8 cores · 1 tick/job
Jobs: 0Ticks: 0
WINNER
GPU256 cores · 4 ticks/job
Jobs: 0Ticks: 0
Pick a task and press Race.

Try all three tasks. The GPU crushes the image and the number grid, because those are made of many independent jobs. But on the recipe, every step needs the one before, so 255 of the GPU's cores just sit there. The CPU's single fast core wins easily.

The lesson: a GPU is only faster when the work can be split up. Real programs mix both kinds of work, which is why computers have both kinds of chip.

CH 04 / Lab 2

Why GPUs were built for video games

Your screen is a grid of tiny colored dots called pixels. A normal HD screen (1920 by 1080) has about 2 million of them. In a game, every pixel's color has to be worked out again for every new picture, called a frame. Games usually show 60 or more frames every second.

That is a cupcake job. The color of one pixel mostly does not depend on its neighbors. So in the 1990s, companies started building special chips that could color many pixels at once. The small program that decides one pixel's color is called a shader. The GPU runs the same shader on every pixel, all in parallel.

Be the GPU: run a pixel shader

Lab 2 · Same program, every pixel

Every square below runs the same tiny program. The only thing that changes is its own x and y position. Move the slider and all 1,024 pixels recompute at once. Hover a pixel, or click the image and use arrow keys, to see one pixel's math.


                
Pick a pixel to see its math.

Now scale that up to a real screen. Pick a screen size and a frame rate to see how many pixel colors a GPU has to work out every second.

124,416,000 pixels every secondThat is one new color about every 8 billionths of a second.

And that is just the final color. Modern games also work out lighting, shadows, and reflections for every pixel, so the real amount of math is far bigger.

CH 05 / Lab 3

Why AI needs GPUs

Most modern AI is built from neural networks. A neural network is made of layers of simple units called neurons. Each neuron does one thing: it takes some input numbers, multiplies each one by a weight (a number the network learned), and adds them all up. That is called a multiply-add.

When you line up all the inputs and all the weights for a layer, you get a grid of numbers called a matrix. Running the layer is matrix multiplication: each row of weights times the column of inputs. And here is the key: every neuron's sum can be done at the same time. It is cupcakes again.

One neural network layer, up close

Lab 3 · Rows times a column

3 neurons, 4 inputs. Each row of the weight matrix belongs to one neuron. Step through it like a CPU, one multiply-add at a time, or let a GPU do every neuron at once.

Press "CPU: one step" to do the first multiply-add.

That tiny layer took 12 multiply-adds (4 inputs × 3 neurons). Real networks are much bigger. Pick a layer to see how fast the count grows.

12 multiply-adds4 inputs × 3 neurons

A big language model has dozens of layers like that, and it runs all of them for every single word it writes. Training (teaching the model by showing it examples and nudging its weights) needs far more: trillions upon trillions of multiply-adds. That is why the biggest AI models are trained on thousands of GPUs at once, in huge buildings called data centers, often running for weeks or months.

A bit of history: around 2007, programmers got tools to use GPUs for general math, not just graphics. In 2012, an image-recognition network called AlexNet was trained on two gaming GPUs and beat every other entry in a famous contest by a wide margin. After that, researchers everywhere switched to GPUs for AI.

CH 06 / Lab 4

VRAM: why the GPU's memory matters

Thousands of cores are useless if they are waiting for numbers. So a graphics card has its own fast memory, sitting right next to the cores, called VRAM (video RAM). Think of it as the counter space in the kitchen. The helpers can only frost cupcakes that fit on the counter.

An AI model is basically a giant list of learned numbers, called parameters. To run the model fast, those numbers need to fit in VRAM. Each parameter takes up memory, and how much depends on how precisely it is stored. Try it:

Will this model fit?

Lab 4 · Memory math
14 GB needed

These numbers only count the model's own weights. Actually running a model needs extra room for the work in progress, and training needs several times more. That is one reason big models are split across many GPUs, and why people compress models (store each number with fewer bytes) to run them on laptops and phones. The trade-off: squeezed numbers are a little less precise.

CH 07 / Beyond the GPU

TPUs, NPUs, and the GPU in your own devices

GPUs are not the only chips built for AI math. Once companies saw how much AI needed matrix multiplication, they built chips that do almost nothing else.

GPU

Graphics processing unit

Thousands of flexible parallel cores. Good at graphics, AI, science simulations, and more. Still the most common AI chip.

TPU

Tensor processing unit

A chip Google designed mostly for neural-network matrix math. Used in Google's own data centers. A tensor is just a grid of numbers with any number of dimensions.

NPU

Neural processing unit

A small, low-power AI helper built into many phones and newer laptops. Runs features like face unlock, photo cleanup, and live captions without draining the battery.

The GPU you already own

DeviceWhat its GPU looks like
Phone or tabletAn integrated GPU, built into the same chip as the CPU. It shares memory with everything else. Many also have an NPU.
LaptopUsually an integrated GPU. Gaming and creator laptops may add a separate GPU with its own VRAM.
Gaming PCOften a separate graphics card: a whole board with its own GPU, VRAM, and cooling fans.
Game consoleA custom chip with the CPU and a powerful GPU combined, sharing one pool of fast memory.

The cost: energy and money

All that math uses electricity, and electricity turns into heat. A single top data-center GPU can draw several hundred watts, roughly like a small space heater. Now picture tens of thousands of them in one building, plus the cooling systems that keep them from overheating. Large AI data centers can use as much electricity as a small town, and they often need lots of water or big air systems for cooling.

The chips are expensive too. Top AI GPUs can cost tens of thousands of dollars each. Exact numbers change fast and companies do not always share them, so be careful with any single figure you read online. The big picture is clear, though: training and running large AI models takes real energy and real money. That is why engineers work hard on smaller, more efficient models and chips.

Think about it: small AI features on your phone often run on its NPU, right on the device. Big chatbots usually run in data centers far away. Which one do you think uses more energy per question, and why?

CH 08 / FAQ

Frequently asked questions

What is a GPU?

A GPU, or graphics processing unit, is a computer chip with thousands of small, simple cores that all do math at the same time. It was first built to draw video game graphics, where millions of pixels each need their color worked out many times a second. Today GPUs are also the main chips used to train and run AI.

What is the difference between a CPU and a GPU?

A CPU has a few very fast, very smart cores that are great at doing different tasks one after another, like a few expert chefs. A GPU has thousands of simpler cores that are great at doing the same small math problem on lots of data at once, like a huge team where each person frosts one cupcake. CPUs win at step-by-step work. GPUs win at work that can be split into many identical pieces.

Why does AI use GPUs instead of CPUs?

A neural network is mostly a giant pile of multiply-and-add problems, organized as matrix math. Most of those problems do not depend on each other, so they can all be done at the same time. A GPU's thousands of cores can work on them in parallel, which makes training and running AI many times faster than on a CPU alone.

Why are they called graphics cards if they are used for AI?

GPUs were invented to draw graphics for games and videos, so the name stuck. Around 2007, programmers got tools to use GPUs for general math, and in 2012 a famous image-recognition network trained on GPUs showed how fast they were for AI. Today many of the most powerful GPUs are built for data centers and have no video output at all.

What is VRAM and why does it matter for AI?

VRAM is the GPU's own fast memory, sitting right next to its cores. An AI model's numbers, called parameters, need to fit in that memory so the cores can reach them quickly. For example, a model with 7 billion parameters stored with 2 bytes each needs about 14 GB just to hold its numbers, which is more than many laptop GPUs have.

What is the difference between a GPU, a TPU, and an NPU?

A GPU is a general parallel chip that is good at graphics and AI. A TPU, or tensor processing unit, is a chip Google designed mainly for the matrix math in neural networks and uses in its data centers. An NPU, or neural processing unit, is a small, low-power AI chip built into many phones and newer laptops for tasks like face unlock, photo cleanup, and voice features.

Does my phone or laptop have a GPU?

Almost certainly, yes. Phones, tablets, and most laptops have a GPU built into the same chip as the CPU, called an integrated GPU, which shares memory with the rest of the system. Gaming PCs often add a separate graphics card with its own VRAM. Game consoles also have a GPU and CPU combined on one custom chip.

CH 09 / Check yourself

Quick quiz

1. Which job would a GPU speed up the most?

2. In the race, why did the CPU win the step-by-step recipe?

3. A layer has 100 inputs and 50 neurons. How many multiply-adds does it take?

4. What is VRAM?

5. Your phone unlocks with your face without using the internet. Which chip most likely does that AI work?

Keep learning

Now you know why AI runs on graphics chips: neural networks are mountains of simple, independent math, and GPUs are built to do that math all at once. Next, look inside the networks those chips are running.