Basis Lab

Memory Is the Limit on a GPU

One Division Says Whether Faster Arithmetic Would Help

Last timeThe Rate Bytes Arrive

Divide a job's operations by its bytes, divide the device's arithmetic rate by its memory rate, and compare the two. The smaller side names the limit you are against.

The last lesson ended with a job far above nothing in particular: adding two arrays took 115 times longer to feed than to compute. This lesson turns that comparison into a single division that can be done for any job on any device, before the job is written.

The ratio of a job

Count the operations the job performs and the bytes it moves, and divide.

Adding two arrays does one addition for each result. That result is four bytes written, from two values of four bytes read. One operation for twelve bytes: a ratio of 1/121/12, about 0.08 operations a byte.

A layer of a model is different. Each weight is two bytes and is used once for every item in the batch, with one multiplication and one addition. A batch of nn items does 2n2n operations on those two bytes, so the ratio is nn operations a byte. Counting only the weights, which dominate, the ratio of a layer is its batch size.

Both numbers are properties of the job. Neither mentions a device.

The balance point of a device

A device has two rates: the arithmetic it can do in a second and the bytes its memory can deliver in a second. Divide the first by the second.

The lesson stops here

6 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. 01Add Up the Largest Moment, Not the Average
  2. 02The Fastest a Job Can Run Is Its Bytes Divided by the Bandwidthopening only
  3. 03One Division Says Whether Faster Arithmetic Would Helpyou are here
  4. 04Where a Byte Is Kept Decides What It Costs to Readopening only
  5. 05A Group That Reads Next-Door Addresses Wastes Nothingopening only
  6. 06Store Each Field in Its Own Array and the Group Reads Next-Door Bytesopening only
  7. 07Use a Value Many Times While It Is Near and the Memory Stops Being the Limitopening only
  8. 08Four Ways to Fit, and What Each One Costsopening only

Read alongside