New applications of program synthesis Armando SolarLezama Synthesis

  • Slides: 31
Download presentation
New applications of program synthesis Armando Solar-Lezama

New applications of program synthesis Armando Solar-Lezama

Synthesis: 1980 s view Complete Formal Specification

Synthesis: 1980 s view Complete Formal Specification

Synthesis: modern view Space of programs Reference Implementation Input/Output Examples Test Harnesses

Synthesis: modern view Space of programs Reference Implementation Input/Output Examples Test Harnesses

Example Sketch Spec bit[W] avg. Spec(bit[W] x, bit[W] y){ bit[W] avg(bit[W] x, bit[W] y)

Example Sketch Spec bit[W] avg. Spec(bit[W] x, bit[W] y){ bit[W] avg(bit[W] x, bit[W] y) implements avg. Spec{ bit[2*W] xx = extend@signed(x, 2*W); bit[2*W] yy = extend@signed(y, 2*W); return expr@signed({x, y}, 4); } bit[2*W] r = rshift@signed(xx+yy, 1); return (r[0: : W]); } expr : : = const | var | expr>>? ? | ~expr | expr + expr | expr ^ expr | expr & expr

And 8 seconds later… (x & y) + (x ^ y) >> 1 Cool!

And 8 seconds later… (x & y) + (x ^ y) >> 1 Cool! Now can you synthesize programs with more than 1 line of code?

Synthesis of distributed memory algorithms (SC 14) • Synthesizer can help with non-trivial distributed

Synthesis of distributed memory algorithms (SC 14) • Synthesizer can help with non-trivial distributed memory implementations • Scalability of resulting code is comparable with hand-crafted Fortran

So how much can you synthesize? • A little more if you are synthesizing

So how much can you synthesize? • A little more if you are synthesizing from scratch • 5 or 6 LOC in one shot • But… • We can synthesize many more if there is independence • We can synthesize them within larger pieces of code • 2 -4 K LOC in many cases • We can do it very reliably So what can you do if you can synthesize small expressions in a large program?

High-Level Language Graphical programming Compiler Sketch C-like language with holes and assertions Automated Tutoring

High-Level Language Graphical programming Compiler Sketch C-like language with holes and assertions Automated Tutoring Synthesis Solution

Analysis Tool Graphical programming Synthesis Subproblems Sketch C-like language with holes and assertions Automated

Analysis Tool Graphical programming Synthesis Subproblems Sketch C-like language with holes and assertions Automated Tutoring Synthesis Program Optimization Solution Solver Synthesis

Optimization with synthesis

Optimization with synthesis

Java to SQL Methods SQL Queries ORM libraries Objects Application Relations Database

Java to SQL Methods SQL Queries ORM libraries Objects Application Relations Database

Java to SQL Methods SQL Queries ORM libraries Objects Application Relations Database

Java to SQL Methods SQL Queries ORM libraries Objects Application Relations Database

Java to SQL List get. Users. With. Roles () { List users = User.

Java to SQL List get. Users. With. Roles () { List users = User. get. All. Users(); List roles = Role. get. All. Roles(); List results = new Array. List(); SELECT * FROM user SELECT * FROM role for (User u : users) { for (Role r : roles) { if (u. role. Id == r. id) results. add(u); }} return results; } List get. Users. With. Roles () { convert to return execute. Query( “SELECT u FROM user u, role r WHERE u. role. Id == r. id ORDER BY u. role. Id, r. id”; }

Join Query 1 K original inferred Page load time (ms) 0 K Nested-loop join

Join Query 1 K original inferred Page load time (ms) 0 K Nested-loop join Hash join! O(n 2) O(n) 0 K 0 K 100 0 6/17/2013 0 K 0 K Number of roles / users in DB PLDI 2013 0 K 15

Real-world Evaluation Wilos (project management application) – 62 k LOC Operation type 6/17/2013 #

Real-world Evaluation Wilos (project management application) – 62 k LOC Operation type 6/17/2013 # Fragments found # Fragments converted Projection 1 1 Selection 13 10 Join 7 7 Aggregation 11 10 Total 33 28 PLDI 2013 16

Real-world Evaluation i. Tracker (bug tracking system) – 61 k LOC Operation type 6/17/2013

Real-world Evaluation i. Tracker (bug tracking system) – 61 k LOC Operation type 6/17/2013 # Fragments found # Fragments converted Projection 3 2 Selection 3 2 Join 1 1 Aggregation 9 7 Total 16 12 PLDI 2013 17

Beyond SQL • This is a general idea Synthesis Source Code Proof of Equivalence

Beyond SQL • This is a general idea Synthesis Source Code Proof of Equivalence DSL Program Enable optimization by raising the level of abstraction!

Legacy code to Halide Synthesis Legacy Fortran/C++ Code Proof of Equivalence Stencil DLS (Halide)

Legacy code to Halide Synthesis Legacy Fortran/C++ Code Proof of Equivalence Stencil DLS (Halide)

Legacy to Halide for (k=y_min-2; k<=y_max+2; k++) { for (j=x_min-2; j<=x_max+2; j++) { post_vol[((x_max+5)*(k-(y_min-2))+(j)-(x_min-2))]

Legacy to Halide for (k=y_min-2; k<=y_max+2; k++) { for (j=x_min-2; j<=x_max+2; j++) { post_vol[((x_max+5)*(k-(y_min-2))+(j)-(x_min-2))] =volume[((x_max+4)*(k-(y_min-2))+(j)-(x_min-2))] + vol_flux_y[((x_max+4)*(k+1 -(y_min-2))+(j)-(x_min-2))] - vol_flux_y[((x_max+4)*(k-(y_min-2))+(j)-(x_min-2))]; } }

Speedups on 24 cores

Speedups on 24 cores

How does it work?

How does it work?

Example out = 0 for(int i=0; i<n-1; ++i){ out[i+1] = in[i]; } How do

Example out = 0 for(int i=0; i<n-1; ++i){ out[i+1] = in[i]; } How do you prove that the code implies the formula? Induction!

Inductive hypothesis out = 0 for(int i=0; i<n-1; ++i){ out[i+1] = in[i]; } Also

Inductive hypothesis out = 0 for(int i=0; i<n-1; ++i){ out[i+1] = in[i]; } Also called a loop invariant

Proofs about loops •

Proofs about loops •

Abstract view • Verification conditions

Abstract view • Verification conditions

 out = 0 for(int i=0; i<n-1; ++i){ out[i+1] = in[i]; } Loop invariant

out = 0 for(int i=0; i<n-1; ++i){ out[i+1] = in[i]; } Loop invariant

Problem • Invariant and Spec are unknown!

Problem • Invariant and Spec are unknown!

Synthesis problem • Find Spec and invariant that satisfy verification conditions

Synthesis problem • Find Spec and invariant that satisfy verification conditions

12 hrs It can be slow 18000 Synthesis Time (s) 14400 10800 7200 3600

12 hrs It can be slow 18000 Synthesis Time (s) 14400 10800 7200 3600 0 ackl 91 ackl 92 ackl 94 ackl 95 amkl 100 amkl 101 amkl 103 amkl 105 amkl 107 amkl 98 amkl 99 Benchmark div 0 heat 0 grad 0 mgl 5 Synthesis time with parallel synthesis on 24 cores

But we know how to parallelize it

But we know how to parallelize it

Moving forward • Applications • Synthesis as a core tool for a variety of

Moving forward • Applications • Synthesis as a core tool for a variety of problems • Techniques • Data driven synthesis • Leveraging big code • Synthesis for synthesizers