Docsity

Lecture Slides on Continuous Compilation: Code Optimization | CS 2001, Study notes of Computer Science

Toggle sidebar
bg1
Page 1
Continuous Compilation: A New
Approach to Aggressive and
Adaptive Code Transformation
Bruce R. Childers
University of Pittsburgh
Pittsburgh, Pennsylvania, USA
http://www.cs.pitt.edu/coco
This work is a collaboration of many people!
Sponsored by Next Generation Systems, National Science Foundation.
Code Optimization
• Sophisticated algorithms exist for many
optimizations that do quite well
• We are at the point of diminishing returns in
applying optimizations - small gains are
considered good
• The challenge is to go beyond current
optimization improvements
Continuous Compilation
• A new approach: Apply optimizations both
statically at compile-time and dynamically at run-
time with static planning
• Plan for both static and dynamic optimizations
– Understand interactions of existing optimizations
– Efficacy of both static and dynamic optimizations
• Determine what optimizations to apply, where to
apply them, the order in which to apply them, and
their parameters
Outline
• Introduction: Continuous Compilation
• CoCo Framework
• Profit-driven Optimization
– Loop optimizations
– Scalar optimizations
• CoCo Run-time System
– Software dynamic translation
– Program instrumentation and optimization
•Summary
Continuous Compilation
Static Compi lation
(using profiles,
estimation mod els)
Phase 1
Static Compilation
(using profiles,
estimation models)
Phase 1
Program Execution
and Dynamic
Optimization (using
monitor and
optimization pl ans)
Phase 2
Program Execution
and Dynamic
Optimization (using
monitor and
optimization plans)
Phase 2
Off-li ne Adaptation
and Refinement of
Monitor and
Optimization Plans
Phase 3
Off-line Adaptation
and Refinement of
Monitor and
Optimizati on Plans
Phase 3
Recompilation and
Regeneration of
Monitor and
Optimization Plans
Phase 4
Recompi lation and
Regeneration of
Monitor and
Optimization Plans
Phase 4
As time passes, the continuous compiler moves through phases, possibly revisiting earlier ones.
Target applications: Long running programs that have different
phases of execution.
CoCo Framework
Dynamic
Optimizer and
SDT
Monitor
Continuous
State
Monitor
Plans
Opt.
Plans
Program
Application
Information
Repository
Application
Static Compiler Dynamic Compiler
Profiles
Program
Models
Static Optimizer
Planner
Machinean
d
Optimization
Information
Repository
Estimation
Models Machine
Models
Conductor
Debugger
Checker
Checker
pf3
pf4
pf5
pf8

Partial preview of the text

Download Lecture Slides on Continuous Compilation: Code Optimization | CS 2001 and more Study notes Computer Science in PDF only on Docsity!

Continuous Compilation: A New

Approach to Aggressive and

Adaptive Code Transformation

Bruce R. Childers

University of Pittsburgh

Pittsburgh, Pennsylvania, USA

[email protected]

http://www.cs.pitt.edu/coco

This work is a collaboration of many people! Sponsored by Next Generation Systems, National Science Foundation.

Code Optimization

  • Sophisticated algorithms exist for many

optimizations that do quite well

  • We are at the point of diminishing returns in

applying optimizations - small gains are

considered good

  • The challenge is to go beyond current

optimization improvements

Continuous Compilation

  • A new approach: Apply optimizations both

statically at compile-time and dynamically at run-

time with static planning

  • Plan for both static and dynamic optimizations
    • Understand interactions of existing optimizations
    • Efficacy of both static and dynamic optimizations
  • Determine what optimizations to apply, where to

apply them, the order in which to apply them, and

their parameters

Outline

  • Introduction: Continuous Compilation
  • CoCo Framework
  • Profit-driven Optimization
    • Loop optimizations
    • Scalar optimizations
  • CoCo Run-time System
    • Software dynamic translation
    • Program instrumentation and optimization
  • Summary

Continuous Compilation

Static Compilation (using profiles, estimation models)

Phase 1

Static Compilation (using profiles, estimation models)

Phase 1

Program Execution and Dynamic Optimization (using monitor and optimization plans) Phase 2

Program Execution and Dynamic Optimization (using monitor and optimization plans) Phase 2

Off-line Adaptation and Refinement of Monitor and Optimization Plans

Phase 3

Off-line Adaptation and Refinement of Monitor and Optimization Plans

Phase 3

Recompilation and Regeneration of Monitor and Optimization Plans

Phase 4

Recompilation and Regeneration of Monitor and Optimization Plans

Phase 4

As time passes, the continuous compiler moves through phases, possibly revisiting earlier ones.

Target applications: Long running programs that have different phases of execution.

CoCo Framework

Dynamic Optimizer and SDT

Monitor

Continuous State

Monitor Plans Opt. Plans

Program

ApplicationI nformationRe pository

Application

Static Compiler Dynamic Compiler

ProgramModels Profiles

Static Optimizer

Planner

Ma chine an dOp tim izationInform atio nRe pository

Estimation Models

Machine Models

Conductor

Debugger

Checker

Checker

CoCo’s Preliminary Prediction

Framework

  • Predict the impact of optimizations
  • With estimates of benefit and penalty:
    • Decision about what optimizations to apply
    • Where to apply them
    • In what order to apply Taking into account the code context and machine resources

Code Predict Impact

Apply

Don’t Apply

Beneficial

Not Beneficial

Motivation

  • Performance problems of the optimizations
    • Optimizations may degrade performance in some circumstances
    • Optimizations interact with one another by enabling and disabling other optimizations
  • Optimizations often applied in an ad hoc fashion
    • Simple heuristic: always apply if applicable
    • Predetermined order to apply optimizations
    • Fixed configurations of optimizations

Challenges

  • Performance varies widely, based on
    • Code context (e.g., loop trip count)
    • Configuration of optimizations (e.g. loop unrolling factor)
    • Machine configurations (e.g. cache configuration)
    • The order of optimizations
  • Many resources impact overall performance
    • Cache configuration
    • Instruction scheduling rules
    • Register numbers and types

Our Approach

  • Build and develop analytic models to predict

when to apply an optimization, without actually

applying the optimization

  • Need models of particular optimizations
  • Need models of the code
  • Need models of the resources that are effected
  • Based on analytic models, make decisions about

what optimizations to apply

  • We don’t need accurate models, just the trend needs to be accurate enough to do the estimates

Framework for Predicting Optimizations

Source Code

Code

Optimizations

Resources

FPO: a Framework, consisting of models, for Predicting the

impact of Optimizations

Consider both loop and scalar optimizations (e.g., PRE)

Prediction

Plug ‘n Play Models

  1. Extract code context
  2. Model effect of the optimization
  3. Model effect on the machine resources

Loop Code Model

Source Code

Code

Optimizations

Resources

Prediction

Express code characteristics that effect resources

For loops and cache: 1. loop header, 2. array references,

3. reference sequence

Refs A I C

Refs

lb

step

ub

loop

= × +

Selectively Applying Loop OptimizationsSelectively Applying Loop Optimizations

alv (100)lgsi (98)lgsi (128)smsi (124)tfsi (42) biquad_N(90)gdevcdj(100)pegwit(100)

adi efluxtomcatvpenta

Interchange Tiling Reversal

52%

Choose Most Beneficial Loop Optimization Choose Most Beneficial Loop Optimization

0%

20%

40%

60%

80%

100%

alv irkernel lgsi gdevcdj smsi srsi biquad_N tfsi tomcat3 lms pegwit

Interchange Tiling Reversal Unrolling Fusion Distribution Not Apply

Loop Opt. Prediction Accuracy

  • Accurate trend
    • Whether an optimization is beneficial or not
  • Correct prediction
    • When prediction matches actual execution behavior
  • Prediction accuracy
    • Single loop nest: varying trip count
    • Multiple loop nests: the number of loop nests

Loop Opt. Prediction AccuracyLoop Opt. Prediction Accuracy

Average 99% 98% 92%

pegwit 100% 100% 81.6%

lms 97.4% 100% 94.7%

gdevcdj 100% 100% 97.4%

biquad_N 89.5% 88.2% 100%

tomcat3 98.7% 92.1% 93.4%

tfsi 100% 97.4% 100%

srsi 100% 100% 86.8%

smsi 100% 100% 86.8%

lgsi 100% 100% 82%

irkernel 98.7% 100% 93.4%

alv 100% 100% 97.4%

Benchmark Interchange Tiling Reversal

Prediction accuracy for single loop nest

Similar results for multiple loop nests

FPO: Scalar Optimizations

  • Transformations that operate on scalar code
    • E.g., constant propogation, dead code elimination, partial redundancy elimination
  • Can have several impacts
    • Reduce amount of computation
    • Change register pressure (for the better or for the worse!)
    • May change memory referencing pattern and cache behavior
  • FPO (initially) considers
    • Affect on computation
    • How register pressure helps or hurts spills and reloads

CODE 1: a Å 1 2: b Å 2

3: c Å a * b (^) 4: c Å 1

5: d Å c + 1 6: f Å d + c 7: g Å f + d 8: hÅ a * b

1

(^23)

4

CODE 1: a Å 1 2: b Å 2

3: c Å a * b 3: v Å a * b 3’: c Å v

4: c Å 1 4’: v Å a * b

5: d Å c + 1 6: f Å d + c 7: g Å f + d 8: hÅ a * b 8: h Å v

1

(^23)

4

Code Model (before PRE) 1: IN () OUT (a, b) 2: IN (a, b) OUT (a, b, c) 3: IN (a, b) OUT (a, b, c) 4: IN (c, a, b) OUT(…)

Code Model (after PRE) 1: IN () OUT (a, b) 2: IN (a, b) OUT (c, v) 3: IN (a, b) OUT (c, v) 4: IN (c, v) OUT(…)

Impact of PRE

PRE OPT Model 1:

2:

3:

Framework for Predicting Optimizations (“Prediction Engine”)

Resource Model (regs)

**OPT Model for register allocation

of load & stores increased or decreased**

Using a Heuristic to Make

Decisions

twolf 1.07 0.88 1.14 0.02 0.52 0.38 2.14 1.

bzip2 7.35 7.52 8.19 7.91 7.02 7.35 6.70 4.

vortex 4.73 5.25 4.66 3.86 4.88 5.69 4.99 5.

parser 1.25 1.50 1.70 1.35 2.55 2.86 1.99 2.

mcf 2.37 2.35 2.31 2.22 2.50 2.62 2.58 2.

vpr 1.22 0.75 1.81 1.83 -0.40 -0.38 0.52 0.

gzip 3.50 3.75 3.78 4.10 2.90 3.29 5.40 3.

H
H
H
H
H
H
H
H

Heuristic-driven PRE Heuristic-driven LCIM

Bench.

Approaches for PRE

0

2

4

6

8

10

gzip vpr m cf parser vortex bzip2 twolf geom ean

Performance Improvement %

A-PRE Best-heuristic Heuristic-8 P-PRE

Scalar Opt. Prediction Accuracy

Average 87.

twolf 475 433 91.

bzip2 56 44 78.

vortex 530 431 81.

parser 293 210 87.

mcf 51 44 86.

vpr 303 291 96.

gzip 48 43 89.

Benchmark PREs Correct %Accuracy

CoCo Framework

Debugger

Checker

Checker

Dynamic Optimizer and SDT

Monitor

Continuous State

Monitor Plans Opt. Plans

Program

ApplicationInform atio nRepository

Application

Static Compiler Dynamic Compiler

ProgramModels Profiles

Static Optimizer

Planner

Machine andOptimizationInformatio nRe pository

Estimation Models

Machine Models

Conductor

CoCo Run-Time System

  • Based on Software Dynamic Translation
  • Layer of software between application binary and the OS/CPU.
  • Application’s instructions are examined and modified before being executed on the CPU.
  • Uses include binary translation, dynamic optimization, & others

Application Binary

CPU

Dynamic Translator

OS

CoCo Run-Time System

  • Strata SDT developed at UVA & Pitt
  • Provides basic functionality for run- time optimization - Memory management - Caching - Code analysis - Overhead reduction - Program instrumentation
  • Includes target Interface
    • Handles all interactions between VM, application binary, and target OS/CPU

Current targets: MIPS/Irix, SPARC/Solaris, x86/Linux, MIPS/Playstation 2

Application Binary

CPU

Dynamic Translator

OS

Target Interface

ManagementMemory Code CachingTranslated Code LinkingTranslated OverheadReduction

Binary to RTLTranslation Control FlowDynamic Graph and DataflowRTL Value Analysis

Comparison of Cache Simulators

bzip 1,325 169.2x 194.1x 26.7x 8.1x

gzip 1,192 228.1x 227.9x 34x 13.1x

vortex 2,747 101.9x 114.4x 21.5x 10.6x

parser 1,979 48.4x 123.2x 21.6x 8.8x

vpr 831 113x 109.8x 20.4x 10.1x

gcc 1,364 111.1x 112.4x 25.2x 11.1x

twolf 3,534 74.9x N/A 15.7x 7.2x

mcf 1,813 10.3x 23.4x 5.5x 2.5x

Strata- Embra-O

Strata- Shade Sim-cache Embra Native Benchmarks (Secs.)

Average improvement over Strata-Embra is 2.4x

Related Work

  • Effective optimization
    • Adaptive optimizing compilers: [Cooper02,04 & Whalley04]
    • Iterative compilation: [Knijnenburg03]
    • Optimization space exploration: [Triantafyllis03]
    • Analytic models: [Wolf91, Sarkar 97, McKinley96, Hu02]
  • Software dynamic translation
    • Dynamo/RIO, Dynamo, Mojo, Vulcan, Walkabout, DELI
  • Cache simulation
    • Shade, Embra, Fast-Cache, FastSim

Summary

  • A new planning-based approach to compilation

called Continuous Compilation (CoCo)

  • Apply whole suite of optimizations with constant

refinement of optimizations and plans for them

  • Results
    • Highly accurate predictions for simple loop optimizations
    • Highly accurate predictions for scalar optimizations
    • Low overhead run-time system based on SDT
    • INSOP reduces instrumentation cost (cache simulation)

Collaborators

Many students have participated, including:

  • FPO: Min Zhao (Pitt)
  • Program instrumentation: Naveen Kumar (Pitt)
  • Strata: Kevin Scott (UVA/Google) and Naveen Kumar
  • Overhead reduction: Kevin Scott, Naveen Kumar,

Jason Mars (Pitt)

Other Faculty: Mary Lou Soffa, Jack Davidson (UVA)

  • Sponsored by the National Science Foundation, Next

Generation Systems, 2002-2003 and 2003-

Current Areas of Focus

  • Continuous compilation
  • Software dynamic translation
    • Low overhead dynamic translation
    • New applications to architecture simulation, security
  • Debugging of dynamically translated code
    • Dynamically optimized code
    • Security checking
    • Dynamically compiled simulation
  • Soft error detection & recovery based on SDT
  • Power-aware memory systems

Current Projects

  • Debugging dyn. translated/optimized code – N. Kumar
  • On-demand structural software testing with dynamic

instrumentation – J. Misurda and J. Clause

  • Static/dynamic optimization planning – S. Zhou
  • Optimization checking – Y. Huang
  • Compiler-driven power management – N. Aboughazaleh
  • Memory systems for cognitive processing
  • Reuse through Speculation on Traces – M. Pilla (from

UFRGS)

Selected Past Projects

  • Instruction code compression/decompression
  • On-demand code downloading for Smartcards
  • Program profiling primitives and profiling language
  • Software based value reuse on traces
  • Power on/Shut down of superscalar functional units
  • Memory bus reordering for power reduction
  • Processor-driven DVS (based on IPC/peak demands)
  • Data width-sensitive VLIWs & scheduling
  • Application-specific processors (automatic design and

target architectures)

CS2002 Projects?

  • Debugging for code security with SDT
  • Dynamically compiled & sampled architecture

simulation

  • Profit-driven optimization for other constraints

(e.g., power, code size)

  • Self-checking programs (for soft errors; e.g.,

memory bit flips)

  • Domain specific languages for structural testing

and automatic planning

  • Reconfigurable / custom memory systems
  • And many others… or your ideas??

Let’s Talk!

  • 6409 Sennott Square
  • Office hours: MW 1-3 PM
  • Or by appointment
  • Send e-mail…. [email protected]
  • See selected papers online….

http://www.cs.pitt.edu/~childers