Basis Lab

How a program runs

Follow a function from the call that launches it to the result coming back, well enough to predict how the grouping of its workers changes the run time and to measure that run time without fooling yourself

How a Program Runs on a GPU

One function, run once per element by a great many workers. This course follows that function through the device: how workers are grouped, which group runs when, how many fit at once, how they share and where they collide.

8 lessons, written and corrected before you arrived. Reading them here needs no account. The first reads the whole way through; the others open and then stop, because a page nobody owns cannot tell who is reading it. Starting the course gives you your own copy, where every idea has problems standing under it and you can ask about any sentence.

Start reading

  1. 01The Loop Had an Order and the Sum Never Needed ItA loop over an array becomes one function of an index when no trip needs another trip's result. Two questions decide whether a given loop qualifies.
  2. 02Nobody Hands a Worker Its Index, So It Works It Out from Where It Sitsopening onlyWorkers come in equal blocks, and blocks come in a grid. A worker finds its element from two positions, and one integer division picks a block count that covers any length.
  3. 03One Worker Disagrees and Thirty-One Others Stand and Waitopening onlyThe device runs workers in fixed groups that execute one instruction at a time. When members disagree at a decision, both sides are run and part of the group idles on each.
  4. 04A Group That Is Waiting Does Not Need the Arithmetic Units, So Another Takes Themopening onlyGroups 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.
  5. 05The Function Asked for a Little More Storage and Half Its Groups Had to Leaveopening onlyA core has fixed private storage and fixed shared storage. What each worker asks for decides how many groups are resident, and so how much of the wait is hidden.
  6. 06Adding 256 Numbers in Eight Stages, with Everyone Waiting at the End of Eachopening onlyThe workers of one block share a small fast store and can wait for each other. Together those make a sum in stages, and the number of stages is the number of halvings.
  7. 07Two Workers Added One to the Same Cell and It Went Up by Oneopening onlyAdding to a cell is three steps, and two workers can interleave them and lose an update. An update that cannot be interrupted repairs it, and makes the workers queue.
  8. 08The Timer Said the Function Took No Time, Because It Had Not Run Yetopening onlyA launch hands the work to the device and returns at once. A clock read straight afterwards measures the hand-over, so a timing must wait for the device on both sides.