4 Compute and Systems 2 / 5
  1. In this chapter
  2. LLM hardware basics
  3. GPUs and the Roofline Model
  4. GPU kernels
  5. Numerical Precision
  6. Collective Communication
All chapters →

Chapter 4 · Compute and Systems 4.2

GPUs and the Roofline Model: Why Big Models Are Bound by Memory Bandwidth

A GPU is limited by two walls: how many operations it can do per second (compute) and how many bytes it can move per second (memory bandwidth). The roofline model uses arithmetic intensity to tell which wall an operator hits first. This page derives it and measures it on a CPU.

Intermediate 41 min read Updated Companion code ↓

After this page you will be able to

  • Explain the three walls of compute, memory bandwidth and memory capacity, and use arithmetic intensity (FLOP/byte) to tell whether an operator is compute-bound or bandwidth-bound.
  • Write the roofline formula and the ridge point, and compute the ridge points of the A100 and the H100 (153 and 295 FLOP/byte).
  • Derive how the arithmetic intensity of a linear layer depends on batch size, and explain why batched decoding is almost free and where that stops (KV cache reads and capacity).
  • Measure a bandwidth ceiling, a compute ceiling and a batch-size sweep on your own machine, and read the gap between the measurements and the roofline.
  • Explain why operator fusion speeds up elementwise operations and what it does inside kernels such as FlashAttention.
On this page
  1. Hardware: compute, bandwidth and capacity
  2. Arithmetic intensity and the roofline
  3. Arithmetic intensity of a linear layer
  4. One decoding step: what is the bottleneck
  5. Measured: the roofline on a laptop
  6. Bandwidth and compute ceilings
  7. A batch-size sweep of a linear layer
  8. Operator fusion: moving the data once
  9. How stable are these numbers
  10. Applying the roofline to large models
  11. What the roofline does not tell you
  12. From the roofline to a performance trace
  13. Common pitfalls
  14. Data layout can change memory traffic at the same FLOP count
  15. How matrix multiplication tiling raises arithmetic intensity
  16. Summary and exercises
  17. Quick self-check
  18. Further reading
  19. FAQ

How fast an operator runs on a GPU depends on which wall it hits first: compute (how many floating-point operations the chip can do per second) or memory bandwidth (how many bytes it can move from memory per second). The roofline model decides with a single number called arithmetic intensity: how many floating-point operations the operator performs for every byte it moves, in FLOP/byte. Below the hardware’s “ridge point” the speed is set by bandwidth; above it, by compute. The most common operators in LLM inference, linear layers at small batch sizes and attention over the KV cache, have intensities between single digits and a few tens, far below the A100’s ridge point of 153. Their speed therefore follows memory bandwidth, not the advertised 312 TFLOPS.

If you are new to this topic, start with LLM hardware basics.

This one judgment is a through line. Batching, weight quantization, GQA, FlashAttention and operator fusion look unrelated, yet they all do the same thing: move fewer bytes, or do more operations per byte. This page builds the model and then measures the roofline on a laptop without a GPU, since the model holds for any processor with a compute ceiling and a bandwidth ceiling. The next two pages of this chapter, on numerical precision and on multi-GPU communication, are two extensions of the same model.

Hardware: compute, bandwidth and capacity

A GPU packages thousands of arithmetic units with a large block of high-bandwidth memory (HBM). Three numbers are enough to understand the speed of a large model:

  • Compute PpeakP_{\text{peak}}: how many floating-point operations per second the chip can do (FLOP/s). Matrix multiplication reaches the peak on dedicated Tensor Cores, whose BF16 peak is more than ten times that of the ordinary FP32 cores on the same card.
  • Bandwidth BWBW: how many bytes per second can move between HBM and the chip.
  • Capacity: how many bytes HBM can hold. Weights, the KV cache, activations and, during training, optimizer states all have to fit.

The table lists the datasheet values of two mainstream data-center GPUs:

ItemA100 80GB SXMH100 SXM
ArchitectureAmpereHopper
BF16 Tensor Core (dense)312 TFLOPS989 TFLOPS
FP32 (ordinary cores)19.5 TFLOPS67 TFLOPS
Memory80 GB HBM2e80 GB HBM3
Memory bandwidth2,039 GB/s3.35 TB/s
Ridge point (compute / bandwidth)153 FLOP/byte295 FLOP/byte
Streaming multiprocessors (SMs)108132
L2 cache40 MB50 MB
L1 and shared memory per SM192 KB256 KB

The 624 TFLOPS of the A100 and 1,979 TFLOPS of the H100 on the datasheets assume structured sparsity; the dense peak is half of that, and the table uses the dense values. Data passes through several levels of storage on a GPU: HBM (tens of GB, TB/s), the L2 cache (tens of MB), the shared memory and L1 cache inside each streaming multiprocessor (SM, hundreds of KB), and registers. The closer to the arithmetic units, the smaller and faster. The BWBW in the roofline is the outermost level, HBM, because most of an operator’s inputs and outputs travel through it; data that stays in on-chip caches and is reused does not count as HBM traffic, which is exactly the starting point of operator fusion and FlashAttention.

The script divides compute by bandwidth to get the ridge point, and it is the starting point of every calculation below:

GPUS = {  # (BF16 dense FLOP/s, HBM byte/s, FP32-core FLOP/s), NVIDIA datasheets
    "A100 80GB SXM": (312e12, 2039e9, 19.5e12),
    "H100 SXM": (989e12, 3.35e12, 67e12),
}
for name, (peak, bw, fp32) in GPUS.items():
    print(f"{name:14s} compute {peak / 1e12:4.0f} TFLOPS  "
          f"bandwidth {bw / 1e12:4.2f} TB/s  ridge {peak / bw:5.1f} FLOP/B  "
          f"TC/FP32 {peak / fp32:4.1f}x")
a100, h100 = GPUS.values()
print(f"H100 / A100: compute {h100[0] / a100[0]:.2f}x, "
      f"bandwidth {h100[1] / a100[1]:.2f}x")
A100 80GB SXM  compute  312 TFLOPS  bandwidth 2.04 TB/s  ridge 153.0 FLOP/B  TC/FP32 16.0x
H100 SXM       compute  989 TFLOPS  bandwidth 3.35 TB/s  ridge 295.2 FLOP/B  TC/FP32 14.8x
H100 / A100: compute 3.17x, bandwidth 1.64x

Two things are worth remembering. First, the H100 has 3.17 times the compute of the A100 but only 1.64 times the bandwidth: compute grows faster than bandwidth with every GPU generation, the ridge point moves right (153 to 295), and more and more operators end up on the slope. Second, BF16 Tensor Cores are 14.8 to 16.0 times faster than the FP32 cores, so an FP32 matrix multiplication stays far below the roof in the table, which is the topic of the next page on numerical precision.

Arithmetic intensity and the roofline

For an operator, count the floating-point operations it performs (FLOPs, one multiply-add counts as two) and the bytes it must read from and write to HBM (Bytes). Their ratio is the arithmetic intensity:

I=FLOPsBytes(in FLOP/byte)I=\frac{\mathrm{FLOPs}}{\mathrm{Bytes}}\qquad(\text{in FLOP/byte})

The roofline model (Williams, Waterman and Patterson, 2009) says the speed PP (FLOP/s) an operator can reach has two upper bounds:

P  ≤  min⁡(Ppeak,  I⋅BW),I∗=PpeakBWP\;\le\;\min\big(P_{\text{peak}},\;I\cdot BW\big),\qquad I^{*}=\frac{P_{\text{peak}}}{BW}
  • I<I∗I<I^{*}: the intensity is too low and bandwidth decides the speed, P=I⋅BWP=I\cdot BW, which rises linearly with intensity. This is the slope of the roofline and the operator is memory-bound.
  • I>I∗I>I^{*}: the intensity is high enough that bandwidth keeps the arithmetic units fed and speed is capped at PpeakP_{\text{peak}}. This is the roof and the operator is compute-bound.
  • The point I∗I^{*} where slope and roof meet is the ridge point.

In terms of time: an operator takes at least max⁡(FLOPs/Ppeak, Bytes/BW)\max(\mathrm{FLOPs}/P_{\text{peak}},\ \mathrm{Bytes}/BW), and exactly that when computation and transfers overlap perfectly. Figure 1 draws the rooflines of the two cards on log-log axes; the dots are typical workloads computed in the next section.

Rooflines of the A100 and the H100 Log-log chart: arithmetic intensity on the x axis, attainable performance on the y axis. The A100 roofline turns from the bandwidth slope into a 312 TFLOPS roof at intensity 153, the H100 at 295 into 989 TFLOPS. Five dots mark a 4096 by 4096 linear layer on the A100: elementwise add and batch-1 decoding sit on the slope, batch-512 decoding and a 2048-token prefill sit on the roof. 0.1 1 10 100 1,000 10,000 0.1 1 10 100 1,000 Arithmetic intensity (FLOP/byte, log scale) Attainable performance (TFLOP/s, log scale) A100 80GB: 312 TFLOPS, 2.04 TB/s, ridge 153 H100 SXM: 989 TFLOPS, 3.35 TB/s, ridge 295 bandwidth-bound (slope) compute-bound (roof) elementwise add I = 0.17 decode B=1 I = 1.0 decode B=64 I = 62.1 decode B=512 I = 409.6 prefill, 2048 tokens I = 1024.0
Roofline = min(peak compute, intensity x bandwidth), with the parameters from the table above (BF16 dense). The dots are a 4096 by 4096 linear layer (BF16, activation traffic included) on the A100; the intensities come from the same function as the intensity script.

Arithmetic intensity of a linear layer

The linear layer is the heaviest operator in a large model. A batch of BB token activations X∈RB×KX\in\mathbb{R}^{B\times K} is multiplied by weights W∈RK×NW\in\mathbb{R}^{K\times N}, and every output takes KK multiply-adds:

FLOPs=2BKN,Bytes=w KN+a B (K+N)\mathrm{FLOPs}=2BKN,\qquad \mathrm{Bytes}=w\,KN+a\,B\,(K+N)

Here ww and aa are the bytes per weight and per activation (2 for BF16), assuming every number is read or written in HBM once. Dividing:

I=2BKNw KN+a B (K+N)  ≈  2Bw(B≪K,N)I=\frac{2BKN}{w\,KN+a\,B\,(K+N)}\;\approx\;\frac{2B}{w}\qquad(B\ll K,N)

With BF16 weights (w=2w=2) this gives I≈BI\approx B: the batch size is the arithmetic intensity. The reason is simple: the weights are read once and shared by every token in the batch, so BB tokens split the cost of the same weight read. As the batch size grows without bound, activation traffic becomes the main bytes and the intensity tends to KN/(K+N)KN/(K+N), which is 2048 for a 4096x4096 layer.

def intensity(B, K, N, w_bytes=2, a_bytes=2):
    """B tokens through a K x N linear layer: FLOPs per byte moved."""
    flop = 2 * B * K * N
    return flop / (w_bytes * K * N + a_bytes * B * (K + N))

print(f"BF16 elementwise add: {1 / 6:.2f} FLOP/B (read 2+2 bytes, write 2)")
print("4096x4096 linear layer (BF16), arithmetic intensity for B tokens:")
for B in (1, 16, 64, 153, 295, 512, 2048, 32768):
    print(f"  B={B:<6d}{intensity(B, 4096, 4096):7.1f}")
print(f"B=1, INT4 weights (0.5 byte): {intensity(1, 4096, 4096, 0.5):.1f}")
BF16 elementwise add: 0.17 FLOP/B (read 2+2 bytes, write 2)
4096x4096 linear layer (BF16), arithmetic intensity for B tokens:
  B=1         1.0
  B=16       15.9
  B=64       62.1
  B=153     142.4
  B=295     257.9
  B=512     409.6
  B=2048   1024.0
  B=32768  1927.5
B=1, INT4 weights (0.5 byte): 4.0

Three things to read from the table:

  1. At B=1B=1 the intensity is only 1.0, two orders of magnitude below the A100 ridge point of 153. When a single sequence is decoded, the linear layers spend almost all their time waiting for the weights to come out of HBM.
  2. Reaching the roof takes a batch of hundreds. At B=153B=153 the intensity is 142.4, still short of the A100 ridge point; the gap is the bytes of activation traffic.
  3. Moving fewer bytes is as good as doing more work. Storing the weights in INT4 (0.5 bytes) lifts the intensity at B=1B=1 from 1.0 to 4.0 without a single extra operation. That is why quantization speeds up decoding; see Quantization. An elementwise add has an intensity of 0.17 and is always on the slope.

One decoding step: what is the bottleneck

Let us use the model to estimate a real decoding step. Take a model with P=7×109P=7\times10^{9} parameters, L=32L=32 layers, H=32H=32 query heads, head dimension dh=128d_h=128 and context length T=4096T=4096, with weights and KV cache in BF16, on an A100. In one decoding step, BB sequences each generate one new token. The bytes and operations of that step split into two kinds with very different behavior:

  • Linear layers (attention projections, feed-forward network): read all the weights once, 2P2P bytes in total, and do 2P2P operations per token. All sequences in the batch share the weights, which is where I≈BI\approx B comes from.
  • Attention: every sequence reads its own KV cache of sKV=4 L hkv dh Ts_{KV}=4\,L\,h_{kv}\,d_h\,T bytes (hkvh_{kv} is the number of KV heads; K and V take 2 bytes each) and does 4LHdhT4LHd_hT operations (HH is the number of query heads). KV caches cannot be shared between sequences, so a larger batch means more reads, and the intensity of attention is H/hkvH/h_{kv}, independent of the batch size: 1 for multi-head attention (MHA) and 4 for grouped-query attention (GQA) with 8 KV heads.

The memory time and the compute time of one step are therefore:

tmem=2P+B sKVBW,tcmp=B (2P+4LHdhT)Ppeak,tstep≈max⁡(tmem, tcmp)\begin{aligned} t_{\text{mem}}&=\frac{2P+B\,s_{KV}}{BW},\\ t_{\text{cmp}}&=\frac{B\,(2P+4LHd_hT)}{P_{\text{peak}}},\\ t_{\text{step}}&\approx\max\big(t_{\text{mem}},\,t_{\text{cmp}}\big) \end{aligned}

The script computes this and compares multi-head attention (32 KV heads) with GQA with 8 KV heads. For the KV cache itself see KV Cache.

PARAMS, LAYERS, HEADS, D_HEAD, CTX = 7e9, 32, 32, 128, 4096  # 7B, context 4096
peak, bw, _ = GPUS["A100 80GB SXM"]
print(f"weights only {2 * PARAMS / bw * 1e3:.2f} ms, "
      f"one token's matmuls {2 * PARAMS / peak * 1e3:.3f} ms")

def step(B, kv_heads):
    """One decode step (B sequences, 1 token each): KV bytes, memory and
    compute time."""
    kv = 2 * LAYERS * kv_heads * D_HEAD * 2 * CTX   # KV cache per sequence
    t_mem = (2 * PARAMS + B * kv) / bw
    t_cmp = B * (2 * PARAMS + 4 * LAYERS * HEADS * D_HEAD * CTX) / peak
    return kv, t_mem, t_cmp

for kv_heads in (32, 8):
    kv = step(1, kv_heads)[0]
    cap = int((80e9 - 2 * PARAMS) // kv)
    print(f"{kv_heads} KV heads: {kv / 1e9:.2f} GB per sequence, at most "
          f"{cap} fit in 80 GB, attention intensity {HEADS / kv_heads:.0f}")
    print(f"  throughput limit as B grows: {bw / kv:.0f} token/s "
          f"(only the KV reads remain)")
    for B in (1, 8, 32, 128):
        _, t_mem, t_cmp = step(B, kv_heads)
        note = "" if B <= cap else "  (does not fit)"
        print(f"  B={B:<4d} memory {t_mem * 1e3:6.1f} ms "
              f"compute {t_cmp * 1e3:5.2f} ms "
              f"{B / max(t_mem, t_cmp):6.0f} token/s{note}")
weights only 6.87 ms, one token's matmuls 0.045 ms
32 KV heads: 2.15 GB per sequence, at most 30 fit in 80 GB, attention intensity 1
  throughput limit as B grows: 949 token/s (only the KV reads remain)
  B=1    memory    7.9 ms compute  0.05 ms    126 token/s
  B=8    memory   15.3 ms compute  0.41 ms    523 token/s
  B=32   memory   40.6 ms compute  1.66 ms    789 token/s  (does not fit)
  B=128  memory  141.7 ms compute  6.62 ms    903 token/s  (does not fit)
8 KV heads: 0.54 GB per sequence, at most 122 fit in 80 GB, attention intensity 4
  throughput limit as B grows: 3798 token/s (only the KV reads remain)
  B=1    memory    7.1 ms compute  0.05 ms    140 token/s
  B=8    memory    9.0 ms compute  0.41 ms    892 token/s
  B=32   memory   15.3 ms compute  1.66 ms   2093 token/s
  B=128  memory   40.6 ms compute  6.62 ms   3155 token/s  (does not fit)

How to read it:

  1. One token’s matrix multiplications take only 0.045 ms, while reading the weights takes 6.87 ms, a factor of about 150, which is exactly the ridge point of 153. In single-sequence decoding the compute is under 1% of the memory time; the rest is waiting for data.
  2. From batch size 1 to 8 throughput goes from 126 to 523 tokens/s, about 4 times: the extra sequences share the same weight read. This is the theoretical basis of continuous batching.
  3. The growth ends. Every sequence reads its own KV cache; at a batch of 128 the memory time is 141.7 ms while the compute is only 6.62 ms, so compute is nowhere near the bottleneck, and throughput is capped at BW/sKVBW/s_{KV}, 949 tokens/s for multi-head attention. Capacity is worse: one sequence has 2.15 GB of KV cache, so after the 14 GB of weights an 80 GB card holds at most 30 sequences, and B=32B=32 no longer fits.
  4. GQA raises the ceiling fourfold. Going from 32 to 8 KV heads shrinks the KV cache of a sequence to 0.54 GB, raises the number of sequences that fit from 30 to 122, lifts the throughput limit from 949 to 3798 tokens/s and the intensity of attention from 1 to 4.

This estimate is an upper bound: it ignores activation traffic and kernel launch overhead, and assumes perfect overlap of compute and memory. But it captures the main tension, and it explains why inference optimization concentrates on two things: making the batch as large as possible (continuous batching) and making the KV cache of every sequence as small as possible (GQA, KV quantization, PagedAttention).

The calculator below puts the formulas of this section and the two before it together: switch to the H100, to INT4 weights, drop the KV heads from 32 to 8, stretch the context to 32,768, and watch the throughput curve and the three dots on the roofline move. Switch to “Linear layer” to drag the batch size: a 4096×4096 BF16 linear layer crosses the ridge point from B=256B=256 on the A100 and only at B=512B=512 on the H100.

Measured: the roofline on a laptop

The numbers above were calculated. Let us now measure the same picture on the machine at hand and see how far the measurement is from the model. There is no GPU, so we use a CPU: the roofline holds for any processor with a compute ceiling and a bandwidth ceiling, and a CPU has both (only much smaller numbers).

The first line of the script’s output shows the environment: Apple M2 Max, 4 threads, Python 3.14.3, torch 2.10.0, numpy 2.4.2, all tensors in float32. The machine was running other jobs during the experiments, so the timings are disturbed. We therefore time with “take turns and keep the fastest”: each task is called several times in a row for one group and the fastest of 5 groups is kept; then all tasks take turns for 7 rounds and the minimum of the per-round best values is reported. Outside load can spoil only some of the rounds. We ran the whole script five times in full; the page uses the numbers of one run, and the table further down compares all five.

import platform, subprocess, time
import numpy as np
import torch
import torch.nn.functional as F

torch.set_num_threads(4)
chip = subprocess.run(["sysctl", "-n", "machdep.cpu.brand_string"],
                      capture_output=True, text=True).stdout.strip()
print(f"{chip}, Python {platform.python_version()}, "
      f"torch {torch.__version__}, numpy {np.__version__}")
NOISE = []   # max/min of each job's per-round best: noise on this machine

def bench(fn, reps, inner):
    """Run fn() inner times per group, reps groups; return the fastest
    group's time per call (seconds)."""
    ts = []
    for _ in range(reps):
        t0 = time.perf_counter()
        for _ in range(inner):
            fn()
        ts.append((time.perf_counter() - t0) / inner)
    return min(ts)

def bench_rounds(jobs, rounds=7, reps=5):
    """jobs is {name: (fn, inner)}. Time every job in turn, rounds times,
    and keep the best over rounds: outside load only spoils some rounds.
    The max/min ratio over rounds goes into NOISE."""
    per = {name: [] for name in jobs}
    for _ in range(rounds):
        for name, (fn, inner) in jobs.items():
            per[name].append(bench(fn, reps, inner))
    NOISE.extend(max(v) / min(v) for v in per.values())
    return {name: min(v) for name, v in per.items()}
Apple M2 Max, Python 3.14.3, torch 2.10.0, numpy 2.4.2

Bandwidth and compute ceilings

We measure each ceiling once. Bandwidth: c = a + b on float32 arrays of 128 MiB, two reads and one write, with arrays much larger than any cache; bytes divided by time is the streaming bandwidth. Compute: matrix multiplications of square matrices of several sizes, taking the fastest. Their ratio is the ridge point.

n = 128 * 2**20 // 4            # 128 MiB per float32 array, far past the caches
a, b, c = torch.ones(n), torch.ones(n), torch.empty(n)
STREAM = {}
for th in (1, 4):
    torch.set_num_threads(th)
    t = bench_rounds({"add": (lambda: torch.add(a, b, out=c), 4)})["add"]
    STREAM[th] = 3 * 4 * n / t  # read a, read b, write c
    print(f"{th} thread(s): c = a + b {STREAM[th] / 1e9:6.1f} GB/s")
torch.set_num_threads(4)
1 thread(s): c = a + b   90.5 GB/s
4 thread(s): c = a + b  149.4 GB/s
SIZES = (512, 1024, 2048, 4096)
mats = {m: (torch.randn(m, m), torch.randn(m, m)) for m in SIZES}
best = bench_rounds({m: (lambda m=m: mats[m][0] @ mats[m][1],
                         max(1, 2**33 // (2 * m**3))) for m in SIZES})
PEAK = 0.0
for m in SIZES:
    gflops = 2 * m**3 / best[m] / 1e9
    PEAK = max(PEAK, gflops)
    print(f"{m}x{m} matmul {gflops:8.1f} GFLOP/s")
print(f"peak {PEAK:.0f} GFLOP/s, divided by 4-thread streaming bandwidth: "
      f"ridge {PEAK * 1e9 / STREAM[4]:.1f} FLOP/B")
512x512 matmul   2089.7 GFLOP/s
1024x1024 matmul   2534.2 GFLOP/s
2048x2048 matmul   2099.4 GFLOP/s
4096x4096 matmul   1999.8 GFLOP/s
peak 2534 GFLOP/s, divided by 4-thread streaming bandwidth: ridge 17.0 FLOP/B

The bandwidth with 4 threads is 149.4 GB/s against 90.5 GB/s with 1 thread: four times the threads give less than twice the bandwidth, because the cores share one memory system and saturate it quickly. The matmul peak is 2534 GFLOP/s, and the ridge point is 17.0 FLOP/B.

A batch-size sweep of a linear layer

Now put a real linear layer on this chart. The weight WW is a 4096×81924096\times8192 float32 matrix of 128 MiB, much larger than the caches, so every call has to read it from memory. The batch size BB sweeps from 1 to 4096. Each row gives the arithmetic intensity (float32, 4 bytes per number), the time, the measured GFLOP/s and the “effective bandwidth” (the ideal byte count divided by the time), the roofline prediction in GFLOP/s (min⁡(Ppeak, I⋅BW)\min(P_{\text{peak}},\,I\cdot BW)) and the ratio of measurement to prediction.

K, N = 8192, 4096
W = torch.randn(N, K)             # nn.Linear weight layout (out, in), 128 MiB
BATCHES = (1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096)
xs = {B: torch.randn(B, K) for B in BATCHES}
best = bench_rounds({B: (lambda B=B: F.linear(xs[B], W),
                         max(1, 16 // max(1, B // 64))) for B in BATCHES})
res = {}
print(f"{'B':>5} {'FLOP/B':>7} {'ms':>7} {'GFLOP/s':>8} {'GB/s':>6} "
      f"{'roof':>7} {'ratio':>5}")
for B in BATCHES:
    t = best[B]
    inten = intensity(B, K, N, 4, 4)          # float32: 4 bytes per number
    flop = 2 * B * K * N
    gf, gb = flop / t / 1e9, flop / inten / t / 1e9
    roof = min(PEAK, inten * STREAM[4] / 1e9)  # roofline prediction, GFLOP/s
    res[B] = (t, gf, gb)
    print(f"{B:5d} {inten:7.1f} {t * 1e3:7.2f} {gf:8.1f} {gb:6.1f} "
          f"{roof:7.0f} {gf / roof:5.2f}")
eff = float(np.median([res[B][2] for B in (4, 8, 16, 32)]))
knee = next(B for B in res if res[B][1] >= PEAK / 2)
print(f"effective bandwidth for B=4..32: median {eff:.1f} GB/s, "
      f"{eff * 1e9 / STREAM[4]:.0%} of streaming add")
print(f"time per call: B=4 {res[4][0] * 1e3:.1f} ms, "
      f"B=32 {res[32][0] * 1e3:.1f} ms")
print(f"first B reaching half of peak: B={knee}")
    B  FLOP/B      ms  GFLOP/s   GB/s    roof ratio
    1     0.5    3.18     21.1   42.2      75  0.28
    2     1.0    9.19     14.6   14.6     149  0.10
    4     2.0    4.52     59.4   29.8     298  0.20
    8     4.0    4.45    120.7   30.3     596  0.20
   16     8.0    4.51    238.3   30.0    1188  0.20
   32    15.8    4.71    456.0   28.8    2363  0.19
   64    31.3    5.46    787.0   25.2    2534  0.31
  128    61.1    7.11   1208.3   19.8    2534  0.48
  256   117.0   11.62   1479.1   12.6    2534  0.58
  512   215.6   22.21   1547.3    7.2    2534  0.61
 1024   372.4   36.57   1879.2    5.0    2534  0.74
 2048   585.1   65.45   2099.7    3.6    2534  0.83
 4096   819.2  126.82   2167.4    2.6    2534  0.86
effective bandwidth for B=4..32: median 29.9 GB/s, 20% of streaming add
time per call: B=4 4.5 ms, B=32 4.7 ms
first B reaching half of peak: B=256
Measured roofline of a linear layer swept over batch size Log-log chart: arithmetic intensity on the x axis, measured GFLOP/s on the y axis. The grey dashed line is the roofline prediction from the streaming bandwidth and the matmul peak, the blue dotted line is the ramp for the effective bandwidth in the small-batch range, and the dots are measurements for batch sizes 1 to 4096. The measurements climb along the much lower blue ramp and approach the roof from a batch of a few hundred. 1 10 100 1,000 10 100 1,000 Arithmetic intensity (FLOP/byte, log scale) Measured performance (GFLOP/s, log scale) B=1 B=2 B=4 B=32 B=256 B=4096 roofline: 149.4 GB/s streaming, 2534 GFLOP/s peak ramp for 29.9 GB/s effective bandwidth measured (B = 1 ... 4096)
Dots are the measurements of the table above, labelled with the batch size B. The grey dashed line uses the limits measured by the stream and gemm steps; the blue dotted line is the ramp for the median effective bandwidth at B=4 to 32. The measurements climb along it rather than along the grey roofline.

Four things to read from the table and the figure:

  1. From B=4B=4 to 32 the time barely changes (4.5 ms and 4.7 ms) while the work grows eightfold. The time of a call is set by “reading 128 MiB of weights once”, and a few more tokens are almost free. This is the principle of batched inference, and it holds on a CPU too.
  2. But the kernel is far from saturating bandwidth. The median effective bandwidth in this range is only 29.9 GB/s, 20% of the streaming add measured above. The roofline is an upper bound, not a prediction: the gap between measurement and bound is the quality of the kernel implementation, including how it tiles and how it uses several threads. The same holds on GPUs: how much bandwidth a real kernel gets at small batch sizes has to be measured with a profiler, not read off the datasheet.
  3. B=2B=2 is slower than B=1B=1: the throughput is only 14.6 GFLOP/s against 21.1 at B=1B=1, and the time is 9.19 ms against 3.18 ms. The library probably picks a different kernel for these two batch sizes; we did not check. The roofline is a smooth line, real curves are not.
  4. The ridge point is far to the right. The predicted ridge point is 17.0 FLOP/B, which for float32 corresponds to about B=B= 34; the measurement first reaches half of the peak at B=B= 256, and even at B=4096B=4096 it reaches only 86% of the roofline prediction.

Operator fusion: moving the data once

For low-intensity operators the roofline gives one prescription: move less data. The simplest example is a chain of elementwise operations. In eager mode every operation is a separate kernel, and every kernel reads the whole tensor from memory and writes it back; torch.compile can fuse a chain of elementwise operations into one kernel that reads and writes once. The script applies kk in-place operations (alternating multiply and add) to a 256 MiB tensor and compares the two. assert torch.equal checks that fusion does not change the result, and both sides use a single thread so that the only difference left is how many times the data is moved.

torch.set_num_threads(1)   # the fused kernel is single-threaded: compare 1 vs 1
x0 = torch.randn(64 * 2**20)                  # 256 MiB
traffic = 2 * 4 * x0.numel()                  # one read, one write each

def chain(k):
    def f(x):
        for i in range(k):                    # k elementwise kernels: mul, add
            if i % 2 == 0:
                x.mul_(1.0001)
            else:
                x.add_(0.5)
        return x
    return f

KS = (1, 2, 4, 8)
jobs = {}
for k in KS:
    f, g = chain(k), torch.compile(chain(k))
    xa, xb = x0.clone(), x0.clone()
    f(xa), g(xb)                              # warm up, which also compiles
    assert torch.equal(xa, xb)                # fusion does not change results
    jobs[k, "eager"] = (lambda f=f, x=xa: f(x), 1)
    jobs[k, "fused"] = (lambda g=g, x=xb: g(x), 1)
best = bench_rounds(jobs)
print(f"{'k':>3} {'eager ms':>9} {'compiled ms':>12} {'speedup':>8} "
      f"{'eager GB/s':>11} {'fused GB/s':>11} {'fused GFLOP/s':>14}")
for k in KS:
    te, tc = best[k, "eager"], best[k, "fused"]
    print(f"{k:3d} {te * 1e3:9.2f} {tc * 1e3:12.2f} {te / tc:8.2f} "
          f"{k * traffic / te / 1e9:11.1f} {traffic / tc / 1e9:11.1f} "
          f"{k * x0.numel() / tc / 1e9:14.1f}")
torch.set_num_threads(4)
  k  eager ms  compiled ms  speedup  eager GB/s  fused GB/s  fused GFLOP/s
  1      5.83         7.37     0.79        92.1        72.9            9.1
  2     12.07         7.54     1.60        88.9        71.2           17.8
  4     24.37         8.66     2.82        88.1        62.0           31.0
  8     48.86        14.51     3.37        87.9        37.0           37.0
  • The eager time is proportional to kk (5.83 ms at k=1k=1 and 48.86 ms at k=8k=8): each operation moves 256 MiB once more.
  • After fusion the data moves once. As kk grows from 1 to 4, the fused time rises only from 7.37 ms to 8.66 ms; the speedup is 1.60 at k=2k=2 and 2.82 at k=4k=4.
  • Fusion does not always help. At k=1k=1 there is no traffic to save, and the compiled kernel is actually slower (speedup 0.79). Fusion saves reads and writes; it does not remove a single operation.
  • At k=8k=8 the fused kernel’s time starts to grow with kk (14.51 ms, speedup 3.37, 37.0 GFLOP/s): every element now takes 8 operations, the intensity rises to 1 FLOP/B, and single-thread compute becomes the new bottleneck. This is what the roofline predicts: fusion raises the intensity until it eventually reaches the roof.

The same principle is everywhere in large models. FlashAttention fuses the matrix multiplications and the softmax of attention into one kernel so that the N×NN\times N score matrix is never written back to HBM; normalization, residual addition and the activation function are often fused into one kernel as well. Ivanov et al. (2021) measured in BERT training that tensor contractions account for over 99% of the arithmetic operations but only 61% of the runtime, and that over a third (37%) of the runtime goes to memory-bound operators.

How stable are these numbers

The table shows five complete runs of the same script on the same machine (about a minute each; the page uses the numbers of the run marked):

Runstream GB/speak GFLOP/seffective GB/shalf-peak Bk=8 speedup
1178.3274929.82563.36
2157.2273029.52563.26
3 (this page)149.4253429.92563.37
4133.5273529.22563.30
5146.8259129.52563.33

The run-to-run spread is largest for the streaming bandwidth: 134 to 178 GB/s, 34% apart, because it depends directly on what else is using memory at that moment; the matmul peak differs by only 8%. What is stable is the shape of the curves: in all five runs the first batch size to reach half of the peak is 256, B=2 takes more than twice as long as B=1, the effective bandwidth at B=4 to 32 is 29 to 30 GB/s, and the speedup from fusion grows with k (0.79 to 0.84 at k=1, 3.26 to 3.37 at k=8). Single timings can still be off: B=1 took 3.18 ms in run 3 against 2.62 to 2.70 ms in the other four. The page uses the run with the median streaming bandwidth, which is run 3.

print(f"{len(NOISE)} jobs, max/min of the per-round best: "
      f"max {max(NOISE):.2f}, median {np.median(NOISE):.2f}")
27 jobs, max/min of the per-round best: max 3.21, median 1.80

The last script counts the spread of every timing job over the 7 rounds: the ratio of the slowest to the fastest round’s best value, with a maximum of 3.21 and a median of 1.80. Do not take any single absolute number as the machine’s “true bandwidth”; what you can trust is the shape of the curves. To redo this on a GPU, put the tensors on cuda and call torch.cuda.synchronize() before and after timing. The shape of the curves stays the same, and where the ridge point lies depends on the precision and the Tensor Cores used.

Applying the roofline to large models

ScenarioMain operatorArithmetic intensity (BF16)BottleneckCommon remedies
Decoding, small batchLinear layersAbout B (about 1 at B=1)Bandwidth to read weightsContinuous batching, weight quantization, speculative decoding
Decoding, long contextAttention over the KV cacheH/hkvH/h_{kv}, independent of batchBandwidth and capacity of the KV cacheGQA, MLA, KV quantization, PagedAttention
PrefillLarge matrix multiplicationsHundreds to thousands (about 1024 for 2048 tokens)ComputeTensor Cores, low precision, fused attention
TrainingLarge matrix multiplicationsSame, with batches of millions of tokensCompute and communicationRaise MFU, overlap communication and compute
Norms, activations, residualsElementwiseAbout 0.2 to a fewBandwidthOperator fusion, recomputation

Beyond compute and bandwidth, capacity is the third wall: once the KV cache fills the memory the batch cannot grow, and in the example above multi-head attention fits only 30 sequences. With several GPUs, the bandwidth of the links between cards is yet another wall, see collective communication. The metric for how well training uses compute is model FLOPs utilization (MFU), see Compute and Memory for Training.

What the roofline does not tell you

  • It is an upper bound. The measured curve here stays below the roofline everywhere: even the best point, B=4096B=4096, reaches only 86% of the prediction, and for BB up to 128 only 10% to 48%. The room for optimization is in that gap.
  • It counts one level of storage. Data reused inside a cache does not appear in the byte count; analyzing several levels needs the cache-aware roofline (Ilic et al., 2014).
  • It ignores latency and overhead. Very small operators spend their time on kernel launches and Python scheduling, which makes them neither compute-bound nor bandwidth-bound but overhead-bound. Horace He’s “Making Deep Learning Go Brrrr” splits time into compute, bandwidth and overhead.
  • It ignores communication. Collective communication across GPUs has its own bandwidth and latency, so the links have to be drawn into the model.
  • FLOP counting is a convention. This page counts a multiply-add as two operations; “equivalent compute” figures for sparsity or low precision need a look at the datasheet footnotes.

From the roofline to a performance trace

Pair the CMU ML Systems GPU and parallelism lectures with the CS336 Systems assignment. Fix matrix shapes, data types, and correctness tolerances, then measure three boundaries:

  • One operator. Warm up first. Use device events, or synchronize the device at both ends of a wall-clock measurement. Use arithmetic intensity to estimate the operator’s ceiling after isolating unrelated work.
  • A full training step. Hold the model, global batch size, and sequence length constant. Mark forward, backward, optimizer, and collective operations. When computation overlaps communication, compare waits on the critical path.
  • The whole job. Account separately for input stalls, checkpoints, and compilation warmup. If device operations are short and separated by long gaps, use the trace to investigate input delivery and scheduling before tuning an operator.

Report the bottleneck hypothesis, the single parameter changed, output error, peak memory, and the distribution across repeated measurements. Report training-step and operator speedups separately.

Common pitfalls

  1. Treating the advertised peak as attainable performance. The advertised 312 TFLOPS is an upper bound for matrix multiplication under ideal conditions; in this page’s experiment the linear layer with BB up to 128 reaches only 10% to 48% of the roofline prediction.
  2. “100% GPU utilization means the compute is fully used.” The GPU-Util of nvidia-smi only says that some kernel is running (the manual defines it as the percentage of the sampling period during which one or more kernels were executing), and a bandwidth-bound kernel keeps it at 100% just as well.
  3. “A bigger batch is always faster.” Batch size is limited by the capacity and the reads of the KV cache; throughput has a ceiling, and latency grows with the batch.
  4. “Fewer operations is always faster.” Elementwise operations and attention have few FLOPs, but because their intensity is low they can take longer than matrix multiplications; the numbers of Ivanov et al. are the evidence.

Data layout can change memory traffic at the same FLOP count

Weeks 4 and 7 of CMU ML Systems examine memory accesses at the thread and tile level. In a row-major array, the address of an element follows from its row and column strides. Adjacent threads reading adjacent columns can share an address sector. If each thread reads the same column in a different row, the same number of useful bytes can span more sectors.

The address model below ran with standard Python 3.14.3 on an Apple M2 Max. The base address is aligned, each lane reads one float32 element, and sectors are 32 bytes. The code counts distinct sectors touched by one warp load.

warp_size, width = 32, 256
element_bytes, sector_bytes = 4, 32
addresses = {
    "columns": [lane * element_bytes for lane in range(warp_size)],
    "rows": [lane * width * element_bytes for lane in range(warp_size)],
}
counts = [
    len({address // sector_bytes for address in values})
    for values in addresses.values()
]
assert counts == [4, 32]
for name, sectors in zip(addresses, counts, strict=True):
    print(f"{name}: {sectors}")
columns: 4
rows: 32

The two mappings read the same useful bytes, and the row-strided mapping touches more sectors. Real performance also depends on caching, overlap across warp accesses, and the hardware. When building matrix multiplication kernels, map neighboring threads to consecutive addresses and tile to reuse data fetched from global memory. Before increasing tile size or fusing more operations, check whether register and shared-memory usage limit how many blocks can reside on an SM.

How matrix multiplication tiling raises arithmetic intensity

The matrix multiplication lecture in CMU ML Systems extends data layout to computation scheduling. For C=ABC=AB, assign each thread block a square output tile of side bb. For every bb steps along the reduction dimension, load two input tiles and update the partial sums for the output tile. An input value can participate in multiple multiply-adds in that tile. Keep partial sums until the reduction ends, then store the output.

The cost model compares independent loads per output with tiled loads. Both do the same number of multiply-adds. It assumes each input tile is shared within one output tile, no cross-tile reuse, and one output write. Caching and spills are excluded. The code ran on an Apple M2 Max with standard Python 3.14.3.

m = n = k = 128
item_bytes = 4
flops = 2 * m * n * k
per_output_bytes = (2 * k + 1) * m * n * item_bytes

def tiled_bytes(tile):
    assert m % tile == n % tile == k % tile == 0
    output_tiles = (m // tile) * (n // tile)
    input_elements = (k // tile) * 2 * tile**2
    return output_tiles * (input_elements + tile**2) * item_bytes

loads = [tiled_bytes(tile) for tile in (8, 16, 32)]
assert per_output_bytes > loads[0] > loads[1] > loads[2]
print(f"1x1: {per_output_bytes:,} B")
for tile, moved in zip((8, 16, 32), loads, strict=True):
    print(f"output tile {tile}: {moved:,} B, {flops / moved:.2f} FLOP/B")
1x1: 16,842,752 B
output tile 8: 2,162,688 B, 1.94 FLOP/B
output tile 16: 1,114,112 B, 3.76 FLOP/B
output tile 32: 589,824 B, 7.11 FLOP/B

Larger tiles lower modeled input traffic and raise arithmetic intensity. A real implementation also has to fit input tiles, accumulators, and pipeline buffers. Large tiles can consume enough shared memory and registers to reduce resident blocks per SM. For tuning, fix shapes, precision, and error tolerances. Measure elapsed time, memory traffic, and active thread blocks. For dimensions that do not divide evenly, compare masked loads and padding. Efficient attention extends the idea with state for online softmax.

Summary and exercises

  • Roofline: P≤min⁡(Ppeak, I⋅BW)P\le\min(P_{\text{peak}},\,I\cdot BW); operators with an intensity below the ridge point Ppeak/BWP_{\text{peak}}/BW are bandwidth-bound (153 FLOP/byte for the A100, 295 for the H100).
  • The intensity of a linear layer is about the batch size (BF16): single-sequence decoding has an intensity of about 1 and is set by the bandwidth to read the weights, so batched decoding is nearly free.
  • Attention over the KV cache has an intensity of H/hkvH/h_{kv} independent of batch size, so with larger batches the reads and the capacity of the KV cache become the bottleneck first; methods that shrink the KV cache, such as GQA, raise the throughput ceiling directly.
  • Measured curves stay below the roofline; the shape can be trusted, the absolute numbers have to be measured on the target hardware.
  • Operator fusion does not reduce operations, only reads and writes, and helps most for low-intensity elementwise operations.

Quick self-check

1. The ridge point of the A100 is 153 FLOP/byte. What is the upper bound on the attainable performance of an operator with an intensity of 20 FLOP/byte?

  • 312 TFLOPS, because that is the peak of the A100
  • About 41 TFLOPS, i.e. 20 x 2.04 TB/s, roughly 13% of the peak
  • About 6 TFLOPS, i.e. 312 / 20 / 2.5
  • It cannot be decided without the batch size

An intensity of 20 is below the ridge point of 153, so the operator sits on the slope: P=I⋅BW=20×2039 GB/s=40.8P=I\cdot BW=20\times2039\ \text{GB/s}=40.8 TFLOPS, only 13.1% of the peak. More compute will not make such an operator faster; moving fewer bytes will.

2. For a 7B-parameter model in BF16 decoding a single sequence on an A100, what is the lower bound of the time per token?

  • 0.045 ms, set by the compute of the matrix multiplications
  • 6.87 ms, set by the bandwidth needed to read the weights once
  • 312 ms, set by 312 TFLOPS
  • There is no lower bound, since it does not depend on context length

The 14 GB of weights have to be read from HBM once: 14 GB / 2039 GB/s is about 6.87 ms, while the arithmetic takes only 0.045 ms. The ratio of about 150 is the ridge point. The context length adds the time to read the KV cache on top of this, so the real time is longer.

3. In the batch-size sweep, going from B=4B=4 to B=32B=32 barely changes the time per call. What does that show?

  • The kernel already reaches the compute peak at B=4B=4
  • The time is set by reading the weights, and the marginal cost of processing a few more tokens is low
  • The timing is wrong, the time should grow eightfold with BB
  • The cache holds the entire weight matrix

The weights are 128 MiB, much larger than the caches, and are read from memory on every call; the work grew eightfold in this range without changing the time to read the weights. This is the basis of batched inference. The last option is wrong: the cache cannot hold 128 MiB.

4. What does reducing the number of KV heads from 32 to 8 (GQA) change in this page’s decoding estimate?

  • The intensity of the linear layers rises fourfold
  • The KV cache per sequence shrinks to a quarter, the intensity of attention rises from 1 to 4, and both the throughput ceiling and the number of sequences that fit grow by about four times
  • The compute drops to a quarter, so decoding becomes compute-bound
  • Nothing, because the KV cache is small

In the table: 2.15 GB against 0.54 GB per sequence, at most 30 against 122 sequences, and a throughput limit of 949 against 3798 tokens/s. The linear layers read weights, which do not depend on the number of KV heads; the number of query heads is unchanged, so the compute hardly changes either.

5. What does fusing 8 elementwise operations into one kernel with torch.compile mainly save?

  • Floating-point operations
  • The number of reads and writes of HBM or memory, from 8 passes to 1
  • Memory capacity
  • Numerical precision

Fusion does not change the operations to perform; it keeps the intermediate results on chip instead of writing them to memory and reading them back. In the experiment the eager time grows with the number of operations, while the fused time is set mostly by one pass of reading and writing, until the computation itself becomes the bottleneck.

Exercises:

  1. The memory bandwidth of the H100 SXM is 3.35 TB/s. For a 7B-parameter model stored in BF16 decoding a single sequence, what is the speed limit in tokens/s if only the weights are read? What if the weights are INT4 (ignoring scale factors and other extra bytes)?
  2. A Llama-style feed-forward layer has input dimension K=4096K=4096 and output dimension N=11008N=11008, in BF16. What is the arithmetic intensity at batch size 1? How large must the batch be to reach the A100 ridge point of 153?
  3. FlashAttention does not perform fewer operations than standard attention. Why is it faster? Use this page’s fusion experiment in your explanation.
Reference answers
  1. BF16: 14 GB14\ \text{GB} of weights, 3.35 TB/s÷14 GB≈2393.35\ \text{TB/s}\div14\ \text{GB}\approx239 tokens/s. INT4: about 3.5 GB of weights, 3.35 TB/s÷3.5 GB≈9573.35\ \text{TB/s}\div3.5\ \text{GB}\approx957 tokens/s, 4 times the BF16 figure. This is the limit from reading weights alone; it ignores the KV cache, the dequantization overhead and kernel efficiency, which real systems cannot match.
  2. I=2BKN2KN+2B(K+N)I=\dfrac{2BKN}{2KN+2B(K+N)}. At B=1B=1 it is ≈1.0\approx1.0. Setting I=153I=153 gives B=153 KNKN−153(K+N)≈162B=\dfrac{153\,KN}{KN-153(K+N)}\approx162, a little more than the 153 that "I≈BI\approx B" suggests, because the activation traffic also takes bytes.
  3. Standard attention writes the N×NN\times N score matrix SS and P=softmax(S)P=\mathrm{softmax}(S) in full to HBM and reads them back, and elementwise operations such as softmax have a low intensity, so the time goes into moving data. FlashAttention tiles the computation and fuses it into one kernel that keeps the intermediate results in on-chip SRAM and writes only the final output to HBM. The operation count is unchanged (the backward pass even recomputes some), but HBM traffic drops sharply, just like kk operations turning into one pass of reads and writes in this page’s fusion experiment.

Further reading

FAQ

What is arithmetic intensity, and what is the roofline model?
Arithmetic intensity is the number of floating-point operations an operator performs divided by the number of bytes it has to move, in FLOP/byte. The roofline model (Williams et al., 2009) compares it with the hardware: attainable performance is at most min(peak compute, intensity x memory bandwidth). Operators below the ridge point (peak compute divided by bandwidth, about 153 FLOP/byte for the A100 and 295 for the H100) are bandwidth-bound and speed up linearly with intensity; operators above it are compute-bound and capped at the peak.
Why is LLM decoding (token-by-token generation) memory-bound rather than compute-bound?
At every step each sequence processes only one new token, yet the GPU has to read all the weights and the sequence's own KV cache. The arithmetic intensity of a linear layer is about the batch size, so at batch size 1 it is about 1 FLOP/byte, two orders of magnitude below the A100 ridge point of 153; attention over the KV cache has an intensity of only 1 (multi-head attention) to a few, independent of batch size. Time is therefore set by data movement: in this page's estimate the matrix multiplications of one token of a 7B model take 0.045 ms, while reading the weights once takes 6.87 ms.
How large must the batch be on an A100 or H100 before a linear layer is compute-bound?
For a BF16 linear layer the arithmetic intensity is about the batch size, so roughly 150 tokens (A100, ridge 153) to 300 tokens (H100, ridge 295) have to go through the same matrix multiplication to cross the ridge. Counting the activation traffic too, a 4096x4096 layer has an intensity of 409.6 at B=512 and sits well on the roof. A single prompt of 2048 tokens is enough for prefill; decoding needs hundreds of concurrent sequences, and KV cache capacity often runs out first.
Why does a bigger batch raise decoding throughput, and why not without limit?
All sequences in a batch share the same weights, which are read once per step, so each token pays for a smaller share of the weight reads and throughput grows almost linearly. But every sequence reads its own KV cache, so those reads grow linearly with the batch and cap throughput at memory bandwidth divided by the KV bytes of one sequence (949 tokens/s for multi-head attention in this page's example). The KV cache also takes memory: a 7B model with a 4096-token context fits at most 30 sequences on an 80 GB A100. Anything that shrinks the KV cache (GQA, KV quantization, PagedAttention) therefore raises the throughput ceiling directly.
nvidia-smi shows 100% GPU utilization. Is the compute fully used?
No. The GPU-Util figure of nvidia-smi is the fraction of the sampling period during which at least one kernel was executing, so it reads 100% as long as some kernel is always running, however little compute it uses. A bandwidth-bound kernel can keep it at 100% while the real compute utilization is a few percent. To judge whether compute is well used, look at model FLOPs utilization (MFU, measured FLOP/s divided by the peak) or at the compute and memory throughput of the kernels in a tool such as Nsight Compute.