Optimizing Synthesis with Metasketches
James Bornholt Emina Torlak Dan Grossman Luis Ceze
C- n
- m
- c
- R
*
E v a l u a t e d
* P O P L *
A r t i f a c t
* A E C
University of Washington
Optimizing Synthesis f a i c t t r A C o m p * * l e - - PowerPoint PPT Presentation
Optimizing Synthesis f a i c t t r A C o m p * * l e t t n e e * A t * s i W s E n e L o l l C C P D * o O * e c s u P u m e E e R n with Metasketches * o t e v t d y s a E * a d
James Bornholt Emina Torlak Dan Grossman Luis Ceze
C*
E v a l u a t e d
* P O P L *
A r t i f a c t
* A E C
University of Washington
Specification
Program Specification
Program Specification
f(x) = 4x
Program Specification
x+x+x+x f(x) = 4x
Program Specification
x+x+x+x f(x) = 4x
C
p i l a t i
[PLDI’14]
Browser Layout
[ P P
P ’ 1 3 ]
Executable Biology
[POPL’13]
End-user Programming
[POPL’11]
Cache Protocols
[PLDI’13]
Data Structures
[PLDI’15]
Program Specification
Ofuen looking for an
any correct program
C
p i l a t i
[PLDI’14]
Browser Layout
[ P P
P ’ 1 3 ]
Executable Biology
[POPL’13]
End-user Programming
[POPL’11]
Cache Protocols
[PLDI’13]
Data Structures
[PLDI’15]
Program Specification
Ofuen looking for an
any correct program There are many programs, so tools must control search strategy
C
p i l a t i
[PLDI’14]
Browser Layout
[ P P
P ’ 1 3 ]
Executable Biology
[POPL’13]
End-user Programming
[POPL’11]
Cache Protocols
[PLDI’13]
Data Structures
[PLDI’15]
Program Specification
Ofuen looking for an
any correct program There are many programs, so tools must control search strategy
C
p i l a t i
[PLDI’14]
Browser Layout
[ P P
P ’ 1 3 ]
Executable Biology
[POPL’13]
End-user Programming
[POPL’11]
Cache Protocols
[PLDI’13]
Data Structures
[PLDI’15]
Program Specification
Program Specification
Metasketches
Program Specification
Metasketches
A framework that makes search strategy and optimality part of the problem definition
Design and structure
Design and structure
A metasketch solver
Design and structure
Better solutions, faster
A metasketch solver
Design and structure
Better solutions, faster
A metasketch solver
Syntax-guided synthesis
Program Specification
Program Specification
Sketch
Program Specification
Sketch
def f(x): return Expr Expr := x | ?? | Expr op Expr
?? := integer constant
def f(x): return Expr Expr := x | ?? | Expr op Expr
?? := integer constant
def f(x): return Expr Expr := x | ?? | Expr op Expr
?? := integer constant
Counterexample-guided inductive synthesis [Solar-Lezama et al, 2006]
f(x) = 4x
Counterexample-guided inductive synthesis [Solar-Lezama et al, 2006]
f(x) = 4x
Counterexample-guided inductive synthesis [Solar-Lezama et al, 2006]
f(x) = 4x
Counterexample-guided inductive synthesis [Solar-Lezama et al, 2006]
f(x) = 4x
Counterexample-guided inductive synthesis [Solar-Lezama et al, 2006]
f(x) = 4x
Counterexample-guided inductive synthesis [Solar-Lezama et al, 2006]
f(x) = 4x x+x+x+x
Counterexample-guided inductive synthesis [Solar-Lezama et al, 2006]
x+x+x+x
Counterexample-guided inductive synthesis [Solar-Lezama et al, 2006]
x+x+x+x
Counterexample-guided inductive synthesis [Solar-Lezama et al, 2006]
x+x+x+x x << 2
Counterexample-guided inductive synthesis [Solar-Lezama et al, 2006]
Design and structure
Better solutions, faster
A metasketch solver
Syntax-guided synthesis
Design and structure
Better solutions, faster
A metasketch solver
Syntax-guided synthesis
S1 S2 S3 S4 S6 S5 S7
A metasketch contains:
S1 S2 S3 S4 S6 S5 S7
A metasketch contains:
S1 S2 S3 S4 S6 S5 S7
A metasketch contains:
S1 S2 S3 S4 S6 S5 S7
A metasketch contains:
S1 S2 S3 S4 S6 S5 S7
A metasketch contains:
S1 S2 S3 S4 S6 S5 S7
Program
A metasketch contains:
S1 S2 S3 S4 S6 S5 S7
Program
Superoptimizer
A metasketch contains:
S1 S2 S3 S4 S6 S5 S7
Program Optimal Program
Superoptimizer
A metasketch contains:
A fragmentation of the candidate space, and an ordering on those fragments.
def S 𝓣 = set of all SSA programs
A fragmentation of the candidate space, and an ordering on those fragments.
def S
S1 S2 S3 S4 S5 …
𝓣 = set of all SSA programs
A fragmentation of the candidate space, and an ordering on those fragments.
def S
S1 S2 S3 S4 S5 …
𝓣 = set of all SSA programs
A fragmentation of the candidate space, and an ordering on those fragments.
def f(x): r1 = ??op(??{x}) r2 = ??op(??{x,r1}) r3 = ??op(??{x,r1,r2}) return r3 S3 (SSA programs of length 3)
S1 S2 S3 S4 S5 …
𝓣 = set of all SSA programs
A fragmentation of the candidate space, and an ordering on those fragments.
def f(x): r1 = ??op(??{x}) r2 = ??op(??{x,r1}) r3 = ??op(??{x,r1,r2}) return r3 S3 (SSA programs of length 3)
S1 S2 S3 S4 S5 …
𝓣 = set of all SSA programs
+, -, <, if, …
A fragmentation of the candidate space, and an ordering on those fragments.
def f(x): r1 = ??op(??{x}) r2 = ??op(??{x,r1}) r3 = ??op(??{x,r1,r2}) return r3 S3 (SSA programs of length 3)
S1 S2 S3 S4 S5 …
𝓣 = set of all SSA programs
+, -, <, if, … Vars & constants
A fragmentation of the candidate space, and an ordering on those fragments.
S1 S2 S3 S4 S5 …
𝓣 = set of all SSA programs def f(x): r1 = ??op(??{x}) r2 = ??op(??{x,r1}) r3 = ??op(??{x,r1,r2}) return r3 S3 (SSA programs of length 3)
A fragmentation of the candidate space, and an ordering on those fragments.
S1 S2 S3 S4 S5 …
𝓣 = set of all SSA programs def f(x): r1 = ??op(??{x}) r2 = ??op(??{x,r1}) r3 = ??op(??{x,r1,r2}) return r3 S3 (SSA programs of length 3)
Ordering expresses high-level search strategy. A fragmentation of the candidate space, and an ordering on those fragments.
S1 S2 S3 S4 S5 …
𝓣 = set of all SSA programs def f(x): r1 = ??op(??{x}) r2 = ??op(??{x,r1}) r3 = ??op(??{x,r1,r2}) return r3 S3 (SSA programs of length 3)
≼ ≼ ≼ ≼ ≼
Ordering expresses high-level search strategy. Here, ≼ expresses iterative deepening. A fragmentation of the candidate space, and an ordering on those fragments.
𝓣 = set of all SSA programs
A fragmentation of the candidate space, and an ordering on those fragments. def f(x): r1 = ??op(??{x}) r2 = ??op(??{x,r1}) r3 = ??op(??{x,r1,r2}) return r3
S3
def f(x): r1 = ??op(??{x}) r2 = ??op(??{x,r1}) return r2
S2
def f(x): r1 = ??op(??{x}) return r1
S1
…
Implemented as a generator that returns the next sketch in the space
𝓣 = set of all SSA programs Semantics
S1 S4 S5 … S2 S3
𝓣 = set of all SSA programs Semantics
⟦S3⟧ S1 S4 S5 … S2 S3
𝓣 = set of all SSA programs Semantics
⟦S2⟧ ⟦S3⟧ S1 S4 S5 … S2 S3
𝓣 = set of all SSA programs Semantics
⟦S2⟧ ⟦S3⟧
Semantic redundancy in the search space.
S1 S4 S5 … S2 S3
𝓣 = set of all SSA programs Semantics
⟦S2⟧ ⟦S3⟧
Semantic redundancy in the search space.
S1 S4 S5 … S2 S3
Structure constraints eliminate some overlap between sketches
𝓣 = set of all SSA programs Semantics
⟦S2⟧ ⟦S3⟧
Semantic redundancy in the search space.
S1 S4 S5 … S2 S3
Structure constraints eliminate some overlap between sketches
def f(x): r1 = ??op(??{x}) r2 = ??op(??{x,r1}) r3 = ??op(??{x,r1,r2}) return r3 S3 (SSA programs of length 3)
𝓣 = set of all SSA programs Semantics
⟦S2⟧ ⟦S3⟧
Semantic redundancy in the search space.
S1 S4 S5 … S2 S3
Structure constraints eliminate some overlap between sketches Eliminate dead-code redundancy: assert that each ri is read
def f(x): r1 = ??op(??{x}) r2 = ??op(??{x,r1}) r3 = ??op(??{x,r1,r2}) return r3 S3 (SSA programs of length 3)
𝓣 = set of all SSA programs
S1 S4 S5 … S2 S3
κ : 𝓜 → ℝ assigns a numeric cost to each program in the language 𝓜
≼ ≼ ≼ ≼ ≼
𝓣 = set of all SSA programs
S1 S4 S5 … S2 S3
κ : 𝓜 → ℝ assigns a numeric cost to each program in the language 𝓜
Cost functions can be based
(dynamic behavior)
≼ ≼ ≼ ≼ ≼
𝓣 = set of all SSA programs
S1 S4 S5 … S2 S3
κ : 𝓜 → ℝ assigns a numeric cost to each program in the language 𝓜 κ(P) = i for P ∈ Si ∈ 𝓣
The number of variables defined in P
≼ ≼ ≼ ≼ ≼
Cost functions can be based
(dynamic behavior)
𝓣 = set of all SSA programs
S1 S4 S5 … S2 S3
κ(P) = i for P ∈ Si ∈ 𝓣 g : ℝ → 2𝓣 g(c) is the set of sketches in 𝓣 that may contain a solution P with κ(P) < c
≼ ≼ ≼ ≼ ≼
𝓣 = set of all SSA programs
S1 S4 S5 … S2 S3
κ(P) = i for P ∈ Si ∈ 𝓣 g : ℝ → 2𝓣 g(c) is the set of sketches in 𝓣 that may contain a solution P with κ(P) < c
The gradient function
behavior of κ on 𝓣
≼ ≼ ≼ ≼ ≼
𝓣 = set of all SSA programs
S1 S4 S5 … S2 S3
κ(P) = i for P ∈ Si ∈ 𝓣 g : ℝ → 2𝓣 g(c) is the set of sketches in 𝓣 that may contain a solution P with κ(P) < c
The gradient function
behavior of κ on 𝓣
g(c) = { Si ∈ 𝓣 | i < c }
≼ ≼ ≼ ≼ ≼
𝓣 = set of all SSA programs
S1 S4 S5 … S2 S3
κ(P) = i for P ∈ Si ∈ 𝓣 g : ℝ → 2𝓣 g(c) is the set of sketches in 𝓣 that may contain a solution P with κ(P) < c
The gradient function
behavior of κ on 𝓣
g(c) = { Si ∈ 𝓣 | i < c }
g(4) = {S1, S2, S3}
≼ ≼ ≼ ≼ ≼
𝓣 = set of all SSA programs
S1 S4 S5 … S2 S3
κ(P) = i for P ∈ Si ∈ 𝓣 g : ℝ → 2𝓣 g(c) is the set of sketches in 𝓣 that may contain a solution P with κ(P) < c
The gradient function
behavior of κ on 𝓣
g(c) = { Si ∈ 𝓣 | i < c }
g(4) = {S1, S2, S3}
≼ ≼ ≼ ≼ ≼
Always sound for g to return all of 𝓣 if a tighter bound is unavailable.
𝓣 = set of all SSA programs
S1 S4 S5 … S2 S3
κ(P) = i for P ∈ Si ∈ 𝓣 g : ℝ → 2𝓣 g(c) is the set of sketches in 𝓣 that may contain a solution P with κ(P) < c
The gradient function
behavior of κ on 𝓣
g(c) = { Si ∈ 𝓣 | i < c }
g(4) = {S1, S2, S3}
≼ ≼ ≼ ≼ ≼
Always sound for g to return all of 𝓣 if a tighter bound is unavailable. g(c) always being finite is sufficient (not necessary) to guarantee termination.
Design and structure
𝓣 = set of all SSA programs
S1 S4 S5 … S2 S3
κ(P) = i for P ∈ Si ∈ 𝓣
≼ ≼ ≼ ≼ ≼
g(c) = { Si ∈ 𝓣 | i < c }
Design and structure
Better solutions, faster
A metasketch solver
Syntax-guided synthesis
Design and structure
Better solutions, faster
A metasketch solver
Syntax-guided synthesis
Global search Local search Local search Local search
⟨𝓣, ≼, κ, g⟩ ...
Coordinates the search for an optimal solution,
local searches
Global search Local search Local search Local search
⟨𝓣, ≼, κ, g⟩ ...
Coordinates the search for an optimal solution,
local searches An incremental form of CEGIS that can accept new information from the global search
Global search Local search Local search
⟨𝓣, ≼, κ, g⟩
S1 S2 S3 S4 S6 S5 S7
Local search Local search
Global search Local search Local search
⟨𝓣, ≼, κ, g⟩
S1 S2 S3 S4 S6 S5 S7
Local search Local search
Global search Local search Local search
⟨𝓣, ≼, κ, g⟩
UNSAT
S1 S2 S3 S4 S6 S5 S7
Local search
S2
Local search
Global search Local search Local search
⟨𝓣, ≼, κ, g⟩
UNSAT
S1 S2 S3 S4 S6 S5 S7
Local search
S2
Local search
Global search Local search Local search
⟨𝓣, ≼, κ, g⟩
S1 S3 S4 S6 S5 S7
Local search Local search
SAT (P)
Global search Local search Local search
⟨𝓣, ≼, κ, g⟩
S1 S3 S4 S6 S5 S7
Local search Local search
SAT (P)
Global search Local search Local search
⟨𝓣, ≼, κ, g⟩
S1 S3 S4 S6 S5 S7
Local search Local search
Global search Local search Local search
⟨𝓣, ≼, κ, g⟩
κ(P) κ(P)
S1 S3 S4 S6 S5 S7
Local search
κ(P)
Local search
Global search Local search Local search
⟨𝓣, ≼, κ, g⟩
κ(P) κ(P)
S1 S3 S4 S6 S5 S7
Local search
κ(P)
Prune local search spaces using κ(P)
Local search
S3
Global search Local search Local search
⟨𝓣, ≼, κ, g⟩
κ(P) κ(P)
S6 S5 S7
Local search
κ(P)
S1 S4 Prune local search spaces using κ(P)
Local search
S3
Global search Local search Local search
⟨𝓣, ≼, κ, g⟩
κ(P) κ(P)
S6 S5 S7
Local search
κ(P)
S1 S4 Prune local search spaces using κ(P) Prune global search space using g(κ(P))
Local search
S3
Global search Local search Local search
⟨𝓣, ≼, κ, g⟩
κ(P) κ(P)
S6 S5
Local search
κ(P)
S1 S4 Prune local search spaces using κ(P) Prune global search space using g(κ(P))
Local search
S3
Global search Local search Local search
⟨𝓣, ≼, κ, g⟩
κ(P) κ(P)
S6 S5
Local search
κ(P)
S1 S4 Prune local search spaces using κ(P) Prune global search space using g(κ(P)) Continues until all search spaces exhausted, yielding an optimal solution.
Local search
Implemented in Rosette, a solver-aided extension of Racket
Global search Local search Local search Local search
⟨𝓣, ≼, κ, g⟩ ...
Implemented in Rosette, a solver-aided extension of Racket Local CEGIS searches can share counterexamples
Global search Local search Local search Local search
⟨𝓣, ≼, κ, g⟩ ...
Implemented in Rosette, a solver-aided extension of Racket Local CEGIS searches can share counterexamples Local searches can time out, which weakens optimality
Global search Local search Local search Local search
⟨𝓣, ≼, κ, g⟩ ...
Design and structure
Better solutions, faster
A metasketch solver
Syntax-guided synthesis
Design and structure
Better solutions, faster
A metasketch solver
Syntax-guided synthesis
Is Synapse a practical approach to solving different kinds of synthesis problems?
Approximate computing, array programs
Is Synapse a practical approach to solving different kinds of synthesis problems?
Approximate computing, array programs
Can Synapse reason about complex cost functions?
Is Synapse a practical approach to solving different kinds of synthesis problems?
Approximate computing, array programs
Can Synapse reason about complex cost functions? In the paper:
Parrot benchmarks from approximate computing [Esmaelizadeh et al., 2012] Find the most efficient approximate program within an error bound
10 100 1000 10000
fft−cos fft−sin inversek2j−1 inversek2j−2 kmeans sobel−x sobel−y
Solving time (secs)
Parrot benchmarks from approximate computing [Esmaelizadeh et al., 2012] Find the most efficient approximate program within an error bound
10 100 1000 10000
fft−cos fft−sin inversek2j−1 inversek2j−2 kmeans sobel−x sobel−y
Solving time (secs)
Parrot benchmarks from approximate computing [Esmaelizadeh et al., 2012] Find the most efficient approximate program within an error bound
All intractable to Sketch and Stoke
Array Search benchmarks from the syntax-guided synthesis (SyGuS) competition [Alur et al., 2015] arraysearch-n: find program that searches lists of length n
10 100 1000 10000
fft−cos fft−sin inversek2j−1 inversek2j−2 kmeans sobel−x sobel−y
Solving time (secs)
arraysearch−2 arraysearch−3 arraysearch−4 arraysearch−5 arraysearch−6 arraysearch−7 arraysearch−8 arraysearch−9 arraysearch−10 arraysearch−11 arraysearch−12 arraysearch−13 arraysearch−14 arraysearch−15
Array Search benchmarks from the syntax-guided synthesis (SyGuS) competition [Alur et al., 2015] arraysearch-n: find program that searches lists of length n
10 100 1000 10000
fft−cos fft−sin inversek2j−1 inversek2j−2 kmeans sobel−x sobel−y
Solving time (secs)
arraysearch−2 arraysearch−3 arraysearch−4 arraysearch−5 arraysearch−6 arraysearch−7 arraysearch−8 arraysearch−9 arraysearch−10 arraysearch−11 arraysearch−12 arraysearch−13 arraysearch−14 arraysearch−15
Synapse: 349 bytes SyGuS: 7.1 MB
Array Search benchmarks from the syntax-guided synthesis (SyGuS) competition [Alur et al., 2015] arraysearch-n: find program that searches lists of length n
?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ??
?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ??
κ(P) =
X
i
|P(xi) − yi|
Classification error executes the program for each point in the training set
Design and structure
Better solutions, faster
A metasketch solver
Design and structure
Better solutions, faster
A metasketch solver