Basis Lab

Memory Is the Limit on a GPU

The Fastest a Job Can Run Is Its Bytes Divided by the Bandwidth

Last timeWhat Has to Fit

A GPU's memory delivers bytes at a published rate. Divide the bytes a job must read and write by that rate and you have a time no version of the job can beat.

The first lesson asked whether a job fits. This one asks how fast it could possibly go once it does, and the answer needs one more number from the product page and no knowledge of the arithmetic.

Bytes moved

The arithmetic units of a GPU cannot work on a value until it has been brought to them from the device's memory, and a result is not finished until it has been written back. Both journeys use the same path. So for any job, count the bytes it must read and the bytes it must write, and add them.

Take the plainest job there is: add two arrays of a billion values into a third, at four bytes a value. Each array is 4 GB. Two are read and one is written, so 12 GB move. Forgetting the result gives 8 GB and an answer a third too low.

FIG 1Counting the bytes four jobs move
stepthe jobread, GBwritten, GBmoved, GBwhat happened
1add two arrays of a billion 4 byte values into a third8412Two inputs and one result, each 4 GB.
2double every value of one such array in place448In place saves memory and saves no traffic: every value still travels out and back.
3one pass of one item through 14 GB of weights14014The model of the first lesson. The item's own values are megabytes and vanish beside the weights.
4copy those weights to another place on the device141428Twice the size of the thing copied.
4 steps
Every figure here is a count of values times bytes per value, as in the first lesson, taken once for each journey. Nothing has been run.

The published rate

The memory of a device can deliver only so many bytes a second. The vendor publishes the figure as memory bandwidth, and this course calls it the memory rate. For the A100 80GB in its SXM form, the product page gives 2,039 GB a second. For the Tesla V100, the device before it, the vendor's performance guide gives approximately 900 GB a second.

Those are large numbers, and they are best read against the size of the memory. The A100 80GB could read its entire 80 GB once in 80/2,03980 / 2{,}039 seconds, which is about 39 milliseconds. A job that passes over everything it holds cannot do so more than about twenty-five times a second, whatever it computes.

The lesson stops here

5 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 Bandwidthyou are here
  3. 03One Division Says Whether Faster Arithmetic Would Helpopening only
  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