

















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’BoyleFebruary, 2011
M. O’Boyle
Instruction Scheduling
1
Course Structure
-^ Introduction and Recap •^ Course Work •^ Scalar optimisation and dataflow •^ L5 Code generation •^ L6 Instruction scheduling •^ Then parallel approaches followed by adaptive compilation M. O’Boyle
Instruction Scheduling
3
Aim
-^ Order instructions to minimise execution time.
Hide latency of instructions
such as loads and branches by executing instructions in their shadow • Exploit
instruction
level
parallelism
by
making
sure
there
are
multiple
instructions available to be simultaneously executed • Two flavours of ILP: Superscalar and vliw.
Both require similar analysis but
vliw is static scheduled and requires more explicit treatment • Affected by machine resources - number and type of functional unit, numberof registers • Assume register allocation is separately performed later. M. O’Boyle
Instruction Scheduling
February, 2011
4
Example Superscalar, 1 FU: New Op each cycle iff operands ready w = w2xyz. Assume global activation pointer in
r
load/stores 3 cycles, mults 2, others 1^ 1 loadAI r0,@w -> r14 add r1,r1 ->r15 loadAI r0,@x -> r28 mult r1,r2->r19 loadAI r0,@y ->r212 mult r1,r2 ->r113 loadAI r0,@z->r216 mult r1,r2 ->r118 storeAI r1->r0,@w21 r1 is free
1 loadAI r0,@w -> r12 loadAI r0,@x -> r23 loadAI r0,@y ->r34 add r1,r1 ->r15 mult r1,r2->r16 loadAI r0,@z->r27 mult r1,r3 ->r19 mult r1,r2 ->r111 storeAI r1->r0,@w14 r1 is free
Second version - extra register, move loads earlier. Space vs time M. O’Boyle
Instruction Scheduling
6
List Scheduling
-^ Build a dependence graph of operations and delays •^ Determine schedule to minimise execution time •^ NP-complete: difficulty comes with determining which of the many availableoperands to schedule- need a priority function for tie breaking •^ Use a greedy approach - list scheduling for local blocks •^ Extend to greater scope later. M. O’Boyle
Instruction Scheduling
7
List Scheduling
cycle = 0ready = leaves of dependence graph Gactive = emptywhile (ready union active != empty)if available remove an instruction from ready based on priorityadd instruction to activefor each instruction in activeif completed remove from activefor each successor of instruction
if successors operand ready then add to ready M. O’Boyle
Instruction Scheduling
9
Example
a b d f 13 c^12 e^10 g^8 h^5 i^3 10 9
7
1 a loadAI r0,@w -> r12 c loadAI r0,@x -> r23 e loadAI r0,@y ->r34 b add r1,r1 ->r15 d mult r1,r2->r16 g loadAI r0,@z->r27 f mult r1,r3 ->r19 h mult r1,r2 ->r111 i
storeAI r1->r0,@w
List Scheduling here uses critical path as priority. The labelled arcs denote criticalpath length for each instruction. Choose highest value first. M. O’Boyle
Instruction Scheduling
10
Priorities
-^ The longest latency path or critical path is a good priority •^ Last use of a value - decreases demand for register as moves it nearer def •^ Number of descendants - encourages scheduler to pursue multiple paths •^ Longer latency first - others can fit in shadow •^ Forward list scheduling does well but sometimes backward does better. M. O’Boyle
Instruction Scheduling
12
Forward and Backward Scheduling: Blanks = noops Int
Int^
Stores
1
loadI
lshift 2
loadI
loadI 3
loadI
add 4
add
add
5
add
addI^
store
6
cmp^
store
7
store
8
store
9
store
10 11 12 13
cbr
Int^
Int^
Stores
1
loadI 2
addI^
lshift
3
add
loadI
4
add
loadI
store
5
add
loadI
store
6
add
store
7
store
8
store
9 10 11
cmp 12
cbr 13
M. O’Boyle
Instruction Scheduling
13
Loop scheduling
-^ Loop structures can dominate execution time •^ Specialist technique software pipelining •^ Calculation of minimum initiation interval •^ This corresponds to the critical path of a loop •^ Modulo Scheduling take into account resources M. O’Boyle
Instruction Scheduling
15
Example
c=0for (i= 1,i <=N,i++)c = c+a[i];
r_c = 0r_@a = @ar1 = n*4r_ub= r1+r_@aif r_@a >r_ub goto exit loop: r_a = load(r_@a) -- 3 cycle stall
r_c = r_c + r_ar_@a = r_@a +4if r_@a <= r_ub goto Loop exit: store(c)=rc
If branches take 1 cycle - each iteration takes 5 cycles after scheduling the loopbody. r
@ = can be performed in shadow of load M. O’Boyle
Instruction Scheduling
16
Iterations can overlapped: Recurrence on r
c shown
r_a = load(r_@a)r_c = r_c + r_ar_@a = r_@a+4if r_@a <= r_ub goto loop
r_a = load(r_@a)
r_a = load(r_@a)r_c = r_c + r_a
r_c = r_c + r_ar_@a = r_@a+4if r_@a <= r_ub goto loop
Iteration 2 r_@a = r_@a+4if r_@a <= r_ub goto loop
Iteration 3
Iteration 1 Time
Resources
M. O’Boyle
Instruction Scheduling
18
Pipeline evaluation: Recurrence on r
c not shown
r_@a = r_@a+4r_c = r_c + r_a
if r_@a <= r_ub goto loop
r_a = load(r_@a)
r_@a = r_@a+4r_c = r_c + r_a
if r_@a <= r_ub goto loop
r_@a = r_@a+
r_a = load(r_@a)r_a = load(r_@a)
r_@a = r_@a+4r_c = r_c + r_ar_@a = r_@a+4r_c = r_c + r_a
r_a = load(r_@a)
if r_@a <= r_ub goto loopif r_@a <= r_ub goto loop
1 2 ... n n+
Load
Int^
Branch
M. O’Boyle
Instruction Scheduling
19
Code template
r_@a = r_@a+4 r_c = r_c + r_a
if r_@a <= r_ub goto loop
r_@a = r_@a+
r_a = load(r_@a)r_a = load(r_@a)r_@a = r_@a+4r_c = r_c + r_a
prologue kernel epilogue
The schedule must consider function unit type, data dependences and latenciesAssume 3 functional units:
Load, Int and Branch and vliw processor Generate
this code filling in with noops M. O’Boyle
Instruction Scheduling
February, 2011