New applications of program synthesis

Slides:



Advertisements
Similar presentations
_Synthesis__________________ __Of_______________________ ___First-Order_____Dynamic___ _____________Programming___ _______________Algorithms___ Yewen (Evan)
Advertisements

Technology from seed Automatic Equivalence Checking of UF+IA Programs Nuno Lopes and José Monteiro.
Constraint Based Synthesis for Beginners PSY 2012 Armando Solar-Lezama.
Software Engineering & Automated Deduction Willem Visser Stellenbosch University With Nikolaj Bjorner (Microsoft Research, Redmond) Natarajan Shankar (SRI.
Rigorous Software Development CSCI-GA Instructor: Thomas Wies Spring 2012 Lecture 13.
ISBN Chapter 3 Describing Syntax and Semantics.
The Future of Correct Software George Necula. 2 Software Correctness is Important ► Where there is software, there are bugs ► It is estimated that software.
From last time S1: l := new Cons p := l S2: t := new Cons *p := t p := t l p S1 l p tS2 l p S1 t S2 l t S1 p S2 l t S1 p S2 l t S1 p L2 l t S1 p S2 l t.
Describing Syntax and Semantics
Session-01. Hibernate Framework ? Why we use Hibernate ?
Making Database Applications Perform Using Program Analysis Alvin Cheung Samuel Madden Armando Solar-Lezama MIT Owen Arden Andrew C. Myers Cornell.
SYSTEMS SUPPORT FOR GRAPHICAL LEARNING Ken Birman 1 CS6410 Fall /18/2014.
Templates of slides for P3 1. A brief update on your problem (important) Describe in English -what artifacts (programs, etc) will you synthesize, -what.
Relational Verification to SIMD Loop Synthesis Mark Marron – IMDEA & Microsoft Research Sumit Gulwani – Microsoft Research Gilles Barthe, Juan M. Crespo,
Have Your Verified Compiler And Extend It Too Zachary Tatlock Sorin Lerner UC San Diego.
From Program Verification to Program Synthesis Saurabh Srivastava * Sumit Gulwani ♯ Jeffrey S. Foster * * University of Maryland, College Park ♯ Microsoft.
Query optimization in relational DBs Leveraging the mathematical formal underpinnings of the relational model.
Generative Programming Meets Constraint Based Synthesis Armando Solar-Lezama.
Outline Announcements: –Homework I on web, due Fri., 5PM by –Small error on homework –Wed and Fri in ACCEL, Attendance required –LAST DAY TO ADD/DROP!
Programming Models & Runtime Systems Breakout Report MICS PI Meeting, June 27, 2002.
Enabling Refinement with Synthesis Armando Solar-Lezama with work by Zhilei Xu and many others*
Synthesis with the Sketch System D AY 1 Armando Solar-Lezama.
Chapter 3 Part II Describing Syntax and Semantics.
Storyboard Programming Rishabh Singh and Armando Solar-Lezama.
CSC310 © Tom Briggs Shippensburg University Fundamentals of the Analysis of Algorithm Efficiency Chapter 2.
More on Correctness. Prime Factorization Problem: Write a program that computes all the prime factors of a given number Solution (Idea): Factors are less.
Synthesis with the Sketch System D AY 2 Armando Solar-Lezama.
1/6/20161 CS 3343: Analysis of Algorithms Lecture 2: Asymptotic Notations.
Static Techniques for V&V. Hierarchy of V&V techniques Static Analysis V&V Dynamic Techniques Model Checking Simulation Symbolic Execution Testing Informal.
CIS 540 Principles of Embedded Computation Spring Instructor: Rajeev Alur
September 1999Compaq Computer CorporationSlide 1 of 16 Verification of cache-coherence protocols with TLA+ Homayoon Akhiani, Damien Doligez, Paul Harter,
CSC3315 (Spring 2009)1 CSC 3315 Languages & Compilers Hamid Harroud School of Science and Engineering, Akhawayn University
C HAPTER 3 Describing Syntax and Semantics. D YNAMIC S EMANTICS Describing syntax is relatively simple There is no single widely acceptable notation or.
Compilers: History and Context COMP Outline Compilers and languages Compilers and architectures – parallelism – memory hierarchies Other uses.
Support for Program Analysis as a First-Class Design Constraint in Legion Michael Bauer 02/22/17.
Chapter 1 Introduction.
Further with Hoare Logic Sections 6.12, 6.10, 6.13
Learning Invariants using Decision Trees and Implication Counterexamples Pranav Garg Amazon India.
Types for Programs and Proofs
Introduction to Sketching
Topic: Difference b/w JDK, JRE, JIT, JVM
CSC 221: Computer Programming I Fall 2005
Database Applications (15-415) DBMS Internals- Part VII Lecture 16, October 25, 2016 Mohammad Hammoud.
Harry Xu University of California, Irvine & Microsoft Research
Reasoning About Code.
Reasoning about code CSE 331 University of Washington.
Chapter 1 Introduction.
Introduction to Algorithms
Optimizing Big-Data Queries using Program Synthesis
Application Development Theory
Introduction to Sketching
State your reasons or how to keep proofs while optimizing code
CS 3343: Analysis of Algorithms
Chapter 15 QUERY EXECUTION.
Making synthesis practical Are we there yet?
Lecture 6 Inductive Synthesis
Lecture 8 Functional synthesis
Relational Operations
Lecture 5 Floyd-Hoare Style Verification
Compiler Back End Panel
Benjamin Goldberg Compiler Verification and Optimization
Compiler Back End Panel
Yikes! Why is my SystemVerilog Testbench So Slooooow?
Resolution Proofs for Combinational Equivalence
Templates of slides for P4 Experiments with your synthesizer
Evaluation of Relational Operations: Other Techniques
CUTE: A Concolic Unit Testing Engine for C
_Synthesis__________________ __Of_______________________ ___First-Order_____Dynamic___ _____________Programming___ _______________Algorithms___ Yewen (Evan)
Translating Imperative Code into SQL
Jiasi Shen, Martin Rinard MIT EECS & CSAIL
Presentation transcript:

New applications of program synthesis Armando Solar-Lezama

Synthesis: 1980s view Complete Formal Specification

Synthesis: modern view 𝑅={ 𝑝 0 … 𝑝 𝑖 } Space of programs 𝜑 𝑝 = 𝜑 1 𝑝 ∧𝜑 2 𝑝 ∧ 𝜑 3 𝑝 ∧ 𝜑 4 𝑝 Reference Implementation Input/Output Examples Test Harnesses 𝜑 𝑝 =∀𝑖𝑛. … 𝑝(𝑖𝑛)…

Example Sketch Spec bit[W] avg(bit[W] x, bit[W] y) implements avgSpec{ return expr@signed({x,y}, 4); } Spec bit[W] avgSpec(bit[W] x, bit[W] y){ bit[2*W] xx = extend@signed(x, 2*W); bit[2*W] yy = extend@signed(y, 2*W); 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! Now can you synthesize programs with more than 1 line of code?

Synthesis of distributed memory algorithms (SC14) 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 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-4K 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?

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

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

Optimization with synthesis

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

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

Java to SQL convert to SELECT * FROM user List getUsersWithRoles () { List users = User.getAllUsers(); List roles = Role.getAllRoles(); List results = new ArrayList(); for (User u : users) { for (Role r : roles) { if (u.roleId == r.id) results.add(u); }} return results; } SELECT * FROM role How bad is the situation? Here is an example from a real-world aplication What the dev didn’t know is that the first two method calls actually fetch records from the db, as a result when the outer loop is executed a query will be sent to the db, and likewise for the inner one To speed things up we could have rewritten this code snippet using a simple SQL query as shown here List getUsersWithRoles () {   return executeQuery( “SELECT u FROM user u, role r WHERE u.roleId == r.id ORDER BY u.roleId, r.id”; } convert to

Join Query Nested-loop join  Hash join! O(n2) O(n) Original scales up quadratically as database size increases There are more experiments in our paper and I invite you to check them out 6/17/2013 PLDI 2013

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

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

Beyond SQL Synthesis Proof of Equivalence Source Code DSL Program This is a general idea Synthesis Proof of Equivalence Source Code 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 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))]; } ∀ 𝑗,𝑘 ∈𝐷𝑜𝑚 post_vol[j,k] = volume[j,k] + vol_flux[j,k+1] + vol_flux[j,k]

Speedups Speedups on 24 cores

How does it work?

Example Induction! How do you prove that the code implies the formula? out = 0 for(int i=0; i<n-1; ++i){ out[i+1] = in[i]; } ∀𝑖𝑑𝑥, 𝑖𝑛, 𝑛. 𝑜𝑢𝑡 𝑖𝑑𝑥 = 𝑖𝑑𝑥∈ 1,𝑛 𝑖𝑛 𝑖𝑑𝑥−1 𝑒𝑙𝑠𝑒 0 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]; } 0≤𝑖≤𝑛−1 ∀𝑗∈[1,𝑖] 𝑜𝑢𝑡 𝑗 =𝑖𝑛 𝑗−1 ∀𝑗∉ 1,𝑖 𝑜𝑢𝑡 𝑗 =0 Also called a loop invariant

Proofs about loops Base case: Invariant holds at step zero Inductive case: If invariant holds at i, it holds at i+1 Invariant ⇒ Spec

Abstract view Verification conditions Base case: 𝐼𝑛𝑣𝑎𝑟𝑖𝑎𝑛𝑡 𝑠𝑡𝑎𝑡 𝑒 0 Inductive case: ∀ 𝑠𝑡𝑎𝑡𝑒. 𝐼𝑛𝑣𝑎𝑟𝑖𝑎𝑛𝑡 𝑠𝑡𝑎𝑡𝑒 ∧𝑐𝑜𝑛𝑑 𝑠𝑡𝑎𝑡𝑒 ⇒𝐼𝑛𝑣𝑎𝑟𝑖𝑎𝑛𝑡(𝑢𝑝𝑑𝑎𝑡𝑒 𝑠𝑡𝑎𝑡𝑒 ) Invariant ⇒ Spec ∀ 𝑠𝑡𝑎𝑡𝑒. 𝐼𝑛𝑣𝑎𝑟𝑖𝑎𝑛𝑡 𝑠𝑡𝑎𝑡𝑒 ∧¬𝑐𝑜𝑛𝑑 𝑠𝑡𝑎𝑡𝑒 ⇒𝑆𝑝𝑒𝑐(𝑠𝑡𝑎𝑡𝑒)

Invariant ⇒ Spec ∀ 𝑖, 𝑛, 𝑜𝑢𝑡, 𝑖𝑛, 𝑖𝑑𝑥 ∧ 𝑖≥𝑛−1 out = 0 for(int i=0; i<n-1; ++i){ out[i+1] = in[i]; } 0≤𝑖≤𝑛−1 ∀𝑗∈[1,𝑖] 𝑜𝑢𝑡 𝑗 =𝑖𝑛 𝑗−1 ∀𝑗∉ 1,𝑖 𝑜𝑢𝑡 𝑗 =0 Loop invariant ⇒ 𝑜𝑢𝑡 𝑖𝑑𝑥 = 𝑖𝑑𝑥∈ 1,𝑛 𝑖𝑛 𝑖𝑑𝑥−1 𝑒𝑙𝑠𝑒 0 𝑜𝑢𝑡=𝑒𝑥𝑝𝑟 ∀ 𝑖, 𝑛, 𝑜𝑢𝑡, 𝑖𝑛, 𝑖𝑑𝑥 ∧ 𝑖≥𝑛−1 ¬loopCond

Problem Invariant and Spec are unknown! Base case: 𝐼𝑛𝑣𝑎𝑟𝑖𝑎𝑛𝑡 𝑠𝑡𝑎𝑡 𝑒 0 Inductive case: ∀ 𝑠𝑡𝑎𝑡𝑒. 𝐼𝑛𝑣𝑎𝑟𝑖𝑎𝑛𝑡 𝑠𝑡𝑎𝑡𝑒 ∧𝑐𝑜𝑛𝑑 𝑠𝑡𝑎𝑡𝑒 ⇒𝐼𝑛𝑣𝑎𝑟𝑖𝑎𝑛𝑡(𝑢𝑝𝑑𝑎𝑡𝑒 𝑠𝑡𝑎𝑡𝑒 ) Invariant ⇒ Spec ∀ 𝑠𝑡𝑎𝑡𝑒. 𝐼𝑛𝑣𝑎𝑟𝑖𝑎𝑛𝑡 𝑠𝑡𝑎𝑡𝑒 ∧¬𝑐𝑜𝑛𝑑 𝑠𝑡𝑎𝑡𝑒 ⇒𝑆𝑝𝑒𝑐(𝑠𝑡𝑎𝑡𝑒) Invariant and Spec are unknown!

Synthesis problem Spec ∀ 𝑗,𝑘 ∈𝐷𝑜𝑚 out[j,k] = Expr({in[i+??,j+??]}) ... Invariant ∀ 𝑗,𝑘 ∈𝐷𝑜𝑚 out[j,k] = Expr({in[i+??,j+??]}) ... Find Spec and invariant that satisfy verification conditions

It can be slow Synthesis time with parallel synthesis on 24 cores 12 hrs Synthesis time with parallel synthesis on 24 cores

But we know how to parallelize it

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