S4 · Lesson 46 · Performance evaluation and simulation
Measurement, analytical models and simulation, statistical sampling, CPI stacks and summarizing results
Architects judge an idea before building it, and they have three tools: measure an existing machine, model it with equations like the ones in this course, or simulate the new design in software. Detailed simulators are honest but slow, often 10,000 to 100,000 times slower than real hardware, so running a whole benchmark in detail can take weeks. Statistical sampling fixes that: simulate a few thousand short, randomly chosen slices in detail, fast-forward through the rest, and report the answer with a confidence interval. Knowing how to sample, how to break performance into its causes, and how to summarize many results without fooling yourself is as much a part of architecture as designing caches.
- The relative error of a sampled CPI estimate against the number of samples n: , where CoV is the coefficient of variation of CPI between samples and z sets the confidence (1.96 for 95%, 3 for 99.7%).
- Halving the error takes four times the samples. With a CoV of 0.5, 2500 samples give ±3% at 99.7% confidence.
- Each sample is a short detailed simulation (say 1000 instructions) after a warm-up, so the total detailed work stays tiny compared with the whole program.
Predict
Two programs each do floating-point operations, one at 100 MFLOPS and one at 400 MFLOPS. What's the average rate over running both?
160 MFLOPS: the pair does operations in 10 s + 2.5 s = 12.5 s. That's the harmonic mean of the two rates, . The arithmetic mean, 250, describes no real run. Rates for equal amounts of work average harmonically; times average arithmetically; ratios to a reference use the geometric mean (lesson 1).
Name it
Three ways to evaluate
- Measurement on real hardware with performance counters: fast and exact, but only for machines that exist.
- Analytical models (the iron law, Amdahl, Little, AMAT, roofline): instant and insightful, but they leave out interactions.
- Simulation: functional simulators (correct results, around 10 to 100 million instructions a second) and cycle-accurate timing simulators (tens of thousands to a few million).
Sampling
- SimPoint finds a few representative phases of a program and simulates each in detail, weighting the results.
- SMARTS simulates many short random samples in detail, with functional warming of caches and predictors in between. With n samples of a quantity whose coefficient of variation is CoV, the relative error at confidence z is ; the samples needed for a target ε are
CPI stacks
Performance counters (or a simulator) split the CPI into a base plus stall components: , which shows where the time goes and which improvement would matter.
Summarizing
- Times: arithmetic mean (weighted by how often each program runs).
- Rates for equal work: harmonic mean, .
- Normalized ratios: geometric mean.
Worked example
A program runs instructions. A detailed simulator manages 100,000 instructions a second, and the CPI's coefficient of variation across samples is 0.5. How long would full detailed simulation take, and how much detail does SMARTS need for ±3% at 99.7%, with 1000-instruction samples?
Show the solution
- Full detailed simulation. which is 11.6 days.
- Samples needed.
- Detail. At 1000 instructions each, that's 2.5 million detailed instructions, 25 seconds of detailed simulation.
- The rest. Fast-forwarding and warming the rest runs at functional speed, so the whole study takes hours instead of days.
Answer full detailed simulation would take 11.6 days; SMARTS needs 2500 samples, 2.5 million detailed instructions or 25 seconds of detailed simulation.
Worked example
A core's CPI stack is base 0.6, branch mispredictions 0.15, L2 hits 0.2 and memory 0.85. What fraction is memory, and what's the speedup if prefetching halves the memory part?
Show the solution
- Total CPI.
- Memory share.
- Halving the memory part. The CPI falls to 1.375:
- Removing branch stalls instead. Even removing every branch stall would give only so prefetching is the better target.
Answer memory is 47% of the CPI, and halving it gives a speedup of 1.31.
Worked example
Two programs do the same amount of work, one at 100 MIPS and one at 400. What is the machine's average rate over the pair?
Show the solution
- Total time. If each program does W instructions:
- Average rate. Two programs' worth of work over that time: the harmonic mean.
- The arithmetic mean. It would give 250, overstating the rate, because the slow program takes four times as long and dominates the time.
Answer the average rate over the pair is 160 MIPS.
Check
The CPI's coefficient of variation across samples is 0.8. How many samples give a relative error of 0.05 at confidence z = 1.96?
Check
With 10000 samples, a coefficient of variation of 0.4 and z = 1.96, what's the relative error?
Check
How many hours does a simulator running at 20 thousand instructions a second take for 50 billion instructions?
Check
Three programs each do the same amount of work, at 50, 300 and 400 MFLOPS. What's the overall rate across all three?
Check
A CPI stack is base 0.5, branches 0.1, L2 hits 0.3 and memory 1.2. An optimization cuts the memory component to 0.3 of its size. What's the speedup?
Check
A CPI stack is base 0.5, branches 0.1, L2 0.3 and memory 1. What fraction of the time goes to memory stalls?
Check
SMARTS sampling must estimate CPI within 0.01 at confidence z = 3; the CPI's coefficient of variation across samples is 0.3, and each sample simulates 10000 instructions in detail at 100 000 instructions a second.
(a)
How many samples does it need?
(b)
How long does the detailed simulation take?
Write units the way you normally would: 1.5 s and 1500 ms are the same answer.
Check
A core's CPI stack is base 0.5, branch mispredictions 0.1, L2 hits 0.2 and memory 1.2.
(a)
What fraction of the time goes to memory?
(b)
What speedup does halving the memory part give?
Check
Two programs of equal work run at rates a and b.
Step 1
What is the average rate over both?
Type it the way you would write it, like 3sin(2πft) or 3*sin(2*pi*f*t). Angles can be in radians or carry a degree sign, like 45°.
Step 2
By how much does the arithmetic mean overstate it?
Explain why
Why can a few thousand short samples predict a whole program's CPI accurately?
A program's CPI varies from one stretch of execution to another, but it varies around a stable average, and samples chosen at random across the run are a fair cross-section of that variation. By the central limit theorem the average of n such samples has an error that shrinks in proportion to one over the square root of n, scaled by how much the CPI varies between samples, so the error can be computed and controlled from the samples themselves. A few thousand samples bring it to a few percent with high confidence, however long the program is. The samples need warmed caches and predictors so each one sees realistic state, which fast functional simulation between samples provides.
Practice
Keep practicing
11 kinds of problem on this topic, dealt one at a time with new numbers every time, for as long as you like.