compiler optimizationweb.eecs.umich.edu/~mahlke/courses/583f18/lectures/dec5/... · 2018. 12....

23
Machine Learning in Compiler Optimization Authors: Zheng Wang and Michael O’Boyle Qi Zhang, Shengpu Tang, Yanqi Wang, Yiting Shen

Upload: others

Post on 17-Nov-2020

2 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Compiler Optimizationweb.eecs.umich.edu/~mahlke/courses/583f18/lectures/Dec5/... · 2018. 12. 4. · Application What hardware problems can machine learning solve? Optimize sequential

Machine Learning in Compiler Optimization

Authors: Zheng Wang and Michael O’Boyle

Qi Zhang, Shengpu Tang, Yanqi Wang, Yiting Shen

Page 2: Compiler Optimizationweb.eecs.umich.edu/~mahlke/courses/583f18/lectures/Dec5/... · 2018. 12. 4. · Application What hardware problems can machine learning solve? Optimize sequential

Main Takeaways● Machine Learning (ML) based compilation is a trustworthy and exciting

direction for compiler research.

● Data is fuel to ML based research.

Page 3: Compiler Optimizationweb.eecs.umich.edu/~mahlke/courses/583f18/lectures/Dec5/... · 2018. 12. 4. · Application What hardware problems can machine learning solve? Optimize sequential

Why do we need ML?● Compilers have two jobs - translation and optimization

○ Compiler writers develop heuristics with the hope of improving

performance

○ ML can serve as a predictor of the optima

● Machine-Learning Compilation

○ Automation!

○ Evidence-based science

Page 4: Compiler Optimizationweb.eecs.umich.edu/~mahlke/courses/583f18/lectures/Dec5/... · 2018. 12. 4. · Application What hardware problems can machine learning solve? Optimize sequential

OpenCL Kernel code snippet

Page 5: Compiler Optimizationweb.eecs.umich.edu/~mahlke/courses/583f18/lectures/Dec5/... · 2018. 12. 4. · Application What hardware problems can machine learning solve? Optimize sequential

Example: Best Thread Coarsening FactorThread Coarsening Pros & Cons

Pros:- Increase instruction-level parallelism

- Reduce # of memory-access operations

- Eliminate redundant computations

Cons:- Reduce the total amount of parallelism

- Increase the register pressure

Page 6: Compiler Optimizationweb.eecs.umich.edu/~mahlke/courses/583f18/lectures/Dec5/... · 2018. 12. 4. · Application What hardware problems can machine learning solve? Optimize sequential

Architecture Overview

Page 7: Compiler Optimizationweb.eecs.umich.edu/~mahlke/courses/583f18/lectures/Dec5/... · 2018. 12. 4. · Application What hardware problems can machine learning solve? Optimize sequential

Stage 1: Feature Engineering

Page 8: Compiler Optimizationweb.eecs.umich.edu/~mahlke/courses/583f18/lectures/Dec5/... · 2018. 12. 4. · Application What hardware problems can machine learning solve? Optimize sequential

Static Code FeaturesExtracted from the intermediate representations

Page 9: Compiler Optimizationweb.eecs.umich.edu/~mahlke/courses/583f18/lectures/Dec5/... · 2018. 12. 4. · Application What hardware problems can machine learning solve? Optimize sequential

Dynamic FeaturesExtracted from multiple layers of the runtime environment.

Page 10: Compiler Optimizationweb.eecs.umich.edu/~mahlke/courses/583f18/lectures/Dec5/... · 2018. 12. 4. · Application What hardware problems can machine learning solve? Optimize sequential

Reaction Based FeaturesCarefully selected compiler options.

Page 11: Compiler Optimizationweb.eecs.umich.edu/~mahlke/courses/583f18/lectures/Dec5/... · 2018. 12. 4. · Application What hardware problems can machine learning solve? Optimize sequential

Feature Selection and Dimension ReductionProblem: Too many features -> need a lot more training examples

Solution: Feature space dimension reduction

Page 12: Compiler Optimizationweb.eecs.umich.edu/~mahlke/courses/583f18/lectures/Dec5/... · 2018. 12. 4. · Application What hardware problems can machine learning solve? Optimize sequential

Example: Best Thread Coarsening Factor

Page 13: Compiler Optimizationweb.eecs.umich.edu/~mahlke/courses/583f18/lectures/Dec5/... · 2018. 12. 4. · Application What hardware problems can machine learning solve? Optimize sequential

Stage 2: Learning a Model

Page 14: Compiler Optimizationweb.eecs.umich.edu/~mahlke/courses/583f18/lectures/Dec5/... · 2018. 12. 4. · Application What hardware problems can machine learning solve? Optimize sequential

ModelsSupervised vs. Unsupervised

Possible supervised setup

Page 15: Compiler Optimizationweb.eecs.umich.edu/~mahlke/courses/583f18/lectures/Dec5/... · 2018. 12. 4. · Application What hardware problems can machine learning solve? Optimize sequential

Supervised Learning: ClassificationGoal: Separate different types of program by a decision boundaryGiven a new unseen program, knows what to do

1

2

4

Page 16: Compiler Optimizationweb.eecs.umich.edu/~mahlke/courses/583f18/lectures/Dec5/... · 2018. 12. 4. · Application What hardware problems can machine learning solve? Optimize sequential

Supervised Learning: Regression

Goal: Learn a function to predict - Power consumption- Latency- Exec. time

Page 17: Compiler Optimizationweb.eecs.umich.edu/~mahlke/courses/583f18/lectures/Dec5/... · 2018. 12. 4. · Application What hardware problems can machine learning solve? Optimize sequential

Unsupervised Learning: Auto-encoderLearn best feature representation

Embedding

Page 18: Compiler Optimizationweb.eecs.umich.edu/~mahlke/courses/583f18/lectures/Dec5/... · 2018. 12. 4. · Application What hardware problems can machine learning solve? Optimize sequential

Stage 3: Deployment

Page 19: Compiler Optimizationweb.eecs.umich.edu/~mahlke/courses/583f18/lectures/Dec5/... · 2018. 12. 4. · Application What hardware problems can machine learning solve? Optimize sequential

DeploymentHow to utilize the learned model:

1. Extract the features of the input program

2. Feed the extracted feature values to the learned model to make a

prediction

3. Apply the predicted results

Page 20: Compiler Optimizationweb.eecs.umich.edu/~mahlke/courses/583f18/lectures/Dec5/... · 2018. 12. 4. · Application What hardware problems can machine learning solve? Optimize sequential

ApplicationWhat hardware problems can machine learning solve?

➢ Optimize sequential programs- target a fixed set of compiler options- represent the optimization problem as a multi-class classification

problem – where each compiler option is a class.

➢ Optimize parallel programs- provide the potential for high performance and energy-efficient

computing

Page 21: Compiler Optimizationweb.eecs.umich.edu/~mahlke/courses/583f18/lectures/Dec5/... · 2018. 12. 4. · Application What hardware problems can machine learning solve? Optimize sequential

Goal: Predict the optimal loop unroll factor

Approach:

● Decision tree based model○ Multi-class Classification

○ Label: loop unroll factor 𝑙 ∈ [0, 15], 16 classes in total

Optimize Sequential Programs - Example

Page 22: Compiler Optimizationweb.eecs.umich.edu/~mahlke/courses/583f18/lectures/Dec5/... · 2018. 12. 4. · Application What hardware problems can machine learning solve? Optimize sequential

Goal: Predict the scheduling policy

Approach:

● Regression based neural net

● SVM classifier

Optimize Parallel Programs - Example

Page 23: Compiler Optimizationweb.eecs.umich.edu/~mahlke/courses/583f18/lectures/Dec5/... · 2018. 12. 4. · Application What hardware problems can machine learning solve? Optimize sequential

Challenges & Limitations● Training cost

● Garbage in, garbage out

● Unable to invent new program

transformations

● Unable to prove the validity