COE 592Lecture 03Part 01
Latency, throughput and energy
The efficiency triangle of storage, latency and energy, what latency and throughput each measure, why one does not imply the other, the analytical latency model, and why data movement dominates energy.
- Concepts
- 5
- Slides
- 1-9
- Reading
- 30 min
Why this part matters
Your research project will put a detector on an embedded board, and the board will judge it by three costs that have nothing to do with accuracy: does the model fit, does it answer before the next frame arrives, and does it drain the battery. Every metric in this lecture exists to predict one of those three costs before you ever flash the board.
This part gives you the map and the first three costs. It fixes the vocabulary (latency, throughput, energy), shows why a latency number is meaningless without the conditions it was measured under, works the batching example that exams love, derives a one-line latency model that separates what the network controls from what the hardware controls, and ends with the energy table that explains why every efficient design of the last decade is really a design for moving fewer bytes. Parts 02 to 04 then fill in the metrics that feed these costs.
By the end you can
- Place any efficiency metric in the memory or computation group and say which of storage, latency and energy it predicts.
- Define latency and throughput, and compute both for a batched design.
- Explain with numbers why higher throughput does not imply lower latency, and lower latency does not imply higher throughput.
- Write Latency ≈ max(T_computation, T_memory) with its sub-formulas, label each term NN or hardware specification, and decide compute-bound versus memory-bound.
- Quote the 45 nm energy table and argue why data movement, not arithmetic, sets the energy bill of an inference.
Suppose the detector you trained in the cloud is to run on a Jetson-class board mounted on a vehicle. Before the board can use it, three separate questions must be answered. Does the model fit in the flash and RAM you have? Does one inference finish before the next camera frame lands, roughly every 33 ms at 30 frames per second? And how much charge does each inference pull from the battery? Slide 4 draws these as the three outer goals of a triangle, Smaller, Faster and Greener, and the three costs that quantify them: Storage, Latency and Energy.
The part of the triangle that matters is the middle. All three costs are driven by only two resources, Computation and Memory. Storage is purely a memory question: how many bytes the weights occupy. Latency and energy depend on both, because an inference both performs arithmetic and moves data, and each of those takes time and burns charge. That is why the metric list on the side of the slide has exactly two groups. The efficiency metrics that are memory-related are the number of parameters, the model size and the total and peak number of activations. The computation-related ones are MACs, FLOPs with their rate FLOPS, and OPs with their rate OPS.
| Goal | Cost | Resource | Metrics that predict it |
|---|---|---|---|
| Smaller | Storage | Memory | #parameters, model size |
| Faster | Latency | Computation and memory | MACs, OPs, model size, peak #activations |
| Greener | Energy | Computation and memory | MACs, OPs, and above all the bytes moved |
This taxonomy is the spine of the whole lecture. Parts 02 and 03 fill the memory group (parameters, model size, activations), part 04 fills the computation group (MACs, FLOPs, OPs), and this part explains the three costs those metrics are meant to predict. Whenever a later metric appears, place it here first: which group is it in, and which cost does it feed?
Metrics you count versus costs you measure
One distinction keeps the rest of the part honest. Parameters and MACs are properties of the network alone. You can count them on paper from the layer shapes, and they do not change when you move the model to another chip. Latency, throughput and energy are properties of the network running on a specific processor with a specific runtime. They must be measured, or at least estimated from hardware numbers. The same split reappears in the latency model of concept 4 as NN specification versus hardware specification.
Quick check
In the efficiency triangle, which pair of resources drives all three of storage, latency and energy?
Recall
Name the two groups of efficiency metrics, list the members of each, and say which cost each group predicts.
Slide 5 shows the same Cityscapes street segmented twice. The two masks look almost identical, and by the usual accuracy metric they are: SegFormer-B5 reaches 82.4 mIoU and EfficientViT-L1 reaches 82.7 mIoU. The difference is time. SegFormer needs 638 ms per frame and EfficientViT needs 45.9 ms (the slide rounds to 46 ms). At 30 frames per second a new frame arrives every 33 ms, so one model falls nineteen frames behind for every frame it finishes, and the other almost keeps up.
That per-frame time is latency: the delay between starting one specific task and finishing it. Patterson and Hennessy call the same quantity response time or execution time, the time between the start and completion of a task. It is a property of one task, not of a stream of tasks, and the next concept shows why that restriction matters. The 13.9x gap (638 / 45.9) is exactly the headline of the EfficientViT paper, which reports up to 13.9x GPU latency reduction over SegFormer at the same or better accuracy (Cai et al., ICCV 2023).
| Model | mIoU | Parameters | MACs | Orin latency | A100 throughput |
|---|---|---|---|---|---|
| SegFormer-B5 | 82.4 | 85M | 1460G | 638 ms | 12 image/s |
| EfficientViT-L1 | 82.7 | 40M | 282G | 45.9 ms | 122 image/s |
| Ratio | +0.3 | 2.1x fewer | 5.2x fewer | 13.9x faster | 10x more |
Read the ratio row carefully, because it plants the seed for concept 4. The MAC count falls 5.2x, but latency falls 13.9x. If latency were simply proportional to arithmetic, the two ratios would match. They do not, because SegFormer's softmax attention moves large intermediate tensors through memory, and that data movement, not its MACs, is what makes it slow on an edge GPU. MACs alone do not predict latency; they are one input to it.
Four conditions every latency must state
The slide's footnote is not fine print. Latency is measured, so it depends on everything in the measurement. The paper's setup sentence names four things: the hardware, the runtime, the numeric precision and the batch size. Change any one of them and the number changes, sometimes by an order of magnitude. The same paper measures EfficientViT-B1 at 24.3 ms on Orin and 0.82 s on a Jetson Nano, and SegFormer-B1 at 146 ms on Orin and 5.6 s on Nano. Same model, same precision, same batch size, different board: 34x to 38x apart.
The measurement conditions behind slide 5
- Hardware
- NVIDIA Jetson AGX Orin: 2048-core Ampere GPU, 64 Tensor Cores at 43 dense FP16 TFLOPS (the CUDA cores alone give 10.6), 204.8 GB/s LPDDR5, 15 W to 60 W
- Runtime
- TensorRT, which NVIDIA describes as turning a trained model into a fast, GPU-specific program for inference; the speedup depends on the model, precision, batch size and GPU
- Precision
- fp16, half the bytes per weight and activation of fp32
- Batch size
- 1, one image per inference, which is what an on-device detector sees
Quick check
Which set of conditions must accompany a reported latency for it to be comparable?
Recall
Define latency in one sentence and name the four conditions that slide 5 states for its numbers.
Slide 6 replaces one street with two mosaics of video clips and asks a different question: not how long one clip takes, but how many clips get done per second. One system manages 6.1 videos per second, the other 77.4. Those two numbers come from Table 5 of the TSM paper (Lin, Gan and Han, ICCV 2019): I3D at 306 GFLOPs versus TSM8F at 33 GFLOPs, both on a single Tesla P100.
That rate is throughput: the amount of work completed per unit time, what Patterson and Hennessy also call bandwidth. The TSM paper is unusually helpful here because it states its protocol: latency was measured with batch size 1 and throughput with batch size 16. TSM8F's latency is 17.4 ms. If throughput were the reciprocal of latency you would expect 1000 / 17.4 = 57.5 videos per second, yet the paper reports 77.4. The extra comes from batching, and it is the whole point of slide 7.
Two designs, same processor, opposite answers
Slide 7 pits two designs against each other. Design 1 handles one image at a time and takes 50 ms per image. Design 2 takes four images together and finishes the whole group in 100 ms. Each image in Design 2 waits the full 100 ms, because nothing leaves the processor until the batch is done.
| Design | How images are handled | Per-image latency | Images per batch | Batch time | Throughput |
|---|---|---|---|---|---|
| Design 1 | One after another | 50 ms | 1 | 50 ms | 1 / 0.050 = 20 image/s |
| Design 2 | Four in parallel | 100 ms | 4 | 100 ms | 4 / 0.100 = 40 image/s |
Worked example
Answering slide 7's two questions
Does higher throughput mean lower latency?
No. Design 2 has twice the throughput (40 versus 20 image/s) and twice the latency (100 versus 50 ms). Batching raised both, because throughput counts images and latency counts the wait of one image, and that image waits for its whole batch.Does lower latency mean higher throughput?
No. Design 1 has half the latency and half the throughput. With no parallelism, a fast single lane still moves only one image per step, so a short step buys a short wait but not a high rate.When the two coincide
Throughput equals 1 / latency only when the batch size is 1 and nothing is pipelined or run in parallel. Any batching or parallelism breaks the identity, always in the direction of more throughput per unit of latency.
Batching multiplies throughput by b = 4 (4x the reciprocal of latency) while latency stays at 100 ms for every image. In one 1 s window this design completes 10 whole batches, 40 images. The TSM preset back-computes its batch time from the paper's 77.4 video/s at batch 16, so it illustrates the arithmetic rather than confirming it.
A second scenario for practice
A cloud server serves the same model at two batch sizes. At batch 1 a request takes 2 ms. At batch 32 the whole batch takes 8 ms, because the GPU can spread thirty-two images over its cores far more efficiently than one.
| Setting | Batch time | Images per batch | Latency per image | Throughput |
|---|---|---|---|---|
| Batch 1 | 2 ms | 1 | 2 ms | 500 image/s |
| Batch 32 | 8 ms | 32 | 8 ms | 4000 image/s |
| Change | 4x longer | 32x more | 4x worse | 8x better |
Batching paid 4x latency to buy 8x throughput. Whether that is a good trade depends on who is waiting. A brake camera needs one frame answered now: latency, at batch size 1, which is why slide 5 measured that way. A data center indexing videos overnight needs clips per hour: throughput, at whatever batch size fills the GPU. Your research project sits on the first side of that line.
Quick check
Design 2 processes 4 images in parallel in 100 ms. What are its latency and throughput?
Recall
A design processes 8 images together every 200 ms. What are its latency and throughput, and what would the naive reciprocal give?
Concept 2 left a puzzle: MACs fell 5.2x but latency fell 13.9x. To resolve it you need a model of where the milliseconds go. Watch one layer execute. The processor loads the input activations, loads the layer's weights, multiplies and accumulates, and stores the output activations. Two of those steps are arithmetic; the other two are data movement. Real hardware does not wait for one to finish before starting the other. While the multipliers chew on the current tile, the memory system is already fetching the next weights, so the two streams run side by side and the layer finishes when the slower stream finishes.
Computation time is the operation count divided by the rate at which the processor retires operations. Memory time is the bytes that must move divided by the memory bandwidth, once for the weights and once for the activations in and out. Now look at the colour coding on the slide, because it is the sentence the exam wants. Every numerator is a property of the network: operations, model size, activation sizes. Every denominator is a property of the processor: operations per second, bandwidth. That split is the NN specification versus hardware specification distinction, and it makes efficiency a co-design problem. You change numerators by redesigning the network, denominators by choosing hardware, and latency by whichever of the two you can actually afford to change.
| Term | Numerator: NN specification | Denominator: hardware specification |
|---|---|---|
| T_computation | Number of operations in the model (MACs, OPs: part 04) | Operations per second of the processor (OPS) |
| T_move(weights) | Model size (part 02) | Memory bandwidth |
| T_move(activations) | Input activation size + output activation size (peak #activations: part 03) | Memory bandwidth |
The same model appears in the industry literature under different names. NVIDIA's GPU performance guide states that memory time is bytes accessed divided by memory bandwidth, math time is operations divided by math bandwidth, and the longer of the two shows what limits performance: math-limited if math time is longer, memory-limited if memory time is longer. The roofline model of Williams, Waterman and Patterson (CACM 2009) writes the same idea as a rate, attainable performance = min(peak compute, bandwidth x operational intensity). The vocabulary to adopt is compute-bound when T_computation wins and memory-bound when T_memory wins. One caution before using datasheet numbers: dividing by a peak OPS figure gives a floor on T_computation, not an estimate of it, because real kernels rarely keep every multiplier busy. The measured time over that floor is the inverse of the utilisation the runtime achieved.
Worked example A: a toy model and two processors
Worked example
Toy numbers that show the regime flipping
Start on a 100 GOPS processor
The model has 1 GOP of work, so T_computation = 1e9 / 1e11 = 10 ms. Weights are 50 MB and activations in plus out are 20 MB, over 10 GB/s: T_weights = 5 ms, T_activations = 2 ms, T_memory = 7 ms. Latency ≈ max(10, 7) = 10 ms, compute-bound.Buy a 200 GOPS processor
T_computation halves to 5 ms, but T_memory is still 7 ms. Latency ≈ max(5, 7) = 7 ms, not 5 ms. The model became memory-bound and 2 ms of the new compute sits idle every inference.Quantize the weights to 8-bit instead
Model size drops to 12.5 MB (part 02 shows why), so T_weights = 1.25 ms and T_memory = 3.25 ms. On the fast processor latency is back to max(5, 3.25) = 5 ms: the hardware upgrade only paid off once the network side shrank too.Three configurations
Configuration T_computation T_memory Latency Regime 100 GOPS, 32-bit weights 10 ms 5 + 2 = 7 ms 10 ms Compute-bound 200 GOPS, 32-bit weights 5 ms 5 + 2 = 7 ms 7 ms Memory-bound 200 GOPS, 8-bit weights 5 ms 1.25 + 2 = 3.25 ms 5 ms Compute-bound
The two Orin presets use 43 TFLOPS dense fp16 on the Tensor Cores and 204.8 GB/s from NVIDIA's Jetson AGX Orin page, MACs and parameters from the EfficientViT paper, and a 1024 × 2048 input with 19 output classes at 2 bytes each. Dividing by a peak rate gives a floor: measured latencies were 45.9 ms and 638 ms, 3.5x and 9.4x above it, and the gap shows what a first-order model leaves out.
Worked example B: back to slide 5
Worked example
Predicting the Orin numbers from public specifications
EfficientViT-L1, computation
282 GMACs is 564 GFLOPs at two FLOPs per MAC (part 04). TensorRT runs fp16 convolutions and matrix multiplies on the Tensor Cores, which the Orin page rates at 43 dense FP16 TFLOPS (the CUDA cores alone would give 10.6), so T_computation ≈ 564 / 43 000 ≈ 13.1 ms.EfficientViT-L1, memory
Weights: 40M x 2 bytes = 80 MB, over 204.8 GB/s gives 0.39 ms. Activations: input 3 x 1024 x 2048 x 2 B = 12.6 MB, output 19 x 1024 x 2048 x 2 B = 79.7 MB, sum 92.3 MB, over the same bandwidth 0.45 ms. T_memory ≈ 0.84 ms.Compare with measurement
Prediction max(13.1, 0.84) ≈ 13.1 ms, strongly compute-bound. Measured: 45.9 ms, 3.5x above the floor, so the runtime achieved roughly 29% of the Tensor Core peak. That is a normal utilisation for a real network: kernel launches, layers too small to fill the GPU, and intermediate activations moving between layers all sit outside the formula.SegFormer-B5 by the same recipe
1460 GMACs = 2920 GFLOPs, so T_computation ≈ 2920 / 43 000 ≈ 68 ms. Weights 85M x 2 B = 170 MB give 0.83 ms; the activations are the same 0.45 ms. Prediction ≈ 68 ms. Measured: 638 ms, 9.4x above the floor, about 11% utilisation.Reading the two misses
Both models land above the floor, as every real model does, but SegFormer misses by almost three times as much. The crude model counts only input and output activations. SegFormer's softmax attention materializes large intermediate attention maps that the formula never sees, which is exactly the memory traffic the EfficientViT paper set out to remove. The model is a first-order floor; the size of the miss tells you which term you forgot.Floor versus measurement
Model T_computation T_memory Floor Measured Miss, utilisation EfficientViT-L1 564 / 43 000 = 13.1 ms 0.39 + 0.45 = 0.84 ms 13.1 ms 45.9 ms 3.5x, about 29% SegFormer-B5 2920 / 43 000 = 68 ms 0.83 + 0.45 = 1.3 ms 68 ms 638 ms 9.4x, about 11%
Quick check
A model is memory-bound on its current processor. Which change is guaranteed to reduce its latency under the max model?
Recall
Write the latency model with its sub-formulas and label every term NN or hardware.
Recall
Why max and not plus?
Recall
In the SegFormer versus EfficientViT comparison, MACs drop 5.2x but latency drops 13.9x. What does that tell you?
The third cost is energy, and slide 9 settles where it goes with one table. In a 45 nm process at 0.9 V, a 32-bit integer add costs 0.1 pJ and a 32-bit integer multiply 3.1 pJ. Reading one 32-bit word from DRAM costs 640 pJ. The multiply is the most expensive arithmetic on the list, and the memory access is two hundred times dearer than it.
Rough energy per operation, 45 nm, 0.9 V, 32-bit (slide 9, after Horowitz 2014 as tabulated by Han et al. 2015)
- int ADD
- 0.1 pJ
- float ADD
- 0.9 pJ
- Register file access
- 1 pJ
- int MULT
- 3.1 pJ
- float MULT
- 3.7 pJ
- SRAM cache access
- 5 pJ
- DRAM memory access
- 640 pJ
Three ratios from that table are worth memorizing. DRAM over integer multiply is 640 / 3.1 ≈ 206, which the slide rounds to 200x. DRAM over SRAM is 640 / 5 = 128, so keeping data on-chip is worth two orders of magnitude on its own. And float add over integer add is 0.9 / 0.1 = 9, a seed for quantization: the same arithmetic in integers is nine times cheaper per add. Han et al. summarize the whole table in one line, that memory access is three orders of magnitude more energy expensive than simple arithmetic (640 / 0.1 = 6400).
The chain the slide writes across the top follows directly: data movement means more memory references, and more memory references mean more energy. Horowitz's own framing in the ISSCC 2014 talk is that a DRAM access at 1 to 2 nJ is a couple of orders of magnitude above a cache access or a functional operation at around 10 pJ, and that even with better I/O circuits DRAM will stay expensive, around 0.6 nJ per 8 bytes, because requests and data still have to travel a long physical distance. The slide's 640 pJ per 32-bit word is about half of the 1.3 nJ per 64-bit access in his Figure 1.1.9, as the provenance note below explains.
The log axis of the slide's chart is not decoration either. On a linear axis the six small bars would be invisible next to DRAM; a 0.1 pJ bar next to a 640 pJ bar is a pixel next to a page. Only a logarithmic axis can show both, and it is the honest way to read any table whose entries span four decades.
Worked example: AlexNet's energy bill
Worked example
Arithmetic versus weight fetch for one AlexNet inference
Arithmetic in 32-bit integers
Weights read once from DRAM
AlexNet has 61M parameters (part 02). Reading each once as a 32-bit word: 61e6 x 640 pJ = 39.0 mJ. That is 16.8x the arithmetic, before a single activation has moved.Two alternatives
Keep the same weights in SRAM: 61e6 x 5 pJ = 0.31 mJ, cheaper than the arithmetic. Or keep DRAM but use float arithmetic: 724e6 x (3.7 + 0.9) = 3.33 mJ, still twelve times below the DRAM bill.Two orders of magnitude versus a factor of two
Changing where the weights live changes the total by two orders of magnitude; changing how the arithmetic is done changes it by less than a factor of two.The bill, line by line
Item Count Energy each Total Integer MACs (multiply + add) 724M 3.1 + 0.1 = 3.2 pJ 2.32 mJ Weights read once from DRAM 61M 640 pJ 39.0 mJ Same weights read from SRAM 61M 5 pJ 0.31 mJ Float MACs instead of integer 724M 3.7 + 0.9 = 4.6 pJ 3.33 mJ
Per-operation costs are the 45 nm, 0.9 V figures from slide 9 (Horowitz 2014, as tabulated by Han et al. 2015). The AlexNet presets use 724M MACs as one multiply plus one add each, and one fetch per weight for its 61M weights.
Every efficiency technique later in the course can be read as a way of cutting that memory line. Keep weights in on-chip SRAM, which is 128x cheaper per access than DRAM. Reuse each fetched value as many times as possible before it leaves the chip; Horowitz notes that efficient designs complete on the order of a thousand operations per DRAM fetch. And make the model small enough to fit on-chip in the first place, which is what model size in part 02, peak activations in part 03, and pruning and quantization later in the course are all about.
Quick check
In the 45 nm table, how does one 32-bit DRAM access compare with one 32-bit integer multiply?
Recall
Quote the DRAM to integer multiply energy ratio, the numbers behind it, and the process conditions.
Recall
For one AlexNet inference, how does the energy of fetching every weight once from DRAM compare with the energy of all its integer MACs?
Recap
If you remember nothing else
- Three goals (smaller, faster, greener) map to three costs (storage, latency, energy). All three are driven by two resources, computation and memory, so the metrics split into memory-related and computation-related.
- Latency is the delay for one task. SegFormer-B5 takes 638 ms and EfficientViT-L1 takes 45.9 ms on Jetson AGX Orin with TensorRT, fp16, batch size 1: a 13.9x gap at equal or better mIoU.
- A latency number without hardware, runtime, precision and batch size is not comparable to any other.
- Throughput is items per second. Batching raises it (Design 2: 40 image/s) while raising latency (100 ms). Throughput equals 1 / latency only with batch size 1 and no parallelism.
- Latency ≈ max(T_computation, T_memory) because data movement and computation overlap. Numerators are NN specification, denominators are hardware specification.
- A faster processor helps only when compute-bound. A memory-bound model needs smaller weights, smaller activations or more bandwidth.
- At 45 nm and 0.9 V: int ADD 0.1 pJ, int MULT 3.1 pJ, SRAM 5 pJ, DRAM 640 pJ. One DRAM access costs about 206 int multiplies, and a float ADD costs 9 int ADDs.
- Fetching AlexNet's 61M weights once from DRAM (39 mJ) costs about 17 times its 724M MACs of integer arithmetic (2.3 mJ).
Sources
- EfficientViT: Multi-Scale Linear Attention for High-Resolution Dense PredictionPaperICCV 2023, Cai, Li, Hu, Gan and HanTable 3: SegFormer-B5 638 ms and EfficientViT-L1 45.9 ms on Jetson AGX Orin, TensorRT, fp16, batch 1; the 13.9x claim; Nano latencies.(opens in a new tab)
- SegFormer: Simple and Efficient Design for Semantic Segmentation with TransformersPaperNeurIPS 2021, Xie et al.Table 1a: 82.4 (single-scale) / 84.0 (multi-scale) mIoU for B5 on Cityscapes validation.(opens in a new tab)
- TSM: Temporal Shift Module for Efficient Video UnderstandingPaperICCV 2019, Lin, Gan and HanTable 5: I3D 6.1 V/s versus TSM8F 77.4 V/s on a Tesla P100; latency at batch 1, throughput at batch 16.(opens in a new tab)
- Learning both Weights and Connections for Efficient Neural NetworksPaperNeurIPS 2015, Han, Pool, Tran and DallyFigure 1: the seven-row 45 nm energy table on slide 9; memory access three orders of magnitude above arithmetic.(opens in a new tab)
- Computing's energy problem (and what we can do about it)PaperIEEE ISSCC 2014, M. HorowitzFigure 1.1.9 arithmetic and 64-bit memory costs; DRAM at 1 to 2 nJ, about 0.6 nJ per 8 bytes even with better I/O.(opens in a new tab)
- MIT 6.5940 TinyML and Efficient Deep Learning Computing, Lecture 2: Basics of Deep LearningDocsMIT HAN Lab, Fall 2023Slides 52 to 57 are the originals of slides 4 to 9, including the overlapped load, compute and store pipeline that justifies the max.(opens in a new tab)
- Roofline: An Insightful Visual Performance Model for Multicore ArchitecturesPaperCommunications of the ACM 2009, Williams, Waterman and PattersonAttainable performance = min(peak compute, bandwidth x operational intensity), the rate form of the max model.(opens in a new tab)
- GPU Performance Background User's GuideDocsNVIDIAMath time versus memory time, and math-limited versus memory-limited, defined exactly as in slide 8.(opens in a new tab)
- Jetson AGX OrinDocsNVIDIA2048-core Ampere GPU, 64 Tensor Cores at 43 dense FP16 TFLOPS (10.6 FP16 TFLOPS on CUDA cores alone), 204.8 GB/s LPDDR5, 15 W to 60 W.(opens in a new tab)
- TensorRT Quick Start GuideDocsNVIDIAWhat TensorRT does, and that speedup depends on model, precision, batch size and GPU.(opens in a new tab)
- Computer Organization and Design, RISC-V Edition, 2nd editionBookElsevier 2020, Patterson and HennessyChapter 1: response time (execution time) versus throughput (bandwidth).(opens in a new tab)