---
title: Midterm exam
heading: "Midterm exam: performance, pipelines, out-of-order execution and caches"
eyebrow: S4 · Midterm exam
type: problems
---

::: hook
Twelve problems from lessons 1 to 20: the iron law and the memory wall, Amdahl's law and multicore sizing, power scaling, instruction encoding, pipeline depth, branch prediction, out-of-order windows and speculation, ILP, multithreading and heterogeneous cores, and cache performance. Give yourself two and a half hours and work without the lessons open. "Another set" deals a different exam.
:::

::: pool
pick: 12

::: check
kind: parts
given: N = 2 | 5; C = 1.1 | 1.6; f = 2.5 | 3.5; m = 0.006 | 0.015; M = 80 | 120

## A program of {N} billion instructions at pipeline CPI {C} on a {f} GHz core, missing {m} times per instruction to a {M} ns memory.

::: part
answer: C + m*M*f
tolerance: 0.5%

### Total CPI?

::: misses
- [any] Penalty in cycles = latency × clock.
:::
:::

::: part
answer: N*(C + m*M*f)/f
unit: s
tolerance: 0.5%

### Execution time?

::: misses
- [any] IC × CPI / f.
:::
:::
:::

::: check
kind: parts
given: F = 0.9 | 0.97; N = 16 | 64; T = 6 | 10

## A program is {F} parallel.

::: part
answer: 1/((1 - F) + F/N)
tolerance: 0.5%

### Speedup on {N} processors?

::: misses
- [any] Amdahl.
:::
:::

::: part
answer: (1 - 1/T)/(1 - 1/N)
tolerance: 0.5%

### Parallel fraction needed for {T}× on {N}?

::: misses
- [any] Solve Amdahl for F.
:::
:::
:::

::: check
kind: parts
given: f = 0.95 | 0.98; n = 128 | 256; r = 4 | 16

## A symmetric multicore of {n} base units, cores of {r} units each (performance $\sqrt r$), on code {f} parallel.

::: part
answer: 1/((1 - f)/sqrt(r) + f*r/(sqrt(r)*n))
tolerance: 0.5%

### Speedup?

::: misses
- [any] Hill–Marty.
:::
:::

::: part
answer: 1/((1 - f) + f/n)
tolerance: 0.5%

### Speedup with {n} one-unit cores instead?

::: misses
- [any] r = 1.
:::
:::
:::

::: check
kind: parts
given: v = 0.85 | 1; n = 3 | 5; f = 3 | 3.5; P = 100 | 140; Q = 180 | 250

## Generations scale dimensions by √2 and voltage by {v}, with a fixed clock; separately, a {f} GHz core uses {P} W, power ∝ $f^3$.

::: part
answer: (sqrt(2)*v^2)^(-n)
tolerance: 0.5%

### Usable fraction after {n} generations?

::: misses
- [any] $(Sv^2)^{-n}$.
:::
:::

::: part
answer: f*(Q/P)^(1/3)
unit: GHz
tolerance: 0.5%

### Clock at {Q} W?

::: misses
- [any] $f(Q/P)^{1/3}$.
:::
:::
:::

::: check
kind: parts
given: R = 32 | 64; k = 8 | 11; b = 13 | 21; g = 2

## A 32-bit ISA with {R} registers and a {k}-bit I-type opcode; branch offsets of {b} bits in {g}-byte units.

::: part
answer: 32 - 2*ceil(log(R - 0.5)/log(2)) - k
tolerance: 0

### I-type immediate bits?

::: misses
- [any] 32 minus two register fields and the opcode.
:::
:::

::: part
answer: 2^(b - 1)*g
unit: B
tolerance: 0

### Backward branch reach?

::: misses
- [any] $2^{b-1}g$.
:::
:::
:::

::: check
kind: parts
given: t = 100 | 140; o = 3 | 4; b = 0.04 | 0.06; k = 12 | 30

## {t} FO4 of logic per instruction, {o} FO4 of overhead per stage, {b} stalls per instruction per stage.

::: part
answer: sqrt(t/(o*b))
tolerance: 1%

### Optimal depth?

::: misses
- [any] $\sqrt{t/(ob)}$.
:::
:::

::: part
answer: (t/k + o)*(1 + b*k)
tolerance: 0.5%

### Time per instruction at {k} stages, in FO4?

::: misses
- [any] $(t/k + o)(1 + bk)$.
:::
:::
:::

::: check
kind: parts
given: N = 5 | 20; c = 0.6 | 1; f = 0.18 | 0.22; a = 0.9 | 0.95; b = 0.97 | 0.99; P = 14 | 20

## A loop of {N} iterations runs repeatedly; separately, a core with base CPI {c}, {f} branches and a {P}-cycle penalty improves its predictor from {a} to {b}.

::: part
answer: 100/N
unit: %
tolerance: 0.5%

### 2-bit counter misprediction rate on the loop?

::: misses
- [any] One miss per run.
:::
:::

::: part
answer: (c + f*(1 - a)*P)/(c + f*(1 - b)*P)
tolerance: 0.5%

### Speedup from the better predictor?

::: misses
- [any] Ratio of total CPI.
:::
:::
:::

::: check
kind: parts
given: w = 4 | 6; L = 25 | 45; W = 96 | 192; c = 2 | 3; g = 0.8

## A {w}-wide core with {L} cycles of average latency and a {W}-entry window; {c} result buses, {g} of instructions producing results.

::: part
answer: w*L
tolerance: 0.5%

### Window for full width?

::: misses
- [any] Little's law.
:::
:::

::: part
answer: (w + W/L - abs(w - W/L))/2
tolerance: 0.5%

### IPC with {W} entries?

::: misses
- [any] min(w, W/L).
:::
:::

::: part
answer: c/g
tolerance: 0.5%

### IPC limit from the buses?

::: misses
- [any] $c/f_w$.
:::
:::
:::

::: check
kind: parts
given: a = 0.95 | 0.98; f = 0.2; W = 150 | 300; l = 0.25 | 0.3; r = 0.01 | 0.02; p = 15 | 20

## A {W}-entry speculative window with a branch every 5 instructions at accuracy {a}; {l} loads, {r} of them replayed at {p} cycles.

::: part
answer: (1 - a^(f*W))/(f*(1 - a))
tolerance: 0.5%

### Useful instructions in the window?

::: misses
- [any] $\frac{1}{f}\frac{1 - a^{fW}}{1 - a}$.
:::
:::

::: part
answer: l*r*p
tolerance: 0.5%

### Replay CPI?

::: misses
- [any] $f_\text{load}rp$.
:::
:::
:::

::: check
kind: parts
given: N = 30 | 60; C = 6 | 15; L = 4 | 5; r = 2

## A block of {N} instructions with a {C}-long dependence chain; a reduction on a unit of latency {L} that starts {r} per cycle.

::: part
answer: N/C
tolerance: 0.5%

### Dataflow IPC?

::: misses
- [any] N/C.
:::
:::

::: part
answer: L*r
tolerance: 0

### Partial sums needed?

::: misses
- [any] Latency × rate.
:::
:::
:::

::: check
kind: parts
given: R = 15 | 30; L = 200 | 350; C = 5 | 10

## Threads run {R} cycles between {L}-cycle misses; coarse switching costs {C}.

::: part
answer: (R + L)/R
tolerance: 0.5%

### Fine-grained threads to saturate?

::: misses
- [any] $(R + L)/R$.
:::
:::

::: part
answer: (R + L)/(R + C)
tolerance: 0.5%

### Coarse-grained threads to reach its ceiling?

::: misses
- [any] $(R + L)/(R + C)$.
:::
:::
:::

::: check
kind: parts
given: h = 1 | 2; m = 0.04 | 0.08; k = 12 | 16; n = 0.2 | 0.35; M = 200 | 300

## L1 hits in {h}, misses {m}; L2 hits in {k}, misses {n} locally; memory {M} cycles.

::: part
answer: h + m*(k + n*M)
tolerance: 0.5%

### AMAT?

::: misses
- [any] Nest the levels.
:::
:::

::: part
answer: 100*m*n
unit: %
tolerance: 0.5%

### L2 global miss rate?

::: misses
- [any] $m_1m_2$.
:::
:::
:::

::: check
kind: parts
given: d = 15000 | 25000; f = 9000 | 14000; c = 3000 | 5000

## {d} misses direct-mapped, {f} fully associative, {c} infinite.

::: part
answer: d - f
tolerance: 0

### Conflict?

::: misses
- [any] DM − FA.
:::
:::

::: part
answer: f - c
tolerance: 0

### Capacity?

::: misses
- [any] FA − infinite.
:::
:::
:::

::: check
kind: parts
given: N = 1024 | 4096; B = 16 | 32; n = 8 | 16; L = 200 | 260; P = 4 | 8

## A blocked {N} × {N} matrix multiply with {B} × {B} tiles; {n} misses of {L} cycles overlapping {P} at a time.

::: part
answer: (2*N^3 + N^2)/(2*N^3/B + N^2)
tolerance: 0.5%

### Traffic reduction?

::: misses
- [any] Ratio of the traffic counts.
:::
:::

::: part
answer: n*L/P
tolerance: 0.5%

### Stall cycles for the misses?

::: misses
- [any] $nL/\text{MLP}$.
:::
:::
:::

::: check
kind: parts
given: c = 2 | 3; e = 8 | 12; V = 0.75 | 0.9; L = 6 | 15; f = 2 | 3; t = 1.2 | 1.6

## A task of {c} billion cycles at {f} GHz and {V} V ({e} nJ per cycle and {L} W of leakage at 1 V); and a VLIW whose code is {t}× larger than dense.

::: part
answer: c*e*V^2 + L*V*c/f
unit: J
tolerance: 0.5%

### Task energy?

::: misses
- [any] Dynamic plus leakage × time.
:::
:::

::: part
answer: 100*(1 - 1/t)
unit: %
tolerance: 0.5%

### Fraction of the VLIW's slots that are NOPs?

::: misses
- [any] One minus filled over total.
:::
:::
:::

::: check
kind: parts
given: n = 64 | 256; r = 4 | 16; f = 0.9 | 0.975

## A chip of {n} base units runs code that's {f} parallel, built either from {r}-unit cores only or with one {r}-unit core and single units elsewhere.

::: part
answer: 1/((1 - f)/sqrt(r) + f*r/(sqrt(r)*n))
tolerance: 0.5%

### What does the symmetric design reach?

::: misses
- [any] $1/((1 - f)/\sqrt r + fr/(\sqrt r\,n))$.
:::
:::

::: part
answer: 1/((1 - f)/sqrt(r) + f/(sqrt(r) + n - r))
tolerance: 0.5%

### And the asymmetric one?

::: misses
- [any] $1/((1 - f)/\sqrt r + f/(\sqrt r + n - r))$.
:::
:::
:::
:::
