S431 of 55
0 XP
  1. Hook
  2. Play
  3. Predict
  4. Name it
  5. Check
  6. Explain

S4 · Lesson 31 · The roofline model

Arithmetic intensity, memory-bound and compute-bound kernels, ceilings and the ridge point

A machine can do 1.5 trillion floating-point operations a second, and its memory delivers 100 billion bytes a second. Which limit does a given program hit? The roofline model answers with one picture. Each kernel has an arithmetic intensity, the operations it does per byte it moves from memory, and its attainable performance is the lower of two roofs: the compute peak, or the memory bandwidth times its intensity. The picture tells a programmer whether to optimize arithmetic or data movement, and tells an architect which kernels a machine is built for.

  • Attainable performance against arithmetic intensity on log scales: the sloped roof is bandwidth × intensity, the flat roof the compute peak. They meet at the ridge point, peak/bandwidth.
  • The markers are typical kernels: DAXPY (y=ax+y, 1/12 flop per byte), sparse matrix-vector product (about 0.25), a stencil (about 0.5) and a blocked matrix multiply (several to tens).
  • Lower ceilings (dashed) show the peak without SIMD or without FMA: a kernel above the ridge that doesn't vectorize hits those instead.

Predict

A machine peaks at 1536 GFLOPS with 100 GB/s of memory bandwidth. DAXPY does 2 operations per 24 bytes moved. What fraction of peak can it reach?

Name it

The model

attainable=min⁡(Ppeak,B×I),I=operationsbytes moved from memory
  • Ridge point I*=Ppeak/B: kernels with I<I* are memory-bound, those above are compute-bound.
  • The intensity counts bytes that actually move from DRAM (or from whichever level the roof represents), so caching and blocking raise it.
  • A kernel's run time is at least max⁡(opsPpeak,bytesB).

Ceilings

Real code rarely reaches the roofs. Compute ceilings below the peak: no SIMD (divide by the lane count), no FMA (divide by 2), poor instruction mix. Bandwidth ceilings below the peak bandwidth: no prefetching, poor locality, NUMA effects. Separate roofs for L1, L2 and DRAM bandwidth give a hierarchical roofline.

Typical intensities (double precision)

Kernelflop/byte
DAXPY2 / 24 = 0.083
sparse matrix-vectorabout 0.25
7-point stencilabout 0.5
FFTabout 1 to 2
matrix multiply blocked by Babout B/8

Worked example

On the 1536 GFLOPS, 100 GB/s machine, where's the ridge, and what do DAXPY and a matrix multiply blocked by 32 and by 128 reach?

Show the solution
  1. Ridge. 1536/100=15.4flop/byte
  2. DAXPY. It does 2 flops per 24 bytes: 100/12=8.3GFLOPS
  3. Matrix multiply intensity. Blocking by B moves about 2N3/B doubles for 2N3 operations, so I≈B/8
  4. B = 32. I = 4 flop/byte, so it's memory-bound: 100×4=400GFLOPS
  5. B = 128. I = 16 flop/byte, above the ridge, so it's compute-bound at 1536 GFLOPS.
  6. Cache size. Larger blocks need larger caches, which is why the last level of blocking targets the L2 or L3.

Answer the ridge is at 15.4 flop/byte; DAXPY reaches 8.3 GFLOPS, and the matrix multiply 400 GFLOPS blocked by 32 and the full 1536 GFLOPS blocked by 128.

Worked example

A stencil updates 109 points, each needing 8 operations and 16 bytes of DRAM traffic. How long does it take on that machine?

Show the solution
  1. Intensity. I=8/16=0.5flop/byte below the ridge, so the attainable rate is 100×0.5=50 GFLOPS.
  2. Time. t=8×10950×109s=0.16s the same as the time to move 16 GB at 100 GB/s.
  3. Compare with the arithmetic. The arithmetic alone would take 5 ms; all the rest is waiting on memory.

Answer the stencil takes 0.16 s.

Worked example

A machine peaks at 2 TFLOP/s with 200 GB/s of memory bandwidth. A kernel performs 4 flops per byte moved. Where does it sit, and what if blocking raises its intensity to 16?

Show the solution
  1. Ridge. 2000/200=10flop/byte
  2. At an intensity of 4. The kernel is memory-bound: 200×4=800GFLOP/s which is 40% of peak.
  3. At an intensity of 16. It's past the ridge and can reach the full 2 TFLOP/s.
  4. What helped. Optimizing its arithmetic would have done nothing at 4; reducing its traffic did everything.

Answer at 4 flop/byte the kernel is memory-bound at 800 GFLOP/s (40% of peak); at 16 it reaches the full 2 TFLOP/s.

Check

A machine peaks at 1500 GFLOPS with 50 GB/s. What does a kernel of intensity 10 flop/byte attain?

Check

A machine peaks at 2500 GFLOPS with 60 GB/s of memory bandwidth. Where's its ridge point?

Check

A loop does 3 operations per element, reading 2 arrays and writing 2, with 8-byte elements and no reuse. What's its arithmetic intensity?

Check

A kernel processes 1 billion elements, each 4 operations and 32 bytes of DRAM traffic, on a 3000 GFLOPS, 100 GB/s machine. What's its minimum run time?

Write units the way you normally would: 1.5 s and 1500 ms are the same answer.

Check

On a 1000 GFLOPS, 100 GB/s machine, what fraction of peak can a kernel of intensity 50 reach?

Check

A matrix multiply is blocked with 64 × 64 tiles of 4-byte numbers. About what intensity does it reach, at 2N3 operations for 2N3/T elements moved?

Check

A machine peaks at 500 GFLOP/s with 50 GB/s. A kernel of 100 G flops has an intensity of 16 flop/byte.

(a)

Where is the ridge point?

(b)

What rate can the kernel reach?

(c)

What is its shortest run time?

Write units the way you normally would: 1.5 s and 1500 ms are the same answer.

Check

A machine peaks at P with bandwidth B; a kernel has intensity I.

Step 1

What is the ridge intensity?

Type it the way you would write it, like 3sin(2πft) or 3*sin(2*pi*f*t). Angles can be in radians or carry a degree sign, like 45°.

Explain why

Why does adding SIMD units or cores not speed up a memory-bound kernel?

Practice

Keep practicing

10 kinds of problem on this topic, dealt one at a time with new numbers every time, for as long as you like.