devutils/ATFQ/book ATFQ git

Part I · How it works

5.1 What a GPU does differently

alsovramvideo memoryintegrated graphicsdiscrete gpuigpudgpusimtshadershaders

TL;DR

  • A CPU has a few powerful cores, built to run one thread fast, branches and all. A GPU has thousands of simple ones, built to run the same instructions on huge amounts of data at once.
  • That fits pixels, video and the matrix maths of machine learning; it doesn't fit branchy, step-by-step code.
  • A discrete GPU has its own memory (VRAM), very fast but separate: data must be copied there over PCIe. An integrated GPU shares the system's RAM.
lspci -k | grep -A3 -E 'VGA|3D|Display'   # GPUs and their drivers

On your machine

alice@laptopexample
$ atfq 5.1
  card0     Intel, driver i915, shows the boot screen
  Screens   eDP-1 1920x1200 · free: DP-1, HDMI-A-1
  Compute   /dev/dri/renderD128

An example: Alice's laptop, one of the test machines. In your terminal, this block shows your own machine, read live.

Pitfalls

Deep dive 2 questions

How does a GPU run thousands of threads?

Threads are grouped by 32 (NVIDIA "warps") or 32 to 64 (AMD "wavefronts"), and a group runs one instruction at a time for all its threads, each on its own data. When threads of a group take different branches, the group runs both paths in turn: that's why branches are expensive. While a group waits on memory, the GPU switches to another at no cost: it hides latency with parallelism, where a CPU uses big caches.

Why is VRAM so fast?

It's built for bandwidth: GDDR memory on wide buses, or HBM stacked next to the chip, reaches hundreds of GB/s to several TB/s, against tens of GB/s for a PC's RAM. The price is size and cost, which is why the amount of VRAM limits the models and scenes a GPU can handle.

Commands
lspci
Paths
/sys/class/drm/
See also
5.4 Computing on the GPU, and when your program can't see it
2.2 Cores, threads and sockets