The cost of moving data #
An accelerator has several levels of storage. Fast on-chip memory holds relatively little data. Larger device memory supplies weights and activations at a different cost. A calculation that repeatedly retrieves the same value from the larger store can spend a substantial share of its time transferring bytes. Reusing a value near the arithmetic units changes that balance.
Putting an upper bound on performance #
The Roofline model relates performance to operational intensity, the number of operations performed per byte transferred across a specified memory boundary. Multiply intensity by the available bandwidth and compare the result with peak arithmetic throughput. The lower of the two values bounds performance in this simplified model.
For example, a device sustaining 100 gigabytes per second across a boundary can feed at most 200 billion operations per second to a workload performing two operations per transferred byte. The application may achieve less because of implementation overhead, irregular accesses or limited parallelism. Reordering its work to reuse data can raise its intensity.
An example in language models #
FlashAttention applies this idea to transformer attention. The algorithm breaks the calculation into tiles that fit in fast memory and avoids writing a complete matrix of intermediate attention scores to larger memory. It still computes exact attention up to ordinary floating-point effects. Faster execution here comes from changing how data travels through the machine, illustrating why a hardware forecast benefits from an accompanying account of software.
Finding the crossover point #
Suppose a processor sustains one trillion arithmetic operations per second and moves 100 billion bytes per second from a particular memory level. The two Roofline limits meet at ten operations per byte. A workload performing two operations per byte would reach its bandwidth limit well before the arithmetic ceiling. At twenty operations per byte the arithmetic ceiling would become the tighter upper bound. These figures illustrate a hypothetical machine, and each boundary in a real memory hierarchy can have a different crossover point.
FlashAttention illustrates a counterintuitive consequence. Recomputing some intermediate values can be cheaper than saving them to slower memory and reading them back. The total count of arithmetic operations can therefore give the wrong ranking of two implementations. A useful measurement pairs elapsed time with bytes transferred and records the sequence lengths, hardware and numerical precision used. Otherwise an improvement in data reuse can look mysterious or disappear when a workload changes.
Why a fast memory link can sit idle #
Larry McVoy and Carl Staelin’s lmbench suite measured bulk transfers and memory latency separately. One latency test follows a chain of pointers. The address needed for the next read is stored in the current result, so the processor must wait for that result before requesting the next link. A program reading many independent arrays can have several requests in flight together. The two programs can therefore experience very different performance on the same memory hardware.
Suppose a read returns a 64-byte line and takes 100 nanoseconds. A single dependent chain missing the cache every time would fetch only 0.64 gigabytes per second, even with no other overhead. To sustain 64 gigabytes per second at that latency, a stream of independent reads would need about 100 lines in flight on average. For an application that visits scattered records one by one, reorganizing the records or processing several independent queries together may matter more than increasing the advertised transfer rate.
Sources
Step 4 of 5