adapton composable demand driven incremental computation
play

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


  1. Adapton: Composable Demand-Driven Incremental Computation Matthew A. Hammer Khoo Yit Phang, Michael Hicks and Jeffrey S. Foster

  2. Incremental Computation Input Output Application Application Code IC IC Framework Framework

  3. ☞ Incremental Computation Input Output Trace Trace records dynamic data Application dependencies IC Framework

  4. ☞ Incremental Computation Input Output Trace Run 1 Mutations Input Trace Output

  5. ☞ Incremental Computation Input Output Trace Run 1 Mutations Inconsistencies Input Trace Output

  6. Incremental Computation Input Output Trace Run 1 Change- Propagation Run 2 Input Trace Output

  7. Incremental Computation Input Output Trace Run 1 Change- Updates Propagation Run 2 Input Trace Output

  8. Incremental Computation Input Output Trace Run 1 Change- Updates Propagation Run 2 Input Trace Output

  9. Incremental Computation Input Output Trace Run 1 Change- Updates Propagation Run 2 Input Trace Output

  10. Incremental Computation Input Output Trace Run 1 Run 2 Input Trace Output

  11. ☞ Incremental Computation Observations Run 2 Input Trace Output

  12. ☞ Incremental Computation loop.. Mutations Observations Run 2 Input Trace Output

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

  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

  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

  16. Interaction Pattern: Laziness Do not (re)compute obscured sheets Sheet A Sheet B Sheet C Legend Consistent No cache (Independent sheets) Inactive

  17. Interaction Pattern: Laziness Do not (re)compute obscured sheets Sheet A Sheet B Sheet C Legend Consistent No cache (Independent sheets) Inactive

  18. Interaction Pattern: Laziness Do not (re)compute obscured sheets Sheet A Sheet B Sheet C Legend Consistent No cache (Independent sheets) Inactive

  19. Interactive Pattern: Switching Demand / control-flow change Sheet A Sheet B Legend Sheet C = f ( A ) Consistent No cache Inactive

  20. Interactive Pattern: Switching Demand / control-flow change Sheet A Sheet B Legend Sheet C = f ( A ) Consistent C = g ( B ) No cache Inactive

  21. Interactive Pattern: Switching Demand / control-flow change Sheet A Sheet B Legend Sheet C = f ( A ) Consistent C = g ( B ) No cache Inactive

  22. Interaction Pattern: Sharing B and C share work for A Sheet A Sheet Sheet B = f ( A ) C = g ( A ) Legend Consistent No cache Inactive

  23. Interaction Pattern: Sharing B and C share work for A Sheet A Sheet Sheet B = f ( A ) C = g ( A ) Legend Consistent No cache Inactive

  24. Interaction Pattern: Sharing B and C share work for A Sheet A Sheet Sheet B = f ( A ) C = g ( A ) Legend Consistent No cache Inactive

  25. Interactive Pattern: Swapping Swaps input / evaluation order Sheet A Sheet B Sheet Legend C = f (A, B) Consistent No cache Inactive

  26. Interactive Pattern: Swapping Swaps input / evaluation order Sheet A Sheet B Sheet Legend C = f (A, B) Consistent C = f (B, A) No cache Inactive

  27. Interactive Pattern: Swapping Swaps input / evaluation order Sheet A Sheet B Sheet Legend C = f (A, B) Consistent C = f (B, A) No cache Inactive

  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

  29. Spread Sheet Evaluator type cell = formula ref and formula = | Leaf of int | Plus of cell * cell

  30. Spread Sheet Evaluator Mutable type cell = formula ref and formula = | Leaf of int | Plus of cell * cell Depends on cells

  31. Spread Sheet Evaluator Example let n 1 = ref (Leaf 1) let n 2 = ref (Leaf 2) let n 3 = ref (Leaf 3) let p 1 = ref (Plus (n 1 , n 2 )) type cell = formula ref let p 2 = ref (Plus (p 1 , n 3 )) and formula = | Leaf of int | Plus of cell * cell

  32. Spread Sheet Evaluator n 1 n 2 1 1 1 2 Example n 3 p 1 1 1 let n 1 = ref (Leaf 1) + 3 let n 2 = ref (Leaf 2) p 2 1 + let n 3 = ref (Leaf 3) let p 1 = ref (Plus (n 1 , n 2 )) type cell = formula ref let p 2 = ref (Plus (p 1 , n 3 )) and formula = | Leaf of int “User interface” (REPL) | Plus of cell * cell

  33. Spread Sheet Evaluator Evaluator logic n 1 n 2 1 1 1 2 eval : cell → (int thunk) n 3 p 1 1 1 eval c = thunk (( + 3 case (get c) of p 2 | Leaf n ⇒ n 1 + | Plus(c1, c2) ⇒ type cell = formula ref force (eval c1) + force (eval c2) and formula = )) | Leaf of int | Plus of cell * cell

  34. Spread Sheet Evaluator n 1 n 2 set : cell x formula → unit 1 1 1 2 eval : cell → (int thunk) n 3 p 1 1 1 + 3 display : (int thunk) → unit “User interface” (REPL) p 2 1 + type cell = formula ref and formula = | Leaf of int | Plus of cell * cell

  35. Spread Sheet Evaluator n 1 n 2 set : cell x formula → unit 1 1 1 2 eval : cell → (int thunk) n 3 p 1 1 1 + 3 display : (int thunk) → unit “User interface” (REPL) p 2 1 + Demands evaluation type cell = formula ref and formula = | Leaf of int | Plus of cell * cell

  36. Spread Sheet Evaluator n 1 n 2 set : cell x formula → unit 1 1 1 2 eval : cell → (int thunk) n 3 p 1 1 1 + 3 display : (int thunk) → unit “User interface” (REPL) p 2 1 + type cell = formula ref and formula = | Leaf of int | Plus of cell * cell

  37. Spread Sheet Evaluator n 1 n 2 set : cell x formula → unit 1 1 1 2 eval : cell → (int thunk) n 3 p 1 1 1 + 3 display : (int thunk) → unit “User interface” (REPL) p 2 1 + type cell = formula ref ☞ let t 1 = eval p 1 and formula = | Leaf of int | Plus of cell * cell

  38. ☞ Spread Sheet Evaluator n 1 n 2 set : cell x formula → unit 1 1 1 2 eval : cell → (int thunk) n 3 p 1 1 1 + 3 display : (int thunk) → unit “User interface” (REPL) p 2 1 + n 1 n 2 ☞ let t 1 = eval p 1 p 1 n 3 t 1 p 2

  39. ☞ Spread Sheet Evaluator n 1 n 2 set : cell x formula → unit 1 1 1 2 eval : cell → (int thunk) n 3 p 1 1 1 + 3 display : (int thunk) → unit “User interface” (REPL) p 2 1 + n 1 n 2 ☞ let t 1 = eval p 1 ☞ let t 2 = eval p 2 p 1 n 3 t 1 p 2 t 2

  40. ☞ Spread Sheet Evaluator n 1 n 2 set : cell x formula → unit 1 1 1 2 eval : cell → (int thunk) n 3 p 1 1 1 + 3 display : (int thunk) → unit get “User interface” (REPL) p 2 1 + ☞ let t 1 = eval p 1 n 1 n 2 3 force ☞ let t 2 = eval p 2 p 1 n 3 ☞ display t 1 t 1 demand! p 2 t 2

  41. ☞ Spread Sheet Evaluator n 1 n 2 set : cell x formula → unit 1 1 1 2 eval : cell → (int thunk) n 3 p 1 1 1 + 3 display : (int thunk) → unit get “User interface” (REPL) p 2 1 + ☞ let t 1 = eval p 1 n 1 n 2 3 force ☞ let t 2 = eval p 2 p 1 n 3 Demanded ☞ display t 1 t 1 Computation p 2 Graph (DCG) t 2

  42. ☞ Spread Sheet Evaluator n 1 n 2 set : cell x formula → unit 1 1 1 2 eval : cell → (int thunk) n 3 p 1 1 1 + 3 display : (int thunk) → unit “User interface” (REPL) p 2 1 + ☞ let t 1 = eval p 1 n 1 n 2 get ☞ let t 2 = eval p 2 6 ☞ display t 1 p 1 n 3 t 1 ☞ display t 2 force p 2 demand! t 2 DCG

  43. ☞ Spread Sheet Evaluator n 1 n 2 set : cell x formula → unit 1 1 1 2 eval : cell → (int thunk) n 3 p 1 1 1 + 3 display : (int thunk) → unit Memo “User interface” (REPL) match ! p 2 1 + ☞ let t 1 = eval p 1 n 1 n 2 get ☞ let t 2 = eval p 2 Memo 6 ☞ display t 1 p 1 n 3 match ! t 1 ☞ display t 2 force Sharing p 2 t 2 DCG

  44. Spread Sheet Evaluator n 1 n 2 set : cell x formula → unit 1 1 1 2 eval : cell → (int thunk) n 3 p 1 1 1 + 3 display : (int thunk) → unit “User interface” (REPL) p 2 1 + ☞ let t 1 = eval p 1 n 1 n 2 get ☞ let t 2 = eval p 2 6 ☞ display t 1 p 1 n 3 t 1 ☞ display t 2 force p 2 ☞ clear t 2 DCG

  45. ☞ Spread Sheet Evaluator n 1 n 2 set : cell x formula → unit 1 1 1 2 eval : cell → (int thunk) n 3 p 1 1 1 + 3 display : (int thunk) → unit “User interface” (REPL) p 2 1 + n 1 n 2 get p 1 n 3 t 1 force p 2 t 2 DCG

  46. Spread Sheet Evaluator n 1 n 2 set : cell x formula → unit 1 1 1 2 eval : cell → (int thunk) n 3 p 1 1 1 + 3 display : (int thunk) → unit “User interface” (REPL) p 2 1 + n 1 n 2 get ☞ set n 1 ← Leaf 5 p 1 n 3 t 1 force p 2 t 2 DCG

  47. ☞ Spread Sheet Evaluator n 1 n 2 set : cell x formula → unit 1 1 5 2 eval : cell → (int thunk) n 3 p 1 Dirty 1 1 + 3 display : (int thunk) → unit dep “User interface” (REPL) p 2 1 + n 1 n 2 Dirty get ☞ set n 1 ← Leaf 5 phase p 1 n 3 t 1 force p 2 t 2 DCG

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend