





















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!






















Michael O’BoyleMarch, 2010
M. O’Boyle^
Machine Learning based Compilation
Overview
-^ Machine learning - what is it and why is it useful? •^ Predictive modelling •^ OSE •^ Scheduling and low level optimisation •^ Loop unrolling •^ Limits and other uses of machine learning •^ Future work and summary M. O’Boyle^
Machine Learning based Compilation
Machine Learning
-^ The inputs are characteristics of the program and processor.
Outputs, the
Program characteristics Executiontime
Program characteristics BestTransformation
M. O’Boyle^
Machine Learning based Compilation
4
Predictive Modelling^ PredictiveModelling
MODEL Training data featuresExecutiontimeor othermetric
Test features Predicted time
-^ Predictive modelling techniques all have the property that they try to learn amodel that describes the correlation between inputs and outputs •^ This can be a classification or a function or Bayesian probability distribution •^ Distinct training and test data. Compiler writers don’t make this distinction! M. O’Boyle^
Machine Learning based Compilation
6
Feature selection of programs
-^ The real crux problem with machine learning is feature selection What featuresof a program are likely to predict it’s eventual behaviour? •^ In a sense, features should be a compact representation of a program thatcapture the essential performance related aspects and ignore the irrelevant •^ Clearly, the number of vowels in the program is unlikely to be significant northe user comments •^ Compiler IRs are a good starting point as they are condensed reps. •^ Loop^
nest^ depth,
control-flow
graph^
structure,
recursion,
pointer
based
accesses, data structure M. O’Boyle^
Machine Learning based Compilation
March, 2010
7
Case studies PredictiveModelling^
MODEL Executiontimeor othermetric
Test features Program Features assumed procTransformationDescription
PredictedOptimalTransformation Original Test
-^ All of the techniques have the above characterisation •^ In fact it is often easier to select a good transformation rather than determineexecution time. Relative vs absolute reasoning M. O’Boyle^
Machine Learning based Compilation
9
-^ Arrange the best optimisation configrations
C^ in a tree.
-^ AlgorithmStep 1: Initially, the set of programs
Q^ =^ P
Step 2: Find configurations
c, c∈^01
C^ that give the best performance across
Q
Step 3: Create
Q, Q⊆^01
Q^ such that
∀p^ ∈^ Qi
:^ perf^ (p, c
)^ ≥^ perfi
(p, c)^1 −i
In other words:
assign each benchmark to one of two sets depending on which configuration gives the best performance.Step 4: Start again at step 2 with
Q^ =^ Q, ifi
Qis not empty. Removei^
c, co^1
-^ Max recursion depth: 3. Note remove best avg so far •^ Paper has 3 nodes per level
c, c, co^12
. We restrict to 2.
M. O’Boyle^
Machine Learning based Compilation
March, 2010
10
M. O’Boyle^
Machine Learning based Compilation
12
c^
c c^
c
c^
c P1 P3 P5 P
P6 P
P1 P^
P2 P4 P6 P8P2 P
P5 P
c1 and c3 are best on average.For^ programs
P1,3,^
and^ 7:^
configurations
c5^ and
c7^ give
next^ best
avg
performanceFor programs P2,4,6 and 8 :
configurations c6 and c8 give next best avg
perfromance M. O’Boyle^
Machine Learning based Compilation
March, 2010
13
To quickly find a good configuration for a new program:^ •^ Start at the root node and compare the performance of the program with thetwo configurations found in its child nodes.^ •^ Move to the node with the configuration that gives a better speedup.^ •^ Repeat these steps until you’ve reached a leaf node.^ •^ Pick the configuration on the path from the root to the leaf node that gavethe best performance. M. O’Boyle^
Machine Learning based Compilation
15
Prog^ Configs
Performance P1^ c1,c
4
P2^ c3, c
P3^ c1, c
4
P4^ c3 c
4
P5^ c1 c
4
P6^ c3 c
P7^ c1 c
4
P8^ c3 c
4
If we apply the tree to the same programs get an improvement.Should not evaluate on training data though!OSE uses performance models to speed up search M. O’Boyle^
Machine Learning based Compilation
16
Learning to schedule Moss, ..,Cavazos et al Given partial schedule 2, which instruction to schedule next 1 or 4?
2 3
4
scheduled available
available
notavailable
-^ One of the first papers to investigate machine learning for compiler optimisation •^ Appeared at NIPS ’07 - not picked up by compiler community till later. M. O’Boyle^
Machine Learning based Compilation
18
Learning to schedule
Feature selection can be a black art. Here dual issue of alpha biases choice.^ •^ Odd Partial (odd): odd or even length schedule^ •^ Instruction Class (ic): which class corresponds to function unit^ •^ weighted critical path (wcp): length of dependent instructions^ •^ Actual Dual (d): can this instruction dual issue with previous^ •^ maxdelay (e): earliest cycle this instruction can go M. O’Boyle^
Machine Learning based Compilation
19
Feature extraction
2 3 4 1
scheduled available
available notavailable
Tuple^ ({^2
},^1 ,^ 4)^ : [odd:T, ic:0, wcp:1, d:T, e:0 ]: TRUE, Tuple^ ({^2
},^4 ,^ 1)^ : [odd:T, ic:0, wcp:0, d:T, e:0 ]: FALSE
-^ Given these tuples apply different learning techniques on data to derive a model •^ Use model to select scheduling for test problems. One of the easiest is tablelookup/nearest neighbour •^ Others used include neural net with hidden layer, induction rule and decisiontree M. O’Boyle^
Machine Learning based Compilation