presented by: sameer kulkarni dept of computer & information sciences university of delaware
DESCRIPTION
Presented by: Sameer Kulkarni Dept of Computer & Information Sciences University of Delaware. Phase Ordering. Optimization??. does it really work??. No. of optimizations. O64 = 264 (on last count) JikesRVM = 67. Search space. Consider a hypothetical case where we apply 40 optimizations - PowerPoint PPT PresentationTRANSCRIPT
![Page 1: Presented by: Sameer Kulkarni Dept of Computer & Information Sciences University of Delaware](https://reader035.vdocument.in/reader035/viewer/2022062222/56816512550346895dd78c7d/html5/thumbnails/1.jpg)
CISC673 – Optimizing Compilers 1/34
• Presented by: Sameer Kulkarni• Dept of Computer & Information Sciences
• University of Delaware
Phase Ordering
![Page 2: Presented by: Sameer Kulkarni Dept of Computer & Information Sciences University of Delaware](https://reader035.vdocument.in/reader035/viewer/2022062222/56816512550346895dd78c7d/html5/thumbnails/2.jpg)
CISC673 – Optimizing Compilers 2/34
Optimization??
does it really work??
_2
09_d
b
_2
13_ja
vac
_2
22_m
pega
udio
_2
02_je
ss
_2
01_c
ompre
ss
_2
05_ra
ytrac
e
_2
28_ja
ck0
0.20.40.60.8
11.21.41.61.8
2
SpecJVM98 relative speedup
O1O2O3
![Page 3: Presented by: Sameer Kulkarni Dept of Computer & Information Sciences University of Delaware](https://reader035.vdocument.in/reader035/viewer/2022062222/56816512550346895dd78c7d/html5/thumbnails/3.jpg)
CISC673 – Optimizing Compilers 3/34
No. of optimizations
• O64 = 264 (on last count)• JikesRVM = 67
![Page 4: Presented by: Sameer Kulkarni Dept of Computer & Information Sciences University of Delaware](https://reader035.vdocument.in/reader035/viewer/2022062222/56816512550346895dd78c7d/html5/thumbnails/4.jpg)
CISC673 – Optimizing Compilers 4/34
Search space
• Consider a hypothetical case where we apply 40 optimizations
• O64 : 3.98 x 1047 • Jikes: 4.1 x 1018
![Page 5: Presented by: Sameer Kulkarni Dept of Computer & Information Sciences University of Delaware](https://reader035.vdocument.in/reader035/viewer/2022062222/56816512550346895dd78c7d/html5/thumbnails/5.jpg)
CISC673 – Optimizing Compilers 5/34
Could take a while
• Considering the smaller problem, assume that running all the benchmarks take just 1 sec to run
• Jikes would take: 130.2 billion years • Age of the universe 13 billion years
![Page 6: Presented by: Sameer Kulkarni Dept of Computer & Information Sciences University of Delaware](https://reader035.vdocument.in/reader035/viewer/2022062222/56816512550346895dd78c7d/html5/thumbnails/6.jpg)
CISC673 – Optimizing Compilers 6/34
Some basic Optimizations
• Constant Sub-expression Elimination• Loop Unrolling• Local Copy Prop • Branch Optimizations ...
![Page 7: Presented by: Sameer Kulkarni Dept of Computer & Information Sciences University of Delaware](https://reader035.vdocument.in/reader035/viewer/2022062222/56816512550346895dd78c7d/html5/thumbnails/7.jpg)
CISC673 – Optimizing Compilers 7/34
Example
for(int i=0; i< 3;i++){
a = a + i + 1;
}
Loop Unrolling
CSE
![Page 8: Presented by: Sameer Kulkarni Dept of Computer & Information Sciences University of Delaware](https://reader035.vdocument.in/reader035/viewer/2022062222/56816512550346895dd78c7d/html5/thumbnails/8.jpg)
CISC673 – Optimizing Compilers 8/34
Instruction Scheduling vs Register Allocation
• Maximizing Parallelism IS• Minimizing Register Spilling RA
![Page 9: Presented by: Sameer Kulkarni Dept of Computer & Information Sciences University of Delaware](https://reader035.vdocument.in/reader035/viewer/2022062222/56816512550346895dd78c7d/html5/thumbnails/9.jpg)
CISC673 – Optimizing Compilers 9/34
Phase Ord. vs Opt Levels
• Opt Levels ~ Timing Constraints• Phase ordering ~ code interactions
![Page 10: Presented by: Sameer Kulkarni Dept of Computer & Information Sciences University of Delaware](https://reader035.vdocument.in/reader035/viewer/2022062222/56816512550346895dd78c7d/html5/thumbnails/10.jpg)
CISC673 – Optimizing Compilers 10/34
Whimsical??
• Opt X would like to go before Opt Y, but not always.
Best d
b
Best ja
vac
Best m
pega
udio
Best je
ss
Best r
aytra
ce
Best C
ompr
ess
0.91
0.92
0.93
0.94
0.95
0.96
0.97
0.98
0.99
1
1.01
_209_db _213_javac _222_mpegaudio _202_jess _205_raytrace _201_compress
![Page 11: Presented by: Sameer Kulkarni Dept of Computer & Information Sciences University of Delaware](https://reader035.vdocument.in/reader035/viewer/2022062222/56816512550346895dd78c7d/html5/thumbnails/11.jpg)
CISC673 – Optimizing Compilers 11/34
Ideal Solution?
• Oracle Perfect sequence at the very start• Wise Man Solution Given the present code
predict the best optimization solution
![Page 12: Presented by: Sameer Kulkarni Dept of Computer & Information Sciences University of Delaware](https://reader035.vdocument.in/reader035/viewer/2022062222/56816512550346895dd78c7d/html5/thumbnails/12.jpg)
CISC673 – Optimizing Compilers 12/34
Wise Man
?• Understand
Compilers
• Optimizations
• Source Code
![Page 13: Presented by: Sameer Kulkarni Dept of Computer & Information Sciences University of Delaware](https://reader035.vdocument.in/reader035/viewer/2022062222/56816512550346895dd78c7d/html5/thumbnails/13.jpg)
CISC673 – Optimizing Compilers 13/34
Possible Solutions• Pruning the search space• Genetic Algorithms• Estimating running times• Precompiled choices
![Page 14: Presented by: Sameer Kulkarni Dept of Computer & Information Sciences University of Delaware](https://reader035.vdocument.in/reader035/viewer/2022062222/56816512550346895dd78c7d/html5/thumbnails/14.jpg)
CISC673 – Optimizing Compilers 14/34
Pruning Search space
Fast and Efficient Searches for Effective Optimization Phase Sequences, Kulkarni et al. TACO 2005
![Page 15: Presented by: Sameer Kulkarni Dept of Computer & Information Sciences University of Delaware](https://reader035.vdocument.in/reader035/viewer/2022062222/56816512550346895dd78c7d/html5/thumbnails/15.jpg)
CISC673 – Optimizing Compilers 15/34
Optimization Profiling
Fast and Efficient Searches for Effective Optimization Phase Sequences, Kulkarni et al. TACO 2005
![Page 16: Presented by: Sameer Kulkarni Dept of Computer & Information Sciences University of Delaware](https://reader035.vdocument.in/reader035/viewer/2022062222/56816512550346895dd78c7d/html5/thumbnails/16.jpg)
CISC673 – Optimizing Compilers 16/34
Genetic Algorithms
Fast Searches for Effective Optimization Phase Sequences, Kulkarni et al. PLDI ‘04
![Page 17: Presented by: Sameer Kulkarni Dept of Computer & Information Sciences University of Delaware](https://reader035.vdocument.in/reader035/viewer/2022062222/56816512550346895dd78c7d/html5/thumbnails/17.jpg)
CISC673 – Optimizing Compilers 17/34
Exhaustive vs Heuristic [2]
![Page 18: Presented by: Sameer Kulkarni Dept of Computer & Information Sciences University of Delaware](https://reader035.vdocument.in/reader035/viewer/2022062222/56816512550346895dd78c7d/html5/thumbnails/18.jpg)
CISC673 – Optimizing Compilers 18/34
Disadvantages• Benchmark Specific• Architecture dependent• Code disregarded
![Page 19: Presented by: Sameer Kulkarni Dept of Computer & Information Sciences University of Delaware](https://reader035.vdocument.in/reader035/viewer/2022062222/56816512550346895dd78c7d/html5/thumbnails/19.jpg)
CISC673 – Optimizing Compilers 19/34
Improvements• Profiling the application• Understand the code• Understanding optimizations• Continuous evaluation of transformations
![Page 20: Presented by: Sameer Kulkarni Dept of Computer & Information Sciences University of Delaware](https://reader035.vdocument.in/reader035/viewer/2022062222/56816512550346895dd78c7d/html5/thumbnails/20.jpg)
CISC673 – Optimizing Compilers 20/34
Proposed solutionInput = Code Features
Output = Running time
Evolve Neural Networks
![Page 21: Presented by: Sameer Kulkarni Dept of Computer & Information Sciences University of Delaware](https://reader035.vdocument.in/reader035/viewer/2022062222/56816512550346895dd78c7d/html5/thumbnails/21.jpg)
CISC673 – Optimizing Compilers 21/34
Proposed solution
![Page 22: Presented by: Sameer Kulkarni Dept of Computer & Information Sciences University of Delaware](https://reader035.vdocument.in/reader035/viewer/2022062222/56816512550346895dd78c7d/html5/thumbnails/22.jpg)
CISC673 – Optimizing Compilers 22/34
Experimental Setup• Neural Network Evolver (ANJI)• Training Set { javaGrande }• Testing Set { SpecJVM, Da Capo }
![Page 23: Presented by: Sameer Kulkarni Dept of Computer & Information Sciences University of Delaware](https://reader035.vdocument.in/reader035/viewer/2022062222/56816512550346895dd78c7d/html5/thumbnails/23.jpg)
CISC673 – Optimizing Compilers 23/34
ANJI• Mutating & generating n/w s• Network phase ordering• Timing Information• Scoring the n/w
![Page 24: Presented by: Sameer Kulkarni Dept of Computer & Information Sciences University of Delaware](https://reader035.vdocument.in/reader035/viewer/2022062222/56816512550346895dd78c7d/html5/thumbnails/24.jpg)
CISC673 – Optimizing Compilers 24/34
Training Phase• Generations and Chromosomes• Random chromosomes• Back Propagation• Add/Remove/Update hidden nodes
![Page 25: Presented by: Sameer Kulkarni Dept of Computer & Information Sciences University of Delaware](https://reader035.vdocument.in/reader035/viewer/2022062222/56816512550346895dd78c7d/html5/thumbnails/25.jpg)
CISC673 – Optimizing Compilers 25/34
Experimental Setup
![Page 26: Presented by: Sameer Kulkarni Dept of Computer & Information Sciences University of Delaware](https://reader035.vdocument.in/reader035/viewer/2022062222/56816512550346895dd78c7d/html5/thumbnails/26.jpg)
CISC673 – Optimizing Compilers 26/34
Network Evolution
Anji Evolution over generations
0.940.960.98
11.021.041.061.08
1.1
0 200 400 600 800 1000
Generation
Spee
dups
Max FitnessO3 (rough)
![Page 27: Presented by: Sameer Kulkarni Dept of Computer & Information Sciences University of Delaware](https://reader035.vdocument.in/reader035/viewer/2022062222/56816512550346895dd78c7d/html5/thumbnails/27.jpg)
CISC673 – Optimizing Compilers 27/34
Network Evolution
![Page 28: Presented by: Sameer Kulkarni Dept of Computer & Information Sciences University of Delaware](https://reader035.vdocument.in/reader035/viewer/2022062222/56816512550346895dd78c7d/html5/thumbnails/28.jpg)
CISC673 – Optimizing Compilers 28/34
javaGrande• Set of very small benchmarks• Low running times• Memory management• Machine Architecture
![Page 29: Presented by: Sameer Kulkarni Dept of Computer & Information Sciences University of Delaware](https://reader035.vdocument.in/reader035/viewer/2022062222/56816512550346895dd78c7d/html5/thumbnails/29.jpg)
CISC673 – Optimizing Compilers 29/34
Testing• SpecJVM’98 & Da Capo• Champion n/w• Running times
![Page 30: Presented by: Sameer Kulkarni Dept of Computer & Information Sciences University of Delaware](https://reader035.vdocument.in/reader035/viewer/2022062222/56816512550346895dd78c7d/html5/thumbnails/30.jpg)
CISC673 – Optimizing Compilers 30/34
Present Solution
![Page 31: Presented by: Sameer Kulkarni Dept of Computer & Information Sciences University of Delaware](https://reader035.vdocument.in/reader035/viewer/2022062222/56816512550346895dd78c7d/html5/thumbnails/31.jpg)
CISC673 – Optimizing Compilers 31/34
Implementation in GCC• Milepost GCC
• Created for intelligent compilation
• Collecting source features
• Submitting features to common loc.
• Hooks into the Compilation process.
![Page 32: Presented by: Sameer Kulkarni Dept of Computer & Information Sciences University of Delaware](https://reader035.vdocument.in/reader035/viewer/2022062222/56816512550346895dd78c7d/html5/thumbnails/32.jpg)
CISC673 – Optimizing Compilers 32/34
Possible Use Case
![Page 33: Presented by: Sameer Kulkarni Dept of Computer & Information Sciences University of Delaware](https://reader035.vdocument.in/reader035/viewer/2022062222/56816512550346895dd78c7d/html5/thumbnails/33.jpg)
CISC673 – Optimizing Compilers 33/34
Structure for Phase Ordering
ANJI network from Source features
![Page 34: Presented by: Sameer Kulkarni Dept of Computer & Information Sciences University of Delaware](https://reader035.vdocument.in/reader035/viewer/2022062222/56816512550346895dd78c7d/html5/thumbnails/34.jpg)
CISC673 – Optimizing Compilers 34/34
LLVM• Open Source Compiler• Modular Design• Easy to work with• All Optimizations are interchangeable
![Page 35: Presented by: Sameer Kulkarni Dept of Computer & Information Sciences University of Delaware](https://reader035.vdocument.in/reader035/viewer/2022062222/56816512550346895dd78c7d/html5/thumbnails/35.jpg)
CISC673 – Optimizing Compilers 35/34
Questions
Most of the files and this presentation have been uploaded to http://www.cis.udel.edu/~skulkarn/ta.html