---
title: "Problem set 4: ILP, threads and caches"
heading: "Problem set 4: superscalar limits, multithreading, cache performance and cache optimizations"
eyebrow: S4 · Problem set 4
type: problems
---

::: hook
These problems cover lessons 13 to 20: dataflow limits and the cost of width, VLIW code size and unrolling, thread counts for hiding latency, heterogeneous multicores, multilevel access times and the three Cs, blocking, memory-level parallelism and prefetching, and multicore cache hierarchies.
:::

::: pool
pick: 12

::: check
kind: parts
given: N = 24 | 40; C = 6 | 8; w = 4 | 6; W = 128 | 224; s = 2 | 3

## A block of {N} instructions with a {C}-long dependence chain runs on a {w}-wide core with a {W}-entry window and {s} bypass stages.

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

### Dataflow-limited IPC?

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

::: part
answer: 2*w*W
tolerance: 0.5%

### Wake-up comparators?

::: misses
- [any] $2wW$.
:::
:::

::: part
answer: 2*s*w^2
tolerance: 0.5%

### Bypass paths?

::: misses
- [any] $2sw^2$.
:::
:::
:::

::: check
kind: parts
given: w = 5 | 8; k = 1.8 | 3.1; L = 4 | 6; r = 2 | 3; R = 4 | 6; b = 3 | 5

## A {w}-slot VLIW filling {k} slots per word; a reduction on a unit of latency {L} starting {r} operations per cycle, with {R} registers per partial sum chain and {b} shared.

::: part
answer: w/k
tolerance: 0.5%

### Code size factor?

::: misses
- [any] $w/\bar k$.
:::
:::

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

### Independent partial sums needed?

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

::: part
answer: L*r*R + b
tolerance: 0

### Registers when unrolled that many times?

::: misses
- [any] $Ur + b$.
:::
:::
:::

::: check
kind: parts
given: R = 10 | 25; L = 150 | 400; C = 4 | 8; N = 3 | 5

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

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

### Fine-grained threads to saturate?

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

::: part
answer: 100*R/(R + C)
unit: %
tolerance: 0.5%

### Coarse-grained ceiling?

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

::: part
answer: 100*N*R/(R + L)
unit: %
tolerance: 0.5%

### Utilization with {N} threads?

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

::: check
kind: parts
given: p = 1.3 | 2; t = 2.1 | 3; T = 4 | 16; A = 32; b = 64

## An SMT core: two threads reaching IPC {p} alone and {t} together; a GPU-style core with {T} threads of {A} 64-bit registers.

::: part
answer: t/p
tolerance: 0.5%

### Throughput gain over one thread?

::: misses
- [any] Total over solo.
:::
:::

::: part
answer: t/(2*p)
tolerance: 0.5%

### Each thread's fraction of its solo speed?

::: misses
- [any] Half the total over solo.
:::
:::

::: part
answer: T*A*b/8/1024
unit: KB
tolerance: 0.5%

### Register state for the {T} threads?

::: misses
- [any] Threads × registers × 8 bytes.
:::
:::
:::

::: check
kind: parts
given: h = 1 | 2; m = 0.03 | 0.06; k = 10 | 15; n = 0.25 | 0.4; M = 180 | 320; a = 1.25 | 1.4

## L1 hits in {h} cycles, misses {m}; L2 hits in {k}, misses {n} locally; memory takes {M}; {a} accesses per instruction.

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

### AMAT?

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

::: part
answer: 1000*a*m*n
tolerance: 0.5%

### L2 MPKI?

::: misses
- [any] 1000 × accesses × global miss rate.
:::
:::

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

### Stall cycles per instruction (no overlap)?

::: misses
- [any] Accesses × (AMAT − hit).
:::
:::
:::

::: check
kind: parts
given: d = 12000 | 20000; f = 7000 | 11000; c = 2000 | 4000; D = 4 | 16; B = 64

## A program: {d} misses direct-mapped, {f} fully associative, {c} with an infinite cache; it also streams once through {D} MB with {B}-byte lines.

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

### Conflict misses?

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

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

### Capacity misses?

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

::: part
answer: D*1024*1024/B
tolerance: 0.5%

### Compulsory misses of the stream?

::: misses
- [any] Bytes over line size.
:::
:::
:::

::: check
kind: parts
given: m = 0.05 | 0.1; S = 16 | 32; T = 256 | 1024; a = 0.45 | 0.55

## A {S} KB cache misses {m}; the power-law exponent is {a}.

::: part
answer: 100*m*(T/S)^(-a)
unit: %
tolerance: 0.5%

### Predicted miss rate at {T} KB?

::: misses
- [any] $m(T/S)^{-\alpha}$.
:::
:::

::: part
answer: (T/S)^a
tolerance: 0.5%

### By what factor did misses fall?

::: misses
- [any] $(T/S)^{\alpha}$.
:::
:::
:::

::: check
kind: parts
given: N = 512 | 2048; K = 32 | 64; e = 8

## A {N} × {N} double-precision matrix multiply, with a {K} KB cache.

::: part
answer: floor(sqrt(K*1024/(3*e)) + 0.0001)
tolerance: 0

### Largest B with three B × B blocks fitting?

::: misses
- [any] $\lfloor\sqrt{C/3}\rfloor$ elements.
:::
:::

::: part
answer: (2*N^3 + N^2)/(2*N^3/floor(sqrt(K*1024/(3*e)) + 0.0001) + N^2)
tolerance: 0.5%

### Traffic reduction at that B?

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

::: check
kind: parts
given: n = 10 | 24; L = 180 | 300; P = 3 | 6; t = 20 | 40

## {n} independent misses of {L} cycles each, overlapping {P} at a time; a loop of {t} cycles per iteration.

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

### Stall cycles?

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

::: part
answer: ceil(L/t - 0.0001)
tolerance: 0

### Prefetch distance in iterations?

::: misses
- [any] $\lceil L/t \rceil$.
:::
:::
:::

::: check
kind: parts
given: p = 0.8 | 0.92; f = 1; s = 3 | 4; m = 0.05 | 0.09; c = 0.25 | 0.45; v = 0.5 | 0.8

## Way prediction {p} accurate (hits of {f} or {s} cycles); a direct-mapped cache missing {m}, {c} conflicts, a victim cache catching {v} of them.

::: part
answer: p*f + (1 - p)*s
tolerance: 0.5%

### Average hit time?

::: misses
- [any] Weighted average.
:::
:::

::: part
answer: 100*m*(1 - c*v)
unit: %
tolerance: 0.5%

### New miss rate?

::: misses
- [any] $m(1 - cv)$.
:::
:::
:::

::: check
kind: parts
given: h = 1 | 2; m = 0.04 | 0.07; M = 100 | 200; k = 12; n = 0.3 | 0.5

## A single cache hits in {h} cycles and misses {m} with a {M}-cycle penalty. Adding an L2 (hit {k} cycles, local miss rate {n}) in front of memory:

::: part
answer: h + m*M
tolerance: 0.5%

### AMAT without the L2?

::: misses
- [any] $h + mM$.
:::
:::

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

### Speedup of memory access with it?

::: misses
- [any] Ratio of AMATs.
:::
:::
:::

::: check
kind: parts
given: w = 4 | 6; L = 30 | 60; W = 128 | 256; A = 32; f = 0.75

## A {w}-wide core averaging {L} cycles per instruction in flight, with a {W}-entry window, {A} architectural registers, {f} of instructions writing one.

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

### Sustainable IPC?

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

::: part
answer: A + W*f
tolerance: 0.5%

### Physical registers?

::: misses
- [any] $A + Wf$.
:::
:::
:::

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

## A chip of {n} base units runs code that's {f} parallel; one design is asymmetric with an {r}-unit big core.

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

### What speedup does it reach?

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

::: check
kind: parts
given: N = 8 | 16; L = 1 | 2; C = 16 | 32

## {N} cores each have an {L} MB L2 under a {C} MB shared L3.

::: part
answer: C + N*L
unit: MB
tolerance: 0.5%

### How much distinct data fits if the L3 is exclusive?

::: misses
- [any] L3 plus the L2s.
:::
:::

::: part
answer: N*L/C*100
unit: %
tolerance: 0.5%

### What fraction of the inclusive L3 is spent duplicating the L2s, at most?

::: misses
- [any] L2 capacity over L3 capacity.
:::
:::
:::

::: check
kind: parts
given: k = 4 | 8; a = 10 | 16; t = 2 | 4

## An L3 is sliced over a {k} × {k} mesh, {a} cycles per slice and {t} per hop.

::: part
answer: a + 2*(2*k/3)*t
unit: cycles
tolerance: 0.5%

### What is its average access latency?

::: misses
- [any] Slice + round trip at the average distance.
:::
:::
:::
:::
