---
title: Heterogeneous multicores
heading: Big and little cores, asymmetric and dynamic chips, and scheduling for energy
eyebrow: S4 · Lesson 15 · Heterogeneous multicores
xp: 50
---

::: hook
Every phone and most laptops pair a few big, fast cores with several small, efficient ones. The reason is in two of the course's rules: Pollack's rule says a core's performance grows only as the square root of its area, while its power grows about in proportion to its area, and Amdahl's law says the serial part of a program decides how far parallelism helps. A chip with one big core for the serial part and many small ones for the parallel part beats any chip of identical cores, and a scheduler that puts each thread on the right kind of core saves energy as well.
:::

::: play
- The curves are Hill and Marty's speedups for a chip of 256 base-core units against the size r of its cores: symmetric (all cores r units) and asymmetric (one r-unit core plus 256 − r single-unit cores), for parallel fraction f.
- The symmetric chip peaks at small cores and falls as they grow; the asymmetric chip keeps one big core for the serial part and still has many small ones.
- The dashed line is the ideal dynamic chip, which fuses all 256 units into one core for the serial part and splits them for the parallel part.
:::

```sim plot
view: graph
x: r = 1..256 log
y: S = 0..250
slider: f = 0.9..0.999 = 0.975
plot: 1/((1 - f)/sqrt(r) + f*r/(sqrt(r)*256)) | label: symmetric
plot: 1/((1 - f)/sqrt(r) + f/(sqrt(r) + 256 - r)) | label: asymmetric
plot: 1/((1 - f)/16 + f/256) + 0*r | dashed | label: dynamic
```

::: predict
## A chip has 256 base-core units and runs code that's 97.5% parallel. The best symmetric design reaches a speedup of about 51. What does an asymmetric design with one 64-unit core and 192 single-unit cores reach?

- [ ] About 30
- [ ] About 51
- [x] About 125
- [ ] About 256

::: reveal
The serial 2.5% runs on the big core at $\sqrt{64} = 8$ times a base core; the parallel part runs on everything at once, $8 + 192 = 200$ base cores' worth: $1/(0.025/8 + 0.975/200) = 125$. A symmetric chip of 64-unit cores would reach only 30, because four big cores do little for the parallel part.
:::
:::

::: nameit
## Pollack's rule and power

A core built from r base units performs about $\sqrt r$ times as well and draws about r times the power, so its performance per watt falls as $1/\sqrt r$. Big cores buy speed on serial code at a steep energy price.

## Hill and Marty's three chips

For n base units and parallel fraction f:
- **Symmetric**, n/r cores of r units: $\dfrac{1}{\frac{1 - f}{\sqrt r} + \frac{fr}{\sqrt r\,n}}$
- **Asymmetric**, one r-unit core plus n − r one-unit cores: $\dfrac{1}{\frac{1 - f}{\sqrt r} + \frac{f}{\sqrt r + n - r}}$
- **Dynamic**, all n units fused for serial work and split for parallel work: $\dfrac{1}{\frac{1 - f}{\sqrt n} + \frac fn}$

## Scheduling

An operating system with big and little cores (Arm's big.LITTLE and DynamIQ, Intel's performance and efficiency cores) moves threads by their behavior: compute-bound threads gain the most from a big core; memory-bound threads, which mostly wait for DRAM, gain little and run more efficiently on a little one. Energy for a task is power × time, so a core that's three times faster but draws ten times the power uses 3.3 times the energy.
:::

::: example
## A big core runs 3 times faster than a little core and draws 10 times the power. How much energy does each use for the same task, and when is the big core still the right choice?

::: solution
1. **Energy ratio.** Energy is power × time, so the big core uses
   $$10/3 = 3.3$$
   times the energy of the little one.
2. **When the big core is right.** It's the right choice when the task is on the critical path (a user is waiting, or it's the serial part holding up parallel work).
3. **Or to sleep sooner.** It also wins when finishing quickly lets the whole chip, with its leakage, go to sleep sooner.

**Answer:** the big core uses 3.3 times the energy; it's still right for critical-path work, or when finishing early lets the whole chip sleep.
:::
:::

::: example
## For the same 256-unit chip, what does the ideal dynamic design reach at f = 0.975, and why is it better than the best asymmetric one?

::: solution
1. **Dynamic speedup.**
   $$\begin{aligned} S &= \frac{1}{0.025/16 + 0.975/256} \\ &= 186 \end{aligned}$$
2. **Serial part.** It runs on all 256 units fused into one core, 16 times a base core.
3. **Parallel part.** It uses all 256 units as small cores.
4. **Compare with asymmetric.** The asymmetric chip has to keep its big core's area as one core even in parallel phases, where it's worth only 8 small cores.

**Answer:** the ideal dynamic design reaches 186, because it gets the big core's speed in serial phases and every unit as a small core in parallel phases.
:::
:::

::: example
## A memory-bound thread speeds up 1.3 times on a big core; a compute-bound one speeds up 3 times. With one big core free, which should get it?

::: solution
1. **Compare the gains.** The compute-bound thread gains 3 times for the big core's cost, while the memory-bound one gains only 1.3, since its time is mostly spent waiting for DRAM whatever core it's on.
2. **The memory-bound thread on a little core.** It loses
   $$1 - 1/1.3 = 23\%$$
   of its speed and saves most of its energy.

**Answer:** the compute-bound thread should get the big core.
:::
:::

::: check
kind: parts
given: r = 4 | 16 | 64

## A core is built from {r} base-core units.

::: part
answer: sqrt(r)
tolerance: 0.5%

### How much faster than a base core is it, by Pollack's rule?

::: misses
- [r] Performance grows as the square root of area.
- [any] $\sqrt r$.
:::
:::

::: part
answer: 1/sqrt(r)
tolerance: 0.5%

### What is its performance per watt relative to a base core, if power grows with area?

::: misses
- [any] $\sqrt r/r$.
:::
:::
:::

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

## A chip has {n} base units; its parallel fraction is {f}, and cores are {r} units.

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

### What is the symmetric chip's speedup?

::: 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 chip's, with one {r}-unit core and the rest single units?

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

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

### And the ideal dynamic chip's?

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

::: check
kind: parts
given: s = 2 | 3 | 4; p = 4 | 8 | 12; t = 10 | 50

## A big core runs {s} times faster than a little one and draws {p} times the power. A task takes {t} ms on the little core.

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

### How much more energy does the big core use for the task?

::: misses
- [p] Energy is power × time, and the time shrinks.
- [any] Power ratio over speed ratio.
:::
:::

::: part
answer: t/s
unit: ms
tolerance: 0.5%

### How long does the big core take?

::: misses
- [any] Little-core time over the speedup.
:::
:::
:::

::: check
kind: choice

## A scheduler has one big core free and two runnable threads: a matrix multiply and a pointer-chasing database scan that misses the cache on most loads. Which should get the big core, and why?

- [ ] The database scan, because it's slower
- [x] The matrix multiply: its time is spent computing, so a faster core speeds it up; the scan mostly waits for memory, which no core makes faster
- [ ] Either; big cores speed everything up equally
- [ ] Neither; big cores should stay idle to save power

::: misses
- [1] Slow because of memory stalls, which the big core can't remove.
- [3] A big core's advantage is in executing instructions faster, not in DRAM latency.
- [4] Idling the big core forgoes a large speedup on compute-bound work.
:::
:::

::: check
kind: derivation
vars: n = 16..1024, r = 1..16, f = 0.5..0.999

## A chip has n base units with parallel fraction f; its big core has r units.

::: step
answer: (1 - f)/sqrt(r)

### How long does the serial part take, relative to one base core running the whole program?
:::

::: step
answer: f/(sqrt(r) + n - r)

### How long does the parallel part take on the asymmetric chip?
:::

::: step
answer: 1/((1 - f)/sqrt(r) + f/(sqrt(r) + n - r))

### What is the asymmetric speedup?
:::

::: right
Right. The big core pays off in the serial part and still contributes $\sqrt r$ in the parallel part.
:::
:::

::: check
kind: python

## Write `best_r(n, f, kind)`: over r = 1, 2, 4, …, n, return (best speedup, best r) for kind 'sym' or 'asym' using Hill and Marty's formulas.

```python starter
def best_r(n, f, kind):
    return (1.0, 1)
```

```python solution
import math

def best_r(n, f, kind):
    best = None
    r = 1
    while r <= n:
        if kind == 'sym':
            s = 1 / ((1 - f) / math.sqrt(r) + f * r / (math.sqrt(r) * n))
        else:
            s = 1 / ((1 - f) / math.sqrt(r) + f / (math.sqrt(r) + n - r))
        if best is None or s > best[0]:
            best = (s, r)
        r *= 2
    return best
```

```python tests
s, r = best_r(256, 0.975, 'sym')
assert r == 8 and abs(s - 51.0) < 0.1, "Symmetric: 8-unit cores, about 51."
s, r = best_r(256, 0.975, 'asym')
assert r == 64 and abs(s - 125) < 0.01, "Asymmetric: one 64-unit core, 125."
assert best_r(256, 0.99, 'asym')[1] == 32, "More parallel code favors a smaller big core."
```

::: right
Right. The more parallel the code, the more area the asymmetric optimum leaves to small cores.
:::
:::

::: explain
## Why does an asymmetric multicore beat any symmetric one for programs with a small serial fraction?

::: model
In a symmetric chip every core has the same size, so making cores bigger speeds up the serial part but leaves fewer cores for the parallel part, and since performance grows only as the square root of area, big cores are an inefficient use of area in parallel phases. Making them small does the opposite. An asymmetric chip spends area on one big core to run the serial part fast, where nothing else can help, and leaves the rest as many small, area-efficient cores for the parallel part. It gets most of the benefit of both choices at once, and the serial fraction, by Amdahl's law, is exactly the part that limits everything else.
:::
:::

::: practice
::: check
given: r = 9 | 25 | 100
answer: sqrt(r)
tolerance: 0.5%

## Pollack speedup of a {r}-unit core?

::: misses
- [any] $\sqrt r$.
:::
:::

::: check
given: f = 0.95 | 0.99; r = 16 | 64
answer: 1/((1 - f)/sqrt(r) + f/(sqrt(r) + 256 - r))
tolerance: 0.5%

## Asymmetric speedup, 256 units, f = {f}, big core {r}?

::: misses
- [any] Hill and Marty's asymmetric formula.
:::
:::

::: check
given: s = 2 | 5; p = 6 | 15
answer: p/s
tolerance: 0.5%

## Energy ratio of a core {s} times faster at {p} times the power?

::: misses
- [any] p/s.
:::
:::
:::
