Skip to content
mlmentorship

GPU memory hierarchy: HBM, SRAM, and roofline reasoning

Decide whether an accelerator operation is limited by compute or by data movement across HBM, caches, and on-chip memory.

Published · 7 min read ·Role-specific ·Advanced
Reading depth

Summary

A kernel must perform arithmetic and move data. Count both for the same operation before choosing an optimization.

Consider 120 GFLOPs and 12 GB transferred across the measured memory boundary. Assume hypothetical ceilings of 20 TFLOP/s at the operation’s precision and 100 GB/s across that boundary. Use decimal units: one GB is bytes. Which could help: twice the compute throughput, or half the traffic?

The compute and bandwidth lower bounds are seconds and seconds. Even perfect overlap cannot finish below the larger bound:

Here counts FLOPs, counts transferred bytes, is a compute ceiling, and is a bandwidth ceiling. Keep units consistent; a multiply-add conventionally counts as two FLOPs.

ChangeCompute boundTraffic boundCombined lower bound
Original s s s
Double s s s
Halve s s s

Halving traffic improves the lower bound; it does not prove a measured twofold speedup.

Arithmetic intensity

Arithmetic intensity is work per transferred byte, at a stated memory boundary:

The fixture has intensity FLOPs/byte and ridge FLOPs/byte. Its bandwidth roof is lower than its compute roof:

The lower roof identifies a first-order limit, not every possible bottleneck.

Same operation, two resource limits

Halving memory traffic raises this example's ceiling from 1 to 2 TFLOP/s

Less traffic raises a ceiling, not a measured speedupAt one TB/s, doubling arithmetic intensity doubles the memory ceiling. Other bottlenecks may prevent reaching either ceiling.Same byte bandwidth; more work perbyteArithmetic intensity 1 FLOP per bytebyteAt 1 TB/s: memory ceiling 1 TFLOP/sArithmetic intensity 2 FLOP per bytebyteAt 1 TB/s: memory ceiling 2 TFLOP/sA ceiling is not a measured achievedspeed.
Derivation
Exact log-scale roofline for the hypothetical 20 TFLOP/s and 100 GB/s device The horizontal coordinate is 54 plus 86 times log10 of arithmetic intensity. The vertical coordinate is 236 minus 62 times log10 of throughput divided by 0.1 TFLOP/s. The original operation is at intensity 10 and bandwidth ceiling 1 TFLOP/s. Halving its bytes gives intensity 20 and ceiling 2 TFLOP/s. The ridge is at intensity 200 and throughput 20 TFLOP/s. These are upper bounds, not observed speeds. compute ceiling: 20 TFLOP/s HBM roof = 0.1 × intensity original: 10 → 1 TFLOP/s half bytes 20 → 2 TFLOP/s ridge: 200 0.1 1 10 1 10 200 1000 FLOPs per HBM byte (log scale) TFLOP/s (log scale) Ceilings only; measure actual kernel time.
Read it this way: halving bytes doubles arithmetic intensity and its bandwidth ceiling. Both points remain below the compute roof. Doubling compute alone leaves their lower bandwidth roof unchanged.
Check: Why does halving HBM traffic double this ceiling without proving a measured speedup?
Read it this way: At one TB/s, doubling arithmetic intensity doubles the memory ceiling. Other bottlenecks may prevent reaching either ceiling.
Does a doubled memory ceiling prove an observed throughput doubled?

Model references: original Roofline report, NERSC Roofline documentation, and NVIDIA matrix-multiplication guide.

Change reuse or local capacity

1. Reuse weights across a batch

New task: small-batch decode repeatedly reads the same BF16 weights.

Picture and change: one multiply-add per two-byte weight gives about one FLOP per weight byte. Reusing each weight across 64 tokens gives about 64, counting weight traffic alone.

Check: include activations, outputs and each sequence’s KV reads. Batching also consumes memory and can increase waiting time.

Use when: measured weight traffic limits small-batch throughput.

2. Reject a tile that cannot stay on chip

New task: two BF16 input tiles require bytes. The kernel also needs a FP32 accumulator: another 65536 bytes.

Picture and change: those arrays cannot all reside in a hypothetical 96 KiB local budget. Choose smaller tiles or a different staging plan. Registers and shared memory have separate constraints; this combined check is only a necessary fit test.

Check: count spills, occupancy, synchronization, output traffic and compiled storage use before claiming reuse.

Use when: local capacity invalidates the proposed traffic reduction.

A faster compute ceiling can leave the limit unchanged

Predicting decode speedup from peak tensor throughput alone ignores bytes and launch costs. Record shapes, dtype, FLOP convention, memory boundary, traffic, attainable rates and measured runtime. Compare the same operation and distinguish useful arithmetic from executed or recomputed work.

Try finding the missing limit

Why might measured runtime exceed both simple lower bounds?

Check your answer

Launch overhead, dependencies, low occupancy, contention, inefficient instructions or uncounted traffic can add limits. The roofline is not a complete runtime simulator.

The hierarchy

TierTypical roleConstraint to inspect
RegistersPer-thread values and accumulatorsRegister allocation, spills, occupancy
Shared memory / L1On-chip staging and cached valuesDistinct APIs and architecture-specific partitioning
L2Cache shared across multiprocessorsActual hit rate and traffic boundary
HBMWeights, activations, KV storageCapacity and achieved bandwidth
PCIe / accelerator linksHost or peer transfersLink, topology and synchronization

Capacities and rates vary by device, precision, sparsity mode and power settings. SRAM is a storage technology, not one universally managed tier. Measure the target machine and kernel.

Other intensity calculations

For square BF16 matrix multiplication, and two input reads cost bytes. Ignoring outputs gives ; output reads, writes or repeated loads lower that estimate. At , this input-only estimate is 1024 FLOPs/byte.

The separate illustrative 989 TFLOP/s, 3 TB/s device has ridge about 330 FLOPs/byte. It is not the fixture device or a measured kernel result.

Implications for LLMs

Large matrix multiplications can approach a compute roof; small operations, communication and elementwise kernels can face other limits. Decode can become limited by weights or KV reads, depending on batch, context and implementation. FlashAttention reduces materialized attention traffic through tiling; it can also change executed work through recomputation.

Common pitfalls

Peak figures do not replace profiling. Include output traffic, spills, cache behavior and the specific boundary at which bytes were measured.