OCR H446, section 1.1.2 (b)
What is a GPU?
A graphics processing unit (GPU) is a specialised processor that is designed to do a very large number of simple calculations at the same time.
A CPU has a few powerful cores, each good at running complex, varied instructions one after another. A GPU has hundreds or thousands of smaller, simpler cores, designed to run the same operation on lots of data at once. This is called data parallelism.
Why GPUs were created: graphics
Displaying a 3D scene means doing the same sums for millions of pixels and points, many times a second.
- Transforming the corners (vertices) of 3D shapes (matrix multiplication).
- Working out lighting and shading for each pixel.
- Texture mapping and rendering the final image for every frame, often 60 or more times a second.
Each pixel can be calculated independently of the others, so thousands of cores can work at once. A CPU doing this one pixel after another would be far too slow.
Graphics uses include computer games, video playback and editing, 3D modelling and CAD, and virtual and augmented reality.
Uses that are not related to graphics
Many problems have the same shape as graphics: the same calculation on a huge amount of data. This is called general purpose computing on a GPU (GPGPU).
| Use | Why a GPU helps |
|---|---|
| Machine learning and AI | Training a neural network means vast numbers of matrix multiplications, which GPUs do very quickly |
| Scientific simulations | Weather and climate models, fluid flow, molecule behaviour: each point on a grid is updated by the same rules |
| Cryptocurrency mining | Repeats the same hashing calculation an enormous number of times |
| Password cracking | Tries a very large number of possible passwords in parallel |
| Video encoding and image processing | The same operation is applied to every pixel or block |
| Data analysis and financial modelling | The same calculation over big data sets |
| Medical imaging | Processing scans such as MRI and CT |
Comparison with a CPU
| CPU | GPU | |
|---|---|---|
| Number of cores | A few (such as 4 to 16) | Hundreds or thousands |
| Each core | Powerful and flexible | Simple |
| Good at | Sequential, varied tasks, with decisions and branches | The same operation on many data items at once |
| Typical job | Running the operating system and programs | Graphics, machine learning, simulations |
| Memory | Large main memory, with caches | Its own fast memory |
A GPU doesn't replace the CPU. The CPU runs the main program and hands the parallel parts to the GPU, then collects the results.
Limitations
- Poor at tasks with lots of decisions or which must be done in order, since the cores are simple and work in lockstep.
- Data must be copied between main memory and the GPU's memory, which takes time and can cancel the gain for small jobs.
- Programs have to be written specially to use it (for example with CUDA or OpenCL).
- Uses a lot of power and produces heat.
Worked example
Task: explain why a GPU is better than a CPU for adding 1 to each of 10 million pixel values, but a CPU is better for a program that checks a long chain of "if" conditions that depend on each other.
- Adding 1 to every pixel: the same, simple operation on millions of independent values. The GPU does thousands at a time, so it finishes far faster.
- A chain of dependent conditions: each step needs the result of the one before, so the work can't be spread out. The CPU's few powerful cores and its handling of branches suit this far better, and the GPU's thousands of cores would sit idle.
Exam tip: describe a GPU as having many simple cores doing the same operation on many data items at once. Give one graphics use and one non-graphics use (such as machine learning or simulations), and explain why it suits a GPU.
Check yourself
What is the main difference between the cores of a CPU and a GPU?
A CPU has a few powerful, flexible cores. A GPU has hundreds or thousands of simpler cores designed to do the same operation on many data items at once.
Give two uses of GPUs that are not related to graphics
Any two of: machine learning and AI; scientific simulations; cryptocurrency mining; password cracking; video encoding; data analysis.
Why is a GPU poor at tasks with many dependent decisions?
Its cores are simple and work together in parallel on similar operations. A task where each step depends on the previous result can't be spread across the cores.