---
title: "Problem set 6: rooflines, coherence and consistency"
heading: "Problem set 6: the roofline model, snooping and directory coherence, networks and synchronization"
eyebrow: S4 · Problem set 6
type: problems
---

::: hook
These problems cover lessons 31 to 35: attainable performance and arithmetic intensity, bus bandwidth and MESI traffic, false sharing, directory storage and network topology, on-chip network latency and saturation, lock traffic, critical sections and barriers.
:::

::: pool
pick: 12

::: check
kind: parts
given: F = 900 | 3000; B = 80 | 400; I = 0.15 | 3 | 40

## A machine peaks at {F} GFLOPS with {B} GB/s; a kernel has intensity {I} flop/byte.

::: part
answer: F/B
tolerance: 0.5%

### Ridge point?

::: misses
- [any] Peak over bandwidth.
:::
:::

::: part
answer: (F + B*I - abs(F - B*I))/2
unit: GFLOPS
tolerance: 0.5%

### Attainable performance?

::: misses
- [any] The lower roof.
:::
:::
:::

::: check
kind: parts
given: o = 2 | 4 | 10; r = 2 | 3; w = 1; e = 4 | 8; B = 100 | 300

## A streaming loop does {o} operations per element, reading {r} arrays and writing {w}, with {e}-byte elements, on a machine with {B} GB/s.

::: part
answer: o/((r + w)*e)
tolerance: 0.5%

### Intensity?

::: misses
- [any] Ops over bytes per element.
:::
:::

::: part
answer: B*o/((r + w)*e)
unit: GFLOPS
tolerance: 0.5%

### Performance if memory-bound?

::: misses
- [any] Bandwidth × intensity.
:::
:::
:::

::: check
kind: parts
given: N = 2 | 8; o = 6 | 30; b = 12 | 40; F = 1500 | 5000; B = 150 | 1000; T = 32 | 96; e = 8

## A kernel of {N} billion elements, {o} ops and {b} bytes each, on a {F} GFLOPS, {B} GB/s machine; separately, a matrix multiply blocked by {T} with {e}-byte numbers.

::: part
answer: (N*o/F + N*b/B + abs(N*o/F - N*b/B))/2
unit: s
tolerance: 0.5%

### The kernel's minimum time?

::: misses
- [any] max(ops/peak, bytes/bandwidth).
:::
:::

::: part
answer: T/e
tolerance: 0.5%

### The multiply's intensity?

::: misses
- [any] T/e.
:::
:::
:::

::: check
kind: parts
given: f = 2.5 | 3.5; m = 0.003 | 0.009; B = 64 | 128; W = 60 | 240

## Cores at {f} GHz, IPC 1, {m} bus misses per instruction, {B}-byte lines, on a {W} GB/s bus.

::: part
answer: f*m*B
unit: GB/s
tolerance: 0.5%

### Traffic per core?

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

::: part
answer: W/(f*m*B)
tolerance: 0.5%

### Cores at saturation?

::: misses
- [any] $W/(fmB)$.
:::
:::
:::

::: check
kind: parts
given: n = 400 | 4000; p = 0.4 | 0.7 | 0.9; k = 1000 | 5000

## A thread reads then writes {n} lines, {p} of them unshared; separately, two cores increment falsely shared counters {k} times each, alternately.

::: part
answer: 2*n
tolerance: 0

### MSI bus transactions?

::: misses
- [any] Read plus upgrade per line.
:::
:::

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

### MESI bus transactions?

::: misses
- [any] Unshared lines need no upgrade.
:::
:::

::: part
answer: 2*k
tolerance: 0.5%

### Coherence misses from the false sharing, about?

::: misses
- [any] Every increment misses.
:::
:::
:::

::: check
kind: parts
given: N = 64 | 256 | 1024; B = 64 | 128; p = 4 | 6

## A directory for {N} cores with {B}-byte lines.

::: part
answer: 100*N/(8*B)
unit: %
tolerance: 0.5%

### Full bit-vector overhead?

::: misses
- [any] $N/8B$.
:::
:::

::: part
answer: 100*p*ceil(log(N - 0.5)/log(2))/(8*B)
unit: %
tolerance: 0.5%

### Overhead with {p} limited pointers?

::: misses
- [any] $p\lceil\log_2N\rceil$ bits per line.
:::
:::
:::

::: check
kind: parts
given: k = 6 | 10 | 16; b = 25 | 50

## A {k} × {k} network with {b} GB/s links.

::: part
answer: 2*(k - 1)
tolerance: 0

### Mesh diameter?

::: misses
- [any] $2(k - 1)$.
:::
:::

::: part
answer: 2*k/3
tolerance: 0.5%

### Mesh average distance between distinct nodes?

::: misses
- [any] $2k/3$.
:::
:::

::: part
answer: 2*k*b
unit: GB/s
tolerance: 0.5%

### Torus bisection bandwidth (one direction)?

::: misses
- [any] 2k links.
:::
:::
:::

::: check
kind: parts
given: m = 2 | 3; k = 8 | 12; t = 2 | 3; o = 10 | 20

## A directory miss with {m} critical-path messages on a {k} × {k} mesh at average distance, {t} ns per hop and {o} ns overhead per message.

::: part
answer: 2*k/3
tolerance: 0.5%

### Average hops per message?

::: misses
- [any] $2k/3$.
:::
:::

::: part
answer: m*(2*k/3*t + o)
unit: ns
tolerance: 0.5%

### Network latency of the miss?

::: misses
- [any] $m(ht + o)$.
:::
:::
:::

::: check
kind: parts
given: N = 8 | 16 | 48

## {N} cores contend for a lock, one holding it, until all have held it.

::: part
answer: N*(N - 1)
tolerance: 0

### Test-and-test-and-set transactions (two misses per waiter per handoff)?

::: misses
- [any] $N(N - 1)$.
:::
:::

::: part
answer: N*(N - 1)/2
tolerance: 0

### Ticket lock (one per waiter per handoff)?

::: misses
- [any] $N(N - 1)/2$.
:::
:::

::: part
answer: N - 1
tolerance: 0

### MCS lock (one per handoff)?

::: misses
- [any] N − 1.
:::
:::
:::

::: check
kind: parts
given: c = 0.02 | 0.05; N = 16 | 64 | 512; k = 2 | 8; t = 40 | 70; a = 25 | 40

## Threads spend {c} of their time under one lock; {N} threads meet at a barrier (tree of fan-in {k} at {t} ns per level, or a central counter at {a} ns per atomic).

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

### Throughput limit, in threads?

::: misses
- [any] 1/c.
:::
:::

::: part
answer: ceil(log(N - 0.5)/log(k))*t
unit: ns
tolerance: 0

### Tree barrier arrival time?

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

::: part
answer: N*a
unit: ns
tolerance: 0.5%

### Central counter arrival time?

::: misses
- [any] N atomics in series.
:::
:::
:::

::: check
kind: parts
given: F = 1200 | 2400; B = 100 | 200; s = 8 | 16; I = 4 | 30

## A machine of {F} GFLOPS and {B} GB/s, whose peak assumes {s}-lane SIMD; a kernel of intensity {I} doesn't vectorize.

::: part
answer: F/s
unit: GFLOPS
tolerance: 0.5%

### The scalar compute ceiling?

::: misses
- [any] Peak over lanes.
:::
:::

::: part
answer: (F/s + B*I - abs(F/s - B*I))/2
unit: GFLOPS
tolerance: 0.5%

### What the kernel attains?

::: misses
- [any] The lower of the scalar ceiling and B·I.
:::
:::
:::

::: check
kind: parts
given: s = 3 | 7 | 15; w = 20 | 50; N = 4 | 8; p = 0.75 | 0.9

## A line shared by {s} other caches is written {w} times, with rereads between writes; separately, {N} cores each read then write a private line under MESI, {p} of the time finding no other copy.

::: part
answer: s*w
tolerance: 0

### Invalidations?

::: misses
- [any] s per write.
:::
:::

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

### MESI transactions for the private lines?

::: misses
- [any] One read each, plus upgrades for shared ones.
:::
:::
:::

::: check
kind: parts
given: k = 4 | 8 | 12; r = 2 | 4; L = 64 | 80; b = 16

## A {k} × {k} mesh has {r}-cycle routers and 1-cycle, 16-byte links; messages carry {L} bytes.

::: part
answer: 2*k/3*(r + 1) + L/16
unit: cycles
tolerance: 0.5%

### What is the zero-load latency at the average distance?

::: misses
- [any] $H(t_r + 1) + L/b$.
:::
:::
:::

::: check
kind: parts
given: k = 4 | 8 | 16

## Uniform random traffic runs on a {k} × {k} network.

::: part
answer: 4/k
unit: flits/cycle
tolerance: 0.5%

### What injection rate per node saturates a mesh?

::: misses
- [any] $4/k$.
:::
:::

::: part
answer: 8/k
unit: flits/cycle
tolerance: 0.5%

### And a torus?

::: misses
- [any] $8/k$.
:::
:::
:::

::: check
kind: parts
given: w = 1 | 2; r = 2 | 4; c = 1 | 2

## A link's credit loop is {w} cycle(s) across, {r} through the router and {c} back.

::: part
answer: w + r + c
unit: buffers
tolerance: 0

### How many buffers per virtual channel keep the link busy?

::: misses
- [any] The round trip in cycles.
:::
:::
:::
:::
