rectangles all the way down - dyalog ltd. · 2018. 11. 5. · is it really “turtles all the way...

74
Rectangles All The Way Down Martin Thompson - @mjpt777

Upload: others

Post on 08-Mar-2021

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Rectangles All The Way Down - Dyalog Ltd. · 2018. 11. 5. · Is it really “Turtles all the way down”? •Networks: Frames •Operating Systems: Pages •File systems and storage:

Rectangles All The Way Down

Martin Thompson - @mjpt777

Page 2: Rectangles All The Way Down - Dyalog Ltd. · 2018. 11. 5. · Is it really “Turtles all the way down”? •Networks: Frames •Operating Systems: Pages •File systems and storage:

“The most amazing achievement of the

computer software industry is its

continuing cancellation of the steady

and staggering gains made by the

computer hardware industry.”

- Henry Peteroski

Page 3: Rectangles All The Way Down - Dyalog Ltd. · 2018. 11. 5. · Is it really “Turtles all the way down”? •Networks: Frames •Operating Systems: Pages •File systems and storage:

Fundamental Laws

Page 4: Rectangles All The Way Down - Dyalog Ltd. · 2018. 11. 5. · Is it really “Turtles all the way down”? •Networks: Frames •Operating Systems: Pages •File systems and storage:

“Transistor density doubles every year”

- Gordon Moore

CPU Performance – Memory Lane

Page 5: Rectangles All The Way Down - Dyalog Ltd. · 2018. 11. 5. · Is it really “Turtles all the way down”? •Networks: Frames •Operating Systems: Pages •File systems and storage:

“Transistor density doubles every year”

- Gordon Moore

“Transistor density doubles every 2 years”

- Gordon Moore

CPU Performance – Memory Lane

Page 6: Rectangles All The Way Down - Dyalog Ltd. · 2018. 11. 5. · Is it really “Turtles all the way down”? •Networks: Frames •Operating Systems: Pages •File systems and storage:

“Transistor density doubles every year”

- Gordon Moore

“Transistor density doubles every 2 years”

- Gordon Moore

“CPUs double in speed every 18 months”

- David House

CPU Performance – Memory Lane

Page 7: Rectangles All The Way Down - Dyalog Ltd. · 2018. 11. 5. · Is it really “Turtles all the way down”? •Networks: Frames •Operating Systems: Pages •File systems and storage:

“Transistor density doubles every year”

- Gordon Moore

“Transistor density doubles every 2 years”

- Gordon Moore

“CPUs double in speed every 18 months”

- David House

“The free lunch is over:”

- Herb Sutter

CPU Performance – Memory Lane

Page 8: Rectangles All The Way Down - Dyalog Ltd. · 2018. 11. 5. · Is it really “Turtles all the way down”? •Networks: Frames •Operating Systems: Pages •File systems and storage:

“Transistor density doubles every year”

- Gordon Moore

“Transistor density doubles every 2 years”

- Gordon Moore

“CPUs double in speed every 18 months”

- David House

“The free lunch is over:”

- Herb Sutter

Retirement of Tick Tock

- Intel

CPU Performance – Memory Lane

Page 9: Rectangles All The Way Down - Dyalog Ltd. · 2018. 11. 5. · Is it really “Turtles all the way down”? •Networks: Frames •Operating Systems: Pages •File systems and storage:

“Transistor density doubles every year”

- Gordon Moore

“Transistor density doubles every 2 years”

- Gordon Moore

“CPUs double in speed every 18 months”

- David House

“The free lunch is over:”

- Herb Sutter

Retirement of Tick Tock

- Intel

Spectre & Meltdown

- Google

CPU Performance – Memory Lane

Page 10: Rectangles All The Way Down - Dyalog Ltd. · 2018. 11. 5. · Is it really “Turtles all the way down”? •Networks: Frames •Operating Systems: Pages •File systems and storage:

Concurrency & Parallelism

Page 11: Rectangles All The Way Down - Dyalog Ltd. · 2018. 11. 5. · Is it really “Turtles all the way down”? •Networks: Frames •Operating Systems: Pages •File systems and storage:
Page 12: Rectangles All The Way Down - Dyalog Ltd. · 2018. 11. 5. · Is it really “Turtles all the way down”? •Networks: Frames •Operating Systems: Pages •File systems and storage:

C(N) = N / (1 + α(N – 1) + ((β* N) * (N – 1)))

C = capacity or throughput

N = number of processors

α = contention penalty

β = coherence penalty

Universal Scalability Law (USL)

Page 13: Rectangles All The Way Down - Dyalog Ltd. · 2018. 11. 5. · Is it really “Turtles all the way down”? •Networks: Frames •Operating Systems: Pages •File systems and storage:

0

2

4

6

8

10

12

14

16

18

20

1 2 4 8 16 32 64 128 256 512 1024

Sp

ee

du

p

Processors

Amdahl USL

Universal Scalability Law (USL)

Page 14: Rectangles All The Way Down - Dyalog Ltd. · 2018. 11. 5. · Is it really “Turtles all the way down”? •Networks: Frames •Operating Systems: Pages •File systems and storage:

If concurrency is so difficult then

what else can we do?

Page 15: Rectangles All The Way Down - Dyalog Ltd. · 2018. 11. 5. · Is it really “Turtles all the way down”? •Networks: Frames •Operating Systems: Pages •File systems and storage:
Page 16: Rectangles All The Way Down - Dyalog Ltd. · 2018. 11. 5. · Is it really “Turtles all the way down”? •Networks: Frames •Operating Systems: Pages •File systems and storage:

0.0

2.0

4.0

6.0

8.0

10.0

12.0

0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0

Re

spo

nse

Tim

e

Utilisation

Queueing Theory

Page 17: Rectangles All The Way Down - Dyalog Ltd. · 2018. 11. 5. · Is it really “Turtles all the way down”? •Networks: Frames •Operating Systems: Pages •File systems and storage:

r = s(2 – ρ) / 2(1 – ρ)

r = mean response time

s = service time

ρ = utilisation

Note: ρ = λ * s

Queueing Theory

Page 18: Rectangles All The Way Down - Dyalog Ltd. · 2018. 11. 5. · Is it really “Turtles all the way down”? •Networks: Frames •Operating Systems: Pages •File systems and storage:
Page 19: Rectangles All The Way Down - Dyalog Ltd. · 2018. 11. 5. · Is it really “Turtles all the way down”? •Networks: Frames •Operating Systems: Pages •File systems and storage:

L = λW

WIP = Throughput * Cycle Time

Little’s Law

Page 20: Rectangles All The Way Down - Dyalog Ltd. · 2018. 11. 5. · Is it really “Turtles all the way down”? •Networks: Frames •Operating Systems: Pages •File systems and storage:

L = λW

WIP = Throughput * Cycle Time

Bandwidth Delay Product:

Bytes in flight = Bandwidth * Latency

Little’s Law

Page 21: Rectangles All The Way Down - Dyalog Ltd. · 2018. 11. 5. · Is it really “Turtles all the way down”? •Networks: Frames •Operating Systems: Pages •File systems and storage:

L = λW

WIP = Throughput * Cycle Time

Bandwidth Delay Product:

Bytes in flight = Bandwidth * Latency

80 bytes / 100ns = 800 MB/s :10 LFBs

Little’s Law

Page 22: Rectangles All The Way Down - Dyalog Ltd. · 2018. 11. 5. · Is it really “Turtles all the way down”? •Networks: Frames •Operating Systems: Pages •File systems and storage:

Memory

Page 23: Rectangles All The Way Down - Dyalog Ltd. · 2018. 11. 5. · Is it really “Turtles all the way down”? •Networks: Frames •Operating Systems: Pages •File systems and storage:

Are all memory

operations equal?

Page 24: Rectangles All The Way Down - Dyalog Ltd. · 2018. 11. 5. · Is it really “Turtles all the way down”? •Networks: Frames •Operating Systems: Pages •File systems and storage:

Sequential Access

-

Average time in ns/op to sum all

longs in a 1GB array?

Page 25: Rectangles All The Way Down - Dyalog Ltd. · 2018. 11. 5. · Is it really “Turtles all the way down”? •Networks: Frames •Operating Systems: Pages •File systems and storage:

Access Pattern Benchmark

~1 ns/op

Benchmark Score Error Units

============================================

sequential 0.832 ± 0.006 ns/op

Page 26: Rectangles All The Way Down - Dyalog Ltd. · 2018. 11. 5. · Is it really “Turtles all the way down”? •Networks: Frames •Operating Systems: Pages •File systems and storage:

Really???

Less than 1ns per operation?

Page 27: Rectangles All The Way Down - Dyalog Ltd. · 2018. 11. 5. · Is it really “Turtles all the way down”? •Networks: Frames •Operating Systems: Pages •File systems and storage:

Instruction Level Parallelism

Page 28: Rectangles All The Way Down - Dyalog Ltd. · 2018. 11. 5. · Is it really “Turtles all the way down”? •Networks: Frames •Operating Systems: Pages •File systems and storage:
Page 29: Rectangles All The Way Down - Dyalog Ltd. · 2018. 11. 5. · Is it really “Turtles all the way down”? •Networks: Frames •Operating Systems: Pages •File systems and storage:

Access Pattern Benchmark

Benchmark Score Error Units

============================================

sequential 0.832 ± 0.006 ns/op

randomPage 2.703 ± 0.025 ns/op

Page 30: Rectangles All The Way Down - Dyalog Ltd. · 2018. 11. 5. · Is it really “Turtles all the way down”? •Networks: Frames •Operating Systems: Pages •File systems and storage:

Access Pattern Benchmark

Benchmark Score Error Units

============================================

sequential 0.832 ± 0.006 ns/op

randomPage 2.703 ± 0.025 ns/op

dependentRandomPage 7.102 ± 0.326 ns/op

Page 31: Rectangles All The Way Down - Dyalog Ltd. · 2018. 11. 5. · Is it really “Turtles all the way down”? •Networks: Frames •Operating Systems: Pages •File systems and storage:

Access Pattern Benchmark

Benchmark Score Error Units

============================================

sequential 0.832 ± 0.006 ns/op

randomPage 2.703 ± 0.025 ns/op

dependentRandomPage 7.102 ± 0.326 ns/op

randomHeap 19.896 ± 3.110 ns/op

Page 32: Rectangles All The Way Down - Dyalog Ltd. · 2018. 11. 5. · Is it really “Turtles all the way down”? •Networks: Frames •Operating Systems: Pages •File systems and storage:

Access Pattern Benchmark

Benchmark Score Error Units

============================================

sequential 0.832 ± 0.006 ns/op

randomPage 2.703 ± 0.025 ns/op

dependentRandomPage 7.102 ± 0.326 ns/op

randomHeap 19.896 ± 3.110 ns/op

dependentRandomHeap 89.516 ± 4.573 ns/op

Page 33: Rectangles All The Way Down - Dyalog Ltd. · 2018. 11. 5. · Is it really “Turtles all the way down”? •Networks: Frames •Operating Systems: Pages •File systems and storage:

Access Pattern Benchmark

Benchmark Score Error Units

============================================

sequential 0.832 ± 0.006 ns/op

randomPage 2.703 ± 0.025 ns/op

dependentRandomPage 7.102 ± 0.326 ns/op

randomHeap 19.896 ± 3.110 ns/op

dependentRandomHeap 89.516 ± 4.573 ns/op

~90 ns/op

Page 34: Rectangles All The Way Down - Dyalog Ltd. · 2018. 11. 5. · Is it really “Turtles all the way down”? •Networks: Frames •Operating Systems: Pages •File systems and storage:
Page 35: Rectangles All The Way Down - Dyalog Ltd. · 2018. 11. 5. · Is it really “Turtles all the way down”? •Networks: Frames •Operating Systems: Pages •File systems and storage:

A 100ns cache-miss is a

lost opportunity to execute

~1000 instructions on CPU

Page 36: Rectangles All The Way Down - Dyalog Ltd. · 2018. 11. 5. · Is it really “Turtles all the way down”? •Networks: Frames •Operating Systems: Pages •File systems and storage:

Algorithms &

Data Structures

Page 37: Rectangles All The Way Down - Dyalog Ltd. · 2018. 11. 5. · Is it really “Turtles all the way down”? •Networks: Frames •Operating Systems: Pages •File systems and storage:

L = λW

Bandwidth Delay Product:

Bytes in flight = Bandwidth * Latency

80 bytes / 100ns = 800 MB/s :10 LFBs

Little’s Law

Page 38: Rectangles All The Way Down - Dyalog Ltd. · 2018. 11. 5. · Is it really “Turtles all the way down”? •Networks: Frames •Operating Systems: Pages •File systems and storage:

L = λW

Bandwidth Delay Product:

Bytes in flight = Bandwidth * Latency

80 bytes / 100ns = 800 MB/s :10 LFBs

80 bytes / 15ns = 5.3 GB/s :prefectch

Little’s Law

Page 39: Rectangles All The Way Down - Dyalog Ltd. · 2018. 11. 5. · Is it really “Turtles all the way down”? •Networks: Frames •Operating Systems: Pages •File systems and storage:

L = λW

Bandwidth Delay Product:

Bytes in flight = Bandwidth * Latency

80 bytes / 100ns = 800 MB/s :10 LFBs

80 bytes / 15ns = 5.3 GB/s :prefectch

640 bytes / 15ns = 42.6 GB/s :cachelines

Little’s Law

Page 40: Rectangles All The Way Down - Dyalog Ltd. · 2018. 11. 5. · Is it really “Turtles all the way down”? •Networks: Frames •Operating Systems: Pages •File systems and storage:

Arrays are the most efficient

data structure to traverse

Page 41: Rectangles All The Way Down - Dyalog Ltd. · 2018. 11. 5. · Is it really “Turtles all the way down”? •Networks: Frames •Operating Systems: Pages •File systems and storage:
Page 42: Rectangles All The Way Down - Dyalog Ltd. · 2018. 11. 5. · Is it really “Turtles all the way down”? •Networks: Frames •Operating Systems: Pages •File systems and storage:

Functional data structures

are like sausages,

the more you see them being

made, the less well you will sleep

Page 43: Rectangles All The Way Down - Dyalog Ltd. · 2018. 11. 5. · Is it really “Turtles all the way down”? •Networks: Frames •Operating Systems: Pages •File systems and storage:

Branches

Page 44: Rectangles All The Way Down - Dyalog Ltd. · 2018. 11. 5. · Is it really “Turtles all the way down”? •Networks: Frames •Operating Systems: Pages •File systems and storage:
Page 45: Rectangles All The Way Down - Dyalog Ltd. · 2018. 11. 5. · Is it really “Turtles all the way down”? •Networks: Frames •Operating Systems: Pages •File systems and storage:

Branch Benchmark

Benchmark Score Error Units

=============================================

baseline 585.600 ± 4.469 us/op

Page 46: Rectangles All The Way Down - Dyalog Ltd. · 2018. 11. 5. · Is it really “Turtles all the way down”? •Networks: Frames •Operating Systems: Pages •File systems and storage:

Branch Benchmark

Benchmark Score Error Units

=============================================

baseline 585.600 ± 4.469 us/op

predictable 578.364 ± 10.906 us/op

Page 47: Rectangles All The Way Down - Dyalog Ltd. · 2018. 11. 5. · Is it really “Turtles all the way down”? •Networks: Frames •Operating Systems: Pages •File systems and storage:

Branch Benchmark

Benchmark Score Error Units

=============================================

baseline 585.600 ± 4.469 us/op

predictable 578.364 ± 10.906 us/op

unPredictable 2234.414 ± 564.472 us/op

Page 48: Rectangles All The Way Down - Dyalog Ltd. · 2018. 11. 5. · Is it really “Turtles all the way down”? •Networks: Frames •Operating Systems: Pages •File systems and storage:

What can we do?

Page 49: Rectangles All The Way Down - Dyalog Ltd. · 2018. 11. 5. · Is it really “Turtles all the way down”? •Networks: Frames •Operating Systems: Pages •File systems and storage:

Count bits as Booleans

Page 50: Rectangles All The Way Down - Dyalog Ltd. · 2018. 11. 5. · Is it really “Turtles all the way down”? •Networks: Frames •Operating Systems: Pages •File systems and storage:

Wide Registers

Page 51: Rectangles All The Way Down - Dyalog Ltd. · 2018. 11. 5. · Is it really “Turtles all the way down”? •Networks: Frames •Operating Systems: Pages •File systems and storage:

Math, Data Dependencies, and

Instruction Level Parallelism

Page 52: Rectangles All The Way Down - Dyalog Ltd. · 2018. 11. 5. · Is it really “Turtles all the way down”? •Networks: Frames •Operating Systems: Pages •File systems and storage:
Page 53: Rectangles All The Way Down - Dyalog Ltd. · 2018. 11. 5. · Is it really “Turtles all the way down”? •Networks: Frames •Operating Systems: Pages •File systems and storage:

Consider Sorting Arrays

Page 54: Rectangles All The Way Down - Dyalog Ltd. · 2018. 11. 5. · Is it really “Turtles all the way down”? •Networks: Frames •Operating Systems: Pages •File systems and storage:

https://lamport.azurewebsites.net/pubs/multiple-byte.pdf

Page 55: Rectangles All The Way Down - Dyalog Ltd. · 2018. 11. 5. · Is it really “Turtles all the way down”? •Networks: Frames •Operating Systems: Pages •File systems and storage:

“It’s a neat hack, and it’s more useful

now than it was then for two reasons.”

- Leslie Lamport (2011)

Page 56: Rectangles All The Way Down - Dyalog Ltd. · 2018. 11. 5. · Is it really “Turtles all the way down”? •Networks: Frames •Operating Systems: Pages •File systems and storage:

“The obvious reason is that word size is

larger now, with many computers

having 64-bit words.”

- Leslie Lamport (2011)

Page 57: Rectangles All The Way Down - Dyalog Ltd. · 2018. 11. 5. · Is it really “Turtles all the way down”? •Networks: Frames •Operating Systems: Pages •File systems and storage:

“The less obvious reason is that

conditional operations are implemented

with masking rather than branching.”

- Leslie Lamport (2011)

Page 58: Rectangles All The Way Down - Dyalog Ltd. · 2018. 11. 5. · Is it really “Turtles all the way down”? •Networks: Frames •Operating Systems: Pages •File systems and storage:

“Branching is more costly on modern

multi-issue computers than it was on the

computers of the 70s.”

- Leslie Lamport (2011)

Page 59: Rectangles All The Way Down - Dyalog Ltd. · 2018. 11. 5. · Is it really “Turtles all the way down”? •Networks: Frames •Operating Systems: Pages •File systems and storage:

https://www.inf.ed.ac.uk/teaching/courses/exc/reading/morris.pdf

Page 60: Rectangles All The Way Down - Dyalog Ltd. · 2018. 11. 5. · Is it really “Turtles all the way down”? •Networks: Frames •Operating Systems: Pages •File systems and storage:

Work with your CPU caches

Page 61: Rectangles All The Way Down - Dyalog Ltd. · 2018. 11. 5. · Is it really “Turtles all the way down”? •Networks: Frames •Operating Systems: Pages •File systems and storage:

Memory Access Considerations

1. Temporal: group accesses in time

Page 62: Rectangles All The Way Down - Dyalog Ltd. · 2018. 11. 5. · Is it really “Turtles all the way down”? •Networks: Frames •Operating Systems: Pages •File systems and storage:

Memory Access Considerations

1. Temporal: group accesses in time

2. Spatial: group access in space

Page 63: Rectangles All The Way Down - Dyalog Ltd. · 2018. 11. 5. · Is it really “Turtles all the way down”? •Networks: Frames •Operating Systems: Pages •File systems and storage:

Memory Access Considerations

1. Temporal: group accesses in time

2. Spatial: group access in space

3. Pattern: create predictable patterns

Page 64: Rectangles All The Way Down - Dyalog Ltd. · 2018. 11. 5. · Is it really “Turtles all the way down”? •Networks: Frames •Operating Systems: Pages •File systems and storage:

Batching

Page 65: Rectangles All The Way Down - Dyalog Ltd. · 2018. 11. 5. · Is it really “Turtles all the way down”? •Networks: Frames •Operating Systems: Pages •File systems and storage:

0%

10%

20%

30%

40%

50%

60%

70%

80%

90%

100%

0 5 10 15 20

Average overhead

per item, or operation,

in a batch

Batching – Amortising Costs

Page 66: Rectangles All The Way Down - Dyalog Ltd. · 2018. 11. 5. · Is it really “Turtles all the way down”? •Networks: Frames •Operating Systems: Pages •File systems and storage:

0%

10%

20%

30%

40%

50%

60%

70%

80%

90%

100%

0 5 10 15 20

Words, Cachelines,

Pages, Blocks,

Frames, etc.

Batching – Amortising Costs

Page 67: Rectangles All The Way Down - Dyalog Ltd. · 2018. 11. 5. · Is it really “Turtles all the way down”? •Networks: Frames •Operating Systems: Pages •File systems and storage:

In closing…

Page 68: Rectangles All The Way Down - Dyalog Ltd. · 2018. 11. 5. · Is it really “Turtles all the way down”? •Networks: Frames •Operating Systems: Pages •File systems and storage:

Profile, profile, profile...

Page 69: Rectangles All The Way Down - Dyalog Ltd. · 2018. 11. 5. · Is it really “Turtles all the way down”? •Networks: Frames •Operating Systems: Pages •File systems and storage:

Eliminate Waste

Batch to Amortise

Access Memory in Patterns

Favour Math over Branches

Favour Predictable Branches

Page 70: Rectangles All The Way Down - Dyalog Ltd. · 2018. 11. 5. · Is it really “Turtles all the way down”? •Networks: Frames •Operating Systems: Pages •File systems and storage:

Consider Parallelism

-

ILP & Task

Page 71: Rectangles All The Way Down - Dyalog Ltd. · 2018. 11. 5. · Is it really “Turtles all the way down”? •Networks: Frames •Operating Systems: Pages •File systems and storage:

Is it really “Turtles all the way down”?

Page 72: Rectangles All The Way Down - Dyalog Ltd. · 2018. 11. 5. · Is it really “Turtles all the way down”? •Networks: Frames •Operating Systems: Pages •File systems and storage:

Is it really “Turtles all the way down”?

• Networks: Frames

• Operating Systems: Pages

• File systems and storage: Blocks

• DRAM memory: Banks and Row Buffers

• CPU cache subsystems: Cache Lines

• Applications use Arrays plus and interesting data structures are made up of small Arrays

Rectangles all the way down…

Page 73: Rectangles All The Way Down - Dyalog Ltd. · 2018. 11. 5. · Is it really “Turtles all the way down”? •Networks: Frames •Operating Systems: Pages •File systems and storage:

“I don’t care what data structure you

use, nothing beats an array”

- a HFT Programmer

Page 74: Rectangles All The Way Down - Dyalog Ltd. · 2018. 11. 5. · Is it really “Turtles all the way down”? •Networks: Frames •Operating Systems: Pages •File systems and storage:

Twitter: @mjpt777

“Travel is fatal to prejudice, bigotry, and

narrow-mindedness, and many of our

people need it sorely on these accounts.

Broad, wholesome, charitable views of

men and things cannot be acquired by

vegetating in one little corner of the earth

all one's lifetime.”

- Mark Twain

Questions?