From a Matrix Multiply to a Forward Pass
Every Operation Has a Fixed Cost to Start, and the Small Ones Are Nearly All Start
Last timeWhat Half the Bits Buys
Starting any operation on the device costs a fixed time that does not shrink with the work. Measure it, and the small operations turn out to be a third of a pass.
Lesson one found that the operations between the multiplies are four ten thousandths of the arithmetic of a block. If time followed arithmetic, this lesson would not exist. It does not, for a reason that has nothing to do with arithmetic.
A fixed cost that does not shrink
Each operation of a pass is a function the host starts on the device. The vendor calls this a kernel launch, and How a Program Runs on a GPU showed that the launch is not the work. Before any worker runs, the host has chosen which function to use, checked the shapes of the tables, reserved somewhere for the result and queued the request. All of it takes time, and none of it depends on how many numbers the operation will touch.
- the fixed cost to start, spent mostly on the host, the same for four numbers or four million
- the work: a cost per number, times the count of numbers the operation touches
Measuring the start
No data sheet prints . It depends on the framework, the host processor and the operation, so it is a thing to measure, and there is one trap in doing so. The programming guide for the device says a launch returns to the host before the device has completed the task. The documentation of PyTorch says the same of its own operations and draws the consequence: timings taken without waiting for the device are not accurate.
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 contentsThis 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