Download Modulo Scheduling II: A Technique for Parallelizing Loops with Cyclic Dependencies - Prof. and more Study notes Electrical and Electronics Engineering in PDF only on Docsity!
EECS 583 – Lecture 19 Modulo Scheduling II^ University of Michigan^ March 19, 2003 – Guest speaker today!
Modulo Scheduling Process^ Y^ Use list scheduling but we need a few twists^ »^ II is predetermined – starts at MII, then is incremented^ »^ Cyclic dependences complicate matters^ y^ Estart/Priority/etc.^ y^ Consumer scheduled before producer is considered
X^ There is a window where something can be scheduled! » Guarantee the repeating pattern Y 2 constraints enforced on the schedule » Each iteration begin exactly II cycles after the previous one » Each time an operation is scheduled in 1 iteration, it is tentativelyscheduled in subsequent iterations at intervals of II y MRT used for this
Calculating Height 1.^ Insert pseudo edges from all nodes to branch with^ latency = 0, distance = 0 (dotted edges) 2.^ Compute II, For this example assume II = 2 3.^ HeightR(4) = 4.^ HeightR(3) = 5.^ HeightR(2) = 6.^ HeightR(1)
The Scheduling Window With cyclic scheduling, not all the predecessors may be scheduled, so a more flexible earliest schedule time
is: 0, if X is not scheduled E(Y) =^ MAX
MAX (0, SchedTime(X) + EffDelay(X,Y)),
otherwise
for all X = pred(Y) where EffDelay(X,Y) = Delay(X,Y) – II*Distance(X,Y) Every II cycles a new loop iteration will be initialized, thus every II cycles the pattern will repeat. Thus, you only have to look in a window of size II, if the operation cannot be scheduled there, then it cannot be scheduled.^ Latest schedule time(Y) = L(Y) = E(Y) + II – 1
Separate Code for Prolog and Epilog
A0A1^ B0A2^ B1^ C0 A^ B^ C^
Prolog -fill thepipe D^ KernelBn Cn-1 Dn-2Epilog -Cn Dn-1drain theDnpipe
A B C D Loop body with 4 ops Generate special code before the loop (preheader) to fill the pipe and special code after the loop to drain the pipe. Peel off II-1 iterations for the prolog. Complete II-1 iterations in epilog
Removing Prolog/Epilog^ Disable usingpredicated execution
II = 3
Prolog
Kernel^ Epilog
Execute loop kernel on every iteration, but for prolog and epilog selectively disable the appropriate operations to fill/drain the pipeline
Modulo Scheduling Architectural Support^ Y^ Loop requiring N iterations^ »^ Will take N + (S – 1) where S is the number of stages^ Y^ 2 special registers created^ »^ LC: loop counter (holds N)^ »^ ESC: epilog stage counter (holds S)^ Y^ Software pipeline branch operations^ »^ Initialize LC = N, ESC = S in loop preheader^ »^ All rotating predicates are cleared^ »^ BRF.B.B.F^ y^ While LC > 0, decrement LC and RRB, P[0] = 1, branch to top ofloop
X^ This occurs for prolog and kernel y If LC = 0, then while ESC > 0, decrement RRB and write a 0 intoP[0], and branch to the top of the loop X^ This occurs for the epilog
Execution History With LC/ESC^ A if P[0];^
LC = 3, ESC = 3 /* Remember 0 relative!! */Clear all rotating predicatesP[0] = 1B if P[1];^ C if P[2]; D if P[3]; P[0] = BRF.B.B.F; LC^ ESC^
P[0]^ P[1]^
P[2]^ P[3]
A
A^ B
A^ B^
C
A^ B^
C^ D
-^ B^
C^ D
-^ -^
C^ D
-^ -^
-^ D
4 iterations, 4 stages, II = 1, Note 4 + 4 –1 iterations of kernel executed
Modulo Scheduling – Iterative Scheduler^ Y^ iterative_schedule(II, budget)^ »^ compute op priorities^ »^ while (there are unscheduled ops and budget > 0) do^ y^ op = unscheduled op with the highest priority^ y^ min = early time for op (E(Y))^ y^ max = min + II – 1^ y^ t = find_slot(op, min, max)^ y^ schedule op at time t
X^ /* Backtracking phase – undo previous scheduling decisions */ X^ Unschedule all previously scheduled ops that conflict with op y budget--
Modulo Scheduling – Find_slot^ Y^ find_slot(op, min, max)^ »^ /* Successively try each time in the range */^ »^ for (t = min to max) do^ y^ if (op has no resource conflicts in MRT at t)
X^ return t » /* Op cannot be scheduled in its specified range / » / So schedule this op and displace all conflicting ops */ » if (op has never been scheduled or min > previous scheduled timeof op) y return min » else y return MIN(1 + prev scheduled time of op, max)
Example – Step 2^ resources: 4 issue, 2 alu, 1 mem, 1 br^ latencies: add=1, mpy=3, ld = 2, st = 1, br = 1
Step 2: DSA convert LC = 99^
LC = 99
1: r3 = load(r1)2: r4 = r3 * 263: store (r2, r4)4: r1 = r1 + 45: r2 = r2 + 47: brlc Loop
1: r3[-1] = load(r1[0])2: r4[-1] = r3[-1] * 263: store (r2[0], r4[-1])4: r1[-1] = r1[0] + 45: r2[-1] = r2[0] + 4remap r1, r2, r3, r47: brlc Loop
Loop:^
Loop:
Example – Step 3
Step3: Draw dependence graph Calculate MII
resources: 4 issue, 2 alu, 1 mem, 1 br latencies: add=1, mpy=3, ld = 2, st = 1, br = 1
LC = 99 1: r3[-1] = load(r1[0]) Loop: 2: r4[-1] = r3[-1] * 263: store (r2[0], r4[-1])4: r1[-1] = r1[0] + 45: r2[-1] = r2[0] + 4remap r1, r2, r3, r47: brlc Loop
0,
RecMII = 1 RESMII = 2 MII = 2
Example – Step 5
Schedule brlc at time II - 1
resources: 4 issue, 2 alu, 1 mem, 1 br latencies: add=1, mpy=3, ld = 2, st = 1, br = 1
Unrolled Schedule Rolled Schedule LC = 99 1: r3[-1] = load(r1[0]) Loop:2: r4[-1] = r3[-1] * 263: store (r2[0], r4[-1])4: r1[-1] = r1[0] + 45: r2[-1] = r2[0] + 4remap r1, r2, r3, r47: brlc Loop
brmemalu alu0 0
MRT
X
Example – Step 6^ Step6: Schedule the highest priority op^ Op1: E = 0, L = 1^ Place at time 0 (0 % 2)
Unrolled Schedule Rolled Schedule LC = 99^
1: r3[-1] = load(r1[0]) Loop:2: r4[-1] = r3[-1] * 263: store (r2[0], r4[-1])4: r1[-1] = r1[0] + 45: r2[-1] = r2[0] + 4remap r1, r2, r3, r47: brlc Loop
brmemalu alu0^ X 0
MRT
X