optimizing the automated programming stack
play

Optimizing the Automated Programming Stack James Bornholt - PowerPoint PPT Presentation

Optimizing the Automated Programming Stack James Bornholt University of Washington Software is everywhere Bugs are everywhere Bugs are everywhere Automated programming tools Program Verifier + test case Specification Language


  1. ⇒ MemSynth: automated programming for memory consistency models Litmus tests 
 Memory models 
 Synthesis as rela`ons as constraints via sketches ∨ ∀ ⋈ ∃ ∈ 1 2 3 ∩ ∧ ⊂ ∪ Litmus tests 
 Formal 
 and prose specifica`ons

  2. Litmus tests as relations Thread 1 Thread 2 X = 1 Y = 1 1 3 if Y == 0: if X == 0: 2 4 print “hello” print “goodbye” All variables initialized to 0

  3. Litmus tests as relations Thread 1 Thread 2 X = 1 Y = 1 1 3 r0 = Y r1 = X 2 4 All variables initialized to 0

  4. Litmus tests as relations Thread 1 Thread 2 X = 1 Y = 1 1 3 r0 = Y r1 = X 2 4 All variables initialized to 0 Encode programs and behaviors as relations in relational logic 
 (like Alloy)

  5. Litmus tests as relations Thread 1 Thread 2 X = 1 Y = 1 1 3 r0 = Y r1 = X 2 4 All variables initialized to 0 Encode programs and behaviors as relations in relational logic 
 (like Alloy) Program relations extracted from program text: po = {( , ), ( , )} 1 2 3 4 Program order : ( a , b ) ∈ po if b is aoer a on the same thread

  6. Litmus tests as relations Thread 1 Thread 2 X = 1 Y = 1 1 3 r0 = Y r1 = X 2 4 All variables initialized to 0 Encode programs and behaviors as relations in relational logic 
 (like Alloy) Program relations Execution relations extracted from program text: describe dynamic behavior: po = {( , ), ( , )} rf = {( , ), ( , )} 1 2 3 4 2 3 4 1 Program order : Reads-from : ( a , b ) ∈ po if b is aoer a on ( r , w ) ∈ rf if r reads the the same thread value wripen by w

  7. Litmus tests as relations Thread 1 Thread 2 X = 1 Y = 1 1 3 r0 = Y r1 = X 2 4 All variables initialized to 0 Encode programs and behaviors as relations in relational logic 
 (like Alloy) Program relations Execution relations extracted from program text: describe dynamic behavior: po = {( , ), ( , )} rf = {( , ), ( , )} 1 2 3 4 2 3 4 1 Program order : Reads-from : ( a , b ) ∈ po if b is aoer a on ( r , w ) ∈ rf if r reads the the same thread value wripen by w

  8. Memory models as relational constraints Program relations Execution relations extracted from program text: describe dynamic behavior: po = {( , ), ( , )} rf = {( , ), ( , )} 1 2 3 4 2 3 4 1 Program order Reads-from A memory model constrains the allowed executions of a program Written as a predicate in relational logic

  9. Memory models as relational constraints Program relations Execution relations extracted from program text: describe dynamic behavior: po = {( , ), ( , )} rf = {( , ), ( , )} 1 2 3 4 2 3 4 1 Program order Reads-from A memory model constrains the allowed executions of a program Written as a predicate in relational logic M ( T , E ) ≜

  10. Memory models as relational constraints (&& Program relations Execution relations (&& (&& extracted from program text: describe dynamic behavior: (in rf (& (-> Writes Reads) (join loc (~ loc)) (join data (~ data)))) (no (- (join rf (~ rf)) iden)) (all ((r4 (- Reads (join Writes rf)))) (= (join r4 data) Zero))) (&& po = {( , ), ( , )} rf = {( , ), ( , )} 1 2 3 4 2 3 4 1 (in ws (& (-> Writes Writes) (join loc (~ loc)))) (no (& iden ws)) (in (join ws ws) ws) (all Program order Reads-from ((r5 Writes)) (all ((r6 (- (& Writes (join loc (join r5 loc))) r5))) (or (in (-> r5 r6) ws) (in (-> r6 r5) ws)))) (in ws (join loc (~ loc))))) (no (& (^ (+ A memory model constrains the allowed executions of a program (+ rf ws (+ (join (~ rf) ws) (& (-> (- Reads (join Writes rf)) Writes) (join loc (~ loc))))) (& po (join loc (~ loc))))) iden)) (no (& (^ (+ po rf)) iden)) (all Written as a predicate in relational logic ((r7 Writes)) (=> (&& (in r7 (- (join univ ws) (join ws univ))) (some (join (join r7 loc) finalValue))) (= (join r7 data) (join (join r7 loc) finalValue)))) (no (& (^ (+ (& po dp) ws (+ (join (~ rf) ws) (& (-> (- Reads (join Writes rf)) Writes) (join loc (~ loc)))) (-> none none) M ( T , E ) ≜ (+ (^ (+ (+ (join (:> po Syncs) po) (join (join (:> po Syncs) po) rf)) (join rf (join (:> po Syncs) po)))) (^ (+ (+ (& (join (:> po Lwsyncs) po) (+ (-> Writes Writes) (-> Reads MemoryEvent))) (:> (join rf (& (join (:> po Lwsyncs) po) (+ (-> Writes Writes) (-> Reads MemoryEvent)))) Writes)) (<: Reads (join (& (join (:> po Lwsyncs) po) (+ (-> Writes Writes) (-> Reads MemoryEvent))) rf))))))) iden)))

  11. Memory models as relational constraints Program relations Execution relations extracted from program text: describe dynamic behavior: po = {( , ), ( , )} rf = {( , ), ( , )} 1 2 3 4 2 3 4 1 Program order Reads-from A memory model constrains the allowed executions of a program Written as a predicate in relational logic M ( T , E ) ≜ ( no (& (^ (+ po rf)) iden))

  12. Memory models as relational constraints Program relations Execution relations extracted from program text: describe dynamic behavior: po = {( , ), ( , )} rf = {( , ), ( , )} 1 2 3 4 2 3 4 1 Program order Reads-from A memory model constrains the allowed executions of a program Written as a predicate in relational logic M ( T , E ) ≜ ( no (& (^ (+ po rf)) iden)) …by forbidding cycles Constraining the possible involving rf ∪ po values of rf …

  13. Memory models as relational constraints Program relations Execution relations extracted from program text: describe dynamic behavior: po = {( , ), ( , )} rf = {( , ), ( , )} 1 2 3 4 2 3 4 1 Program order Reads-from A memory model constrains the allowed executions of a program Written as a predicate in relational logic A memory model allows a test T if there exists an execu`on E that sa`sfies the predicate M ( T , E ) ≜ ( no (& (^ (+ po rf)) iden)) …by forbidding cycles Constraining the possible involving rf ∪ po values of rf …

  14. Synthesis from a memory model sketch ( no (& (^ (+ po rf)) iden)) M ( T , E ) ≜

  15. Synthesis from a memory model sketch M ( T , E ) ≜ ( no (& (^ (+ ?? ?? )) iden )) ( no (& (^ (+ po rf)) iden)) Expression holes for a synthesizer to complete

  16. Synthesis from a memory model sketch M ( T , E ) ≜ ( no (& (^ (+ ?? ?? )) iden )) ( no (& (^ (+ po rf)) iden)) po Expression holes for rf a synthesizer to po + rf complete po & rf po - rf …

  17. Synthesis from a memory model sketch A sketch specifies things we know (e.g., want a happens- before ordering)… M ( T , E ) ≜ ( no (& (^ (+ ?? ?? )) iden )) ( no (& (^ (+ po rf)) iden)) po Expression holes for rf a synthesizer to po + rf complete po & rf po - rf …

  18. Synthesis from a memory model sketch A sketch specifies things we …and defines the shape of know (e.g., want a happens- the parts we don’t know before ordering)… M ( T , E ) ≜ ( no (& (^ (+ ?? ?? )) iden )) ( no (& (^ (+ po rf)) iden)) po Expression holes for rf a synthesizer to po + rf complete po & rf po - rf …

  19. Memory model frameworks ( no (& (^ (+ ws rf ppo grf )) iden )) M ( T , E ) ≜ [Alglave et al, CAV’10]

  20. Memory model frameworks ( no (& (^ (+ ws rf ppo grf )) iden )) M ( T , E ) ≜ Preserved program order: Global reads-from: same-thread reorderings inter-thread reorderings [Alglave et al, CAV’10]

  21. Memory model frameworks ( no (& (^ (+ ws rf ppo grf )) iden )) M ( T , E ) ≜ Preserved program order: Global reads-from: same-thread reorderings inter-thread reorderings Sequential po rf consistency Total store 
 po - (Wr→Rd) rf & SameThd order (x86) [Alglave et al, CAV’10]

  22. Memory model frameworks ( no (& (^ (+ ws rf ppo grf )) iden )) M ( T , E ) ≜ ?? ?? Preserved program order: Global reads-from: same-thread reorderings inter-thread reorderings Sequential po rf consistency Total store 
 po - (Wr→Rd) rf & SameThd order (x86) [Alglave et al, CAV’10]

  23. Ocelot DSL for relational logic with holes Expression holes for a synthesizer to complete ( no (& (^ (+ ws rf ppo grf )) iden )) M ( T , E ) ≜ ?? ?? Ocelot embeds rela`onal logic in the RoseZe solver-aided language [Torlak & Bodik 2014] Also in use for SQL query synthesis and protocol reasoning http://ocelot.tools

  24. The synthesis query Allowed litmus tests Synth Completed memory model M Forbidden litmus tests ˆ Memory model sketch M

  25. The synthesis query 2 allowed tests 3 5 Synth Total store order 1 2 4 6 7 8 9 10 8 forbidden tests x86 ˆ Memory model sketch M

  26. The synthesis query Allowed litmus tests Synth Completed memory model M Forbidden litmus tests ˆ Memory model sketch M

  27. The synthesis query ∃ M. ∀ T ∈ T + . M allows T Allowed litmus tests Memory model M Forbidden litmus tests ˆ Memory model sketch M

  28. The synthesis query ∃ M. ∀ T ∈ T + . M allows T Allowed litmus tests Memory model M ∃ M. ∀ T ∈ T - . M forbids T Forbidden litmus tests ˆ Memory model sketch M

  29. The synthesis query Standard exists-forall quan`fier papern for synthesis ∃ M. ∀ T ∈ T + . M allows T Allowed litmus tests Memory model M ∃ M. ∀ T ∈ T - . M forbids T Forbidden litmus tests ˆ Memory model sketch M

  30. The synthesis query M allows T : Standard exists-forall quan`fier ∃ E . M ( T , E ) papern for synthesis ∃ M. ∀ T ∈ T + . M allows T Allowed litmus tests Memory model M ∃ M. ∀ T ∈ T - . M forbids T Forbidden litmus tests ˆ Memory model sketch M

  31. The synthesis query M allows T : Standard exists-forall quan`fier ∃ E . M ( T , E ) papern for synthesis ∃ M. ∀ T ∈ T + . ∃ E. M ( T , E ) Allowed litmus tests Memory model M ∃ M. ∀ T ∈ T - . ∀ E. ¬ M ( T , E ) Forbidden litmus tests ˆ Memory model sketch M

  32. The synthesis query M allows T : Standard exists-forall quan`fier ∃ E . M ( T , E ) papern for synthesis ∃ M. ∀ T ∈ T + . ∃ E. M ( T , E ) Allowed litmus tests Memory model M ∃ M. ∀ T ∈ T - . ∀ E. ¬ M ( T , E ) Forbidden litmus tests Higher-order quan`fica`on ˆ Memory model sketch M over rela`ons! 😲

  33. The synthesis query M allows T : ∃ E . M ( T , E ) ∃ M. ∀ T ∈ T + . ∃ E. M ( T , E ) Allowed litmus tests Memory model M ∃ M. ∀ T ∈ T - . ∀ E. ¬ M ( T , E ) Forbidden litmus tests ˆ Memory model sketch M

  34. The synthesis query M allows T : ∃ E . M ( T , E ) ∃ M. ∀ T ∈ T + . ∃ E. M ( T , E ) Allowed litmus tests Memory model M ∃ M. ∀ T ∈ T - . ∀ E. ¬ M ( T , E ) Forbidden litmus tests Handled by a quan`fied ˆ Memory model sketch M boolean formula (QBF) solver

  35. The synthesis query M allows T : ∃ E . M ( T , E ) ∃ M. ∀ T ∈ T + . ∃ E. M ( T , E ) Allowed litmus tests Memory model M ∃ M. ∀ T ∈ T - . ∀ E. ¬ M ( T , E ) Forbidden litmus tests Handled by incremental Handled by a quan`fied ˆ Memory model sketch M synthesis engine boolean formula (QBF) solver

  36. Incremental synthesis T 1 T T T T T T T T Synth Allowed litmus tests Forbidden litmus tests T 2 T T T T T T T T

  37. Incremental synthesis T T T T T T T T T T T T T Synth Allowed litmus tests Forbidden litmus tests T 1 T 2 T T T T T T T T

  38. Incremental synthesis Handled by a quan`fied boolean formula (QBF) solver T T T T T T T T T T T T T Synth Allowed litmus tests Forbidden litmus tests T 1 T 2 T T T T T T T T

  39. Incremental synthesis Handled by a quan`fied boolean formula (QBF) solver T T T T T T T T T T T T T Synth Allowed litmus tests M’ Forbidden litmus tests T 1 T 2 T T T T T T T T

  40. Incremental synthesis Handled by a quan`fied boolean formula (QBF) solver T T T T T T T T T T T T T T Synth Allowed litmus tests M’ Forbidden litmus tests T 1 T 2 T T T T T T T T

  41. Incremental synthesis Handled by a quan`fied boolean formula (QBF) solver T T T T T T T Synth Allowed litmus tests M’ Forbidden litmus tests T 1 T 2 T T T T T T T T T

  42. Incremental synthesis Handled by a quan`fied boolean formula (QBF) solver T T T T T T T Synth Allowed litmus tests M’ Completed memory model M Forbidden litmus tests T 1 T 2 T T T T T T T T T

  43. Incremental synthesis Handled by a quan`fied boolean formula (QBF) solver T T T T T T T Synth Allowed litmus tests M’ Completed memory model M Forbidden litmus tests T 1 T 2 T T T T T T T T T Empirically, need very few itera`ons to converge

  44. Disambiguating synthesized models Key idea : aoer synthesis, is there a different memory model that also explains the input tests? Ambig

  45. Disambiguating synthesized models Key idea : aoer synthesis, is there a different memory model that also explains the input tests? Allowed litmus tests Ambig Forbidden litmus tests ˆ Memory model sketch M

  46. Disambiguating synthesized models Key idea : aoer synthesis, is there a different memory model that also explains the input tests? Allowed litmus tests Ambig Forbidden litmus tests Completed memory model M ˆ Memory model sketch M

  47. Disambiguating synthesized models Key idea : aoer synthesis, is there a different memory model that also explains the input tests? Allowed litmus tests Completed memory model M 2 Ambig Forbidden litmus tests Litmus test T Completed memory model M ˆ Memory model sketch M

  48. Disambiguating synthesized models Key idea : aoer synthesis, is there a different memory model that also explains the input tests? Allowed litmus tests Completed memory model M 2 Ambig Forbidden litmus tests Litmus test T Completed memory model M Difference between M and M 2 is not just ˆ Memory model sketch M syntac`c: they disagree about test T

  49. Synthesizing existing memory models x86 PowerPC

  50. Synthesizing existing memory models x86 10 tests PowerPC 768 tests [Alglave et al, CAV’10]

  51. Synthesizing existing memory models Synthesis x86 10 tests ✓ 2 seconds PowerPC 768 tests ✓ 12 seconds [Alglave et al, CAV’10]

  52. Synthesizing existing memory models Synthesis x86 10 tests ✓ 2 seconds Not equivalent to TSO! PowerPC 768 tests ✓ 12 seconds [Alglave et al, CAV’10]

  53. Synthesizing existing memory models Synthesis x86 10 tests ✓ 2 seconds Not equivalent to TSO! PowerPC 768 tests ✓ 12 seconds [Alglave et al, CAV’10] Not equivalent to published model!

  54. Synthesizing existing memory models Synthesis Ambiguity x86 10 tests ✓ 2 seconds 4 new tests mfence , xchg Not equivalent to TSO! PowerPC 768 tests ✓ 12 seconds 9 new tests [Alglave et al, CAV’10] sync , lwsync Not equivalent to published model!

  55. ⇒ MemSynth: automated programming for memory consistency models x86: 2 seconds PowerPC: 12 seconds Synthesize specifica`ons from litmus tests ∨ ∀ ⋈ ∃ ∈ ∩ ∧ ⊂ ∪ Detect ambigui`es in synthesized models Litmus tests 
 Formal 
 and prose specifica`ons x86: 4 ambigui`es PowerPC: 9 ambigui`es

  56. Automated tools are worth building The case of memory models [PLDI’17] Building them can be made systematic Symbolic profiling [OOPSLA’18] The future is more automation Automating the automated programming stack

  57. Automated tools are worth building The case of memory models [PLDI’17] Building them can be made systematic Symbolic profiling [OOPSLA’18] The future is more automation Automating the automated programming stack

  58. Scaling a synthesis tool is hard work 12 seconds

  59. Scaling a synthesis tool is hard work 12000 9000 Time (secs) 6000 3000 12 seconds 0 January February March April May June

  60. Scaling a synthesis tool is hard work 12000 3 hours 9000 Time (secs) 6000 3000 12 seconds 0 January February March April May June

  61. Scaling a synthesis tool is hard work 12000 3 hours Finding these op`miza`on opportuni`es is the key to good performance and new func`onality 9000 Time (secs) 6000 3000 12 seconds 0 January February March April May June

  62. Symbolic profiling 12000 3 hours A symbolic profiler identifies optimization opportunities in an 9000 automated tool. Time (secs) 6000 3000 12 seconds 0 January February March April May June

Recommend


More recommend