accuracy-aware program transformationscrest.cs.ucl.ac.uk/cow/26/slides/cow26_misailovic.pdf ·...

57
Accuracy-Aware Program Transformations Sasa Misailovic MIT CSAIL

Upload: others

Post on 13-Jul-2020

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Accuracy-Aware Program Transformationscrest.cs.ucl.ac.uk/cow/26/slides/COW26_Misailovic.pdf · Solving Problems with Transformations Data center needs to draw less power Voltage drops,

Accuracy-Aware

Program

Transformations

Sasa Misailovic

MIT CSAIL

Page 2: Accuracy-Aware Program Transformationscrest.cs.ucl.ac.uk/cow/26/slides/COW26_Misailovic.pdf · Solving Problems with Transformations Data center needs to draw less power Voltage drops,

Collaborators

Martin Rinard, Michael Carbin,

Stelios Sidiroglou, Henry Hoffmann,

Deokhwan Kim, Daniel Roy,

Zeyuan Allen Zhu, Michael Kling,

Jonathan Kelner, Anant Agarwal

Page 3: Accuracy-Aware Program Transformationscrest.cs.ucl.ac.uk/cow/26/slides/COW26_Misailovic.pdf · Solving Problems with Transformations Data center needs to draw less power Voltage drops,

Emerging Software and Hardware

Page 4: Accuracy-Aware Program Transformationscrest.cs.ucl.ac.uk/cow/26/slides/COW26_Misailovic.pdf · Solving Problems with Transformations Data center needs to draw less power Voltage drops,

Emerging Software and Hardware

Big Data; Approximate

Page 5: Accuracy-Aware Program Transformationscrest.cs.ucl.ac.uk/cow/26/slides/COW26_Misailovic.pdf · Solving Problems with Transformations Data center needs to draw less power Voltage drops,

Emerging Software and Hardware

Energy ConsciousBig Data; Approximate

Page 6: Accuracy-Aware Program Transformationscrest.cs.ucl.ac.uk/cow/26/slides/COW26_Misailovic.pdf · Solving Problems with Transformations Data center needs to draw less power Voltage drops,

Emerging Software and Hardware

Energy Conscious

Automatically Transform

Computations to Trade

Accuracy for Performance

and Energy

Big Data; Approximate

Page 7: Accuracy-Aware Program Transformationscrest.cs.ucl.ac.uk/cow/26/slides/COW26_Misailovic.pdf · Solving Problems with Transformations Data center needs to draw less power Voltage drops,

Solving Problems with Transformations

Data center

needs to draw

less power

Voltage drops, clock

ticks slower, start

missing deadlines

Program is

taking too

long to run

System gets

loaded, start

missing deadlines

Hand held needs

to go longer

between charges

Lose cores,

start missing

deadlines

Automatically Transform

Computations to Trade

Accuracy for Performance

and Energy

Page 8: Accuracy-Aware Program Transformationscrest.cs.ucl.ac.uk/cow/26/slides/COW26_Misailovic.pdf · Solving Problems with Transformations Data center needs to draw less power Voltage drops,

Consider This Transformation

for (i = 0; i < n; i++) { … }

for (i = 0; i < n; i += 2) { … }

Page 9: Accuracy-Aware Program Transformationscrest.cs.ucl.ac.uk/cow/26/slides/COW26_Misailovic.pdf · Solving Problems with Transformations Data center needs to draw less power Voltage drops,

Loop Perforation

Effects:

Should improve performance

Broadly applicable

for (i = 0; i < n; i++) { … }

for (i = 0; i < n; i += 2) { … }

Page 10: Accuracy-Aware Program Transformationscrest.cs.ucl.ac.uk/cow/26/slides/COW26_Misailovic.pdf · Solving Problems with Transformations Data center needs to draw less power Voltage drops,

Loop Perforation

Common Reaction:

But it changes the program semantics!

The result will be wrong ?!

for (i = 0; i < n; i++) { … }

for (i = 0; i < n; i += 2) { … }

Page 11: Accuracy-Aware Program Transformationscrest.cs.ucl.ac.uk/cow/26/slides/COW26_Misailovic.pdf · Solving Problems with Transformations Data center needs to draw less power Voltage drops,

Loop Perforation

Common Reaction:

But it changes the program semantics!

The result will be wrong ?!

The result can be less accurate!

for (i = 0; i < n; i++) { … }

for (i = 0; i < n; i += 2) { … }

Page 12: Accuracy-Aware Program Transformationscrest.cs.ucl.ac.uk/cow/26/slides/COW26_Misailovic.pdf · Solving Problems with Transformations Data center needs to draw less power Voltage drops,

Acceptability =

Accuracy + Integrity

Page 13: Accuracy-Aware Program Transformationscrest.cs.ucl.ac.uk/cow/26/slides/COW26_Misailovic.pdf · Solving Problems with Transformations Data center needs to draw less power Voltage drops,

Acceptability =

Accuracy + Integrity

Optimization problem:

minimize execution time given constraints on

accuracy and integrity of the computation

Page 14: Accuracy-Aware Program Transformationscrest.cs.ucl.ac.uk/cow/26/slides/COW26_Misailovic.pdf · Solving Problems with Transformations Data center needs to draw less power Voltage drops,

Optimization Inputs

Original

Program

for (i = 0; i < n; i++) { … }

for (i = 0; i < n; i += 2) { … }

Input &

Accuracy

Specification

Program

Transformation

Page 15: Accuracy-Aware Program Transformationscrest.cs.ucl.ac.uk/cow/26/slides/COW26_Misailovic.pdf · Solving Problems with Transformations Data center needs to draw less power Voltage drops,

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

Page 16: Accuracy-Aware Program Transformationscrest.cs.ucl.ac.uk/cow/26/slides/COW26_Misailovic.pdf · Solving Problems with Transformations Data center needs to draw less power Voltage drops,

Error

Time

ccc

for (i = 0; i < n; i++) { … }

for (i = 0; i < n; i += 2) { … }

Page 17: Accuracy-Aware Program Transformationscrest.cs.ucl.ac.uk/cow/26/slides/COW26_Misailovic.pdf · Solving Problems with Transformations Data center needs to draw less power Voltage drops,

Error

Time

ccc

for (i = 0; i < n; i++) { … }

for (i = 0; i < n; i += 2) { … }

Page 18: Accuracy-Aware Program Transformationscrest.cs.ucl.ac.uk/cow/26/slides/COW26_Misailovic.pdf · Solving Problems with Transformations Data center needs to draw less power Voltage drops,

Time

Error

Page 19: Accuracy-Aware Program Transformationscrest.cs.ucl.ac.uk/cow/26/slides/COW26_Misailovic.pdf · Solving Problems with Transformations Data center needs to draw less power Voltage drops,

Time

Error

Page 20: Accuracy-Aware Program Transformationscrest.cs.ucl.ac.uk/cow/26/slides/COW26_Misailovic.pdf · Solving Problems with Transformations Data center needs to draw less power Voltage drops,

Time

Error

Property: the result of the optimized

program is within the specified

error bound

Query: Return the program that

executes in minimal time

Page 21: Accuracy-Aware Program Transformationscrest.cs.ucl.ac.uk/cow/26/slides/COW26_Misailovic.pdf · Solving Problems with Transformations Data center needs to draw less power Voltage drops,

Find Transformation Candidates:

• Profile program to find time-consuming for loops

Analyze the Effects of Perforation:

• Integrity: memory safety, well formed output

• Performance: Compare execution times

• Accuracy: Compare the quality of the results

Navigate 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

Page 22: Accuracy-Aware Program Transformationscrest.cs.ucl.ac.uk/cow/26/slides/COW26_Misailovic.pdf · Solving Problems with Transformations Data center needs to draw less power Voltage drops,

Accuracy Analysis of Computation

c

Input

Original

Program Output

Output Abstraction

(Application-Specific)

Transformed

Program

Difference Bound

δ<

Page 23: Accuracy-Aware Program Transformationscrest.cs.ucl.ac.uk/cow/26/slides/COW26_Misailovic.pdf · Solving Problems with Transformations Data center needs to draw less power Voltage drops,

Analysis for Individual Loop Perforation

1. Perforate one time-consuming loop at a time

2. Execute perforated program

3. Filter out critical loops:

a) Program crashes

b) Accuracy loss > δmax

c) Execution slows down

d) Latent memory errors (Valgrind)

4. Repeat 1-3 for all loops, inputs, perforation rates

Page 24: Accuracy-Aware Program Transformationscrest.cs.ucl.ac.uk/cow/26/slides/COW26_Misailovic.pdf · Solving Problems with Transformations Data center needs to draw less power Voltage drops,

Individual Loop Perforation Results

0

5

10

15

20

25

30

35

40

Perforatable

Latent Errors

Bad Speedup

Bad Accuracy

Crash

# loops

From [ICSE 2010]

Page 25: Accuracy-Aware Program Transformationscrest.cs.ucl.ac.uk/cow/26/slides/COW26_Misailovic.pdf · Solving Problems with Transformations Data center needs to draw less power Voltage drops,

Individual Loop Perforation Results

0

5

10

15

20

25

30

35

40

Perforatable

Latent Errors

Bad Speedup

Bad Accuracy

Crash

# loops

From [ICSE 2010]

Page 26: Accuracy-Aware Program Transformationscrest.cs.ucl.ac.uk/cow/26/slides/COW26_Misailovic.pdf · Solving Problems with Transformations Data center needs to draw less power Voltage drops,

Individual Loop Perforation Results

0

5

10

15

20

25

30

35

40

Perforatable

Latent Errors

Bad Speedup

Bad Accuracy

Crash

# loops

From [ICSE 2010]

Page 27: Accuracy-Aware Program Transformationscrest.cs.ucl.ac.uk/cow/26/slides/COW26_Misailovic.pdf · Solving Problems with Transformations Data center needs to draw less power Voltage drops,

Individual Loop Perforation Results

0

5

10

15

20

25

30

35

40

Perforatable

Latent Errors

Bad Speedup

Bad Accuracy

Crash

# loops

From [ICSE 2010]

Page 28: Accuracy-Aware Program Transformationscrest.cs.ucl.ac.uk/cow/26/slides/COW26_Misailovic.pdf · Solving Problems with Transformations Data center needs to draw less power Voltage drops,

Individual Loop Perforation Results

0

5

10

15

20

25

30

35

40

Perforatable

Latent Errors

Bad Speedup

Bad Accuracy

Crash

# loops

From [ICSE 2010]

Page 29: Accuracy-Aware Program Transformationscrest.cs.ucl.ac.uk/cow/26/slides/COW26_Misailovic.pdf · Solving Problems with Transformations Data center needs to draw less power Voltage drops,

Individual Loop Perforation Results

0

5

10

15

20

25

30

35

40

Perforatable

Latent Errors

Bad Speedup

Bad Accuracy

Crash

# loops

From [ICSE 2010]

Page 30: Accuracy-Aware Program Transformationscrest.cs.ucl.ac.uk/cow/26/slides/COW26_Misailovic.pdf · Solving Problems with Transformations Data center needs to draw less power Voltage drops,

Percentage of Work Done

in Perforatable Loops

0

20

40

60

80

100

120

% inst

ruct

ions

Page 31: Accuracy-Aware Program Transformationscrest.cs.ucl.ac.uk/cow/26/slides/COW26_Misailovic.pdf · Solving Problems with Transformations Data center needs to draw less power Voltage drops,

Performance Increase of the Top

Perforatable Loop (Relative Error < 0.1)

1

1.2

1.4

1.6

1.8

2

2.2

Speedup

Page 32: Accuracy-Aware Program Transformationscrest.cs.ucl.ac.uk/cow/26/slides/COW26_Misailovic.pdf · Solving Problems with Transformations Data center needs to draw less power Voltage drops,

Result Interpretation

Manual inspection of perforatable computations:

x264: motion estimation

bodytrack: MCMC

swaptions: Monte Carlo simulation

ferret: similarity hashing

blackscholes: redundant computation

canneal: simulated annealing

streamcluster: cluster center search

Common: Approximate/heuristic computations

Page 33: Accuracy-Aware Program Transformationscrest.cs.ucl.ac.uk/cow/26/slides/COW26_Misailovic.pdf · Solving Problems with Transformations Data center needs to draw less power Voltage drops,

x264 Cumulative Loop ScoresM

ean N

orm

aliz

ed T

ime

Accuracy loss

From [FSE 2011]

Page 34: Accuracy-Aware Program Transformationscrest.cs.ucl.ac.uk/cow/26/slides/COW26_Misailovic.pdf · Solving Problems with Transformations Data center needs to draw less power Voltage drops,

x264 Cumulative Loop ScoresM

ean N

orm

aliz

ed T

ime

Accuracy loss

From [FSE 2011]

Page 35: Accuracy-Aware Program Transformationscrest.cs.ucl.ac.uk/cow/26/slides/COW26_Misailovic.pdf · Solving Problems with Transformations Data center needs to draw less power Voltage drops,

Status

Good:

Profitable accuracy/performance tradeoffs

Matches the approximate computations

But:

No guarantees on accuracy

No guarantees on safety

How to improve it?

How often large errors happen?

What safety guarantees can we provide?

Page 36: Accuracy-Aware Program Transformationscrest.cs.ucl.ac.uk/cow/26/slides/COW26_Misailovic.pdf · Solving Problems with Transformations Data center needs to draw less power Voltage drops,

Reasoning About Transformed Programs

Accuracy

Probabilistic Reasoning [SAS ’11, POPL ‘12]

(with Z. Zhu, J. Kelner, D. Roy, M. Rinard)

Integrity

Relational Logic Reasoning [PLDI ‘12, PEPM ‘13]

(with M. Carbin, D. Kim, M. Rinard)

Page 37: Accuracy-Aware Program Transformationscrest.cs.ucl.ac.uk/cow/26/slides/COW26_Misailovic.pdf · Solving Problems with Transformations Data center needs to draw less power Voltage drops,

… … … …

• Nodes represent computation

• Edges represent flow of data

From [POPL ‘12]

Page 38: Accuracy-Aware Program Transformationscrest.cs.ucl.ac.uk/cow/26/slides/COW26_Misailovic.pdf · Solving Problems with Transformations Data center needs to draw less power Voltage drops,

• Functions – process individual data

• Reduction nodes – aggregate data

… … … …

Page 39: Accuracy-Aware Program Transformationscrest.cs.ucl.ac.uk/cow/26/slides/COW26_Misailovic.pdf · Solving Problems with Transformations Data center needs to draw less power Voltage drops,

min

avgavg avgavg

• Functions – process individual data

• Reduction nodes – aggregate data

… … … …

Page 40: Accuracy-Aware Program Transformationscrest.cs.ucl.ac.uk/cow/26/slides/COW26_Misailovic.pdf · Solving Problems with Transformations Data center needs to draw less power Voltage drops,

min

avgavg avgavg

Function substitution• Multiple implementations

• Each has expected error/time (𝐸, 𝑇)

f2 f3f1

… … … …

Page 41: Accuracy-Aware Program Transformationscrest.cs.ucl.ac.uk/cow/26/slides/COW26_Misailovic.pdf · Solving Problems with Transformations Data center needs to draw less power Voltage drops,

min

avgavg avgavg

Function substitution• Multiple implementations

• Each has expected error/time (𝐸, 𝑇)

… … … …

Page 42: Accuracy-Aware Program Transformationscrest.cs.ucl.ac.uk/cow/26/slides/COW26_Misailovic.pdf · Solving Problems with Transformations Data center needs to draw less power Voltage drops,

min

avgavg avgavg

Function substitution• Inputs of functions have specified ranges

• Each function has Lipschitz property

… … … …

[a,b] [c,d] [a,b] [c,d] [a,b] [c,d]… … …[a,b] [c,d]

Page 43: Accuracy-Aware Program Transformationscrest.cs.ucl.ac.uk/cow/26/slides/COW26_Misailovic.pdf · Solving Problems with Transformations Data center needs to draw less power Voltage drops,

Sampling inputs of reduction nodes

• Reductions consume fewer inputs

min

avgavg avgavg

… … … …

Page 44: Accuracy-Aware Program Transformationscrest.cs.ucl.ac.uk/cow/26/slides/COW26_Misailovic.pdf · Solving Problems with Transformations Data center needs to draw less power Voltage drops,

min

avgavg

Sampling inputs of reduction nodes

• Reductions consume fewer inputs

… … … …

Page 45: Accuracy-Aware Program Transformationscrest.cs.ucl.ac.uk/cow/26/slides/COW26_Misailovic.pdf · Solving Problems with Transformations Data center needs to draw less power Voltage drops,

Search for Optimized Programs

Time Property: With high probability

the result of the optimized program

is within the specified error bound

Error

Page 46: Accuracy-Aware Program Transformationscrest.cs.ucl.ac.uk/cow/26/slides/COW26_Misailovic.pdf · Solving Problems with Transformations Data center needs to draw less power Voltage drops,

Search for Optimized Programs

Time Property: With high probability

the result of the optimized program

is within the specified error bound

Error

𝐏𝐫 𝐑𝐞𝐬 − 𝐑𝐞𝐬′ < 𝐁 > 𝟏 − 𝛅

Page 47: Accuracy-Aware Program Transformationscrest.cs.ucl.ac.uk/cow/26/slides/COW26_Misailovic.pdf · Solving Problems with Transformations Data center needs to draw less power Voltage drops,

Search for Optimized Programs

Time Property:

Query: Generate randomized program

that executes in minimal time

Error

𝐏𝐫 𝐑𝐞𝐬 − 𝐑𝐞𝐬′ < 𝐁 > 𝟏 − 𝛅

Page 48: Accuracy-Aware Program Transformationscrest.cs.ucl.ac.uk/cow/26/slides/COW26_Misailovic.pdf · Solving Problems with Transformations Data center needs to draw less power Voltage drops,

Find Transformation Candidates:

• User provides function implementations and specs

Analyze Transformed Computations:

• Construct analytic expressions for (1) performanceand (2) error emergence and propagation

• Variables: probabilities of executing alternate versions

Navigate Tradeoff Space:

• Construct mathematical optimization problem:

Using expressions for performance and error

• Non-linear Non-convex tradeoff space:

1 + 𝜀 -approximation of globally optimal tradeoff curve

Constraint Based Search Algorithm

From [POPL ‘12]

Page 49: Accuracy-Aware Program Transformationscrest.cs.ucl.ac.uk/cow/26/slides/COW26_Misailovic.pdf · Solving Problems with Transformations Data center needs to draw less power Voltage drops,

Divide and conquer

• For each subcomputation

construct tradeoff curve

• Dynamic programming

Properties

• Polynomial time

• 1 + 𝜀 -approximation of

true tradeoff curve

Tradeoff Curve Construction Algorithm

min

1

n

n n

avg avg

m m

Page 50: Accuracy-Aware Program Transformationscrest.cs.ucl.ac.uk/cow/26/slides/COW26_Misailovic.pdf · Solving Problems with Transformations Data center needs to draw less power Voltage drops,

Divide and conquer

• For each subcomputation

construct tradeoff curve

• Dynamic programming

Properties

• Polynomial time

• 1 + 𝜀 -approximation of

true tradeoff curve

Tradeoff Curve Construction Algorithm

min

1

n

n n

avg avg

m m

Page 51: Accuracy-Aware Program Transformationscrest.cs.ucl.ac.uk/cow/26/slides/COW26_Misailovic.pdf · Solving Problems with Transformations Data center needs to draw less power Voltage drops,

Divide and conquer

• For each subcomputation

construct tradeoff curve

• Dynamic programming

Properties

• Polynomial time

• 1 + 𝜀 -approximation of

true tradeoff curve

Tradeoff Curve Construction Algorithm

min

1

n

n n

avg

m

Page 52: Accuracy-Aware Program Transformationscrest.cs.ucl.ac.uk/cow/26/slides/COW26_Misailovic.pdf · Solving Problems with Transformations Data center needs to draw less power Voltage drops,

Divide and conquer

• For each subcomputation

construct tradeoff curve

• Dynamic programming

Properties

• Polynomial time

• 1 + 𝜀 -approximation of

true tradeoff curve

Tradeoff Curve Construction Algorithm

min

1

n

n n

Page 53: Accuracy-Aware Program Transformationscrest.cs.ucl.ac.uk/cow/26/slides/COW26_Misailovic.pdf · Solving Problems with Transformations Data center needs to draw less power Voltage drops,

Divide and conquer

• For each subcomputation

construct tradeoff curve

• Dynamic programming

Properties

• Polynomial time

• 1 + 𝜀 -approximation of

true tradeoff curve

Tradeoff Curve Construction Algorithm

min

1

n

Page 54: Accuracy-Aware Program Transformationscrest.cs.ucl.ac.uk/cow/26/slides/COW26_Misailovic.pdf · Solving Problems with Transformations Data center needs to draw less power Voltage drops,

Divide and conquer

• For each subcomputation

construct tradeoff curve

• Dynamic programming

Properties

• Polynomial time

• 1 + 𝜀 -approximation of

true tradeoff curve

Tradeoff Curve Construction Algorithm

Page 55: Accuracy-Aware Program Transformationscrest.cs.ucl.ac.uk/cow/26/slides/COW26_Misailovic.pdf · Solving Problems with Transformations Data center needs to draw less power Voltage drops,

Comparison With Explicit Search

Finite vs Infinite Size Search Space

Input vs Declarative Specification Based

General vs Restricted Model of Computation

Page 56: Accuracy-Aware Program Transformationscrest.cs.ucl.ac.uk/cow/26/slides/COW26_Misailovic.pdf · Solving Problems with Transformations Data center needs to draw less power Voltage drops,

Related Work

Other Accuracy-aware Transformations We Explored:

• Task Skipping [Rinard ICS ‘06, Rinard OOPSLA ’07]

• Loop Parallelization with Data Races [TECS PEC ’12, RACES ‘12]

• Dynamic Knobs [ASPLOS ‘11]

Our group has also been working on transformations to prevent otherwise fatal errors (segmentation faults, infinite loops, buffer overflows, SQL injection attacks)

More Accuracy-aware Transformations Researchers Explored:

• Unreliable Data Stores [Liu et al ASPLOS ‘11, Sampson et al PLDI ’11]

• Multiple Implementations [Ansel et al PLDI ‘09, Chilimbi et al PLDI ’10]

• Approximate Memoization [Chaudhuri et al FSE ’11]

Page 57: Accuracy-Aware Program Transformationscrest.cs.ucl.ac.uk/cow/26/slides/COW26_Misailovic.pdf · Solving Problems with Transformations Data center needs to draw less power Voltage drops,

Takeaway

Emerging trend of computations on large data sets

Accuracy-aware transformations are powerful tool

• Improve performance

• Reduce power

• Facilitate dynamic adaptation

Interaction of program analysis and search techniques

to find profitable, safe, and predictable tradeoffs