← Inference From First Principles

Memory Bandwidth and Compute Bottlenecks

Build and audit a three-term GPU performance model against 58 isolated operations and a batched GPT-2 decode that exposes its limitations.

Can a simple model predict how long a GPU operation will take?

I built a deliberately small one and tested it on 58 GPU operations. It takes three inputs about each operation: roughly how much arithmetic it does, the minimum number of bytes it must move, and three rates measured on the same machine (a timing floor for tiny operations, a bandwidth and an arithmetic throughput). Across two runs, the median operation took 1.10–1.14 times the model’s estimate, and 55 of 58 operations in the worse run (all 58 in the other) fell within a factor of two.

Then I applied the same model to a whole cached decode step, at increasing batch sizes, and it failed. By batch 64 the step had started to slow visibly; at batch 256 it took 30.5–33.4 ms, about 3.1–3.3 times the model’s 9.9–10.1 ms estimate. And that was despite calibrating the model on the real batch-1 step.

A model that works for single operations but fails when they are composed has still done something useful: it has located a cost it does not account for. This chapter builds the model, tests it against its own calibration and new shapes, and records where it stops explaining the data. Later chapters can use it to form specific hypotheses about batching, fusion, precision and overhead, but not to certify a speed-up without measuring it.

Where this sits

Matrix Multiplication and GPU Execution introduced the compute-and-memory roofline, and showed how hard it is to separate GPU work from Python submission time. Attention and Its Computational Cost exposed attention’s intermediate-memory costs. Prefill and Decode found a nearly flat per-step decode time for GPT-2 small, and Key-Value Caching measured cache reuse and allocator effects. This chapter combines them into one testable cost model, while keeping visible the difference between a theoretical lower bound and a calibrated estimate.

The Inference Lab gains predict_time(flops, bytes_moved, launch_s, bandwidth_gb_s, peak_gflops), which returns three time estimates, their maximum, and which term is largest under the supplied assumptions. It also gains measure_ceilings() and two test paths: a 58-operation suite and a batched decode experiment. And it gains a habit: state the change, predict its effect, measure it, and record any disagreement rather than relabelling it as success.

For the Pi series, this is a diagnostic method, not a verdict. A slow local model can be limited by launch and host overhead, memory movement, arithmetic, kernel efficiency, synchronisation, allocation or scheduling. The three-term model is a first screen. A large unexplained gap is the signal to look for what the screen leaves out.

Three ceilings

Three ceilings on a kernel

The intuition. Any GPU operation has to do three things: get issued, move its data, and do its arithmetic. Each takes at least some time. If they can overlap, the operation takes at least as long as the slowest of the three.

The model. For a stated operation and timing boundary:

\[ \hat t = \max\!\left(t_{\mathrm{issue}},\frac{D_{\mathrm{nominal}}}{B_{\mathrm{ref}}},\frac{F_{\mathrm{model}}}{P_{\mathrm{ref}}}\right). \]
| Term | Code | What it is | What it is *not* | |---|---|---|---| | Issue floor \(t_{\mathrm{issue}}\) | `launch_s` | Measured elapsed time of a tiny PyTorch operation of the same kind | A portable constant, or pure driver launch latency; it includes the framework, GPU queue and timing method | | Memory time \(D_{\mathrm{nominal}}/B_{\mathrm{ref}}\) | `bytes_moved / bandwidth_gb_s` | Bytes counted from tensor shapes, divided by a bandwidth achieved on a reference kernel | Measured memory traffic; caches can serve some bytes, and kernels can move extra ones | | Compute time \(F_{\mathrm{model}}/P_{\mathrm{ref}}\) | `flops / peak_gflops` | Counted operations divided by the best throughput observed on a reference benchmark | Exact; FLOP counts for elementwise kernels are approximate conventions |

predict_time labels the largest term launch, memory or compute. These are labels from the model, not diagnoses from a profiler. An operation can have “memory” as its largest estimated term and still be slow for an entirely different reason.

Estimate, not bound. If we knew the true minimum traffic and the hardware’s true maximum rates, the memory and compute terms would be lower bounds. We don’t: \(B_{\mathrm{ref}}\) and \(P_{\mathrm{ref}}\) are rates achieved on reference kernels, not proven maxima. So \(\hat t\) is a calibrated estimate. (The classic roofline bounds attainable arithmetic rate given ceilings and intensity; adding an issue floor is a useful extension for small operations, not a universal law.)

Reading the result. Compare measured time with \(\hat t\):

  • A ratio above one means there is time the model does not explain.
  • A ratio below one means an assumption is off: a reference rate too low, counts too rough, caching, or timing noise.

Neither outcome, on its own, says which hardware resource was saturated.

Measuring the ceilings

An estimate is only as good as its calibration. measure_ceilings() benchmarks copy, reduction and fill throughput across tensor sizes; tiny operations for per-class timing floors; and large matrix products for fp32 and fp16 throughput. It uses CUDA events around many queued calls, so the short-operation figures are steady-state time per call, not the latency a single isolated call would see. The GPU was a Windows display card; clocks and competing work were not controlled.

Bandwidth

Nominal GB/s is a calculated byte count divided by CUDA-event time: two buffers’ worth for copy_ (read plus write), one for sum (read) and one for fill_ (write). Two runs:

Buffer Copy Reduction (sum) Fill Copy time per call
4 KiB 0.89–0.91 GB/s 0.41–0.42 GB/s 0.55 GB/s 9.0–9.2 µs
256 KiB 67–73 GB/s 28–30 GB/s 35–42 GB/s 7.2–7.8 µs
1 MiB 261–269 GB/s 78–80 GB/s 128–162 GB/s 7.8–8.0 µs
16 MiB 274–275 GB/s 275 GB/s 288–293 GB/s 122 µs
64 MiB 276–279 GB/s 298 GB/s 290–297 GB/s 482–486 µs
256 MiB 277–279 GB/s 304–305 GB/s 292–299 GB/s 1.9 ms
1 GiB 213–231 GB/s 253–300 GB/s 244–292 GB/s 9.3–10.1 ms

(Rates in decimal GB/s; buffer sizes in binary units.)

Look at the last column first. Up to 1 MiB, a copy takes about 7–9 µs regardless of size: fixed per-call cost dominates, and dividing a small byte count by that time gives a uselessly low rate. From tens of megabytes upwards, time grows with size and the rates level off at a few hundred GB/s. The highest was about 305 GB/s, for the 256 MiB reduction.

measure_ceilings() takes the highest rate measured at 64 MiB or more as its bandwidth reference. That is a calibration reference, not a guaranteed maximum. The 1 GiB copy was slower (213–231 GB/s) for reasons not isolated, and the differences between copy, sum and fill cannot be pinned on read/write physics without kernel details and memory counters.

Arithmetic

The best large matrix products reached about 6.2–6.4 TFLOP/s in fp32 and 27.2–30.8 TFLOP/s in fp16 in these runs. Matrix Multiplication and GPU Execution saw higher figures in another session. A best-observed rate is a practical reference for that precision and shape family, not the GPU’s absolute maximum. Clock variation is a plausible cause of the difference; power, temperature, scheduling and kernel choice were not isolated.

Small operations

The timing floor queues many tiny calls between CUDA events and divides by the number of calls:

Operation Observed steady-state time per call
8×8 matrix product 12.1–13.5 µs
1,024-element add 9.0–9.6 µs
Layer norm, 4×768 11.1–11.8 µs
Softmax, 4×1,024 8.7–8.9 µs

These times include whatever stops the queue draining faster; calling all of it “kernel launch cost” would claim too much.

A discrepancy to note. The 8×8 product took 12.1–13.5 µs here, but about 35.4 µs in Chapter 7, which used a different timing method in a different session. The evidence does not say why. Host scheduling, PyTorch dispatch, other GPU work, clock state, synchronisation and how calls were batched could all contribute. (Similarly, cached decode step times differed between Chapters 9 and 10.) Treat it as a reproducibility problem, to be settled with a profiler or isolated host and GPU measurements.

The practical rule: calibrate as close as possible to the benchmark, and keep the calibration record (kernel, shape, precision, how calls were batched, synchronisation boundary, environment). For comparative claims, repeat calibration and measurement across sessions. Calibrating in the same session reduces drift; it does not remove it.

Counting the bytes

Counting the bytes a request moves

The model needs a FLOP count and a byte count for each operation. These are conventions, counted from the tensors an operation logically reads and writes. They leave out data reuse, extra intermediates, padding, kernel-specific algorithms and caching.

Operation FLOP estimate Nominal bytes (element size \(s\))
Matrix product \((M\times K)(K\times N)\) \(2MNK\) \((MK+KN+MN)s\), counting each input once and output once
Elementwise binary add over \(n\) elements \(n\) \(3ns\) if two inputs and one output are distinct
GELU over \(n\) elements implementation-dependent; Lab assumes \(8n\) \(2ns\) for an input and output
Layer norm over \(n\) elements implementation-dependent; Lab assumes \(8n\) \(2ns\), excluding parameter and workspace traffic
Softmax over \(n\) elements implementation-dependent; Lab assumes \(5n\) \(2ns\), excluding reduction workspace
One-layer decode attention, \(B\) sequences, \(h\) heads, \(T\) cached keys and head size \(d\) \(4BhTd\) for two products \(2BhTds\) for key/value reads alone, excluding queries, outputs and intermediates

What the intensities suggest. Under these fp32 conventions, an add does \(1/(3\times4)\approx0.083\) FLOP per byte; GELU and layer norm \(8/(2\times4)=1\); softmax \(5/8\approx0.625\). The ridge point of our references is about \(6.4\,\mathrm{TFLOP/s}/305\,\mathrm{GB/s}\approx21\) FLOP per byte. So all of these sit far below the ridge, which suggests they are limited by memory once fixed overhead and kernel inefficiency stop dominating. Intensity alone does not establish that bandwidth is saturated. (Fusing several operations into one kernel can change both counts and raise intensity a lot.)

Why a byte count is not a strict bound. A kernel that copies or spills intermediates moves more than the count; one whose data stays in cache moves less off-chip. So nominal bytes divided by a bandwidth reference is a useful estimate, not always a lower bound on time. Profiler memory counters, where available, should be used alongside it.

58 predictions

The test. cmd_model() runs 29 operation shapes, in both fp32 and fp16, for 58 cases: thin and square matrix products, adds, GELU, layer norm and softmax. For each it computes a prediction from a fresh measure_ceilings() calibration and times the operation with CUDA events over batches of calls. There are two separate runs. (The shapes were chosen by the experimenter, many resembling GPT-2’s, and the calibration comes from the same machinery, so this is evaluation on related shapes, not a held-out test.)

The statistic. \(r=t_{\mathrm{measured}}/\hat t\). The code counts “within 25%” as \(0.8\le r\le1.25\), “within 2×” as \(0.5\le r\le2\), and “faster than estimate” as \(r<0.95\).

Summary over 58 cases Run 1 Run 2
Median measured / estimated time 1.14 1.10
Within the code’s 0.8–1.25 band 60% 74%
Within a factor of two 100% (58/58) 95% (55/58)
More than 5% faster than estimate 16% 10%

Grouped by the term the model says is largest (not by any measured saturation):

Model’s dominant term Cases (run 1 / run 2) Median measured / estimated More than 5% below estimate
Memory 29 / 28 1.21 / 1.13 0% / 0%
Compute 12 / 12 1.09 / 1.07 25% / 17%
Launch 17 / 18 1.02 / 1.08 35% / 22%

Seven cases from the first run show the spread:

Operation Measured Estimated Assigned class Measured / estimated
1×768 @ 768×3,072 (fp32) 34 µs 31 µs memory 1.11
1×768 @ 768×50,257 (fp32) 644 µs 504 µs memory 1.28
512×768 @ 768×3,072 (fp32) 355 µs 382 µs compute 0.93
4,096² (fp32) 21.97 ms 21.73 ms compute 1.01
Add, 134 M elements (fp32) 6.83 ms 5.25 ms memory 1.30
Layer norm, 16,384×768 375 µs 328 µs memory 1.14
Layer norm, 1×768 12.3 µs 7.9 µs launch 1.57

What it shows. For isolated operations, the model is often right to within tens of per cent, especially for operations it labels memory-dominated: none of those finished more than 5% faster than its estimate, in either run. That is consistent with the bandwidth reference being a reasonable floor for these kernels, though it does not prove the reference is a physical limit.

Where it misses. Other groups did beat the estimate: the first run’s lowest ratio was about 0.68, and the second run had three cases outside a factor of two. A slower reference kernel, rough operation counts, caching or timing noise could each explain that. So the classifications cannot show that the bandwidth reference is definitely correct, or that host state explains the short-operation misses.

What it does not test. These are isolated PyTorch operations, mostly timed in batches between CUDA events. There is no autoregressive loop, sampling, model input and output, allocation under concurrency or queueing. The next step would be to freeze the calibration and test on held-out shapes and another device. For now, this is a diagnostic baseline, not a validated predictor.

The composition fails

Now the harder test: many operations composed into one cached decode step.

The set-up. cmd_batch() uses the unfused hand-written GPT-2 forward pass from Key-Value Caching, with fp32 weights, a static cache and a 128-token starting prefix. Each timed iteration advances every sequence in the batch by one position, using synthetic token ids. Ten wall-clock timings per batch size, synchronising the GPU after each pass. This is a model-step benchmark, not text-generation throughput.

The estimate. The model counts about 475 MiB of weights, 128 cached positions per sequence at \(73{,}728\) fp32 KV bytes per position, and the per-token FLOPs. It divides total bytes and total FLOPs by the reference rates and takes the maximum of those and the measured batch-1 step time (8.3–8.5 ms). That last term is an empirical calibration, not a pure launch measurement. The estimate therefore stays at the batch-1 time until batch 128 and only rises near batch 256. (The cache grows during each run, so the fixed-context calculation is approximate.)

Batch Measured step time Tokens/second proxy Max-of-totals estimate Measured / estimated
1 8.3–8.5 ms 118–121 8.3–8.5 ms 1.0 (calibrated)
8 9.8–10.3 ms 774–816 8.3–8.5 ms 1.2
32 9.1–9.9 ms 3,224–3,523 8.3–8.5 ms 1.1–1.2
64 11.7–12.4 ms 5,160–5,470 8.3–8.5 ms 1.4–1.5
128 18.0–21.3 ms 5,997–7,117 8.3–8.5 ms 2.1–2.6
256 30.5–33.4 ms 7,673–8,406 9.9–10.1 ms 3.1–3.3
512 87.9–96.0 ms 5,331–5,823 19.8–20.1 ms 4.4–4.8

(The “tokens/second proxy” is batch size divided by step time: positions advanced per second.)

What batching bought

Before the model’s failure, notice the result. At batch 32, the step took only about 7–20% longer than at batch 1, while advancing roughly 27–30 times as many positions per second. The proxy peaked at batch 256, about 7,700–8,400 positions per second, then fell at 512.

That is a throughput–latency trade-off for this forward pass, context and GPU. It is not measured serving throughput: there are no variable arrivals, no sampling and no streaming.

Why the model missed

The estimate stays flat far too long and underestimates large batches badly. The reason is in its structure: taking one maximum over total bytes and total FLOPs assumes all the work overlaps perfectly, as if the whole step were one fused kernel. But a real step runs a sequence of different kernels one after another, and their costs add up.

Adding the parts that run in sequence. A better estimate separates weight-matrix work from cached-attention traffic and adds them where they cannot overlap:

Batch Composed estimate Measured Remaining gap
128 about 8.9 ms 18.0–21.3 ms 2.0–2.4×
256 about 17.8 ms 30.5–33.4 ms 1.7–1.9×
512 about 35.6 ms 87.9–96.0 ms 2.5–2.7×

Better, but still a factor of about two short. (This composed estimate is an analytical calculation done after the fact, not a separately implemented and tested per-kernel pipeline. A full per-kernel sum would also need layer norms, activations, biases and their launch costs.)

Testing one suspected hidden cost. StaticCache returns slices of a larger preallocated tensor. Could attention on those slices be secretly copying them? A single-layer test at batch 256 compared attention on the views with attention on contiguous copies: 0.754 ms versus 0.766 ms, against a nominal memory-time estimate of 0.665 ms. The views were not slower. That argues against an expensive implicit copy for this shape; it does not rule out other layout penalties or extra traffic in the full model.

What remains unexplained. Candidates for the rest include unfused elementwise operations and biases, imperfect matrix-product and attention occupancy, cache-reuse assumptions, allocator pressure, clock and power changes, and scheduling. The throughput drop at batch 512 was not profiled. At batch 256, the measured 30–33 ms is well above even the improved 17.8 ms estimate. But that difference is a gap between a coarse model and a wall-clock measurement, not a measured breakdown of GPU time.

Moving the dots

Moving the dots: from model to measurement

What is the model good for, then? It suggests which changes are worth trying and roughly what each should do. Two small experiments show the method on controlled shapes.

Fusion removes an intermediate

The prediction. Compute (x * y) + z as two PyTorch operations, and the intermediate x * y must be written and read back. Counting each operand read once and each result written once, the separate version moves six tensor-lengths of data and the fused torch.addcmul(z, x, y) moves four: a predicted ratio of 1.5.

The measurement. 67,108,864 elements (64 Mi), CUDA-event timing:

Precision Separate operations torch.addcmul Speedup Nominal fused throughput
fp32 5.89 ms 3.70 ms 1.59× 290 GB/s
fp16 2.82 ms 1.83 ms 1.54× 293 GB/s

The observed 1.54–1.59× is close to the predicted 1.5×, and the fused kernel’s nominal throughput, about 290–293 GB/s, is near the reference reduction rate. (Those are counted bytes, not measured traffic; the small excess over 1.5× could come from caching, instructions, clocks or kernel choice.) The claim is narrow: for this memory-heavy elementwise expression, removing an intermediate tensor improved throughput by about what the byte count predicted.

Halving the bytes

The same expression ran 2.09× faster in fp16 than fp32 unfused, and 2.02× fused: about what halving the bytes would predict. That is a speed result only. It says nothing about whether a model can switch precision without changing its outputs, and not every memory-bound kernel will scale exactly with byte width. Quantization and Numerical Precision tests the numerical side.

The levers, and what evidence exists for each

A change can affect more than one term, and its benefit depends on the actual bottleneck and shape:

Lever First-order cost effect Evidence and limitation
Larger batch Amortises weight reads and issue work over more tokens; raises compute and KV work This chapter measures a throughput gain followed by a drop at batch 512
KV cache Removes recomputation but stores and rereads keys and values Key-Value Caching, validated on a bounded GPT-2 workload
Narrower weights or cache Reduces nominal bytes; may alter kernels and numerical outputs Matrix Multiplication and GPU Execution’s precision tests; Quantization and Numerical Precision and later must test inference accuracy
Fusion Eliminates launches and intermediate reads/writes This chapter tests one elementwise expression only
Compilation and execution graphs Can reduce host dispatch and replay costs Hypothesis to test in Compilation and Execution Graphs
Block-wise attention Reduces intermediate storage and slow-memory traffic Attention and Its Computational Cost and FlashAttention and Optimized Kernels; backend-specific performance

Changing a term that is not the largest may achieve little. But avoid categorical rules such as “quantisation cannot help a launch-bound step”: a dtype change can also change kernels, instruction paths and launch counts. Treat the largest estimate as a hint for where to look first. Then set an accuracy requirement, predict the cost change, implement it, measure total latency and throughput, and keep or reject the change on the evidence.

A procedure

For diagnosing an operation or a step:

  1. Define the timing boundary. A CUDA-event kernel interval, a synchronised model step and client-observed latency are different things; do not compare across them.
  2. Calibrate alongside the experiment. Record hardware, software, clocks where available, precision, warm-up, call batching, shapes and reference rates. Repeat across sessions for important claims.
  3. Count the nominal work. FLOPs and minimum logical bytes; note any known reuse, workspace or omitted non-matmul operations.
  4. Compute and label the three estimates with predict_time, naming the largest modelled term without claiming measured saturation.
  5. Compare distributions, not single numbers. Report the measured/estimated ratio, its spread and any cases faster than the estimate. A ratio of 1.3 may be useful, but it is not a universal acceptance threshold.
  6. Instrument the gap. If it persists, get per-kernel timings, allocations and hardware counters where possible, and test each candidate explanation separately.
  7. Validate the optimisation end to end: numerical parity, plus whole-step throughput and latency, not just one kernel’s speed.

On this Windows set-up, hardware counters were not available, and the PyTorch profiler recorded no CUDA activity (as in Matrix Multiplication and GPU Execution). So this chapter cannot report measured memory traffic, occupancy, kernel launch counts or a breakdown of the 30–96 ms batched steps. The model raises the questions; it cannot answer them in place of counters.

Inference Lab increment

The Lab now has:

  • predict_time, classify, matmul_flops_bytes, elementwise_flops_bytes, decode_step_bytes, decode_step_flops and ratio_summary, pure helpers exercised by the unit tests with illustrative values.
  • measure_ceilings(), which measures three access patterns, fp32 and fp16 large matrix products and small-operation timing floors. It must be rerun for any new environment.
  • model, batch and fusion commands in examples/ch11/bottlenecks.py, with results in research/ch11/results.json. The GPU benchmarks are not covered by the unit tests.

A new acceptance rule: a performance claim names the modelled term, the testable prediction, the measured scope and its uncertainty. For example: “fusing this 64 Mi-element expression cut the nominal memory passes from six to four; expected 1.5×; observed 1.54–1.59× on this GPU.” That should never be shortened to “fusion gives 1.5×”.

Still needed before predictions can be claimed to transfer: automatic environment capture and regression gates.

Limits of this chapter’s evidence

About the set-up

  • One consumer GPU under Windows WDDM. Calibration and measurement share hardware, but short-operation behaviour differed between sessions.
  • No profiler counters. The large-batch gap, the slow 1 GiB copy and the throughput drop at batch 512 remain unexplained.

About the measurements

  • Two runs, one device. The 58-case summary is descriptive; no held-out devices or kernels were tested.
  • Different timing methods. Isolated operations use CUDA events over repeated calls; batched steps use host wall time with GPU synchronisation.
  • Estimates, not rigorous bounds. Byte counts assume logical reads and writes; matrix-product and reduction rates are references, not certified maxima.

About scope

  • One unfused model configuration. The batch sweep uses fp32, one starting context (128), a static cache and synthetic token ids; no token selection or client transport.
  • No numerical check for fusion or precision. The elementwise experiments say nothing about whether an fp16 language model keeps its outputs.

What you should now be able to do

  • Build the issue, memory and compute terms, and distinguish this calibrated estimate from a strict hardware lower bound.
  • Compute nominal FLOPs, bytes, intensity and ridge point, stating which intermediates and memory-hierarchy effects are left out.
  • Measure reference rates with appropriate synchronisation, and distinguish CUDA-event batches from whole-step wall time.
  • Interpret measured/estimated ratios, including operations that finish faster than the estimate.
  • Explain why one maximum over total bytes and FLOPs underestimates a sequence of kernels whose costs add up.
  • Quantify the measured throughput–latency trade-off of batched GPT-2 on this hardware, without implying production throughput.
  • Predict, and then check, the benefit of removing an intermediate tensor from an elementwise expression.
  • Design an experiment that could disprove an expected improvement.

One lever in this chapter’s experiments was fewer bytes: halving the element size roughly halved the time of one memory-heavy expression. Whether a model can tolerate fewer bits is a separate question, and Quantization and Numerical Precision measures what reduced precision does to the weights, the logits and the generated text.

Key terms

  • Modeled launch-, memory-, compute-dominated: whichever of the three estimated costs is largest; not proof of an observed hardware stall.
  • Reference bandwidth: achieved throughput on a documented access-pattern probe, used to calibrate a model.
  • Reference arithmetic rate: best observed GEMM throughput at a precision and selected sizes, not a hardware guarantee.
  • Nominal bytes: logical tensor traffic counted from shapes; distinct from measured DRAM transactions.
  • Estimated floor: the maximum of calibrated issue, byte-time and arithmetic-time estimates.
  • Fusion: combining operations to avoid some intermediate tensors and launches.
  • Arithmetic intensity: modeled FLOPs per counted byte; depends on the choice of counted traffic.
  • Ridge point: compute reference rate divided by bandwidth reference rate.
  • Event-batched timing: elapsed GPU-event time across repeated calls, divided by the number of calls.
  • Composed-step gap: measured time not explained by the current aggregate or partial component model.

Reader exercises

  1. Run ceilings in multiple fresh processes and compare the four small-operation floors, bandwidth probes and fp32/fp16 GEMM rates. Record GPU and CPU conditions.
  2. Freeze one set of calibration values and test on ten held-out matrix and elementwise shapes. How much do error rates change from the 58-case evaluation?
  3. Repeat the batch sweep at contexts 128 and 1,024 without exceeding positional or memory capacity. Which nominal costs grow with context and which do not?
  4. Profile a batch-256 forward step to attribute elapsed time to matrix products, KV attention, layer norm, GELU, bias operations and synchronisation. Can the unexplained gap be reduced?
  5. Repeat batch 512 with several clock, temperature and memory traces. Is the throughput decline reproducible, and can any proposed cause be ruled out?
  6. Reproduce the fusion test in fp16 and fp32, and verify its numerical result against a higher-precision reference as well as measuring time.
  7. Extend the model to more than one device. Add measured communication, collective-operation launch and synchronization terms and state which can overlap.
  8. Compare end-to-end generation with and without one proposed optimization while fixing output sequence, token limit, batch and precision policy.

References

  1. Williams, Waterman & Patterson (2009), Roofline: An Insightful Visual Performance Model for Multicore Architectures. Primary research establishing the compute-and-bandwidth model; it does not supply the chapter’s GPU timing values.
  2. Pope et al. (2023), Efficiently Scaling Transformer Inference. Primary research modelling transformer inference memory and arithmetic costs, including weight and KV traffic; its TPU results must not be transplanted to this GPU.
  3. Dao et al. (2022), FlashAttention: Fast and Memory-Efficient Exact Attention with IO-Awareness. Primary research demonstrating how execution structure and intermediate memory movement change performance; the FlashAttention kernel was not measured here.
  4. NVIDIA, Deep Learning Performance: Matrix Multiplication. Vendor documentation for shape, arithmetic intensity and hardware utilisation; a technical guide rather than a primary research paper.
  5. PyTorch, CUDA semantics. Framework guidance on asynchronous execution and correct timing methodology.

Evidence in this chapter

Claim Evidentiary status and limitation
The roofline relates throughput to arithmetic intensity and bandwidth Established theory: Williams et al.; chapter adds a heuristic issue-time term
The largest of three terms is a strict hard lower bound for every PyTorch operation Not established: empirical bandwidth, peak and issue references can overestimate minimum time
Reduction probe reached ~305 GB/s, copy ~279 GB/s in these runs Recorded nominal-throughput measurements; not memory-controller counters
Small-operation observed floors changed from ~35 µs in Matrix Multiplication and GPU Execution to ~12–14 µs here Recorded across sessions; cause not isolated
58 tested operations had median measured/estimated ratio 1.10–1.14 Book experiment, two runs; 58 specified cases per run
Zero memory-classified cases beat the estimate by >5% Book experiment, classification-specific; not a hardware theorem
Batched step reaches ~7,700–8,400 token advances/s at batch 256 then falls at 512 Book experiment: fp32, GPT-2, static cache, synthetic tokens, no server
Max-of-totals estimate misses batch 256 by 3.1–3.3× Book experiment, including batch-1-calibrated latency floor
Partial composed-cost analysis reduces but does not close the large-batch gap Post-hoc model comparison, not measured per-kernel attribution
A non-contiguous KV view caused a triple-traffic copy Proposed explanation not supported by the single-layer contiguous-control test
Fusion of the tested expression gives 1.54–1.59× Book experiment on one operation and two dtypes; nominal traffic estimate
Actual cause of the batch-512 regression, achieved occupancy, cache transactions Not measured or established