Benchmarks: Fixed Work, a Score and the Score per Megahertz
A benchmark is fixed work with a checked answer, timed between two reads of a counter. Its score counts iterations for each second. Divided by the clock, it counts cycles instead, and that hides something.
You Will Be Able To
- Say what makes a program a benchmark, and turn a timed run into a score.
- Compute a score per MHz, and say what it hides about the clock.
- Split the cycles of a run by class of instruction, and relate CPI and IPC to the score.
- Lesson
- S8.14
- Time
- 26 min
- Runs on
- Your browser
- Check
- 5 questions
Two builds of the same core run the same loop. The table of scores per MHz says that the simple build wins by a quarter.
Put both in a product, and the other one finishes first. Which table lied?
Before You Start
You need Performance Counters: a window, read before and after, and CPI.
You need Single-Cycle, Multicycle or Pipelined: the two builds of ap_rv32, and why a taken branch costs the five-stage core two cycles.
It helps to have read Performance: CPU Time and Amdahl's Law: time is instructions, times CPI, times the clock period.
| Question | |
|---|---|
| 1 | What makes a program a benchmark? |
| 2 | How does a timed run become a score, and a score per MHz? |
| 3 | What does a score per MHz hide? |
| 4 | How are CPI and IPC related, and where did the five-stage core lose its cycles? |
| 5 | The run has 20 iterations, not 10. What is the five-stage score per MHz? |
The Idea: Same Work, Same Answer, Then Count
To compare two cores, run the same work on both and measure the time. That work must be fixed: one program and one input. Its answer must be checked, or a broken core could look fast.
Such a program is a benchmark. Ours repeats one small loop several times. One pass of that loop is an iteration. The run is timed in a window, between two reads of the cycle counter.
The result is turned into a score: iterations for each second. A bigger score means a faster run. Vendors often quote the score divided by the clock, in MHz. That number counts iterations for each million cycles.
Cycles depend on two things. One is the number of instructions in an iteration. The other is how many cycles an instruction takes on average. Split the cycles by class of instruction, and you see where a core loses time.
New Words
| Word | Meaning |
|---|---|
| Benchmark | A program chosen to compare the performance of computers. It does fixed work on a fixed input, and checks its answer. |
| Workload | The set of programs that a user really runs. A benchmark stands in for it. |
| Benchmark kernel | A small loop that does the heavy part of a job. Our benchmark is one such kernel: a checksum. |
| Iteration | One pass of the work of a benchmark. Ours is the checksum of eight words. |
| Score of a benchmark | Iterations for each second. A bigger score means a faster run. |
| Score per MHz | The score divided by the clock in megahertz. It equals the iterations for each million cycles. |
| IPC | Instructions per cycle: the instructions of a window divided by its cycles. It is one divided by the CPI. |
| mcycle, minstret | Two counters of ap_rv32, read by a CSR instruction. mcycle counts clock cycles, minstret retired instructions. |
| Turn left by one bit | Every bit moves one place up, and the top bit comes in at the bottom. The checksum does this. |
| Dhrystone | A small benchmark from 1984 for integer work, much used for embedded cores. |
| CoreMark | A small benchmark for embedded cores. It walks lists, works on a matrix, runs a state machine and computes a CRC (cyclic redundancy check). |
| SPEC CPU | A suite of large real programs, such as a compiler and a chess program, for computers in general. SPEC (System Performance Evaluation Cooperative) is the vendor group that makes it. |
One Picture: From Fixed Work to a Score
- Memory
- Clock / reset
- Processor
- Control / FSM
- Peripheral
- Fixed work
Every core runs the same program on the same input. Only then can two runs be compared.
- A window
The program reads the cycle counter before the loop and after it. The difference is the time of the work.
- A checked answer
The run counts only if the checksum is right. A fast wrong answer is no result.
- A score
Iterations divided by seconds. A bigger score means a faster run.
- Per megahertz
Divide the score by the clock in MHz. What is left counts cycles, not seconds.
Read the diagram as text
- Fixed work: one program, one input of eight words
- Read mcycle: the window opens
- The loop: ROUNDS iterations of the same work
- Read mcycle again: the window closes
- Check the answer: a wrong checksum makes the run worthless
- Score: iterations for each second
- Score per MHz: iterations for each million cycles
- Fixed work → Read mcycle: start
- Read mcycle → The loop: count cycles
- The loop → Read mcycle again: stop
- Read mcycle again → Check the answer: answer
- Check the answer → Score: cycles and clock
- Score → Score per MHz: divide by the clock
The run of the lab on this page. The cycle counter is mcycle, the one that S8.6 reads in a window.
The kernel of this page, in C. The test reads mcycle just before the outer loop, and again just after it.
uint32_t sum = 0;
for (int r = 0; r < ROUNDS; r++) // one round is one iteration of the benchmark
for (int i = 0; i < 8; i++)
sum = ((sum << 1) | (sum >> 31)) ^ buf[i]; // turn left by one bit, then mix in a wordThe Smallest Example, Worked by Hand
One iteration in machine code has 60 instructions. Two set up the inner loop. Each of the eight words takes seven: a load, four steps of the checksum, a step of the address, and the branch. Two more close the outer loop.
The single-cycle core takes one cycle for each instruction: 60 cycles. The five-stage core takes one for each instruction too. Each taken branch costs it 2 more. In one iteration 8 branches are taken: 7 of the inner loop and 1 of the outer. So it needs 60 + 16 = 76 cycles.
| Single-cycle | Five-stage | |
|---|---|---|
| Cycles for each iteration | 60 | 76 |
| CPI, and IPC | 1.00, and 1.00 | 1.27, and 0.79 |
| Score per MHz: 1,000,000 / cycles | 16,666 | 13,157 |
| Clock (exercise values) | 65 MHz | 100 MHz |
| Score: iterations for each second | 1,083,333 | 1,315,789 |
Read the table twice. Per MHz, the single-cycle core wins: it needs fewer cycles. Per second, the five-stage core wins: its cycles are shorter.
Where do the clocks come from? S2.6 and S2.24 measured the longest paths: 122 levels of logic and 80. At an assumed 0.125 ns for each level, that gives about 65 MHz and 100 MHz.
The Rules
Rule 1: A benchmark is fixed work with a checked answer.
Same program, same input on every core. A run with a wrong answer does not count.
Rule 2: Time it in a window, and make the window long.
The reads of the counter and the start of the loop cost cycles. A long run makes them small.
Rule 3: The score is iterations for each second.
It is the inverse of a time, so a bigger score is better.
Rule 4: The score per MHz is iterations for each million cycles.
Score = iterations × clock / cycles. Divide by the clock in MHz, and the clock is gone.
Rule 5: A score per MHz hides the clock.
Multiply it by the clock that the core really reaches before you compare.
Rule 6: Cycles for each iteration = instructions for each iteration × CPI.
IPC is one divided by CPI. Split the cycles by class to see where they went.
Sources for These Rules
Benchmark, workload and SPEC CPU2006: Patterson and Hennessy, Computer Organization and Design, ARM edition, section 1.9.
Fixed code, fixed data and one proper answer as the usual rules, and SPECrate with many copies: the same book, section 6.10.
Time as instructions, times CPI, times the clock period: the same book, section 1.6. Section 1.10 warns against using part of it.
Dhrystone: from 1984, for embedded use, and not very representative. CoreMark: matrix work, linked lists, state machines and a CRC. Both are small. Source: Harris and Harris, Digital Design and Computer Architecture, ARM edition, section 7.2.
The same section of that book calls SPEC programs real programs, and says that CPI is one divided by IPC.
The score per MHz as a common way to quote CoreMark is common practice. No source in our library defines it. The run rules of CoreMark and of Dhrystone are not checked here.
The kernel, its input and the clocks are choices of this lab. The cost of a taken branch and of a CSR instruction on the five-stage core: docs/soc/ap_soc-facts.md, section 20.
Now Run It
The lab at the end of this page runs 10 iterations of the kernel. It walks the instructions of the window and counts cycles for both builds. A probe ran the same program on the real cores. Both read the same numbers from mcycle.
window | 602 instructions | 10 iterations | alu 430 | load 80 | store 0 | branch 90 | csr 2
five-stage cycles by class | alu 430 | load 80 | store 0 | branch 248 | csr 8
five-stage extra cycles | taken branches 158 | load-use 0 | waits 0 | counter reads 6
single-cycle | cycles 602 | CPI 1.00 | IPC 1.00 | per iteration 60.2 | per MHz 16611 | at 65 MHz 1079734 per second
five-stage | cycles 766 | CPI 1.27 | IPC 0.79 | per iteration 76.6 | per MHz 13054 | at 100 MHz 1305483 per secondRule 1: the window holds 602 instructions for 10 iterations. That is 60 for each, plus the 2 counter reads.
Rule 2, in the last two rows: 60.2 and 76.6 cycles for each iteration, not 60 and 76. The counter reads and the last pass of the loop are in the window too. With 20 iterations the five-stage core shows 76.3.
Rules 4 and 5, in the same rows. Per MHz: 16611 against 13054, so the single-cycle core leads by a quarter. Per second: 1079734 against 1305483, so the five-stage core leads by a fifth.
Rule 6, in the second and third rows. Of 766 cycles, 602 are one for each instruction. Taken branches add 158, and the counter reads add 6.
| Class | Instructions | Single-cycle cycles | Five-stage cycles | Why the five-stage core needs more |
|---|---|---|---|---|
| Arithmetic | 430 | 430 | 430 | Nothing: one cycle each |
| Load | 80 | 80 | 80 | Nothing here: no instruction uses a load at once |
| Branch | 90 | 90 | 248 | 79 taken branches, 2 more cycles each |
| Counter read (CSR) | 2 | 2 | 8 | 3 more cycles for each CSR instruction |
| All | 602 | 602 | 766 |
Every cell comes from the first three rows that the lab prints. A taken branch throws away the two words fetched behind it.
The run on a real chip measures the same window. A short window flatters nobody: with one iteration, the five-stage core read 82 cycles from mcycle, not 76. Its score per MHz would be 12195, seven percent low.
Why It Is Built This Way
| Design choice | The alternative | What the choice buys, and costs |
|---|---|---|
| Score as iterations for each second | Quote the time of a run | Bigger is better, and runs of any length compare. The number of iterations must be stated. |
| Quote the score per MHz | Quote the score at one clock | One number for a core that ships at many clocks. It hides the clock that the core can reach. |
| A small kernel | A suite of real programs, as SPEC CPU does | Easy to run on a small chip. It fits in any cache and tests little of the memory. |
The last row matters most. Our kernel reads eight words. Dhrystone and CoreMark are small too, so a small cache holds them whole. A real workload may not fit.
The Trap: The Winner per Megahertz
A team chose a core from a table of scores per MHz. The simple core led by a quarter. In the product it was slower, because its clock could not go as high.
That is our lab. The single-cycle core packs a whole instruction into one long cycle. Its cycle count is low and its clock is low. A score per MHz shows only the first half.
The second trap is the short run. The same core read 82 cycles for one iteration and 76 for each iteration of a long run. A quoted score must say how long the run was.
The third is a fast wrong answer. A compiler that drops work whose result nobody checks makes a loop look very fast. A benchmark checks its answer for that reason.
At Scale
This section looks ahead. A large chip is measured with larger work, by several cores at once.
Real programs
SPEC CPU uses large real programs. Each result is the time of a reference computer divided by the measured time. The results of a suite are joined by a geometric mean.
Cores that finish more than one instruction
A wider core can reach an IPC above 1. See Out-of-Order Execution.
Several cores
A throughput score runs one copy of the work on each core at once. That measures the shared memory as much as the cores.
Energy
A score for each watt matters as much as a score for each second in a phone. See Power, Area and Cost.
The next lesson, What Moves a Score, keeps the core fixed. It changes the compiler and the memory, and then reads a vendor's number.
Try It
Run the lab. Find the two rows that end in "per second". Which core has the higher score per MHz, and which the higher score?
Set ROUNDS to 1, then to 100. Watch the score per MHz of the five-stage core. Why does it rise?
Set MHZ_SINGLE to 100. Which core wins now, and does the clock of a real single-cycle core allow it?
Names Printed by the Lab
| Name | Meaning |
|---|---|
| window | The instructions between the two reads of mcycle: how many, and how many of each class. |
| alu, load, store, branch, csr | The classes: arithmetic and logic, loads, stores, branches, and CSR instructions such as the counter reads. |
| cycles by class | The five-stage cycles charged to each class. A taken branch is charged its two lost cycles. |
| extra cycles | The five-stage cycles above one for each instruction, by cause. |
| per iteration | Cycles of the window divided by the iterations. |
| per MHz | Iterations for each million cycles, cut down to a whole number. |
| at .. MHz | Iterations for each second at that clock, cut down to a whole number. |
window | 602 instructions | 10 iterations | alu 430 | load 80 | store 0 | branch 90 | csr 2 five-stage cycles by class | alu 430 | load 80 | store 0 | branch 248 | csr 8 five-stage extra cycles | taken branches 158 | load-use 0 | waits 0 | counter reads 6 single-cycle | cycles 602 | CPI 1.00 | IPC 1.00 | per iteration 60.2 | per MHz 16611 | at 65 MHz 1079734 per second five-stage | cycles 766 | CPI 1.27 | IPC 0.79 | per iteration 76.6 | per MHz 13054 | at 100 MHz 1305483 per secondCheck Yourself
Common Mistakes
Wrong Compare two cores by their scores per MHz alone.
It hides the clock, and the clock may differ a lot.
Fix Multiply by the clock that each core reaches, then compare.
Wrong Time one short iteration and scale it up.
The counter reads and the start of the loop are in the window.
Fix Run many iterations, and state how many.
Wrong Read a low CPI as a fast core.
Time is instructions, times CPI, times the clock period.
Fix Look at all three before you rank two cores.
Remember
- A benchmark is fixed work with a checked answer, timed in a long window.
- Score: iterations for each second. Score per MHz: iterations for each million cycles.
- A score per MHz hides the clock: the simpler core can win per MHz and lose per second.
- Cycles for each iteration = instructions × CPI. Split them by class to find the lost cycles.