Basis Lab

From a Matrix Multiply to a Forward Pass

A Multiply Fills the Device Only Above a Certain Batch, and the Batch Can Be Computed

Last timeJoining Small Operations Together

Below a certain batch a layer leaves the arithmetic units waiting and extra requests are nearly free. Above it each request costs its full arithmetic. The knee is a formula.

After joining, a pass is a shorter list of larger operations. The largest are the multiplies by weight tables, and how much of the device each one uses depends on one number the operator controls: how many rows go through together. What It Costs to Run a Model follows that number to the bill. This lesson follows it into the device, for one layer.

Two ways to leave the device idle

The device is not one unit. NVIDIA's performance guide describes the A100 of 2020 as 108 sets of units, and says that a function started with a single block of workers gives work to a single set. It recommends several times as many blocks as sets, about four, so that no set runs dry while others finish.

Take the layer of 4,096 by 4,096 weights, and suppose as an illustration one worker for each output cell in blocks of 256. A batch of bb rows has 4,096b4{,}096b cells, which is 16b16b blocks. One row gives sixteen blocks: ninety-two sets of units have nothing. Seven rows reach 108 blocks and twenty-seven reach four for every set.

That is the first way to be idle, and a small batch escapes it quickly. The second lasts longer. A set of units with work to do can still be waiting on memory, and that is decided by the operations per byte of lesson one.

FIG 1Operations per byte of a square layer, and the batch that fills the device
the arithmetic, 2 b n squared, after dividing top and bottom by the width n
the bytes after the same division: the weights give n and the inputs and outputs give 2b, at f bytes a number
the batch at which I equals the balance point B of the device, found by setting the first expression equal to B and solving for b
On the representative machine B is 100, and with two-byte numbers and a width of 4,096 the knee is at 105.1, so 106 rows. That is a little above the hundred of the neighbouring course because the inputs and outputs are counted here.

The same formula on a named device: the A100 with 80 gigabytes has a peak of 312 trillion two-byte operations a second and moves 2,039 gigabytes a second, a balance point of 153. Its knee for this layer is at 165.4, so 166 rows.

The lesson stops here

3 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. 01A Forward Pass Is a List of Matrix Multiplies, and You Can Count Each One
  2. 02A Multiply Is Cut Into Tiles So That Each Block of Workers Reuses What It Fetchedopening only
  3. 03A Unit That Only Multiplies Small Matrices Is Worth Eight Times, on the Multiplies That Can Feed Itopening only
  4. 04Halving the Size of a Number Is Worth Exactly Two to Memory and Whatever the Units Say to Arithmeticopening only
  5. 05Every Operation Has a Fixed Cost to Start, and the Small Ones Are Nearly All Startopening only
  6. 06A Run of Small Operations Joined Into One Pass Pays for One Start and One Trip Through Memoryopening only
  7. 07A Multiply Fills the Device Only Above a Certain Batch, and the Batch Can Be Computedyou are here
  8. 08A Device Reported as Fully Busy May Be Using One Hundredth of Its Arithmeticopening only

Read alongside