SLIDE 1 Scaling Program Synthesis by Exploiting Existing Code
James Bornholt Emina Torlak
University of Washington
SLIDE 2
Synthesis: write programs automatically
Semantics Syntax
SLIDE 3
Synthesis: write programs automatically
Semantics Syntax
SLIDE 4 Synthesis: write programs automatically
Target Behavior
Semantics Syntax
f(x) = 4x + 1
SLIDE 5 Synthesis: write programs automatically
Target Behavior 4*x + 1
Semantics Syntax
f(x) = 4x + 1
SLIDE 6 Synthesis: write programs automatically
Target Behavior x + x + x + x + 1 4*x + 1
Semantics Syntax
f(x) = 4x + 1
(x<<2) + 1
SLIDE 7 Synthesis: write programs automatically
Target Behavior
Semantics Syntax
Permutation(L, f(L)) ∧ Sorted(f(L))
SLIDE 8 Synthesis: write programs automatically
Target Behavior
Semantics Syntax
Permutation(L, f(L)) ∧ Sorted(f(L))
Quicksort Bubble Sort
SLIDE 9 The success of synthesis
End-user programming by example [FlashFill, POPL’11] Cache coherence protocols
[Transit, PLDI’13]
Parallel browser layout engines [PPoPP’13] Compilers for new spatial architectures [Chlorophyll, PLDI’14]
SLIDE 10 The success of synthesis
End-user programming by example [FlashFill, POPL’11] Cache coherence protocols
[Transit, PLDI’13]
Parallel browser layout engines [PPoPP’13] Compilers for new spatial architectures [Chlorophyll, PLDI’14]
S y n t h e s i s
turns
h i g h
e v e l i n t e n t
into
l
e v e l d e t a i l
SLIDE 11 The success of synthesis
End-user programming by example [FlashFill, POPL’11] Cache coherence protocols
[Transit, PLDI’13]
Parallel browser layout engines [PPoPP’13] Compilers for new spatial architectures [Chlorophyll, PLDI’14]
S y n t h e s i s
turns
h i g h
e v e l i n t e n t
into
l
e v e l d e t a i l
Approximate Computing
quality bounds
into
approximate programs
SLIDE 12 The success of synthesis
End-user programming by example [FlashFill, POPL’11] Cache coherence protocols
[Transit, PLDI’13]
Parallel browser layout engines [PPoPP’13] Compilers for new spatial architectures [Chlorophyll, PLDI’14]
S y n t h e s i s
turns
h i g h
e v e l i n t e n t
into
l
e v e l d e t a i l
Approximate Computing
quality bounds
into
approximate programs
Hardware Synthesis
programs
into
hardware designs
SLIDE 13 The success of synthesis
End-user programming by example [FlashFill, POPL’11] Cache coherence protocols
[Transit, PLDI’13]
Parallel browser layout engines [PPoPP’13] Compilers for new spatial architectures [Chlorophyll, PLDI’14]
S y n t h e s i s
turns
h i g h
e v e l i n t e n t
into
l
e v e l d e t a i l
Approximate Computing
quality bounds
into
approximate programs
Hardware Synthesis
programs
into
hardware designs
Black Box Systems
into
specifjcations
SLIDE 14 Not all applications require perfect accuracy
Approximate Computing
quality bounds
into
approximate programs
SLIDE 15 Not all applications require perfect accuracy
Approximate Computing
quality bounds
into
approximate programs
SLIDE 16 Not all applications require perfect accuracy
Approximate Computing
quality bounds
into
approximate programs
Video and image quality
SLIDE 17 Not all applications require perfect accuracy
Approximate Computing
quality bounds
into
approximate programs
Video and image quality Sensors and simulation Machine learning
SLIDE 18 Not all applications require perfect accuracy
Approximate Computing
quality bounds
into
approximate programs Precise Implementation
SLIDE 19 Not all applications require perfect accuracy
Approximate Computing
quality bounds
into
approximate programs Precise Implementation Desired Quality
SLIDE 20 Not all applications require perfect accuracy
Approximate Computing
quality bounds
into
approximate programs
Approximate Compiler
Precise Implementation Desired Quality
SLIDE 21 Not all applications require perfect accuracy
Approximate Computing
quality bounds
into
approximate programs
Approximate Compiler
Precise Implementation Desired Quality Approximate Program
SLIDE 22 Not all applications require perfect accuracy
Approximate Computing
quality bounds
into
approximate programs
Approximate Program Synthesis†
Precise Implementation Desired Quality Approximate Program
† Bornholt, Torlak, Ceze, Grossman. Approximate Program Synthesis. At WAX’15, collocated with PLDI’15.
SLIDE 23 Hardware Synthesis
programs
into
hardware designs
Synthesizing circuits from high-level languages
SLIDE 24 Hardware Synthesis
programs
into
hardware designs
Synthesizing circuits from high-level languages
module example(input a, b, c, output y); assign y = ~a & ~b & ~c | a & ~b & ~c | a & ~b & c; endmodule
SLIDE 25 Hardware Synthesis
programs
into
hardware designs
Synthesizing circuits from high-level languages
module example(input a, b, c, output y); assign y = ~a & ~b & ~c | a & ~b & ~c | a & ~b & c; endmodule
SLIDE 26 Hardware Synthesis
programs
into
hardware designs
Synthesizing circuits from high-level languages
module example(input a, b, c, output y); assign y = ~a & ~b & ~c | a & ~b & ~c | a & ~b & c; endmodule
SLIDE 27 Hardware Synthesis
programs
into
hardware designs
Synthesizing circuits from high-level languages
High-Level Synthesis (HLS)
SLIDE 28 Hardware Synthesis
programs
into
hardware designs
Synthesizing circuits from high-level languages
High-Level Synthesis (HLS)
Place and route Timing closure Crosstalk and feedback Quantum!
SLIDE 29 Hardware Synthesis
programs
into
hardware designs
Synthesizing circuits from high-level languages
Mark Wyse
UW grad student and HLS extraordinaire
SLIDE 30 Hardware Synthesis
programs
into
hardware designs
Synthesizing circuits from high-level languages
float dist(float a[3], float b[3]) { float r = 0; r += (a[0] - b[0]) * (a[0] - b[0]); r += (a[1] - b[1]) * (a[1] - b[1]); r += (a[2] - b[2]) * (a[2] - b[2]); return sqrt(r); }
Mark Wyse
UW grad student and HLS extraordinaire
SLIDE 31 Black Box Systems
into
specifjcations
Defjning system behavior by observation
SLIDE 32 Black Box Systems
into
specifjcations
Defjning system behavior by observation
SLIDE 33 Black Box Systems
into
specifjcations
Defjning system behavior by observation
SLIDE 34 Black Box Systems
into
specifjcations
Defjning system behavior by observation
SLIDE 35 Black Box Systems
into
specifjcations
Defjning system behavior by observation
Programming by example
SLIDE 36 Black Box Systems
into
specifjcations
Defjning system behavior by observation
Programming by example Synthesizing x86 instruction specs
Godefroid and Taly. Automated Synthesis of Symbolic Instruction Encodings from I/O Samples. PLDI’12.
SLIDE 37 Black Box Systems
into
specifjcations
Approximate Computing
quality bounds
into
approximate programs
Hardware Synthesis
programs
into
hardware designs
SLIDE 38
Machine Learning and Synthesis
SLIDE 39 Learning programs from examples
Black Box Systems
into
specifjcations
∃P. ^
xi∈X
ϕ(xi, P(xi))
SLIDE 40 Learning programs from examples
Black Box Systems
into
specifjcations
∃P. ^
xi∈X
ϕ(xi, P(xi))
FlashFill
SLIDE 41
Learning programs from examples
FlashFill Version Space Algebra
SLIDE 42
Machine learning and synthesis
Program Synthesis Statistical Machine Learning
SLIDE 43
Machine learning and synthesis
Program Synthesis Statistical Machine Learning
Millions of examples/parameters
SLIDE 44
Machine learning and synthesis
Program Synthesis Statistical Machine Learning
Millions of examples/parameters 100 instructions
SLIDE 45 Machine learning and synthesis
Program Synthesis Statistical Machine Learning
Millions of examples/parameters 100 instructions
Approximate Computing Hardware Synthesis Black Box Systems
SLIDE 46 Machine learning and synthesis
Program Synthesis Statistical Machine Learning
Millions of examples/parameters 100 instructions
Approximate Computing Hardware Synthesis Black Box Systems
SLIDE 47
Programs are not uniformly distributed.
SLIDE 48 Programs are not uniformly distributed.
Stack Overfmow mentions 20000 40000 60000 80000 malloc longjmp
SLIDE 49 Programs are not uniformly distributed.
Stack Overfmow mentions 20000 40000 60000 80000 malloc longjmp
SLIDE 50 Programs are not uniformly distributed.
Stack Overfmow mentions 20000 40000 60000 80000 malloc longjmp
SLIDE 51 Programs are not uniformly distributed.
Stack Overfmow mentions 20000 40000 60000 80000 malloc longjmp mov
call
push
mov call test jmp lea push sub
SLIDE 52
Component-Based Synthesis
SLIDE 53 Synthesis of Loop-Free Programs
Gulwani, Jha, Tiwari, and Venkatesan. Synthesis of loop-free programs. PLDI’11.
SLIDE 54 Synthesis of Loop-Free Programs
Gulwani, Jha, Tiwari, and Venkatesan. Synthesis of loop-free programs. PLDI’11.
f(x, y) = x + y 2 ⌫
SLIDE 55 Synthesis of Loop-Free Programs
Gulwani, Jha, Tiwari, and Venkatesan. Synthesis of loop-free programs. PLDI’11.
f(x, y) = x + y 2 ⌫
and xor add >> 1
SLIDE 56 Synthesis of Loop-Free Programs
Gulwani, Jha, Tiwari, and Venkatesan. Synthesis of loop-free programs. PLDI’11.
f(x, y) = x + y 2 ⌫
and xor add >> 1 x y
SLIDE 57 Synthesis of Loop-Free Programs
Gulwani, Jha, Tiwari, and Venkatesan. Synthesis of loop-free programs. PLDI’11.
f(x, y) = x + y 2 ⌫
and xor add >> 1 x y f(x,y)
SLIDE 58 Synthesis of Loop-Free Programs
Gulwani, Jha, Tiwari, and Venkatesan. Synthesis of loop-free programs. PLDI’11.
f(x, y) = x + y 2 ⌫
and xor add >> 1 x y f(x,y)
SLIDE 59 Synthesis of Loop-Free Programs
f(x, y) = x + y 2 ⌫
and xor add >> 1
Gulwani, Jha, Tiwari, and Venkatesan. Synthesis of loop-free programs. PLDI’11.
SLIDE 60 lt gt
Synthesis of Loop-Free Programs
f(x, y) = x + y 2 ⌫
and xor add >> 1 sub mul div udiv rem urem
nand not neg << 1 >>> 1 << 2 eq le ge
Gulwani, Jha, Tiwari, and Venkatesan. Synthesis of loop-free programs. PLDI’11.
SLIDE 61 lt gt
Synthesis of Loop-Free Programs
f(x, y) = x + y 2 ⌫
and xor add >> 1 sub mul div udiv rem urem
nand not neg << 1 >>> 1 << 2 eq le ge
Gulwani, Jha, Tiwari, and Venkatesan. Synthesis of loop-free programs. PLDI’11. Solving time (secs) 500 1000 1500 2000 Number of components 4 8 12 16
SLIDE 62 lt gt
Higher-level components
and xor add >> 1 sub mul div udiv rem urem
nand not neg << 1 >>> 1 << 2 eq le ge
f(L) = min{li | li ∈ L}
SLIDE 63
Higher-level components
f(L) = min{li | li ∈ L}
SLIDE 64
Higher-level components
f(L) = min{li | li ∈ L}
quicksort [ ]
SLIDE 65
Higher-level components
f(L) = min{li | li ∈ L}
quicksort f(L) = quicksort(L)[0] [ ]
SLIDE 66
Higher-level components
f(L) = min{li | li ∈ L}
quicksort f(L) = quicksort(L)[0] [ ] Mine existing code bases for common idioms
SLIDE 67 Higher-level components
f(L) = min{li | li ∈ L}
quicksort f(L) = quicksort(L)[0] [ ] Mine existing code bases for common idioms Hardware Synthesis
programs
into
hardware designs
SLIDE 68
Producing candidate programs
f(x, y) = x + y 2 ⌫
and xor add >> 1 x y f(x,y)
SLIDE 69
Producing candidate programs
f(x, y) = x + y 2 ⌫
and xor add >> 1 x y
SLIDE 70 Producing candidate programs
f(x, y) = x + y 2 ⌫
and xor add >> 1 x y
mov
call
push
mov call test jmp lea push sub
SLIDE 71 Producing candidate programs
f(x, y) = x + y 2 ⌫
and xor add >> 1 x y Learn search heuristics from existing code
mov
call
push
mov call test jmp lea push sub
SLIDE 72 Producing candidate programs
f(x, y) = x + y 2 ⌫
and xor add >> 1 x y Learn search heuristics from existing code Programming by example
[FlashFill, POPL’11]
Autocomplete with synthesis
[CodeHint, ICSE’14]
mov
call
push
mov call test jmp lea push sub
SLIDE 73 Producing candidate programs
f(x, y) = x + y 2 ⌫
and xor add >> 1 x y Learn search heuristics from existing code Programming by example
[FlashFill, POPL’11]
Autocomplete with synthesis
[CodeHint, ICSE’14] Mine existing code bases for common idioms
mov
call
push
mov call test jmp lea push sub
SLIDE 74 Producing candidate programs
Learn search heuristics from existing code
Mine existing code bases for common idioms
Black Box Systems
into
specifjcations
Selecting among many candidate solutions
SLIDE 75
Sketch-Based Synthesis
SLIDE 76
Sketches make synthesis more tractable
SLIDE 77
Sketches make synthesis more tractable
bit[W] popCount(bit[W] x) { x = (x & 0x5555) + ((x >> 1) & 0x5555); x = (x & 0x3333) + ((x >> 2) & 0x3333); x = (x & 0x0077) + ((x >> 8) & 0x0077); x = (x & 0x000F) + ((x >> 4) & 0x000F); return x; }
SLIDE 78
Sketches make synthesis more tractable
bit[W] popSketched(bit[W] x) { loop (??) { x = (x & ??) + ((x >> ??) & ??); } return x; } bit[W] popCount(bit[W] x) { x = (x & 0x5555) + ((x >> 1) & 0x5555); x = (x & 0x3333) + ((x >> 2) & 0x3333); x = (x & 0x0077) + ((x >> 8) & 0x0077); x = (x & 0x000F) + ((x >> 4) & 0x000F); return x; }
SLIDE 79
Sketches make synthesis more tractable
bit[W] popSketched(bit[W] x) { loop (??) { x = (x & ??) + ((x >> ??) & ??); } return x; }
SLIDE 80 Sketches make synthesis more tractable
bit[W] popSketched(bit[W] x) { loop (??) { x = (x & ??) + ((x >> ??) & ??); } return x; }
int[] map(int[] xs) { int[] ys = {}; for (int i=0; i<xs.length; i++) { ys.append(??(xs[i])); } return ys; } int[] filter(int[] xs) { int[] ys = {}; for (int i=0; i<xs.length; i++) { if (??(xs[i])) ys.append(xs[i]); } } int[] foldl(int[] xs) { int acc = ??; for (int i=0; i<xs.length; i++) { acc = ??(acc, xs[i]); } return ys; }
SLIDE 81
Sketches make synthesis more tractable
Identify common sketches from existing code
SLIDE 82 Sketches make synthesis more tractable
Identify common sketches from existing code
Mine existing code bases for common idioms
SLIDE 83 Sketches make synthesis more tractable
Identify common sketches from existing code
Mine existing code bases for common idioms
Approximate Computing
quality bounds
into
approximate programs
SLIDE 84 Sketches make synthesis more tractable
Identify common sketches from existing code
Mine existing code bases for common idioms
Approximate Computing
quality bounds
into
approximate programs Precise Implementation Approximate Program Synthesis
SLIDE 85 Program Synthesis Statistical Machine Learning
Approximate Computing Hardware Synthesis Black Box Systems
SLIDE 86 Program Synthesis Statistical Machine Learning
Approximate Computing Hardware Synthesis Black Box Systems
SLIDE 87 Program Synthesis Statistical Machine Learning
Approximate Computing Hardware Synthesis Black Box Systems
Thanks!