_synthesis__________________ __of_______________________ ___first-order_____dynamic___...
TRANSCRIPT
![Page 1: _Synthesis__________________ __Of_______________________ ___First-Order_____Dynamic___ _____________Programming___ _______________Algorithms___ Yewen (Evan)](https://reader037.vdocuments.us/reader037/viewer/2022110116/5516e98255034603568b4875/html5/thumbnails/1.jpg)
_Synthesis____________________Of__________________________First-Order_____Dynamic________________Programming__________________Algorithms___
Yewen (Evan) PuRastislav BodikSaurabh SrivastavaUniversity of California, Berkeley
![Page 2: _Synthesis__________________ __Of_______________________ ___First-Order_____Dynamic___ _____________Programming___ _______________Algorithms___ Yewen (Evan)](https://reader037.vdocuments.us/reader037/viewer/2022110116/5516e98255034603568b4875/html5/thumbnails/2.jpg)
Do you feel lucky?
![Page 3: _Synthesis__________________ __Of_______________________ ___First-Order_____Dynamic___ _____________Programming___ _______________Algorithms___ Yewen (Evan)](https://reader037.vdocuments.us/reader037/viewer/2022110116/5516e98255034603568b4875/html5/thumbnails/3.jpg)
A new way to build an island?Conventional Domain Specific Compiler:
• Require deep domain theories
• Takes a long time to implement
Constraint Based Synthesizer:
• Write a template for desired algorithm
• Constraint solver fills in the template
![Page 4: _Synthesis__________________ __Of_______________________ ___First-Order_____Dynamic___ _____________Programming___ _______________Algorithms___ Yewen (Evan)](https://reader037.vdocuments.us/reader037/viewer/2022110116/5516e98255034603568b4875/html5/thumbnails/4.jpg)
Make Templates not TheoriesSuppose we want to optimize x+x+x+x
With domain-specific rewrite rules:
With a template in SKETCH [Solar-Lezama]:
spec(x): return x+x+x+x
sketch(x): return x << ??
program equivalence found using bounded model checking
![Page 5: _Synthesis__________________ __Of_______________________ ___First-Order_____Dynamic___ _____________Programming___ _______________Algorithms___ Yewen (Evan)](https://reader037.vdocuments.us/reader037/viewer/2022110116/5516e98255034603568b4875/html5/thumbnails/5.jpg)
A Search for a Correct ProgramSynthesizer finds in a space of candidate programs a correct one (it matches the specification)
![Page 6: _Synthesis__________________ __Of_______________________ ___First-Order_____Dynamic___ _____________Programming___ _______________Algorithms___ Yewen (Evan)](https://reader037.vdocuments.us/reader037/viewer/2022110116/5516e98255034603568b4875/html5/thumbnails/6.jpg)
Research Question in This Talk
Can we write a synthesizer for an entire problem domain using a single template (sketch)?
![Page 7: _Synthesis__________________ __Of_______________________ ___First-Order_____Dynamic___ _____________Programming___ _______________Algorithms___ Yewen (Evan)](https://reader037.vdocuments.us/reader037/viewer/2022110116/5516e98255034603568b4875/html5/thumbnails/7.jpg)
The Challenge
How do we write a template that covers all of our domain, yet the constraints it induces can be efficiently solved?
![Page 8: _Synthesis__________________ __Of_______________________ ___First-Order_____Dynamic___ _____________Programming___ _______________Algorithms___ Yewen (Evan)](https://reader037.vdocuments.us/reader037/viewer/2022110116/5516e98255034603568b4875/html5/thumbnails/8.jpg)
Our ApproachDefine a general template that contains the entire domainOptimize the search by reducing the search space
![Page 9: _Synthesis__________________ __Of_______________________ ___First-Order_____Dynamic___ _____________Programming___ _______________Algorithms___ Yewen (Evan)](https://reader037.vdocuments.us/reader037/viewer/2022110116/5516e98255034603568b4875/html5/thumbnails/9.jpg)
Dynamic Programming AlgorithmsA well-defined domain
We have no “DSL compiler” for it (taught as an art)
Difficulties:• inventing sub-problems• inventing recurrences
We focus on a first-order sub-class, FORDP, which captures many O(n) DP algorithms
![Page 10: _Synthesis__________________ __Of_______________________ ___First-Order_____Dynamic___ _____________Programming___ _______________Algorithms___ Yewen (Evan)](https://reader037.vdocuments.us/reader037/viewer/2022110116/5516e98255034603568b4875/html5/thumbnails/10.jpg)
An Easy Problem
Fibonacci Sequence:fib(n) = fib(n-1) + fib(n-2)
![Page 11: _Synthesis__________________ __Of_______________________ ___First-Order_____Dynamic___ _____________Programming___ _______________Algorithms___ Yewen (Evan)](https://reader037.vdocuments.us/reader037/viewer/2022110116/5516e98255034603568b4875/html5/thumbnails/11.jpg)
A Harder Problem
Maximal Independent Sum (MIS)
Input: Array of positive integers
Output: Maximum sum of a non-consecutive selections of its elements.
![Page 12: _Synthesis__________________ __Of_______________________ ___First-Order_____Dynamic___ _____________Programming___ _______________Algorithms___ Yewen (Evan)](https://reader037.vdocuments.us/reader037/viewer/2022110116/5516e98255034603568b4875/html5/thumbnails/12.jpg)
What does the user do?
mis(A): best = 0 forall selections: if non_consec(selection): best = max(best, value(A[selection])) return best
![Page 13: _Synthesis__________________ __Of_______________________ ___First-Order_____Dynamic___ _____________Programming___ _______________Algorithms___ Yewen (Evan)](https://reader037.vdocuments.us/reader037/viewer/2022110116/5516e98255034603568b4875/html5/thumbnails/13.jpg)
What does the template do?• Define a general template that
contains the entire domain
![Page 14: _Synthesis__________________ __Of_______________________ ___First-Order_____Dynamic___ _____________Programming___ _______________Algorithms___ Yewen (Evan)](https://reader037.vdocuments.us/reader037/viewer/2022110116/5516e98255034603568b4875/html5/thumbnails/14.jpg)
A General Templatefor_dpa(a): p1 = array() p2 = array() p1[0] = init1() p2[0] = init2() for i from 1 to n: p1[i] = update1(p1[i-1],p2[i-1],a[i]) p2[i] = update2(p1[i-1],p2[i-1],a[i]) return term(p1[n],p2[n])
Covers every FORDP algorithm
![Page 15: _Synthesis__________________ __Of_______________________ ___First-Order_____Dynamic___ _____________Programming___ _______________Algorithms___ Yewen (Evan)](https://reader037.vdocuments.us/reader037/viewer/2022110116/5516e98255034603568b4875/html5/thumbnails/15.jpg)
General Template for updateAll possible compositions of user provided operators
![Page 16: _Synthesis__________________ __Of_______________________ ___First-Order_____Dynamic___ _____________Programming___ _______________Algorithms___ Yewen (Evan)](https://reader037.vdocuments.us/reader037/viewer/2022110116/5516e98255034603568b4875/html5/thumbnails/16.jpg)
Space Reduction: Optimality
All FORDP recurrences have this syntactic form
![Page 17: _Synthesis__________________ __Of_______________________ ___First-Order_____Dynamic___ _____________Programming___ _______________Algorithms___ Yewen (Evan)](https://reader037.vdocuments.us/reader037/viewer/2022110116/5516e98255034603568b4875/html5/thumbnails/17.jpg)
Space Reduction: Optimality
Recurrence for MIS:
![Page 18: _Synthesis__________________ __Of_______________________ ___First-Order_____Dynamic___ _____________Programming___ _______________Algorithms___ Yewen (Evan)](https://reader037.vdocuments.us/reader037/viewer/2022110116/5516e98255034603568b4875/html5/thumbnails/18.jpg)
Space Reduction: Symmetry
Many operators are commutative
Pick a canonical representative syntactically
![Page 19: _Synthesis__________________ __Of_______________________ ___First-Order_____Dynamic___ _____________Programming___ _______________Algorithms___ Yewen (Evan)](https://reader037.vdocuments.us/reader037/viewer/2022110116/5516e98255034603568b4875/html5/thumbnails/19.jpg)
Space Reduction: Recap
All possible compositions
Syntactically Reduced
![Page 20: _Synthesis__________________ __Of_______________________ ___First-Order_____Dynamic___ _____________Programming___ _______________Algorithms___ Yewen (Evan)](https://reader037.vdocuments.us/reader037/viewer/2022110116/5516e98255034603568b4875/html5/thumbnails/20.jpg)
DEMO
![Page 21: _Synthesis__________________ __Of_______________________ ___First-Order_____Dynamic___ _____________Programming___ _______________Algorithms___ Yewen (Evan)](https://reader037.vdocuments.us/reader037/viewer/2022110116/5516e98255034603568b4875/html5/thumbnails/21.jpg)
Benchmarks
Here are some synthesized recurrences
![Page 22: _Synthesis__________________ __Of_______________________ ___First-Order_____Dynamic___ _____________Programming___ _______________Algorithms___ Yewen (Evan)](https://reader037.vdocuments.us/reader037/viewer/2022110116/5516e98255034603568b4875/html5/thumbnails/22.jpg)
Experiments
mis mss mas mmm asm osm euc1
10
100
1000
compsymmopti
Synthesizer solving time, in seconds
out of memory
![Page 23: _Synthesis__________________ __Of_______________________ ___First-Order_____Dynamic___ _____________Programming___ _______________Algorithms___ Yewen (Evan)](https://reader037.vdocuments.us/reader037/viewer/2022110116/5516e98255034603568b4875/html5/thumbnails/23.jpg)
Conclusion
It is possible to build a domain-specific synthesizer for FORDPA
Synthesizer developer only find a syntactic domain structure
The lessons learned in building the synthesizer may be general
If so, we can build more islands with constraint-based synthesis