Accuracy-Aware Program
Transformations
Sasa Misailovic
MIT CSAIL
Collaborators
Martin Rinard, Michael Carbin, Stelios Sidiroglou, Henry Hoffmann,
Deokhwan Kim, Fan Long, Daniel Roy, Zeyuan Allen Zhu, Michael Kling, Jonathan Kelner, Anant Agarwal
Trade Accuracyfor Energy and Performance
[Rinard ICS’06, OOPSLA’07; Misailovic, Sidiroglou, Hoffmann, Rinard ICSE’10; Carbin, Rinard, ISSTA’10; Hoffmann, Sidiroglou, Carbin, Misailovic, Agarwal, Rinard ASPLOS’11; Sidiroglou, Misailovic, Hoffmann, Rinard FSE’11; Misailovic, Roy, Rinard, SAS‘11; Zhu, Misailovic, Kelner, Rinard POPL’12; Carbin, Kim, Misailovic, Rinard PLDI’12; Misailovic, Sidiroglou, Rinard, RACES‘12; Misailovic, Kim, Rinard TECS PEC’13; Carbin, Kim, Misailovic, Rinard PEPM’13; Carbin, Misailovic, Rinard, OOPSLA ‘13; …]
Harness Approximate Computing
How to systematically generate approximate programs?
How to predict accuracy of the results ofapproximate programs?
How to find the most profitable approximate programs?
Automated Transformations
Probabilistic Reasoning
Explicit Search and Mathematical Optimization
Transformations
Do less work• Loop perforation• Sampling, Task skipping
for (i = 0; i < n; i += 2) { … }
r = var +. 2;
r = f_0(x) f_1(x);
Do different kind of work• Randomized substitution
Exploit Execution Environment• Unreliable operation placement• Unreliable memory regions, Lock elision
Where and when should we apply the transformations?
What are the benefits and costs?
Optimization Framework
• Find Candidates for Transformation
• Analyze Effects of the Transformations
• Navigate Tradeoff Space
for (i = 0; i < n; i++) { … }
for (i = 0; i < n; i += 2) { … }
ccc
Find Transformation Candidates:• Profile program to find time-consuming for
loopsAnalyze the Effects of Transformation:• Performance: Compare execution times• Accuracy: Compare the quality of the results• Safety: memory safety, well formed outputNavigate Tradeoff Space:• Combine multiple perforatable loops
Prioritize loops by their individual performance and accuracy
Greedy or Exhaustive Search with Pruning
Explicit Search Algorithm for Perforation
[Misailovic, Sidiroglou, Hoffmann, Rinard ICSE’10; Hoffmann, Sidiroglou, Carbin, Misailovic, Agarwal, Rinard ASPLOS’11; Sidiroglou, Misailovic,
Hoffmann, Rinard FSE’11]
x264 Cumulative Loop Scores
M
ean
Nor
mal
ized
Tim
e
Accuracy loss (%)
Computational Kernels: Several perforatable computations execute for the majority of the time
Computational patterns:• Distance metrics• Data Statistics• Iteration steps• Monte-Carlo
Benchmark
# Perforatable
Loops
% Time
X264 14 > 60%
Bodytrack 8 > 75%
Swaptions 4 > 99%
Ferret 2 > 40%
Blackscholes
1 > 98%
Canneal 1 > 5%
Streamcluster
1 > 98%
Next Step: Analyses with Guarantees
Accuracy analysis: Results valid for a whole range of inputs, not just those used in testing
Navigation: Explore the space of transformed programs to find those with optimal tradeoffs
Accuracy Analysis: Probabilistic Reasoning
𝐏𝐫 [|𝐑𝐞𝐬−𝐑𝐞𝐬 ′ (𝐪)|>𝐁 ]<𝜺
[Misailovic, Roy, Rinard SAS ’11; Zhu, Misailovic, Kelner, Rinard POPL ’12; Misailovic, Sidiroglou, Rinard, RACES ‘12, Misailovic, Kim, Rinard
TECS PEC ’13, Carbin, Misailovic, Rinard, OOPSLA ’13, Misailovic, Rinard WACAS ‘14,
Misailovic, Carbin, Achour, Qi, Rinard MIT-TR ‘14]
For approximate program configuration
Optimization of Map-Fold Computations
outList = Map ( Func(x),
inputList
)
Func0: (0,T0) Func1: (1,T1)Func2: (2,T2)
[Zhu, Misailovic, Kelner, Rinard POPL 2012; Misailovic, Rinard WACAS 2014]
Accuracy Requirement:
Optimization of Map-Fold Computations
Configuration: Probability to execute each version of Func Range: , Sum:
Accuracy Loss Constraint:
Goal:
Linear + Dynamic programming
outList = Map(
Func0(x)
Func1(x)
Func2(x) ,
inputList)
Func0: (0,T0) Func1: (1,T1) Func2: (2,T2)
[Zhu, Misailovic, Kelner, Rinard POPL 2012; Misailovic, Rinard WACAS 2014]
float<0.99*R(x)>
f(float in unrel x) { y = g(x) +. h(x);
return y *. y; }
Developer’s reliability specification
Chisel: Automatic Generation of Approximate Rely Programs
[Misailovic, Carbin, Achour, Qi, Rinard MIT-TR 14]
Variable and Operation Annotations
Chisel: Automatic Generation of Approximate Rely Programs
Configuration: Unreliable variable or unreliable operationRange:
Reliability Constraint:
Goal:
Integer Linear Programming
float<0.99*R(x)>
f(float x) { y = g(x) + h(x);
return y * y; }
Developer’s specification
[Misailovic, Carbin, Achour, Qi, Rinard MIT-TR 14]
Navigate Search Space: Mathematical Optimization
Find configuration s. t.
[Zhu, Misailovic, Kelner, Rinard POPL ’12; Misailovic, Rinard WACAS ‘14
Misailovic, Carbin, Achour, Qi, Rinard, MIT-TR ‘14]
Looking Forward
Fully Exploit Optimization Opportunities: both application- and hardware-level transformations
Reasoning About Uncertainty: • logic-based techniques• probabilistic techniques• empirical techniques
Practical Aspects: provide intuition and control for developers and domain experts
Takeaway
Accuracy-aware transformations• Improve performance• Reduce energy consumption• Facilitate dynamic adaptation
and software specialization
Program analysis and search can help find profitable, safe, and predictable tradeoffs
Takeaway
Accuracy-aware transformations• Improve performance• Reduce energy consumption• Facilitate dynamic adaptation
and software specialization
Program analysis and search can help find profitable, safe, and predictable tradeoffs