Approximate Program Synthesis
James Bornholt Emina Torlak Luis Ceze Dan Grossman
University of Washington
Approximate Program Synthesis James Bornholt Emina Torlak Luis - - PowerPoint PPT Presentation
Approximate Program Synthesis James Bornholt Emina Torlak Luis Ceze Dan Grossman University of Washington Writing approximate programs is hard Precise Implementation Writing approximate programs is hard Precise Implementation Writing
James Bornholt Emina Torlak Luis Ceze Dan Grossman
University of Washington
Writing approximate programs is hard
Writing approximate programs is hard
Precise Implementation
Writing approximate programs is hard
Precise Implementation Desired Quality
Writing approximate programs is hard
Approximate Compiler
ACCEPT, Chisel, iACT, ExpAX, …
Precise Implementation Desired Quality
Writing approximate programs is hard
Approximate Compiler
ACCEPT, Chisel, iACT, ExpAX, …
Precise Implementation Desired Quality Approximate Program
Writing approximate programs is hard
Approximate Compiler
ACCEPT, Chisel, iACT, ExpAX, …
Precise Implementation Desired Quality Approximate Program
s p e c i fj c a p p r
i m a t i
p
t u n i t i e s global
p r
r a m a n n
a t i
s target language q u a l i t y m e t r i c
Synthesis: write programs automatically
Semantics Programs
Synthesis: write programs automatically
Target Behavior
Semantics Programs
f(x) = 4x + 1
Synthesis: write programs automatically
Target Behavior
Semantics Programs
f(x) = 4x + 1
Synthesis: write programs automatically
Target Behavior 4*x + 1
Semantics Programs
f(x) = 4x + 1
Synthesis: write programs automatically
Target Behavior 4*x + 1
Semantics Programs
f(x) = 4x + 1
Synthesis: write programs automatically
Target Behavior x + x + x + x + 1 4*x + 1
Semantics Programs
f(x) = 4x + 1
(x<<2) + 1
Synthesizing approximate programs
(x<<2) + 1
Semantics Programs
Target Behavior
f(x) = 4x + 1
x + x + x + x + 1 4*x + 1
Synthesizing approximate programs
Approximate Behavior (x<<2) + 1
Semantics Programs
Target Behavior
f(x) = 4x + 1
x + x + x + x + 1 4*x + 1
Synthesizing approximate programs
Approximate Behavior (x<<2) + 1
Semantics Programs
Target Behavior
f(x) = 4x + 1
x<<2 x + x + x + x + 1 4*x + 1
Synthesizing approximate programs
Approximate Behavior (x<<2) + 1
Semantics Programs
Target Behavior
f(x) = 4x + 1
x<<2 x + x + x + x + 1 4*x + 1
κ = 10 κ = 8 κ = 6 κ = 4
Synthesizing approximate programs
Approximate Behavior (x<<2) + 1
Semantics Programs
Target Behavior
f(x) = 4x + 1
x<<2 x + x + x + x + 1 4*x + 1
κ = 10 κ = 8 κ = 6 κ = 4
Synthesis automates approximation
Approximate Compiler
ACCEPT, Chisel, iACT, ExpAX, …
Precise Implementation Desired Quality Approximate Program
s p e c i fj c a p p r
i m a t i
p
t u n i t i e s global
p r
r a m a n n
a t i
s target language q u a l i t y m e t r i c
Synthesis automates approximation
Approximate Program Synthesis
Precise Implementation Desired Quality Approximate Program
s p e c i fj c a p p r
i m a t i
p
t u n i t i e s global
p r
r a m a n n
a t i
s target language q u a l i t y m e t r i c
Synthesis automates approximation
Approximate Program Synthesis
Precise Implementation Desired Quality Approximate Program
specifjc approximation
global
program annotations
target language q u a l i t y m e t r i c
Existing synthesizers don’t scale enough
† Alur et al. Syntax-Guided Synthesis. FMCAD 2013.
Approximate benchmarks
∀p, c. |dist(p, c) − f(p, c)| < 50%
Existing synthesizers don’t scale enough
† Alur et al. Syntax-Guided Synthesis. FMCAD 2013.
Approximate benchmarks
Off-the-shelf synthesizers†
∀p, c. |dist(p, c) − f(p, c)| < 50%
float dist(float p[3], float c[3]) { float r = 0; r += (p[0] - c[0])*(p[0] - c[0]); r += (p[1] - c[1])*(p[1] - c[1]); r += (p[2] - c[2])*(p[2] - c[2]); float ret = sqrt(r); return ret; } float f(float p[3], float c[3]) { ?? } assert
Existing synthesizers don’t scale enough
† Alur et al. Syntax-Guided Synthesis. FMCAD 2013.
Approximate benchmarks
Off-the-shelf synthesizers†
∀p, c. |dist(p, c) − f(p, c)| < 50%
float dist(float p[3], float c[3]) { float r = 0; r += (p[0] - c[0])*(p[0] - c[0]); r += (p[1] - c[1])*(p[1] - c[1]); r += (p[2] - c[2])*(p[2] - c[2]); float ret = sqrt(r); return ret; } float f(float p[3], float c[3]) { ?? } assert
Existing synthesizers don’t scale enough
† Alur et al. Syntax-Guided Synthesis. FMCAD 2013.
Approximate benchmarks
Off-the-shelf synthesizers†
∀p, c. |dist(p, c) − f(p, c)| < 50%
+ - * / & | ^ << >> …
float dist(float p[3], float c[3]) { float r = 0; r += (p[0] - c[0])*(p[0] - c[0]); r += (p[1] - c[1])*(p[1] - c[1]); r += (p[2] - c[2])*(p[2] - c[2]); float ret = sqrt(r); return ret; } float f(float p[3], float c[3]) { ?? } assert
Existing synthesizers don’t scale enough
† Alur et al. Syntax-Guided Synthesis. FMCAD 2013.
Approximate benchmarks
Off-the-shelf synthesizers†
∀p, c. |dist(p, c) − f(p, c)| < 50%
+ - * / & | ^ << >> … Program being synthesized Reference program
Existing synthesizers don’t scale enough
† Alur et al. Syntax-Guided Synthesis. FMCAD 2013.
Approximate benchmarks
Off-the-shelf synthesizers†
float dist(float p[3], float c[3]) { float r = 0; r += (p[0] - c[0])*(p[0] - c[0]); r += (p[1] - c[1])*(p[1] - c[1]); r += (p[2] - c[2])*(p[2] - c[2]); float ret = sqrt(r); return ret; } float f(float p[3], float c[3]) { ?? } assert ∀p, c. |dist(p, c) − f(p, c)| < 50%
+ - * / & | ^ << >> … Program being synthesized Reference program
float dist(float p[3], float c[3]) { float r = 0; r += (p[0] - c[0])*(p[0] - c[0]); r += (p[1] - c[1])*(p[1] - c[1]); r += (p[2] - c[2])*(p[2] - c[2]); float ret = sqrt(r); return ret; } float f(float p[3], float c[3]) { ?? } assert
Existing synthesizers don’t scale enough
Programs
∀p, c. |dist(p, c) − f(p, c)| < 50%
+ - * / & | ^ << >> … Program being synthesized Reference program
float dist(float p[3], float c[3]) { float r = 0; r += (p[0] - c[0])*(p[0] - c[0]); r += (p[1] - c[1])*(p[1] - c[1]); r += (p[2] - c[2])*(p[2] - c[2]); float ret = sqrt(r); return ret; } float f(float p[3], float c[3]) { ?? } assert
Existing synthesizers don’t scale enough
Programs
∀p, c. |dist(p, c) − f(p, c)| < 50%
+ - * / & | ^ << >> … Program being synthesized Reference program
float dist(float p[3], float c[3]) { float r = 0; r += (p[0] - c[0])*(p[0] - c[0]); r += (p[1] - c[1])*(p[1] - c[1]); r += (p[2] - c[2])*(p[2] - c[2]); float ret = sqrt(r); return ret; } float f(float p[3], float c[3]) { ?? } assert
Existing synthesizers don’t scale enough
Programs
programs
∀p, c. |dist(p, c) − f(p, c)| < 50%
+ - * / & | ^ << >> … Program being synthesized Reference program
float dist(float p[3], float c[3]) { float r = 0; r += (p[0] - c[0])*(p[0] - c[0]); r += (p[1] - c[1])*(p[1] - c[1]); r += (p[2] - c[2])*(p[2] - c[2]); float ret = sqrt(r); return ret; } float f(float p[3], float c[3]) { ?? } assert
Use reference programs to guide synthesis
Programs
programs
∀p, c. |dist(p, c) − f(p, c)| < 50%
+ - * / & | ^ << >> … Program being synthesized Reference program
float dist(float p[3], float c[3]) { float r = 0; r += (p[0] - c[0])*(p[0] - c[0]); r += (p[1] - c[1])*(p[1] - c[1]); r += (p[2] - c[2])*(p[2] - c[2]); float ret = sqrt(r); return ret; } float f(float p[3], float c[3]) { ?? } assert
Use reference programs to guide synthesis
Programs
programs
∀p, c. |dist(p, c) − f(p, c)| < 50%
+ - * / & | ^ << >> … Program being synthesized Reference program
float dist(float p[3], float c[3]) { float r = 0; r += (p[0] - c[0])*(p[0] - c[0]); r += (p[1] - c[1])*(p[1] - c[1]); r += (p[2] - c[2])*(p[2] - c[2]); float ret = sqrt(r); return ret; } float f(float p[3], float c[3]) { ?? } assert
Use reference programs to guide synthesis
Programs
programs
∀p, c. |dist(p, c) − f(p, c)| < 50%
+ - * / & | ^ << >> … Program being synthesized Reference program
float dist(float p[3], float c[3]) { float r = 0; r += (p[0] - c[0])*(p[0] - c[0]); r += (p[1] - c[1])*(p[1] - c[1]); r += (p[2] - c[2])*(p[2] - c[2]); float ret = sqrt(r); return ret; } float f(float p[3], float c[3]) { ?? } assert
Use reference programs to guide synthesis
Programs
programs
∀p, c. |dist(p, c) − f(p, c)| < 50%
+ - * / & | ^ << >> … Program being synthesized Reference program + - * / & | ^ << >> …
Synthesis produces good approximations
Benchmark Speedup Error ffts 11.4× 21.3% fftc 12.0× 28.9% dist3 1.6× 14.9% sobelx 10.6× 0% sobely 10.7× 0% inversek2j1 34.8× 16.3% inversek2j2 10.0× 18.5%
Spec: < 50% average error
Synthesis produces good approximations
Benchmark Speedup Error ffts 11.4× 21.3% fftc 12.0× 28.9% dist3 1.6× 14.9% sobelx 10.6× 0% sobely 10.7× 0% inversek2j1 34.8× 16.3% inversek2j2 10.0× 18.5%
Missed compiler
Missed compiler
Spec: < 50% average error
Synthesis produces clever approximations
float dist_approx(int a[3], int b[3]) { int c1 = abs(b[0] - a[0]); int c2 = abs(b[1] - a[1]); int c3 = abs(a[2] - b[2]); int c4 = c1 | c2; int c5 = abs(c3 > c4 ? c3 : c4); return (float)c5; } 3D Euclidean distance 1.6× faster, 14.9% error
Approximate Program Synthesis
Precise Implementation Desired Quality Approximate Program
Thanks!