Basis Lab

How a Program Runs on a GPU

A Group That Is Waiting Does Not Need the Arithmetic Units, So Another Takes Them

Last timeWorkers That Step Together

Groups take turns on one set of arithmetic units. A group waiting for memory gives way to a ready one, and the fraction of time the units are busy can be computed.

More groups than the units can run

The last lesson followed one group. A core of the device holds many groups at once, far more than it has arithmetic units to run in a single step. So the groups take turns.

The vendor's guide describes the rule in one sentence: on each cycle a scheduler selects a group that is ready to execute its next instruction, and issues the instruction to it. The word that matters is ready. A group is not always ready, and the reason is nearly always memory.

Why a GPU Is Built This Way made the case that memory answers slowly compared with arithmetic. A group that reads an element has to send the request and then do nothing until the data returns. For those steps it has no use for the arithmetic units at all.

To make that countable, take an illustrative function. Every group runs for 1 step, waits 4 steps for memory, and repeats, three runs in all. The numbers are made up to keep the pictures small. Take the simplest model of a core: one set of units, serving one group per step.

Two groups, and the units mostly idle

Start with only two groups on the core.

FIG 1Two groups taking turns on one set of units
step123456789101112
the unitgroup Agroup Bidleidleidlegroup Agroup Bidleidleidlegroup Agroup B
group Arunningwaitingwaitingwaitingwaitingrunningwaitingwaitingwaitingwaitingrunningfinished
group Bready, no unit freerunningwaitingwaitingwaitingwaitingrunningwaitingwaitingwaitingwaitingrunning

Busy for 6 of 12 unit steps, 50 per cent. A free unit goes to the first ready task, top to bottom.

12 steps
Group A runs on step 1 and starts waiting. The units pass at once to group B. After step 2 both are waiting and the units have nothing to do until step 6. The whole job takes 12 steps and the units work in only 6 of them.

Two things are visible. The first is the giving way: A does not sit on the units through its wait. The second is that two groups are not enough. Between them they want the units for 2 steps in every 5, and for the other 3 steps both are waiting and the arithmetic units stand idle.

The lesson stops here

7 more paragraphs to go

You have read the opening. The rest of the argument, the problems that check whether it landed, and the lines worth keeping at the end all come with a plan.

The first lesson of every course in the library reads the whole way through, free, so you can see exactly what the rest of them are.

See the planThe contents

This is the reading half

Starting the course gives you your own copy of it. Every idea on every page has problems standing under it, marked with a reason rather than a tick, and any sentence you do not believe can be opened and argued with. None of that can happen on a page nobody owns.

The contents

The rest of this course

  1. 01The Loop Had an Order and the Sum Never Needed It
  2. 02Nobody Hands a Worker Its Index, So It Works It Out from Where It Sitsopening only
  3. 03One Worker Disagrees and Thirty-One Others Stand and Waitopening only
  4. 04A Group That Is Waiting Does Not Need the Arithmetic Units, So Another Takes Themyou are here
  5. 05The Function Asked for a Little More Storage and Half Its Groups Had to Leaveopening only
  6. 06Adding 256 Numbers in Eight Stages, with Everyone Waiting at the End of Eachopening only
  7. 07Two Workers Added One to the Same Cell and It Went Up by Oneopening only
  8. 08The Timer Said the Function Took No Time, Because It Had Not Run Yetopening only

Read alongside