Adapton: Composable Demand-Driven Incremental Computation Matthew - - PowerPoint PPT Presentation

adapton composable demand driven incremental computation
SMART_READER_LITE
LIVE PREVIEW

Adapton: Composable Demand-Driven Incremental Computation Matthew - - PowerPoint PPT Presentation

Adapton: Composable Demand-Driven Incremental Computation Matthew A. Hammer Khoo Yit Phang, Michael Hicks and Jeffrey S. Foster Incremental Computation Input Output Application Application Code IC IC Framework Framework


slide-1
SLIDE 1

Adapton: Composable Demand-Driven Incremental Computation

Matthew A. Hammer Khoo Yit Phang, Michael Hicks and Jeffrey S. Foster

slide-2
SLIDE 2

Incremental Computation

Input Output

Application Code IC Framework Application IC Framework

slide-3
SLIDE 3

Incremental Computation

Input Trace Output

Application IC Framework

Trace records dynamic data dependencies

slide-4
SLIDE 4

Incremental Computation

Input Trace Output Run 1 Mutations Input Trace Output

slide-5
SLIDE 5

Incremental Computation

Input Trace Output Run 1 Inconsistencies Mutations Input Trace Output

slide-6
SLIDE 6

Incremental Computation

Input Trace Output Run 1 Input Trace Output Change- Propagation Run 2

slide-7
SLIDE 7

Incremental Computation

Input Trace Output Run 1 Run 2 Change- Propagation Updates Input Trace Output

slide-8
SLIDE 8

Incremental Computation

Input Trace Output Run 1 Run 2 Change- Propagation Updates Input Trace Output

slide-9
SLIDE 9

Incremental Computation

Input Trace Output Run 1 Run 2 Change- Propagation Updates Input Trace Output

slide-10
SLIDE 10

Incremental Computation

Run 2 Input Trace Output Input Trace Output Run 1

slide-11
SLIDE 11

Incremental Computation

Run 2 Input Trace Output Observations

slide-12
SLIDE 12

Incremental Computation

Run 2 Input Trace Output loop.. Observations Mutations

slide-13
SLIDE 13

Incremental Computation

Run 2 Theorem: Trace and output are “from-scratch”- consistent Equivalently: Change propagation is History independent Input Trace Output Propagation respects program semantics:

slide-14
SLIDE 14

Existing Limitations (self-adjusting computation)

  • Change propagation is eager

Not driven by output observations

  • Trace representation

= Total ordering Limits reuse, excluding certain patterns Interactive settings suffer in particular

?

slide-15
SLIDE 15

Adapton: Composable, Demand-Driven IC

  • Key concepts:

Lazy thunks: programming interface Demanded Computation Graph (DCG): represents execution trace

  • Formal semantics, proven sound
  • Implemented in OCaml (and Python)
  • Speedups for all patterns (unlike SAC)
  • Freely available at http://ter.ps/adapton
slide-16
SLIDE 16

Interaction Pattern: Laziness

Do not (re)compute obscured sheets Sheet A Sheet B Sheet C (Independent sheets) Legend

Consistent Inactive No cache

slide-17
SLIDE 17

Do not (re)compute obscured sheets Sheet A Sheet B Sheet C (Independent sheets)

Interaction Pattern: Laziness

Legend

Consistent Inactive No cache

slide-18
SLIDE 18

Do not (re)compute obscured sheets Sheet A Sheet B Sheet C (Independent sheets)

Interaction Pattern: Laziness

Legend

Consistent Inactive No cache

slide-19
SLIDE 19

Interactive Pattern: Switching

Sheet A Sheet B Demand / control-flow change Legend

Consistent Inactive No cache

Sheet C = f ( A )

slide-20
SLIDE 20

Sheet A Sheet B Demand / control-flow change

Interactive Pattern: Switching

Legend

Consistent Inactive No cache

C = f ( A ) C = g ( B ) Sheet

slide-21
SLIDE 21

Sheet A Sheet B Demand / control-flow change

Interactive Pattern: Switching

Legend

Consistent Inactive No cache

C = f ( A ) C = g ( B ) Sheet

slide-22
SLIDE 22

Interaction Pattern: Sharing

Sheet A B and C share work for A Legend

Consistent Inactive No cache

B = f ( A ) C = g ( A ) Sheet Sheet

slide-23
SLIDE 23

Interaction Pattern: Sharing

Sheet A B and C share work for A Legend

Consistent Inactive No cache

B = f ( A ) C = g ( A ) Sheet Sheet

slide-24
SLIDE 24

Interaction Pattern: Sharing

Sheet A B and C share work for A Legend

Consistent Inactive No cache

B = f ( A ) C = g ( A ) Sheet Sheet

slide-25
SLIDE 25

Sheet A Sheet B Swaps input / evaluation order

Interactive Pattern: Swapping

Legend

Consistent Inactive No cache

Sheet C = f (A, B)

slide-26
SLIDE 26

Sheet B Sheet Sheet A Swaps input / evaluation order

Interactive Pattern: Swapping

Legend

Consistent Inactive No cache

C = f (B, A) C = f (A, B)

slide-27
SLIDE 27

Sheet B Sheet Sheet A Swaps input / evaluation order

Interactive Pattern: Swapping

Legend

Consistent Inactive No cache

C = f (B, A) C = f (A, B)

slide-28
SLIDE 28

Adapton’s Approach

  • When we mutate an input, we mark

dependent computations as dirty

  • When we demand a thunk:
  • Memo-match equivalent thunks
  • Change-propagation repairs

inconsistencies, on demand

slide-29
SLIDE 29

Spread Sheet Evaluator

type cell = formula ref and formula = | Leaf of int | Plus of cell * cell

slide-30
SLIDE 30

Spread Sheet Evaluator

type cell = formula ref and formula = | Leaf of int | Plus of cell * cell

Mutable Depends

  • n cells
slide-31
SLIDE 31

Spread Sheet Evaluator

type cell = formula ref and formula = | Leaf of int | Plus of cell * cell Example

let n1 = ref (Leaf 1) let n2 = ref (Leaf 2) let n3 = ref (Leaf 3) let p1 = ref (Plus (n1, n2)) let p2 = ref (Plus (p1, n3))

slide-32
SLIDE 32

Spread Sheet Evaluator

Example type cell = formula ref and formula = | Leaf of int | Plus of cell * cell

let n1 = ref (Leaf 1) let n2 = ref (Leaf 2) let n3 = ref (Leaf 3) let p1 = ref (Plus (n1, n2)) let p2 = ref (Plus (p1, n3))

1

+

1

1

1

2

1

+

1

3 n1 n2 n3 p1 p2

“User interface” (REPL)

slide-33
SLIDE 33

Spread Sheet Evaluator

eval : cell → (int thunk) eval c = thunk (( case (get c) of | Leaf n ⇒ n | Plus(c1, c2) ⇒ force (eval c1) + force (eval c2) ))

Evaluator logic type cell = formula ref and formula = | Leaf of int | Plus of cell * cell

1

+

1

1

1

2

1

+

1

3 n1 n2 n3 p1 p2

slide-34
SLIDE 34

Spread Sheet Evaluator

set : cell x formula → unit eval : cell → (int thunk) display : (int thunk) → unit

“User interface” (REPL) type cell = formula ref and formula = | Leaf of int | Plus of cell * cell

1

+

1

1

1

2

1

+

1

3 n1 n2 n3 p1 p2

slide-35
SLIDE 35

Spread Sheet Evaluator

set : cell x formula → unit eval : cell → (int thunk) display : (int thunk) → unit

“User interface” (REPL) type cell = formula ref and formula = | Leaf of int | Plus of cell * cell

Demands evaluation 1

+

1

1

1

2

1

+

1

3 n1 n2 n3 p1 p2

slide-36
SLIDE 36

Spread Sheet Evaluator

set : cell x formula → unit eval : cell → (int thunk) display : (int thunk) → unit

“User interface” (REPL) type cell = formula ref and formula = | Leaf of int | Plus of cell * cell

1

+

1

1

1

2

1

+

1

3 n1 n2 n3 p1 p2

slide-37
SLIDE 37

Spread Sheet Evaluator

set : cell x formula → unit eval : cell → (int thunk) display : (int thunk) → unit

“User interface” (REPL) type cell = formula ref and formula = | Leaf of int | Plus of cell * cell

1

+

1

1

1

2

1

+

1

3 n1 n2 n3 p1 p2 ☞ let t1 = eval p1

slide-38
SLIDE 38

Spread Sheet Evaluator

set : cell x formula → unit eval : cell → (int thunk) display : (int thunk) → unit

“User interface” (REPL)

1

+

1

1

1

2

1

+

1

3 n1 n2 n3 p1 p2 ☞ let t1 = eval p1 ☞

n1 n2 p1 n3 p2

t1

slide-39
SLIDE 39

Spread Sheet Evaluator

set : cell x formula → unit eval : cell → (int thunk) display : (int thunk) → unit

“User interface” (REPL)

1

+

1

1

1

2

1

+

1

3 n1 n2 n3 p1 p2 ☞ let t1 = eval p1 ☞ let t2 = eval p2 ☞

n1 n2 p1 n3 p2

t1 t2

slide-40
SLIDE 40

1

+

1

1

1

2

1

+

1

3 n1 n2 n3 p1 p2

Spread Sheet Evaluator

set : cell x formula → unit eval : cell → (int thunk) display : (int thunk) → unit

“User interface” (REPL)

☞ let t1 = eval p1 ☞ let t2 = eval p2 ☞ display t1 ☞

n1 n2 p1 n3 p2

t1 t2 get force

demand!

3

slide-41
SLIDE 41

1

+

1

1

1

2

1

+

1

3 n1 n2 n3 p1 p2

Spread Sheet Evaluator

set : cell x formula → unit eval : cell → (int thunk) display : (int thunk) → unit

“User interface” (REPL)

☞ let t1 = eval p1 ☞ let t2 = eval p2 ☞ display t1 ☞

n1 n2 p1 n3 p2

t1 t2 get force Demanded Computation Graph (DCG)

3

slide-42
SLIDE 42

1

+

1

1

1

2

1

+

1

3 n1 n2 n3 p1 p2

Spread Sheet Evaluator

set : cell x formula → unit eval : cell → (int thunk) display : (int thunk) → unit

“User interface” (REPL)

☞ let t1 = eval p1 ☞ let t2 = eval p2 ☞ display t1 ☞ display t2 ☞

n1 n2 p1 n3 p2

t1 t2 force get DCG

demand!

6

slide-43
SLIDE 43

1

+

1

1

1

2

1

+

1

3 n1 n2 n3 p1 p2

Spread Sheet Evaluator

set : cell x formula → unit eval : cell → (int thunk) display : (int thunk) → unit

“User interface” (REPL)

☞ let t1 = eval p1 ☞ let t2 = eval p2 ☞ display t1 ☞ display t2 ☞

n1 n2 p1 n3 p2

t1 t2 force get Memo match! Memo match! Sharing DCG

6

slide-44
SLIDE 44

1

+

1

1

1

2

1

+

1

3 n1 n2 n3 p1 p2

Spread Sheet Evaluator

set : cell x formula → unit eval : cell → (int thunk) display : (int thunk) → unit

“User interface” (REPL)

☞ let t1 = eval p1 ☞ let t2 = eval p2 ☞ display t1 ☞ display t2 ☞ clear

n1 n2 p1 n3 p2

t1 t2 force get DCG

6

slide-45
SLIDE 45

1

+

1

1

1

2

1

+

1

3 n1 n2 n3 p1 p2

Spread Sheet Evaluator

set : cell x formula → unit eval : cell → (int thunk) display : (int thunk) → unit

“User interface” (REPL)

n1 n2 p1 n3 p2

t1 t2 force get DCG

slide-46
SLIDE 46

1

+

1

1

1

2

1

+

1

3 n1 n2 n3 p1 p2

Spread Sheet Evaluator

set : cell x formula → unit eval : cell → (int thunk) display : (int thunk) → unit

“User interface” (REPL)

☞ set n1 ← Leaf 5

n1 n2 p1 n3 p2

t1 t2 force get DCG

slide-47
SLIDE 47

1

+

1

5

1

2

1

+

1

3 n1 n2 n3 p1 p2

Spread Sheet Evaluator

set : cell x formula → unit eval : cell → (int thunk) display : (int thunk) → unit

“User interface” (REPL)

☞ set n1 ← Leaf 5 ☞

n1 n2 p1 n3 p2

t1 t2 force get DCG Dirty dep Dirty phase

slide-48
SLIDE 48

1

+

1

5

1

2

1

+

1

3 n1 n2 n3 p1 p2

Spread Sheet Evaluator

set : cell x formula → unit eval : cell → (int thunk) display : (int thunk) → unit

“User interface” (REPL)

☞ let t1 = eval p1 ☞ let t2 = eval p2 ☞ display t1 ☞ display t2 ☞

n1 n2 p1 n3 p2

t1 t2 force get DCG

☞ set n1 ← Leaf 5 ☞ display t1

7

Re- eval

slide-49
SLIDE 49

1

+

1

5

1

2

1

+

1

3 n1 n2 n3 p1 p2

Spread Sheet Evaluator

set : cell x formula → unit eval : cell → (int thunk) display : (int thunk) → unit

“User interface” (REPL)

☞ let t1 = eval p1 ☞ let t2 = eval p2 ☞ display t1 ☞ display t2 ☞

n1 n2 p1 n3 p2

t1 t2 force get DCG

☞ set n1 ← Leaf 5 ☞ display t1

7

Memo match!

slide-50
SLIDE 50

1

+

1

5

1

2

1

+

1

3 n1 n2 n3 p1 p2

Spread Sheet Evaluator

set : cell x formula → unit eval : cell → (int thunk) display : (int thunk) → unit

“User interface” (REPL)

☞ let t1 = eval p1 ☞ let t2 = eval p2 ☞ display t1 ☞ display t2 ☞

n1 n2 p1 n3 p2

t1 t2 force get DCG

☞ set n1 ← Leaf 5 ☞ display t1

7

slide-51
SLIDE 51

1

+

1

5

1

2

1

+

1

3 n1 n2 n3 p1 p2

Spread Sheet Evaluator

set : cell x formula → unit eval : cell → (int thunk) display : (int thunk) → unit

“User interface” (REPL)

☞ let t1 = eval p1 ☞ let t2 = eval p2 ☞ display t1 ☞ display t2 ☞

n1 n2 p1 n3 p2

t1 t2 force get DCG

☞ set n1 ← Leaf 5 ☞ display t1 ☞ set p2 ← Plus(n3,p1)

slide-52
SLIDE 52

1

+

1

5

1

2

1

+

1

3 n1 n2 n3 p1 p2

Spread Sheet Evaluator

set : cell x formula → unit eval : cell → (int thunk) display : (int thunk) → unit

“User interface” (REPL)

☞ let t1 = eval p1 ☞ let t2 = eval p2 ☞ display t1 ☞ display t2 ☞

n1 n2 p1 n3 p2

t1 t2 force get DCG

☞ set n1 ← Leaf 5 ☞ display t1 ☞ set p2 ← Plus(n3, p1) ☞

Swap!

slide-53
SLIDE 53

1

+

1

5

1

2

1

+

1

3 n1 n2 n3 p1 p2

Spread Sheet Evaluator

set : cell x formula → unit eval : cell → (int thunk) display : (int thunk) → unit

“User interface” (REPL)

☞ let t1 = eval p1 ☞ let t2 = eval p2 ☞ display t1 ☞ display t2 ☞

n1 n2 p1 n3 p2

t1 t2 force get DCG

☞ set n1 ← Leaf 5 ☞ display t1 ☞ set p2 ← Plus(n3, p1) ☞

Swap! Dirty

slide-54
SLIDE 54

1

+

1

5

1

2

1

+

1

3 n1 n2 n3 p1 p2

Spread Sheet Evaluator

set : cell x formula → unit eval : cell → (int thunk) display : (int thunk) → unit

“User interface” (REPL)

☞ let t1 = eval p1 ☞ let t2 = eval p2 ☞ display t1 ☞ display t2 ☞

n1 n2 p1 n3 p2

t1 t2 force get DCG

☞ set n1 ← Leaf 5 ☞ display t1 ☞ set p2 ← Plus(n3, p1) ☞ display t2

Swap! Dirty

slide-55
SLIDE 55

1

+

1

5

1

2

1

+

1

3 n1 n2 n3 p1 p2

Spread Sheet Evaluator

set : cell x formula → unit eval : cell → (int thunk) display : (int thunk) → unit

“User interface” (REPL)

☞ let t1 = eval p1 ☞ let t2 = eval p2 ☞ display t1 ☞ display t2 ☞

n1 n2 p1 n3 p2

t1 t2 force get DCG

☞ set n1 ← Leaf 5 ☞ display t1 ☞ set p2 ← Plus(n3, p1) ☞ display t2 ☞

Swap!

10

slide-56
SLIDE 56

1

+

1

5

1

2

1

+

1

3 n1 n2 n3 p1 p2

Spread Sheet Evaluator

set : cell x formula → unit eval : cell → (int thunk) display : (int thunk) → unit

“User interface” (REPL)

☞ let t1 = eval p1 ☞ let t2 = eval p2 ☞ display t1 ☞ display t2 ☞

n1 n2 p1 n3 p2

t1 t2 force get DCG

☞ set n1 ← Leaf 5 ☞ display t1 ☞ set p2 ← Plus(n3, p1) ☞ display t2 ☞

Memo match! Swap!

10

slide-57
SLIDE 57

Lazy Structures

Laziness generalizes beyond scalars Recursive structures: lists, trees and graphs

type 'a lzlist = | Nil | Cons of 'a * ('a lzlist) thunk

Recursive lazy structure

slide-58
SLIDE 58

let rec merge l1 l2 = function | l1, Nil ⇒ l1 | Nil, l2 ⇒ l2 | Cons(h1,t1), Cons(h2,t2) ⇒ if h1 <= h2 then Cons(h1, thunk(merge (force t1) l2) else Cons(h2, thunk(merge l1 (force t2))

Merging Lazy Lists

As in conventional lazy programming

slide-59
SLIDE 59

Mergesort DCG Viz.

Graphics by Piotr Mardziel

slide-60
SLIDE 60

Micro Benchmarks

List and tree applications: filter, map fold{min,sum} quicksort, mergesort expression tree evaluation

slide-61
SLIDE 61

Batch

Baseline time (s) Adapton speedup SAC speedup filter 0.6 2.0 4.11 map 1.2 2.2 3.32 fold min 1.4 4350 3090 fold sum 1.5 1640 4220 exptree 0.3 497 1490

Mutate random input Demand full output Batch Pattern: Experimental procedure:

slide-62
SLIDE 62

Swap

Baseline time (s) Adapton speedup SAC speedup filter 0.5 2.0 0.14 map 0.9 2.4 0.25 fold min 1.0 472 0.12 fold sum 1.1 501 0.13 exptree 0.3 667 10

Swap input halves Demand full output Swap Pattern: Experimental procedure:

slide-63
SLIDE 63

Lazy

Baseline time (s) Adapton speedup SAC speedup filter 1.16E-05 12.8 2.2 map 6.86E-06 7.8 1.5 quicksort 7.41E-02 2020 22.9 mergesort 3.46E-01 336 0.148

Demand first output Mutate random input Lazy Pattern: Experimental procedure:

slide-64
SLIDE 64

Demand first output Switch Pattern: Experimental procedure:

  • 1. Remove
  • 2. Insert

Switch

Baseline time (s) Adapton speedup SAC speedup updown1 3.28E-02 22.4 2.47E-03 updown2 3.26E-02 24.7 4.28

  • 3. Toggle order
slide-65
SLIDE 65

Spreadsheet Experiments

Sheet 2 Sheet 1 Random binary formula

slide-66
SLIDE 66

Spreadsheet Experiments

Sheet 2 Sheet 1 Random binary formula Fixed Depth

slide-67
SLIDE 67

Spreadsheet Experiments

Sheet 2 Sheet 1

  • 1. Random

Mutations Random binary formula Fixed Depth

slide-68
SLIDE 68

Spreadsheet Experiments

Sheet 2 Sheet 1

  • 1. Random

Mutations Random binary formula

  • 2. Observe

last sheet Fixed Depth

slide-69
SLIDE 69

Spreadsheet Experiments

Sheet 2 Sheet 1 Fixed Depth Random binary formula

  • 2. Observe

last sheet

  • 1. Random

Mutations

slide-70
SLIDE 70

Speedup vs # Changes

S p e e d u p Number of Changes

!" #" $!" $#" %!" %#" %" &" $%" $&" %%" %&" '()*+,-" .)/012,+)341(01"

(15 sheets deep)

SAC Adapton

slide-71
SLIDE 71

Speedup vs # Changes

S p e e d u p Number of Changes

!" #" $!" $#" %!" %#" %" &" $%" $&" %%" %&" '()*+,-" .)/012,+)341(01"

100x Slowdown! SAC Adapton Exponential Speedup

slide-72
SLIDE 72

Spreadsheet Experiments

Sheet 1 Sheet 2 Depth

  • 1. Random

Mutations Random binary formula

  • 2. Observe

last sheet

slide-73
SLIDE 73

Spreadsheet Experiments

Sheet 1 Sheet 2 Depth

  • 1. Random

Mutations Random binary formula

  • 2. Observe

last sheet Vary

slide-74
SLIDE 74

Speedup vs Sheet Depth

Speedup (over Naive)

!" #" $" %" &" '!" #" (" '#"

)*+,-./" 0+1234.-+563*23"

  • Num. Sheets (10 Changes)

S p e e d u p Depth (10 changes between observations)

SAC Adapton

slide-75
SLIDE 75

Speedup vs Sheet Depth

Speedup (over Naive)

!" #" $" %" &" '!" #" (" '#"

)*+,-./" 0+1234.-+563*23"

  • Num. Sheets (10 Changes)

S p e e d u p Depth (10 changes between observations)

100x Slowdown! SAC Adapton Exponential Speedup

slide-76
SLIDE 76

Paper and Technical Report

  • Formal semantics of Adapton
  • Algorithms to implement Adapton
  • More empirical data and analysis
slide-77
SLIDE 77

Aside: Formal Semantics

  • CBPV + Refs + Layers (outer versus inner)
  • Syntax for traces and knowledge

formally represents DCG structure

  • Formal specification of change propagation
  • Theorems:
  • Type soundness
  • Incremental soundness

(“ from-scratch consistency ”)

slide-78
SLIDE 78

Summary

  • Adapton: Composable, Demand-Driven IC
  • Demand-driven change propagation
  • Reuse patterns:

Sharing, swapping and switching

  • Formal specification (see paper)
  • Implemented in OCaml (and Python)
  • Empirical evaluation shows speedups

http://ter.ps/adapton

slide-79
SLIDE 79
slide-80
SLIDE 80

pattern input #

LazyNonInc

ADAPTON

EagerTotalOrder

baseline

  • vs. LazyNonInc
  • vs. LazyNonInc

time mem time mem time mem (s) (MB) spdup

  • vrhd

spdup

  • vrhd

filter

lazy 1e6 1.16e-5 96.7 12.8 2.7 2.24 8.0

map

1e6 6.85e-6 96.7 7.80 2.7 1.53 8.0

quicksort

1e5 0.0741 18.6 2020 8.7 22.9 144.1

mergesort

1e5 0.346 50.8 336 7.8 0.148 96.5

filter

swap 1e6 0.502 157 1.99 10.1 0.143 17.3

map

1e6 0.894 232 2.36 6.9 0.248 12.5

fold(min)

1e6 1.04 179 472 9.1 0.123 33.9

fold(sum)

1e6 1.11 180 501 9.1 0.128 33.8

exptree

1e6 0.307 152 667 11.7 10.1 11.9

updown1

switch 4e4 0.0328 8.63 22.4 14.0 0.00247 429.9

updown2

4e4 0.0326 8.63 24.7 13.8 4.28 245.7

filter

batch 1e6 0.629 157 2.04 10.1 4.11 9.0

map

1e6 1.20 232 2.21 6.9 3.32 6.6

fold(min)

1e6 1.43 179 4350 9.0 3090 8.0

fold(sum)

1e6 1.48 180 1640 9.1 4220 8.0

exptree

1e6 0.308 152 497 11.7 1490 9.7 Legend time spdup: LazyNonInc time / X time