ML for ML: Learning Cost Semantics by Experimentankushd/docs/TACAS17_Pres.pdf · Jan Hoffmann (CMU)...
Transcript of ML for ML: Learning Cost Semantics by Experimentankushd/docs/TACAS17_Pres.pdf · Jan Hoffmann (CMU)...
![Page 1: ML for ML: Learning Cost Semantics by Experimentankushd/docs/TACAS17_Pres.pdf · Jan Hoffmann (CMU) TACAS 2017 1 Machine Learning ML for ML: Learning Cost Semantics by Experiment](https://reader034.fdocuments.net/reader034/viewer/2022051811/6028793efc0c311ffe5d4119/html5/thumbnails/1.jpg)
ML for ML: Learning Cost Semantics by
Experiment
Ankush Das (CMU)Jan Hoffmann (CMU)
TACAS 20171
![Page 2: ML for ML: Learning Cost Semantics by Experimentankushd/docs/TACAS17_Pres.pdf · Jan Hoffmann (CMU) TACAS 2017 1 Machine Learning ML for ML: Learning Cost Semantics by Experiment](https://reader034.fdocuments.net/reader034/viewer/2022051811/6028793efc0c311ffe5d4119/html5/thumbnails/2.jpg)
ML for ML: Learning Cost Semantics by
Experiment
Ankush Das (CMU)Jan Hoffmann (CMU)
TACAS 20171
Machine Learning
![Page 3: ML for ML: Learning Cost Semantics by Experimentankushd/docs/TACAS17_Pres.pdf · Jan Hoffmann (CMU) TACAS 2017 1 Machine Learning ML for ML: Learning Cost Semantics by Experiment](https://reader034.fdocuments.net/reader034/viewer/2022051811/6028793efc0c311ffe5d4119/html5/thumbnails/3.jpg)
ML for ML: Learning Cost Semantics by
Experiment
Ankush Das (CMU)Jan Hoffmann (CMU)
TACAS 20171
Machine Learning
OCaml SML
![Page 4: ML for ML: Learning Cost Semantics by Experimentankushd/docs/TACAS17_Pres.pdf · Jan Hoffmann (CMU) TACAS 2017 1 Machine Learning ML for ML: Learning Cost Semantics by Experiment](https://reader034.fdocuments.net/reader034/viewer/2022051811/6028793efc0c311ffe5d4119/html5/thumbnails/4.jpg)
Which one’s faster?let rec append l1 l2 = match l1 with | [] -> l2 | hd::tl -> hd::(append tl l2);;
let rec append l1 l2 = match l1 with | [] -> l2 | x::[] -> x::l2 | x::y::[] -> x::y::l2 | x::y::tl -> x::y::(append tl l2);;
2
![Page 5: ML for ML: Learning Cost Semantics by Experimentankushd/docs/TACAS17_Pres.pdf · Jan Hoffmann (CMU) TACAS 2017 1 Machine Learning ML for ML: Learning Cost Semantics by Experiment](https://reader034.fdocuments.net/reader034/viewer/2022051811/6028793efc0c311ffe5d4119/html5/thumbnails/5.jpg)
What do existing resource analysis tools do?
3
![Page 6: ML for ML: Learning Cost Semantics by Experimentankushd/docs/TACAS17_Pres.pdf · Jan Hoffmann (CMU) TACAS 2017 1 Machine Learning ML for ML: Learning Cost Semantics by Experiment](https://reader034.fdocuments.net/reader034/viewer/2022051811/6028793efc0c311ffe5d4119/html5/thumbnails/6.jpg)
What do existing resource analysis tools do?
Rely on abstract cost modelsloop iterationsfunction calls
arithmetic operationscomparisons
3
![Page 7: ML for ML: Learning Cost Semantics by Experimentankushd/docs/TACAS17_Pres.pdf · Jan Hoffmann (CMU) TACAS 2017 1 Machine Learning ML for ML: Learning Cost Semantics by Experiment](https://reader034.fdocuments.net/reader034/viewer/2022051811/6028793efc0c311ffe5d4119/html5/thumbnails/7.jpg)
Abstract cost models?
4
![Page 8: ML for ML: Learning Cost Semantics by Experimentankushd/docs/TACAS17_Pres.pdf · Jan Hoffmann (CMU) TACAS 2017 1 Machine Learning ML for ML: Learning Cost Semantics by Experiment](https://reader034.fdocuments.net/reader034/viewer/2022051811/6028793efc0c311ffe5d4119/html5/thumbnails/8.jpg)
Abstract cost models?Program
P (n)
4
![Page 9: ML for ML: Learning Cost Semantics by Experimentankushd/docs/TACAS17_Pres.pdf · Jan Hoffmann (CMU) TACAS 2017 1 Machine Learning ML for ML: Learning Cost Semantics by Experiment](https://reader034.fdocuments.net/reader034/viewer/2022051811/6028793efc0c311ffe5d4119/html5/thumbnails/9.jpg)
Abstract cost models?Program
P (n)loop
iterations
n2 + n
4
![Page 10: ML for ML: Learning Cost Semantics by Experimentankushd/docs/TACAS17_Pres.pdf · Jan Hoffmann (CMU) TACAS 2017 1 Machine Learning ML for ML: Learning Cost Semantics by Experiment](https://reader034.fdocuments.net/reader034/viewer/2022051811/6028793efc0c311ffe5d4119/html5/thumbnails/10.jpg)
Abstract cost models?Program
P (n)loop
iterationstransition
steps
n2 + n 3n2 + 2n
4
![Page 11: ML for ML: Learning Cost Semantics by Experimentankushd/docs/TACAS17_Pres.pdf · Jan Hoffmann (CMU) TACAS 2017 1 Machine Learning ML for ML: Learning Cost Semantics by Experiment](https://reader034.fdocuments.net/reader034/viewer/2022051811/6028793efc0c311ffe5d4119/html5/thumbnails/11.jpg)
Abstract cost models?Program
P (n)loop
iterationstransition
steps
n2 + n 3n2 + 2nTime on hardware?
4
![Page 12: ML for ML: Learning Cost Semantics by Experimentankushd/docs/TACAS17_Pres.pdf · Jan Hoffmann (CMU) TACAS 2017 1 Machine Learning ML for ML: Learning Cost Semantics by Experiment](https://reader034.fdocuments.net/reader034/viewer/2022051811/6028793efc0c311ffe5d4119/html5/thumbnails/12.jpg)
Abstract cost models?Program
P (n)loop
iterationstransition
steps
n2 + n 3n2 + 2nTime on hardware?c1n
2 + c2n + c34
![Page 13: ML for ML: Learning Cost Semantics by Experimentankushd/docs/TACAS17_Pres.pdf · Jan Hoffmann (CMU) TACAS 2017 1 Machine Learning ML for ML: Learning Cost Semantics by Experiment](https://reader034.fdocuments.net/reader034/viewer/2022051811/6028793efc0c311ffe5d4119/html5/thumbnails/13.jpg)
Abstract cost models?Program
P (n)loop
iterationstransition
steps
n2 + n 3n2 + 2nTime on hardware?c1n
2 + c2n + c3
Cost Semantics can
help bridge the gap!
4
![Page 14: ML for ML: Learning Cost Semantics by Experimentankushd/docs/TACAS17_Pres.pdf · Jan Hoffmann (CMU) TACAS 2017 1 Machine Learning ML for ML: Learning Cost Semantics by Experiment](https://reader034.fdocuments.net/reader034/viewer/2022051811/6028793efc0c311ffe5d4119/html5/thumbnails/14.jpg)
What is Cost Semantics? A cost semantics specifies the abstract cost of a program that is validated by a provable implementation that transfers the abstract cost to a precise concrete cost on a particular platform.
— Robert Harper
5
![Page 15: ML for ML: Learning Cost Semantics by Experimentankushd/docs/TACAS17_Pres.pdf · Jan Hoffmann (CMU) TACAS 2017 1 Machine Learning ML for ML: Learning Cost Semantics by Experiment](https://reader034.fdocuments.net/reader034/viewer/2022051811/6028793efc0c311ffe5d4119/html5/thumbnails/15.jpg)
How do we define a cost semantics for execution time that works well on
real hardware?
6
![Page 16: ML for ML: Learning Cost Semantics by Experimentankushd/docs/TACAS17_Pres.pdf · Jan Hoffmann (CMU) TACAS 2017 1 Machine Learning ML for ML: Learning Cost Semantics by Experiment](https://reader034.fdocuments.net/reader034/viewer/2022051811/6028793efc0c311ffe5d4119/html5/thumbnails/16.jpg)
Challenges
Garbage CollectorCompiler Optimizations
7
![Page 17: ML for ML: Learning Cost Semantics by Experimentankushd/docs/TACAS17_Pres.pdf · Jan Hoffmann (CMU) TACAS 2017 1 Machine Learning ML for ML: Learning Cost Semantics by Experiment](https://reader034.fdocuments.net/reader034/viewer/2022051811/6028793efc0c311ffe5d4119/html5/thumbnails/17.jpg)
Contributions• Cost semantics for execution time
• Learn hardware specific constants
• Model for the garbage collector
• Model some compiler optimizations
• Reasonable error on Intel x86 and ARM
• Fast / slow implementations of same specification
8
![Page 18: ML for ML: Learning Cost Semantics by Experimentankushd/docs/TACAS17_Pres.pdf · Jan Hoffmann (CMU) TACAS 2017 1 Machine Learning ML for ML: Learning Cost Semantics by Experiment](https://reader034.fdocuments.net/reader034/viewer/2022051811/6028793efc0c311ffe5d4119/html5/thumbnails/18.jpg)
Intuition
9
![Page 19: ML for ML: Learning Cost Semantics by Experimentankushd/docs/TACAS17_Pres.pdf · Jan Hoffmann (CMU) TACAS 2017 1 Machine Learning ML for ML: Learning Cost Semantics by Experiment](https://reader034.fdocuments.net/reader034/viewer/2022051811/6028793efc0c311ffe5d4119/html5/thumbnails/19.jpg)
Examplelet rec fact n = if (n = 0) then 1 else n * fact (n-1);;
(fact 10);;
10
![Page 20: ML for ML: Learning Cost Semantics by Experimentankushd/docs/TACAS17_Pres.pdf · Jan Hoffmann (CMU) TACAS 2017 1 Machine Learning ML for ML: Learning Cost Semantics by Experiment](https://reader034.fdocuments.net/reader034/viewer/2022051811/6028793efc0c311ffe5d4119/html5/thumbnails/20.jpg)
Examplelet rec fact n = if (n = 0) then 1 else n * fact (n-1);;
(fact 10);;
✦ Startup = 1✦ Integer Comparison = 11✦ Function Application = 11✦ Integer Multiplication = 10✦ Integer Subtraction = 10✦ Let Rec = 1
10
![Page 21: ML for ML: Learning Cost Semantics by Experimentankushd/docs/TACAS17_Pres.pdf · Jan Hoffmann (CMU) TACAS 2017 1 Machine Learning ML for ML: Learning Cost Semantics by Experiment](https://reader034.fdocuments.net/reader034/viewer/2022051811/6028793efc0c311ffe5d4119/html5/thumbnails/21.jpg)
Examplelet rec fact n = if (n = 0) then 1 else n * fact (n-1);;
(fact 10);;
✦ Startup = 1✦ Integer Comparison = 11
✦ Function Application = 11✦ Integer Multiplication = 10✦ Integer Subtraction = 10✦ Let Rec = 1
Execution Time =Tstartup +
11×TintCompEq +11×Tapp +10×TintMult +10×TintSub +1×Tletrec10
![Page 22: ML for ML: Learning Cost Semantics by Experimentankushd/docs/TACAS17_Pres.pdf · Jan Hoffmann (CMU) TACAS 2017 1 Machine Learning ML for ML: Learning Cost Semantics by Experiment](https://reader034.fdocuments.net/reader034/viewer/2022051811/6028793efc0c311ffe5d4119/html5/thumbnails/22.jpg)
Our Work
Program
Interpreternc
T
T =X
c2CncTc
11
![Page 23: ML for ML: Learning Cost Semantics by Experimentankushd/docs/TACAS17_Pres.pdf · Jan Hoffmann (CMU) TACAS 2017 1 Machine Learning ML for ML: Learning Cost Semantics by Experiment](https://reader034.fdocuments.net/reader034/viewer/2022051811/6028793efc0c311ffe5d4119/html5/thumbnails/23.jpg)
12
T =X
c2CncTc
![Page 24: ML for ML: Learning Cost Semantics by Experimentankushd/docs/TACAS17_Pres.pdf · Jan Hoffmann (CMU) TACAS 2017 1 Machine Learning ML for ML: Learning Cost Semantics by Experiment](https://reader034.fdocuments.net/reader034/viewer/2022051811/6028793efc0c311ffe5d4119/html5/thumbnails/24.jpg)
Model
Training
Model Design
Testing
Accuracy
Designing
12
T =X
c2CncTc
![Page 25: ML for ML: Learning Cost Semantics by Experimentankushd/docs/TACAS17_Pres.pdf · Jan Hoffmann (CMU) TACAS 2017 1 Machine Learning ML for ML: Learning Cost Semantics by Experiment](https://reader034.fdocuments.net/reader034/viewer/2022051811/6028793efc0c311ffe5d4119/html5/thumbnails/25.jpg)
Model
Training
Model Design
Testing
Accuracy
Designing
12
T =X
c2CncTc
![Page 26: ML for ML: Learning Cost Semantics by Experimentankushd/docs/TACAS17_Pres.pdf · Jan Hoffmann (CMU) TACAS 2017 1 Machine Learning ML for ML: Learning Cost Semantics by Experiment](https://reader034.fdocuments.net/reader034/viewer/2022051811/6028793efc0c311ffe5d4119/html5/thumbnails/26.jpg)
Model
Training
Model Design
Testing
Accuracy
DesigningMachine Learning
Programs
12
T =X
c2CncTc
![Page 27: ML for ML: Learning Cost Semantics by Experimentankushd/docs/TACAS17_Pres.pdf · Jan Hoffmann (CMU) TACAS 2017 1 Machine Learning ML for ML: Learning Cost Semantics by Experiment](https://reader034.fdocuments.net/reader034/viewer/2022051811/6028793efc0c311ffe5d4119/html5/thumbnails/27.jpg)
Model
Training
Model Design
Testing
Accuracy
DesigningMachine Learning
Programs
Programs12
T =X
c2CncTc
![Page 28: ML for ML: Learning Cost Semantics by Experimentankushd/docs/TACAS17_Pres.pdf · Jan Hoffmann (CMU) TACAS 2017 1 Machine Learning ML for ML: Learning Cost Semantics by Experiment](https://reader034.fdocuments.net/reader034/viewer/2022051811/6028793efc0c311ffe5d4119/html5/thumbnails/28.jpg)
Model
Training
Model Design
Testing
Accuracy
DesigningMachine Learning
Programs
Programs12
T =X
c2CncTc
![Page 29: ML for ML: Learning Cost Semantics by Experimentankushd/docs/TACAS17_Pres.pdf · Jan Hoffmann (CMU) TACAS 2017 1 Machine Learning ML for ML: Learning Cost Semantics by Experiment](https://reader034.fdocuments.net/reader034/viewer/2022051811/6028793efc0c311ffe5d4119/html5/thumbnails/29.jpg)
Training Programs• One program per construct• Execute with different values of x and y
let rec fadd x y = if (x = 0) then 0 else y + y + y + fadd (x-1) y;;
13
![Page 30: ML for ML: Learning Cost Semantics by Experimentankushd/docs/TACAS17_Pres.pdf · Jan Hoffmann (CMU) TACAS 2017 1 Machine Learning ML for ML: Learning Cost Semantics by Experiment](https://reader034.fdocuments.net/reader034/viewer/2022051811/6028793efc0c311ffe5d4119/html5/thumbnails/30.jpg)
Training Programs• One program per construct• Execute with different values of x and y
let rec fadd x y = if (x = 0) then 0 else y + y + y + fadd (x-1) y;;
Interpreter13
![Page 31: ML for ML: Learning Cost Semantics by Experimentankushd/docs/TACAS17_Pres.pdf · Jan Hoffmann (CMU) TACAS 2017 1 Machine Learning ML for ML: Learning Cost Semantics by Experiment](https://reader034.fdocuments.net/reader034/viewer/2022051811/6028793efc0c311ffe5d4119/html5/thumbnails/31.jpg)
Linear Regression
Learn
Minimize
Interpreter
T =X
c2CncTc T �
X
c2CncTc
!2
14
![Page 32: ML for ML: Learning Cost Semantics by Experimentankushd/docs/TACAS17_Pres.pdf · Jan Hoffmann (CMU) TACAS 2017 1 Machine Learning ML for ML: Learning Cost Semantics by Experiment](https://reader034.fdocuments.net/reader034/viewer/2022051811/6028793efc0c311ffe5d4119/html5/thumbnails/32.jpg)
What about the challenges?
Garbage CollectorCompiler Optimizations
15
![Page 33: ML for ML: Learning Cost Semantics by Experimentankushd/docs/TACAS17_Pres.pdf · Jan Hoffmann (CMU) TACAS 2017 1 Machine Learning ML for ML: Learning Cost Semantics by Experiment](https://reader034.fdocuments.net/reader034/viewer/2022051811/6028793efc0c311ffe5d4119/html5/thumbnails/33.jpg)
What about the challenges?
Garbage CollectorCompiler Optimizations
15
![Page 34: ML for ML: Learning Cost Semantics by Experimentankushd/docs/TACAS17_Pres.pdf · Jan Hoffmann (CMU) TACAS 2017 1 Machine Learning ML for ML: Learning Cost Semantics by Experiment](https://reader034.fdocuments.net/reader034/viewer/2022051811/6028793efc0c311ffe5d4119/html5/thumbnails/34.jpg)
Simplified GC model• Only model the minor heap
• Each GC cycle starts with the full heap and ends with the empty heap
• All GC cycles take the same time
• Number of cycles is heap allocations divided by minor heap size
16
![Page 35: ML for ML: Learning Cost Semantics by Experimentankushd/docs/TACAS17_Pres.pdf · Jan Hoffmann (CMU) TACAS 2017 1 Machine Learning ML for ML: Learning Cost Semantics by Experiment](https://reader034.fdocuments.net/reader034/viewer/2022051811/6028793efc0c311ffe5d4119/html5/thumbnails/35.jpg)
GC model
17
�M
H0
⌫TgcGC time
Tgc Time for 1 minor GC cycle
H0 Size of Minor Heap
M Memory allocations of program
![Page 36: ML for ML: Learning Cost Semantics by Experimentankushd/docs/TACAS17_Pres.pdf · Jan Hoffmann (CMU) TACAS 2017 1 Machine Learning ML for ML: Learning Cost Semantics by Experiment](https://reader034.fdocuments.net/reader034/viewer/2022051811/6028793efc0c311ffe5d4119/html5/thumbnails/36.jpg)
Heap Allocations
18
Interpreter
•Learn time without GC•Use same interpreter for number of allocations
(T,M) =
X
c2CncTc,
X
c2CncMc
!
![Page 37: ML for ML: Learning Cost Semantics by Experimentankushd/docs/TACAS17_Pres.pdf · Jan Hoffmann (CMU) TACAS 2017 1 Machine Learning ML for ML: Learning Cost Semantics by Experiment](https://reader034.fdocuments.net/reader034/viewer/2022051811/6028793efc0c311ffe5d4119/html5/thumbnails/37.jpg)
Time with GC
T =X
c2CncTc +
�Pc2C ncMc
H0
⌫Tgc
19
![Page 38: ML for ML: Learning Cost Semantics by Experimentankushd/docs/TACAS17_Pres.pdf · Jan Hoffmann (CMU) TACAS 2017 1 Machine Learning ML for ML: Learning Cost Semantics by Experiment](https://reader034.fdocuments.net/reader034/viewer/2022051811/6028793efc0c311ffe5d4119/html5/thumbnails/38.jpg)
Time with GC
without GC
T =X
c2CncTc +
�Pc2C ncMc
H0
⌫Tgc
19
![Page 39: ML for ML: Learning Cost Semantics by Experimentankushd/docs/TACAS17_Pres.pdf · Jan Hoffmann (CMU) TACAS 2017 1 Machine Learning ML for ML: Learning Cost Semantics by Experiment](https://reader034.fdocuments.net/reader034/viewer/2022051811/6028793efc0c311ffe5d4119/html5/thumbnails/39.jpg)
Time with GC
without GC GC time
T =X
c2CncTc +
�Pc2C ncMc
H0
⌫Tgc
19
![Page 40: ML for ML: Learning Cost Semantics by Experimentankushd/docs/TACAS17_Pres.pdf · Jan Hoffmann (CMU) TACAS 2017 1 Machine Learning ML for ML: Learning Cost Semantics by Experiment](https://reader034.fdocuments.net/reader034/viewer/2022051811/6028793efc0c311ffe5d4119/html5/thumbnails/40.jpg)
Cost Model
Model
Training
Model Design
Testing
Accuracy
DesigningMachine Learning
Programs
Programs20
![Page 41: ML for ML: Learning Cost Semantics by Experimentankushd/docs/TACAS17_Pres.pdf · Jan Hoffmann (CMU) TACAS 2017 1 Machine Learning ML for ML: Learning Cost Semantics by Experiment](https://reader034.fdocuments.net/reader034/viewer/2022051811/6028793efc0c311ffe5d4119/html5/thumbnails/41.jpg)
Cost Model
Model
Training
Model Design
Testing
Accuracy
DesigningMachine Learning
Programs
Programs20
![Page 42: ML for ML: Learning Cost Semantics by Experimentankushd/docs/TACAS17_Pres.pdf · Jan Hoffmann (CMU) TACAS 2017 1 Machine Learning ML for ML: Learning Cost Semantics by Experiment](https://reader034.fdocuments.net/reader034/viewer/2022051811/6028793efc0c311ffe5d4119/html5/thumbnails/42.jpg)
Factorial
0
0.01
0.02
0.03
0.04
0.05
0.06
0.07
0.08
0.09
0.1
0 2 4 6 8 10 12 14 16 18 20
Exec
utio
n Ti
me
(ms)
ErrorActual Time
Expected Time
Input Size (x1000)
Error = 11.77%
21
![Page 43: ML for ML: Learning Cost Semantics by Experimentankushd/docs/TACAS17_Pres.pdf · Jan Hoffmann (CMU) TACAS 2017 1 Machine Learning ML for ML: Learning Cost Semantics by Experiment](https://reader034.fdocuments.net/reader034/viewer/2022051811/6028793efc0c311ffe5d4119/html5/thumbnails/43.jpg)
Append
0
5
10
15
20
25
30
35
40
45
0 2 4 6 8 10 12 14 16 18 20
Exec
utio
n Ti
me
(ms)
ErrorActual Time
Expected Time
Input Size (x10000)
Error = 13.68%
22
![Page 44: ML for ML: Learning Cost Semantics by Experimentankushd/docs/TACAS17_Pres.pdf · Jan Hoffmann (CMU) TACAS 2017 1 Machine Learning ML for ML: Learning Cost Semantics by Experiment](https://reader034.fdocuments.net/reader034/viewer/2022051811/6028793efc0c311ffe5d4119/html5/thumbnails/44.jpg)
Applications
23
![Page 45: ML for ML: Learning Cost Semantics by Experimentankushd/docs/TACAS17_Pres.pdf · Jan Hoffmann (CMU) TACAS 2017 1 Machine Learning ML for ML: Learning Cost Semantics by Experiment](https://reader034.fdocuments.net/reader034/viewer/2022051811/6028793efc0c311ffe5d4119/html5/thumbnails/45.jpg)
Which one’s faster?let rec append l1 l2 = match l1 with | [] -> l2 | hd::tl -> hd::(append tl l2);;
let rec append l1 l2 = match l1 with | [] -> l2 | x::[] -> x::l2 | x::y::[] -> x::y::l2 | x::y::tl -> x::y::(append tl l2);;
24
![Page 46: ML for ML: Learning Cost Semantics by Experimentankushd/docs/TACAS17_Pres.pdf · Jan Hoffmann (CMU) TACAS 2017 1 Machine Learning ML for ML: Learning Cost Semantics by Experiment](https://reader034.fdocuments.net/reader034/viewer/2022051811/6028793efc0c311ffe5d4119/html5/thumbnails/46.jpg)
Which one’s faster?let rec append l1 l2 = match l1 with | [] -> l2 | hd::tl -> hd::(append tl l2);;
let rec append l1 l2 = match l1 with | [] -> l2 | x::[] -> x::l2 | x::y::[] -> x::y::l2 | x::y::tl -> x::y::(append tl l2);;
24
![Page 47: ML for ML: Learning Cost Semantics by Experimentankushd/docs/TACAS17_Pres.pdf · Jan Hoffmann (CMU) TACAS 2017 1 Machine Learning ML for ML: Learning Cost Semantics by Experiment](https://reader034.fdocuments.net/reader034/viewer/2022051811/6028793efc0c311ffe5d4119/html5/thumbnails/47.jpg)
Symbolic Bounds (RAML)
Program Time Bound (ns)
append
map
insertion sort
0.45 + 11.28M +
�24M
2097448
⌫⇥ 3125429.15
0.60 + 13.16M +
�24M
2097448
⌫⇥ 3125429.15
0.45 + 6.06M + 5.83M2 +
�12M + 12M2
2097448
⌫⇥ 3125429.15
25
![Page 48: ML for ML: Learning Cost Semantics by Experimentankushd/docs/TACAS17_Pres.pdf · Jan Hoffmann (CMU) TACAS 2017 1 Machine Learning ML for ML: Learning Cost Semantics by Experiment](https://reader034.fdocuments.net/reader034/viewer/2022051811/6028793efc0c311ffe5d4119/html5/thumbnails/48.jpg)
Conclusion• Cost model for execution time and heap allocations
• Learned hardware specific constants
• Added a simple model for the garbage collector
• Roughly 20% on Intel x86 and ARM
• Fast and slow implementations of specification
• Execution time prediction (symbolic bounds)
26
![Page 49: ML for ML: Learning Cost Semantics by Experimentankushd/docs/TACAS17_Pres.pdf · Jan Hoffmann (CMU) TACAS 2017 1 Machine Learning ML for ML: Learning Cost Semantics by Experiment](https://reader034.fdocuments.net/reader034/viewer/2022051811/6028793efc0c311ffe5d4119/html5/thumbnails/49.jpg)
Conclusion• Cost model for execution time and heap allocations
• Learned hardware specific constants
• Added a simple model for the garbage collector
• Roughly 20% on Intel x86 and ARM
• Fast and slow implementations of specification
• Execution time prediction (symbolic bounds)
26
It works!
![Page 50: ML for ML: Learning Cost Semantics by Experimentankushd/docs/TACAS17_Pres.pdf · Jan Hoffmann (CMU) TACAS 2017 1 Machine Learning ML for ML: Learning Cost Semantics by Experiment](https://reader034.fdocuments.net/reader034/viewer/2022051811/6028793efc0c311ffe5d4119/html5/thumbnails/50.jpg)
Learned Cost for Time without GC (x86)
Base : 832.6918
Float Add : 2.1020 Float Sub : 2.1166 Float Mult : 1.7370 Float Div : 8.5757
Float Uminus : 1.2322 Float Eq : 0.5826 Float (<) : 0.6191
Float (<=) : 0.6258 Float (>) : 0.5855
Float (>=) : 0.6295Not op : 0.4242 And op : 0.1843
Or op : 0.1838
Pattern Match : 0.2231 Tuple Head : 5.8929 Tuple Elem : 1.7177
Tuple Match : 0.2370
App : 1.5056 App (tail) : 0.1562 Let Const : 2.8280 Let Func : 1.3127 Let Rec : 3.7381 Closure : 2.9210
Int Add : 0.2972 Int Sub : 0.2781 Int Mult : 1.2992
Int Mod : 19.2316 Int Div : 19.0119
Int Uminus : 0.4196 Int Eq : 0.3826 Int (<) : 0.3818
Int (<=) : 0.3815 Int (>) : 0.3750
Int (>=) : 0.3819
27
![Page 51: ML for ML: Learning Cost Semantics by Experimentankushd/docs/TACAS17_Pres.pdf · Jan Hoffmann (CMU) TACAS 2017 1 Machine Learning ML for ML: Learning Cost Semantics by Experiment](https://reader034.fdocuments.net/reader034/viewer/2022051811/6028793efc0c311ffe5d4119/html5/thumbnails/51.jpg)
Heap Consumption (x86)Base : 96.03
Not op : 0.00 And op : 0.00
Or op : 0.00
App : 0.00 App (tail) : 0.00 Let Const : 0.00 Let Func : 0.00 Let Rec : 0.00
Pattern Match : 0.00 Tuple Match : 0.00
Int Add : 0.00 Int Sub : 0.00 Int Mult : 0.00 Int Mod : 0.00 Int Div : 0.00
Int Uminus : 0.00 Int Eq : 0.00 Int (<) : 0.00
Int (<=) : 0.00 Int (>) : 0.00
Int (>=) : 0.00
Fun Def : 24.00 Closure : 7.99 Cons : 24.00
28
![Page 52: ML for ML: Learning Cost Semantics by Experimentankushd/docs/TACAS17_Pres.pdf · Jan Hoffmann (CMU) TACAS 2017 1 Machine Learning ML for ML: Learning Cost Semantics by Experiment](https://reader034.fdocuments.net/reader034/viewer/2022051811/6028793efc0c311ffe5d4119/html5/thumbnails/52.jpg)
Tail Call • Function call on the outermost
• Optimized to “jump” instruction in assembly
let f x = 1 + x;;
let g n = if (n = 0) then 0 else f n;;
let h n = if (n = 0) then 0 else 1 + f n;;
29
![Page 53: ML for ML: Learning Cost Semantics by Experimentankushd/docs/TACAS17_Pres.pdf · Jan Hoffmann (CMU) TACAS 2017 1 Machine Learning ML for ML: Learning Cost Semantics by Experiment](https://reader034.fdocuments.net/reader034/viewer/2022051811/6028793efc0c311ffe5d4119/html5/thumbnails/53.jpg)
Tuples
let x = (1, 2, 3) let x = 1::(2::[])
Tuple Head = 1 Tuple Elem = 3
Tuple Head = 2 Tuple Elem = 4
30