S446 of 55
0 XP
  1. Hook
  2. Play
  3. Predict
  4. Name it
  5. Check
  6. Explain

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: ε=zCoVn, 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 109 floating-point operations, one at 100 MFLOPS and one at 400 MFLOPS. What's the average rate over running both?

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 ε=zCoV/n; the samples needed for a target ε are
n=(zCoVε)2

CPI stacks

Performance counters (or a simulator) split the CPI into a base plus stall components: CPI=CPIbase+CPIbranch+CPIL2+CPImemory+…, 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, n∑1/ri.
  • Normalized ratios: geometric mean.

Worked example

A program runs 1011 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
  1. Full detailed simulation. 1011/105=106s which is 11.6 days.
  2. Samples needed. n=(3×0.5/0.03)2=2500samples
  3. Detail. At 1000 instructions each, that's 2.5 million detailed instructions, 25 seconds of detailed simulation.
  4. 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
  1. Total CPI. 0.6+0.15+0.2+0.85=1.8
  2. Memory share. 0.85/1.8=47%
  3. Halving the memory part. The CPI falls to 1.375: 1.8/1.375=1.31
  4. Removing branch stalls instead. Even removing every branch stall would give only 1.8/1.65=1.09 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
  1. Total time. If each program does W instructions: t=W/100+W/400
  2. Average rate. Two programs' worth of work over that time: 21/100+1/400=160MIPS the harmonic mean.
  3. 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°.

Explain why

Why can a few thousand short samples predict a whole program's CPI accurately?

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.