Algorithm Search⌘K

Algorithmadvanced

Iterative modulo scheduling

Also called Rau modulo scheduling.

Software pipelines a loop by trying initiation intervals from a lower bound up, placing operations in a modulo reservation table with backtracking.

Time
O(n^3 log D + I (n e + B n (n + e + P w))) worst
Space
O(n^2 + e + n w) extra
Where
B = the budget ratio; D = the sum of the positive delays; I = the number of values of II tried; P = the largest II tried; e = the number of dependence edges; n = the number of operations; w = the length of the longest reservation table
Properties
deterministicnot exactofflineiterative
Origin
B. Ramakrishna Rau, 1994

Iterative modulo scheduling is an algorithm for the central step of software pipelining: it chooses a start time t(v)t(v) for each operation of a loop body so that a new iteration can start every IIII cycles. Software pipelining is the general technique, with its prologue, kernel, epilogue and register renaming. This page is only about the choice of tt and IIII, as Rau (1994) gave it. It starts at the lower bound MII=max⁡(ResMII,RecMII)\mathrm{MII} = \max(\mathrm{ResMII}, \mathrm{RecMII}) and tries each IIII in turn. For one IIII, it places the operations one at a time, by priority, into a modulo reservation table with IIII rows. When an operation finds no free row in its window, it takes a slot anyway and pushes out the operations that are in the way. These are placed again later, and a budget limits the number of steps. The result is always legal. It is not always the least IIII, but on most loops it is equal to MII.

In plain words

Picture a loop that starts a new pass every few clock ticks. Each pass must do the same steps at the same offsets, so every step has a fixed seat in a short repeating table, one row per tick. Two steps that need the same unit cannot sit in the same row. The method seats the most urgent steps first. If a step finds every seat it could take already full, it sits down anyway and makes the others stand up and look for new seats. After too many moves it gives up and tries again with a longer table, which has more seats. The first table length that works gives the speed of the loop.

The problem

The input is a loop body with operations 0,…,n−10, \dots, n - 1 and a machine. Each operation vv has a reservation table, a list of pairs (r,o)(r, o): in each iteration, vv uses one unit of resource rr in cycle t(v)+ot(v) + o. Resource rr has crc_r units. Each dependence edge (u,v)(u, v) has a delay δ(u,v)\delta(u, v) and a distance d(u,v)≥0d(u, v) \ge 0: operation vv of iteration i+di + d starts at least δ\delta cycles after operation uu of iteration ii. Edges with distance 0 form no cycle, as described on the loop-carried dependence page.

The output is an II≥1II \ge 1 and starts t(v)≥0t(v) \ge 0 that form a legal modulo schedule:

  • every edge has t(v)+II⋅d(u,v)≥t(u)+δ(u,v)t(v) + II \cdot d(u, v) \ge t(u) + \delta(u, v);
  • for each resource rr and each slot k∈{0,…,II−1}k \in \{0, \dots, II - 1\}, at most crc_r table entries of rr fall in cycles t(v)+o≡k(modII)t(v) + o \equiv k \pmod{II}.

Then iteration ii can start at cycle i⋅IIi \cdot II, and the overlapped run keeps every dependence and every unit limit. The goal is a small IIII. Finding the least one is NP-hard in general, so the algorithm is a heuristic.

The algorithm

  1. ITERATIVE-MODULO-SCHEDULE(G, machine, ratio)
  2. 1MII <- max(1, ResMII, RecMII)
  3. 2for II <- MII, MII + 1, ... do
  4. 3if ITERATIVE-SCHEDULE(II, ratio * n) returns t then return (II, t)
  5. ITERATIVE-SCHEDULE(II, budget)
  6. 4if some operation alone overfills the table then fail; H <- HeightR at II; t, MRT <- empty
  7. 5while some operation is unscheduled and budget > 0 do
  8. 6v <- the unscheduled operation of greatest H(v), the lowest index on ties
  9. 7Estart <- max(0, max over scheduled predecessors p of t(p) + delta(p, v) - II * d(p, v))
  10. 8s <- the first time in Estart .. Estart + II - 1 at which v fits in the MRT
  11. 9if there is none then s <- Estart if v was never scheduled or Estart > prev(v), else prev(v) + 1
  12. 10unschedule the operations that hold the slots that v needs at s, until v fits
  13. 11unschedule each scheduled successor w of v with t(w) < s + delta(v, w) - II * d(v, w)
  14. 12t(v) <- s; prev(v) <- s; put v in the MRT; budget <- budget - 1
  15. 13if all operations are scheduled then return t else fail

The bounds (line L1). If the tables hold uru_r entries of resource rr, then ResMII=max⁡r⌈ur/cr⌉\mathrm{ResMII} = \max_r \lceil u_r / c_r \rceil. For RecMII, give each edge the weight δ−II⋅d\delta - II \cdot d. A cycle CC of weight δ(C)−II⋅d(C)>0\delta(C) - II \cdot d(C) > 0 makes IIII impossible, so RecMII\mathrm{RecMII} is the least II≥0II \ge 0 with no positive cycle, that is max⁡C⌈δ(C)/d(C)⌉\max_C \lceil \delta(C) / d(C) \rceil. Rau finds it with the MinDist matrix, the all-pairs longest path weights, which Floyd-Warshall computes in O(n3)O(n^3). A positive cycle shows up as a positive diagonal entry. The weights only shrink as IIII grows, so a binary search over IIII from 0 to the sum DD of the positive delays finds RecMII.

Priority (line L4). HeightR(v)\mathrm{HeightR}(v) is the longest weight of a path from vv, and at least 0. It measures how far the rest of the iteration reaches beyond vv, counted at this IIII. With no positive cycle, Bellman-Ford rounds reach it. The check before it rejects an IIII at which some operation alone uses one row of the table too often, such as a divide that holds the multiplier at offsets 0 and 2 when II=2II = 2.

One step (lines L6 to L12). The earliest start of line L7 uses only the predecessors that are scheduled now. The window of line L8 has IIII times, so it tries every row of the table once. If all rows are full, line L9 forces a time. The rule with prev(v)\mathrm{prev}(v) makes an operation that comes back to the same Estart\mathrm{Estart} move one cycle later each time, so that it does not push out the same operations again and again. Line L10 makes room in the table. Line L11 pushes out the successors whose dependence on vv the new time breaks. Predecessors cannot break, since s≥Estarts \ge \mathrm{Estart}.

The budget (line L5). Each step costs one unit, and the budget is ratio times nn. When it runs out, the attempt fails and line L2 tries II+1II + 1. Rau chose the ratio by measurement. The code uses 3.

Example

The loop computes acc = acc * c + x[i] * y[i] and steps i. The machine has one memory unit, one multiplier and one ALU, each pipelined, so each table is one entry at offset 0.

index name operation resource edges out (delay, distance)
0 lx x = load x[i] mem to m2 (2, 0), to inc (0, 0)
1 ly y = load y[i] mem to m2 (2, 0), to inc (0, 0)
2 m1 p = acc * c mul to a (2, 0)
3 m2 q = x * y mul to a (2, 0)
4 a acc = p + q alu to m1 (1, 1)
5 inc i = i + 1 alu to lx (1, 1), to ly (1, 1), to itself (1, 1)

The edges into inc with delay 0 keep the loads before the write of i. Two operations use each resource, so ResMII=2\mathrm{ResMII} = 2. The cycle m1, a has delay 2+1=32 + 1 = 3 and distance 1, so RecMII=3\mathrm{RecMII} = 3, and at II=2II = 2 Floyd-Warshall finds a positive diagonal. So MII=3\mathrm{MII} = 3. At II=3II = 3 the heights are 4 for lx and ly, 2 for m1, m2 and inc, and 0 for a. The budget is 3⋅6=183 \cdot 6 = 18 steps. The steps are:

step op Estart first free time in the window time pushed out why
1 lx 0 0 0 none
2 ly 0 1 1 none memory row 0 is full
3 m1 0 0 0 none
4 m2 3 4 4 none multiplier row 0 holds m1
5 inc 1 1 1 none
6 a 6 6 6 m1 m1 at 0 breaks t(m1)+3≥t(a)+1t(m_1) + 3 \ge t(a) + 1
7 m1 4 5 5 a a at 6 breaks t(a)≥t(m1)+2t(a) \ge t(m_1) + 2
8 a 7 8 8 m1 m1 at 5 breaks t(m1)+3≥9t(m_1) + 3 \ge 9
9 m1 6 6 6 none

Line L11 does all the pushing here: each time a or m1 moves, the recurrence moves the other one. After 9 steps every operation is placed, with II=3=MIIII = 3 = \mathrm{MII}, so the result is optimal. The modulo reservation table is:

row mem mul alu
0 lx (0) m1 (6)
1 ly (1) m2 (4) inc (1)
2 a (8)

One iteration spans cycles 0 to 8, in three stages of three cycles. For 100 iterations the pipelined loop takes 99⋅3+9=30699 \cdot 3 + 9 = 306 cycles. Without overlap, the best schedule of one iteration takes 6 cycles (lx and m1 at 0, ly and inc at 1, m2 at 3, a at 5), so 600 cycles.

Correctness

Theorem. If ITERATIVE-MODULO-SCHEDULE returns (II,t)(II, t), then tt is a legal modulo schedule for IIII, and MII≤II∗≤II\mathrm{MII} \le II^* \le II, where II∗II^* is the least IIII of any legal modulo schedule.

The full proof is in the proof file. The lower bound comes from two sums. Each resource has crc_r units in each of IIII rows, so ur≤II⋅cru_r \le II \cdot c_r. Around a cycle the starts cancel, so the edge constraints add up to II⋅d(C)≥δ(C)II \cdot d(C) \ge \delta(C). For the schedule, the key invariant of line L5 is that the scheduled operations already form a legal partial schedule: the table rows are within their limits, and every edge between two scheduled operations holds. Line L7 makes the edges from scheduled predecessors hold, line L10 keeps the table rows within limits, and line L11 removes every successor whose edge would break. Self-loops hold at every II≥RecMIIII \ge \mathrm{RecMII}. So when every operation is scheduled, the schedule is legal. Each attempt stops within its budget.

Proof: MII is a lower bound on the initiation interval, and iterative modulo scheduling returns a legal modulo schedulefull

We prove four things. Every legal modulo schedule has II≥MIIII \ge \mathrm{MII} (Theorem 1). Line L1 computes ResMII\mathrm{ResMII} and RecMII\mathrm{RecMII} exactly (Lemmas 2 to 4). Each call of ITERATIVE-SCHEDULE stops, and when it succeeds its result is a legal modulo schedule (Theorem 5). A legal modulo schedule gives a legal overlapped run of any number of iterations (Theorem 6). The search over IIII is a heuristic: we do not claim that the returned IIII is the least one.

Setup

The loop body has operations 0,…,n−10, \dots, n - 1. Operation vv has a reservation table res(v)\mathrm{res}(v), a list of pairs (r,o)(r, o) with o≥0o \ge 0: in iteration ii, vv holds one unit of resource rr in cycle start+o\mathrm{start} + o. Resource rr has cr≥1c_r \ge 1 units. An edge e=(u,v,δ,d)e = (u, v, \delta, d) has a delay δ∈Z\delta \in \mathbb{Z} and a distance d≥0d \ge 0. The edges of distance 0 form no cycle.

For an integer II≥1II \ge 1, a modulo schedule is a map tt from operations to integers t(v)≥0t(v) \ge 0. It is legal if

  • (D) t(v)+II⋅d≥t(u)+δt(v) + II \cdot d \ge t(u) + \delta for every edge (u,v,δ,d)(u, v, \delta, d), and
  • (R) for every resource rr and every slot k∈{0,…,II−1}k \in \{0, \dots, II - 1\}, the number of pairs (v,(r,o))(v, (r, o)) with (r,o)∈res(v)(r, o) \in \mathrm{res}(v) and t(v)+o≡k(modII)t(v) + o \equiv k \pmod{II} is at most crc_r.

Let uru_r be the number of entries (r,⋅)(r, \cdot) in all tables. For a cycle CC of edges, let δ(C)\delta(C) and d(C)d(C) be the sums of its delays and distances. Every cycle has d(C)≥1d(C) \ge 1, since the edges of distance 0 form no cycle. Define

ResMII=max⁡r⌈ur/cr⌉,RecMII=max⁡(0,max⁡C⌈δ(C)/d(C)⌉),MII=max⁡(1,ResMII,RecMII),\mathrm{ResMII} = \max_r \lceil u_r / c_r \rceil, \qquad \mathrm{RecMII} = \max\Big(0, \max_C \lceil \delta(C) / d(C) \rceil\Big), \qquad \mathrm{MII} = \max(1, \mathrm{ResMII}, \mathrm{RecMII}),

with the maximum over all cycles CC, simple or not, and max⁡∅=0\max \emptyset = 0.

Part 1. The lower bound

Theorem 1. If tt is a legal modulo schedule for IIII, then II≥MIIII \ge \mathrm{MII}.

Proof. II≥1II \ge 1 by definition.

Resources. Fix rr. By (R), each of the IIII slots holds at most crc_r of the uru_r entries of rr, and each entry falls in exactly one slot. So ur≤II⋅cru_r \le II \cdot c_r, that is II≥ur/crII \ge u_r / c_r. As IIII is an integer, II≥⌈ur/cr⌉II \ge \lceil u_r / c_r \rceil. This holds for every rr, so II≥ResMIIII \ge \mathrm{ResMII}.

Recurrences. Fix a cycle C=(e1,…,em)C = (e_1, \dots, e_m) with ej=(xj−1,xj,δj,dj)e_j = (x_{j-1}, x_j, \delta_j, d_j) and xm=x0x_m = x_0. Adding (D) over the edges of CC gives

∑j=1m(t(xj)−t(xj−1))+II⋅d(C)≥δ(C).\sum_{j=1}^m \big(t(x_j) - t(x_{j-1})\big) + II \cdot d(C) \ge \delta(C).

The first sum telescopes to t(xm)−t(x0)=0t(x_m) - t(x_0) = 0. So II⋅d(C)≥δ(C)II \cdot d(C) \ge \delta(C), and as d(C)≥1d(C) \ge 1, II≥δ(C)/d(C)II \ge \delta(C) / d(C), hence II≥⌈δ(C)/d(C)⌉II \ge \lceil \delta(C) / d(C) \rceil. With II≥1>0II \ge 1 > 0, this gives II≥RecMIIII \ge \mathrm{RecMII}. □\square

So the least IIII of any legal modulo schedule, the optimum, is at least MII, and the IIII that the algorithm returns is at least the optimum, once Theorem 5 shows that it is legal.

Part 2. Computing MII

res_mii counts the entries of each resource and returns the largest ⌈ur/cr⌉\lceil u_r / c_r \rceil, which is ResMII\mathrm{ResMII} by definition. For RecMII, give each edge the weight wII(e)=δ−II⋅dw_{II}(e) = \delta - II \cdot d and call a cycle positive if its weight δ(C)−II⋅d(C)\delta(C) - II \cdot d(C) is >0> 0.

Lemma 2. For II≥0II \ge 0, there is no positive cycle at IIII if and only if II≥RecMIIII \ge \mathrm{RecMII}. In particular, "no positive cycle" holds for all IIII from RecMII\mathrm{RecMII} on, and for no smaller II≥0II \ge 0.

Proof. There is no positive cycle iff II⋅d(C)≥δ(C)II \cdot d(C) \ge \delta(C) for every cycle, iff II≥δ(C)/d(C)II \ge \delta(C) / d(C) for every cycle (as d(C)≥1d(C) \ge 1), iff II≥⌈δ(C)/d(C)⌉II \ge \lceil \delta(C)/d(C) \rceil for every cycle (as IIII is an integer). With II≥0II \ge 0, this is II≥RecMIIII \ge \mathrm{RecMII}. □\square

Lemma 3. min_dist returns a matrix with some diagonal entry M[i][i]>0M[i][i] > 0 if and only if there is a positive cycle.

Proof. Two invariants of the Floyd-Warshall loop, in the max-plus form of the code.

(a) Every finite entry M[i][j]M[i][j] is the weight of some walk from ii to jj with at least one edge. True at the start, where M[i][j]M[i][j] is the weight of the heaviest edge from ii to jj. An update sets M[i][j]=M[i][k]+M[k][j]M[i][j] = M[i][k] + M[k][j], the weight of the two walks joined at kk.

(b) After the round for kk, M[i][j]≥w(P)M[i][j] \ge w(P) for every walk PP from ii to jj with at least one edge whose inner vertices are distinct, are different from ii and jj, and are at most kk. (A walk with i=ji = j is a cycle through ii.) Before the first round, such a walk has no inner vertex and is one edge, and the claim holds. In the round for kk, a walk PP that has kk as an inner vertex splits at kk into P1P_1 from ii to kk and P2P_2 from kk to jj, whose inner vertices are distinct, are at most k−1k - 1 and do not contain kk. By the claim for round k−1k - 1, M[i][k]≥w(P1)M[i][k] \ge w(P_1) and M[k][j]≥w(P2)M[k][j] \ge w(P_2) when the update for (i,j)(i, j) runs, since entries never decrease. So after the update M[i][j]≥w(P1)+w(P2)=w(P)M[i][j] \ge w(P_1) + w(P_2) = w(P). A walk without kk as an inner vertex is covered by round k−1k - 1.

If there is a positive cycle, there is a positive simple cycle: a closed walk splits into simple cycles whose weights add up to its weight, so one of them is positive. A simple cycle through its vertex ii satisfies the condition of (b), so after the last round M[i][i]≥M[i][i] \ge its weight >0> 0. Conversely, if M[i][i]>0M[i][i] > 0, by (a) it is the weight of a closed walk, which splits into simple cycles, one of them positive. □\square

Lemma 4. rec_mii returns RecMII\mathrm{RecMII}.

Proof. Let h0=∑emax⁡(δe,0)h_0 = \sum_e \max(\delta_e, 0). At II=h0II = h_0, every cycle has δ(C)−h0d(C)≤h0−h0d(C)≤0\delta(C) - h_0 d(C) \le h_0 - h_0 d(C) \le 0, since δ(C)≤h0\delta(C) \le h_0 and d(C)≥1d(C) \ge 1. So RecMII≤h0\mathrm{RecMII} \le h_0 by Lemma 2. The binary search keeps the invariant lo≤RecMII≤hi\mathrm{lo} \le \mathrm{RecMII} \le \mathrm{hi}. It holds at the start with lo=0\mathrm{lo} = 0. If the test at mid\mathrm{mid} finds a positive cycle (Lemma 3), then mid<RecMII\mathrm{mid} < \mathrm{RecMII} by Lemma 2 and lo=mid+1\mathrm{lo} = \mathrm{mid} + 1 keeps it. Otherwise mid≥RecMII\mathrm{mid} \ge \mathrm{RecMII} and hi=mid\mathrm{hi} = \mathrm{mid} keeps it. The interval shrinks in each step, and at the end lo=hi=RecMII\mathrm{lo} = \mathrm{hi} = \mathrm{RecMII}. □\square

Part 3. One attempt at a fixed II

Fix II≥MIIII \ge \mathrm{MII} and a budget bb. By Lemma 2, there is no positive cycle at IIII. In particular, every self-loop (v,v,δ,d)(v, v, \delta, d) has δ−II⋅d≤0\delta - II \cdot d \le 0, so (D) holds for it for every value of t(v)t(v). The code leaves self-loops out of the lists preds and succs.

Heights (line L4). height_r runs Bellman-Ford rounds of h(u)←max⁡(h(u),h(v)+wII(e))h(u) \leftarrow \max(h(u), h(v) + w_{II}(e)) from h=0h = 0. As there is no positive cycle, the values are bounded by the longest simple path weights, and nn rounds reach the fixed point. The heights only fix the order of line L6. The proof below does not use them, so any order gives a legal result.

The check before line L4. The attempt fails at once if some operation vv alone does not satisfy (R) at t(v)=0t(v) = 0, which is the same as at every start, since a shift of the start shifts all slots of vv by the same amount modulo IIII. Otherwise every operation fits into an empty table.

The state is the partial map tt on the scheduled set SS, the map prev\mathrm{prev}, and the table MRT\mathrm{MRT}, which maps each pair (r,k)(r, k) to a list of operations.

Invariant. Before each step of the loop of line L5:

  • (I1) MRT[(r,k)]\mathrm{MRT}[(r, k)] lists each v∈Sv \in S once for each entry (r,o)∈res(v)(r, o) \in \mathrm{res}(v) with t(v)+o≡kt(v) + o \equiv k, and nothing else;
  • (I2) every list MRT[(r,k)]\mathrm{MRT}[(r, k)] has at most crc_r items;
  • (I3) every edge (u,v,δ,d)(u, v, \delta, d) with u≠vu \ne v and u,v∈Su, v \in S has t(v)+II⋅d≥t(u)+δt(v) + II \cdot d \ge t(u) + \delta;
  • (I4) t(v)≥0t(v) \ge 0 for every v∈Sv \in S.

Theorem 5. Each call of ITERATIVE-SCHEDULE stops after at most bb steps. If it returns tt, then tt is a legal modulo schedule for IIII.

Proof. Initialization. SS and MRT\mathrm{MRT} are empty, so (I1) to (I4) hold.

Unscheduling keeps (I1) to (I4). unschedule(w) removes ww from SS and removes exactly its entries from the table, so (I1) holds. Lists only get shorter, and constraints between members of SS only disappear.

Maintenance. Let v∉Sv \notin S be the operation of line L6 and S0S_0 the scheduled set at that moment. Line L7 sets E=max⁡(0,max⁡{t(p)+δ−II⋅d:(p,v,δ,d),p≠v,p∈S0})E = \max(0, \max \{ t(p) + \delta - II \cdot d : (p, v, \delta, d), p \ne v, p \in S_0 \}), and every later choice ss satisfies s≥Es \ge E: line L8 takes s∈[E,E+II−1]s \in [E, E + II - 1], and line L9 takes EE or prev(v)+1\mathrm{prev}(v) + 1, the latter only when E≤prev(v)E \le \mathrm{prev}(v). So s≥E≥0s \ge E \ge 0.

Resources. If line L8 found ss, then _fits says that every list (r,k)(r, k) that vv needs, with cc new entries, has at most cr−cc_r - c items, so adding vv keeps (I2). If line L9 chose ss, line L10 removes items from each such list while it has more than cr−cc_r - c items. Each removal makes the list shorter, and c≤crc \le c_r by the check before line L4, so the loop stops with at most cr−cc_r - c items. Removing an operation never lengthens another list. So after line L10, adding the entries of vv keeps (I2), and line L12 adds exactly these entries, so (I1) holds.

Dependences. After lines L10 and L11 the scheduled set is S1⊆S0S_1 \subseteq S_0. For an edge (p,v,δ,d)(p, v, \delta, d) with p∈S1p \in S_1, p≠vp \ne v: p∈S0p \in S_0, so s≥E≥t(p)+δ−II⋅ds \ge E \ge t(p) + \delta - II \cdot d. For an edge (v,w,δ,d)(v, w, \delta, d) with w∈S1w \in S_1, w≠vw \ne v: line L11 removed every ww with t(w)<s+δ−II⋅dt(w) < s + \delta - II \cdot d, so t(w)+II⋅d≥s+δt(w) + II \cdot d \ge s + \delta. Edges between two members of S1S_1 held before by (I3). So (I3) holds with t(v)=st(v) = s, and (I4) holds as s≥0s \ge 0.

Termination. Each step decreases the budget by 1, and the loop stops when the budget is 0 or SS holds all operations. Line L10 stops as shown, and lines L6 to L8 and L11 are finite.

Result. The call returns tt only when SS holds all operations. Then (I1) and (I2) give (R), (I3) and the remark on self-loops give (D), and (I4) gives t≥0t \ge 0. □\square

Corollary. If modulo_schedule returns (II,t,MII)(II, t, \mathrm{MII}), then tt is a legal modulo schedule for IIII, and MII≤II∗≤II\mathrm{MII} \le II^* \le II for the least II∗II^* of any legal modulo schedule.

Proof. The loop of line L2 starts at MII, computed exactly by Lemma 4, so every attempt has II≥MIIII \ge \mathrm{MII} and Theorem 5 applies to the one that returns. Theorem 1 gives MII≤II∗\mathrm{MII} \le II^*, and II∗≤IIII^* \le II because tt is legal. The loop of line L2 is finite, since it stops at max_ii, so modulo_schedule stops: it returns or raises an error. □\square

Part 4. The overlapped run

Theorem 6. Let tt be a legal modulo schedule for IIII, and run iterations i=0,1,…,N−1i = 0, 1, \dots, N - 1, with operation vv of iteration ii starting at cycle σ(v,i)=i⋅II+t(v)\sigma(v, i) = i \cdot II + t(v). Then for every edge (u,v,δ,d)(u, v, \delta, d) and every ii with i+d<Ni + d < N, σ(v,i+d)≥σ(u,i)+δ\sigma(v, i + d) \ge \sigma(u, i) + \delta. And in every cycle cc, at most crc_r units of each resource rr are in use.

Proof. σ(v,i+d)−σ(u,i)=t(v)+II⋅d−t(u)≥δ\sigma(v, i + d) - \sigma(u, i) = t(v) + II \cdot d - t(u) \ge \delta by (D). For resources, an entry (r,o)(r, o) of vv in iteration ii uses rr in cycle i⋅II+t(v)+oi \cdot II + t(v) + o, which is congruent to t(v)+ot(v) + o modulo IIII. So all uses of rr in cycle cc come from entries in the slot c mod IIc \bmod II. Two uses in cycle cc from the same entry (v,(r,o))(v, (r, o)) would have i⋅II+t(v)+o=i′⋅II+t(v)+oi \cdot II + t(v) + o = i' \cdot II + t(v) + o, so i=i′i = i', the same use. So the uses of rr in cycle cc are at most the number of entries in slot c mod IIc \bmod II, which is at most crc_r by (R). ■\blacksquare

Complexity

The model is the word RAM. Let nn, ee, DD, ww, BB, II and PP be as in the front matter, with a constant number of units per resource.

  • Line L1. ResMII takes O(nw)O(n w). The binary search for RecMII runs Floyd-Warshall O(log⁡D)O(\log D) times, at O(n3+e)O(n^3 + e) each.
  • Line L4. The check takes O(nw)O(n w), and the heights take at most nn rounds over the edges, O(ne)O(n e).
  • Lines L6 to L12, per step. Line L6 scans O(n)O(n) operations, line L7 and line L11 scan O(e)O(e) edges, and line L8 tests at most II≤PII \le P times at O(w)O(w) each. Every operation that lines L10 and L11 remove was placed by an earlier step, so all removals cost O(w)O(w) per step on average.
  • One attempt. At most BnB n steps: O(ne+Bn(n+e+Pw))O(n e + B n (n + e + P w)).

So the run costs O(n3log⁡D+I(ne+Bn(n+e+Pw)))O(n^3 \log D + I (n e + B n (n + e + P w))) time. The space is O(n2)O(n^2) for MinDist, O(e)O(e) for the edges and O(nw)O(n w) for the table. The Python code computes the tests of line L8 with dictionaries, which keeps these bounds.

Properties

  • Always legal. Every returned schedule meets every dependence with its distance and every row limit of the table.
  • Not exact. The returned IIII can be larger than the least one: the budget can run out, and the order of line L6 can block a better choice. The least IIII can also be larger than MII.
  • Usually optimal in practice. On 150 random loops of at most 5 operations in the tests, the returned IIII equalled the exhaustive optimum on all of them, and the optimum was above MII on 3. In a larger run with 300 loops of up to 6 operations, it equalled the optimum on 298. These are measurements on small random loops, not bounds.
  • Deterministic. The order of line L6, the scan of line L8 and the removal order are fixed.
  • General resources. A table may use several resources at several offsets, as for a divide that holds a unit for many cycles.
  • Blind to registers. It does not look at the lifetimes of values, so it can need many registers.

Variants and improvements

  • Lifetime-sensitive scheduling. Huff (1993) places each operation early or late inside its slack to keep values short. Swing modulo scheduling (Llosa et al. 1996) orders the operations by recurrences and places each one next to its scheduled neighbors, without backtracking. It is the pipeliner of GCC.
  • No backtracking. Lam (1988) schedules the strongly connected components first and raises IIII when an operation finds no slot.
  • Constraint and integer programming. SDC-based modulo scheduling keeps the dependences as a system of difference constraints, and an integer program gives the least IIII for small loops.
  • Faster RecMII. The ratio max⁡Cδ(C)/d(C)\max_C \delta(C)/d(C) is a minimum cycle ratio problem. With all distances 1 it is a maximum mean cycle, which Karp's algorithm solves in O(ne)O(n e).

When to use it

Use it to pipeline inner loops for VLIW, EPIC and DSP processors, where it is a standard method with a simple implementation and schedules close to MII. Prefer swing modulo scheduling when registers are few, since it keeps lifetimes short. Prefer an integer program for small, hot loops where the least IIII is worth a long compile. In high-level synthesis, SDC-based modulo scheduling handles timing rules that are not plain dependences. For code with branches and no loop, use trace scheduling or superblock scheduling.

Pitfalls

  • Missing the successor check. If line L11 is left out, the schedule can break a dependence. In the example, step 6 puts a at 6 while m1 stays at 0, and then the next iteration multiplies the old acc. Line L11 must push out every scheduled successor whose edge the new time breaks.
  • Forcing the same time again. If line L9 always takes Estart, an operation that is pushed out and comes back with the same Estart pushes out the same operations, which then push it out again, until the budget is gone. Take prev(v)+1\mathrm{prev}(v) + 1 when Estart≤prev(v)\mathrm{Estart} \le \mathrm{prev}(v).
  • The wrong earliest start. If line L7 reads the old times of operations that are not scheduled, or leaves out −II⋅d- II \cdot d, the start of an operation on a recurrence is too late or too early. Use only the scheduled predecessors, with the weight δ−II⋅d\delta - II \cdot d.
  • No check of a single operation. If line L4 does not reject an operation that alone overfills a row, line L10 cannot make room for it, even when it empties the table. Reject that IIII at once.
  • Rounding down. If line L1 rounds ur/cru_r / c_r or δ(C)/d(C)\delta(C)/d(C) down, the first attempts run at an IIII that no schedule can meet. Three loads on two memory ports need II=2II = 2, and a cycle with delay 5 and distance 2 needs II=3II = 3.
  • A window of the wrong size. If line L8 tries fewer than IIII times, it misses free rows. More than IIII times only repeats rows at later times.

Implementations

Each implementation follows the pseudocode above. A comment @line links a line of code to a line of the pseudocode. Point at a line of the pseudocode to see the matching code. The build runs the native tests of each language.

iterative_modulo_scheduling.pyI0RawGitHub
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/iterative-modulo-scheduling/. The authors are listed in prov/PJN90C.jsonl.
"""Iterative modulo scheduling (Rau 1994) of the body of a loop.

A loop body is given by
- n: the number of operations, numbered 0 .. n-1;
- res[v]: the reservation table of operation v, a list of pairs
  (resource, offset): v holds one unit of the resource in cycle
  t(v) + offset of its iteration;
- edges: a list of (u, v, delay, distance): operation v of iteration
  i + distance starts at least delay cycles after operation u of
  iteration i starts;
- machine: a dict from each resource to its number of units.

A modulo schedule for an initiation interval II gives each operation a
start t(v) >= 0 such that every edge has
t(v) + II * distance >= t(u) + delay, and for each resource r and slot k
in 0 .. II-1, at most machine[r] uses of r fall in cycles congruent to k
modulo II. Iteration i then starts at cycle i * II.

Precondition: offsets >= 0, distances >= 0, every resource of a table is
in machine with at least one unit, and the edges of distance 0 form no
cycle (check_loop raises ValueError otherwise).

modulo_schedule returns (II, t, MII) with MII = max(1, ResMII, RecMII).
The result is always a legal modulo schedule and II >= MII. It is a
heuristic: II may be larger than the least possible one.

Cost: with e edges, D the sum of the positive delays and w the longest
reservation table, RecMII takes O(n^3 log D) by binary search with
Floyd-Warshall. One attempt at a given II takes O(n e) for the heights
and O(budget (n + e + II w)) for the steps, budget = budget_ratio * n.
"""

NEG = float("-inf")


def check_loop(n, res, edges, machine):
    if len(res) != n:
        raise ValueError("one reservation table per operation")
    for v in range(n):
        for r, off in res[v]:
            if machine.get(r, 0) < 1 or off < 0:
                raise ValueError("bad reservation (%r, %r) of operation %d" % (r, off, v))
    succ = [[] for _ in range(n)]
    indeg = [0] * n
    for u, v, delay, dist in edges:
        if not (0 <= u < n and 0 <= v < n) or dist < 0:
            raise ValueError("bad edge %r" % ((u, v, delay, dist),))
        if dist == 0:
            succ[u].append(v)
            indeg[v] += 1
    stack = [v for v in range(n) if indeg[v] == 0]
    seen = 0
    while stack:
        u = stack.pop()
        seen += 1
        for v in succ[u]:
            indeg[v] -= 1
            if indeg[v] == 0:
                stack.append(v)
    if seen != n:
        raise ValueError("the edges of distance 0 form a cycle")


def res_mii(n, res, machine):
    """max over resources r of ceil(uses of r / units of r)."""
    uses = {}
    for v in range(n):
        for r, _ in res[v]:
            uses[r] = uses.get(r, 0) + 1
    return max([-(-u // machine[r]) for r, u in uses.items()], default=0)


def min_dist(n, edges, ii):
    """M[i][j]: the largest sum of delay - ii * distance over the walks from
    i to j with at least one edge that Floyd-Warshall builds; -inf if there
    is none. Some M[i][i] > 0 exactly when some cycle has a positive sum."""
    m = [[NEG] * n for _ in range(n)]
    for u, v, delay, dist in edges:
        m[u][v] = max(m[u][v], delay - ii * dist)
    for k in range(n):
        mk = m[k]
        for i in range(n):
            a = m[i][k]
            if a == NEG:
                continue
            mi = m[i]
            for j in range(n):
                if a + mk[j] > mi[j]:
                    mi[j] = a + mk[j]
    return m


def has_positive_cycle(n, edges, ii):
    m = min_dist(n, edges, ii)
    return any(m[i][i] > 0 for i in range(n))


def rec_mii(n, edges):
    """The least II >= 0 such that no cycle has delay(C) > II * distance(C),
    that is max(0, max over cycles C of ceil(delay(C) / distance(C)))."""
    lo, hi = 0, sum(max(e[2], 0) for e in edges)
    while lo < hi:
        mid = (lo + hi) // 2
        if has_positive_cycle(n, edges, mid):
            lo = mid + 1
        else:
            hi = mid
    return lo


def height_r(n, edges, ii):
    """HeightR(v): the longest sum of delay - ii * distance over paths from v,
    at least 0. Bellman-Ford rounds; there is no positive cycle."""
    h = [0] * n
    for _ in range(n):
        changed = False
        for u, v, delay, dist in edges:
            x = h[v] + delay - ii * dist
            if x > h[u]:
                h[u] = x
                changed = True
        if not changed:
            break
    return h


def _slots(v, s, res, ii):
    need = {}
    for r, off in res[v]:
        key = (r, (s + off) % ii)
        need[key] = need.get(key, 0) + 1
    return need


def _fits(v, s, mrt, res, machine, ii):
    return all(len(mrt.get(key, ())) + c <= machine[key[0]] for key, c in _slots(v, s, res, ii).items())


def iterative_schedule(n, res, edges, machine, ii, budget, log=None):
    """One attempt at II. Returns (t, mrt) or None. mrt maps (resource,
    slot) to the list of operations that use it, once per use. If log is a
    list, each step appends (op, estart, slot, displaced ops)."""
    if not all(_fits(v, 0, {}, res, machine, ii) for v in range(n)):
        return None
    h = height_r(n, edges, ii)  # @line L4
    preds = [[] for _ in range(n)]
    succs = [[] for _ in range(n)]
    for u, v, delay, dist in edges:
        if u != v:
            preds[v].append((u, delay - ii * dist))
            succs[u].append((v, delay - ii * dist))
    t, prev, mrt = {}, {}, {}

    def unschedule(w):
        for key, c in _slots(w, t[w], res, ii).items():
            for _ in range(c):
                mrt[key].remove(w)
        del t[w]

    while len(t) < n and budget > 0:  # @line L5
        v = max((w for w in range(n) if w not in t), key=lambda w: (h[w], -w))  # @line L6
        estart = max([0] + [t[p] + wt for p, wt in preds[v] if p in t])  # @line L7
        s = next((x for x in range(estart, estart + ii) if _fits(v, x, mrt, res, machine, ii)), None)  # @line L8
        out = []
        if s is None:
            s = estart if v not in prev or estart > prev[v] else prev[v] + 1  # @line L9
            for key, c in _slots(v, s, res, ii).items():
                while len(mrt.get(key, ())) + c > machine[key[0]]:
                    out.append(mrt[key][0])
                    unschedule(mrt[key][0])  # @line L10
        for w, wt in succs[v]:
            if w in t and t[w] < s + wt:
                out.append(w)
                unschedule(w)  # @line L11
        t[v] = s  # @line L12
        prev[v] = s
        for key, c in _slots(v, s, res, ii).items():
            mrt.setdefault(key, []).extend([v] * c)
        budget -= 1
        if log is not None:
            log.append((v, estart, s, out))
    if len(t) < n:
        return None
    return t, mrt  # @line L13


def modulo_schedule(n, res, edges, machine, budget_ratio=3, max_ii=None, log=None):
    """Returns (II, t, MII). Tries II = MII, MII + 1, ... up to max_ii and
    raises RuntimeError if every attempt runs out of budget."""
    check_loop(n, res, edges, machine)
    mii = max(1, res_mii(n, res, machine), rec_mii(n, edges))  # @line L1
    if max_ii is None:
        max_ii = mii + sum(max(e[2], 0) for e in edges) + sum(len(r) for r in res) + n
    for ii in range(mii, max_ii + 1):  # @line L2
        if log is not None:
            log.append(("II", ii))
        got = iterative_schedule(n, res, edges, machine, ii, budget_ratio * n, log)
        if got is not None:
            return ii, got[0], mii  # @line L3
    raise RuntimeError("no schedule up to II = %d" % max_ii)


def stages(t, ii):
    """stage(v) = t(v) div II, and the number of stages SC."""
    st = {v: s // ii for v, s in t.items()}
    return st, 1 + max(st.values(), default=0)
test_iterative_modulo_scheduling.py 239 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/iterative-modulo-scheduling/. The authors are listed in prov/PJN90C.jsonl.
import random

import pytest

import iterative_modulo_scheduling as ims

# acc = acc * c + x[i] * y[i], with i = i + 1
NAMES = ["lx", "ly", "m1", "m2", "a", "inc"]
RES = [[("mem", 0)], [("mem", 0)], [("mul", 0)], [("mul", 0)], [("alu", 0)], [("alu", 0)]]
EDGES = [
    (0, 3, 2, 0), (1, 3, 2, 0), (2, 4, 2, 0), (3, 4, 2, 0), (4, 2, 1, 1),
    (5, 0, 1, 1), (5, 1, 1, 1), (5, 5, 1, 1), (0, 5, 0, 0), (1, 5, 0, 0),
]
MACHINE = {"mem": 1, "mul": 1, "alu": 1}


def ceil_div(a, b):
    return -(-a // b)


def legal(n, res, edges, machine, ii, t):
    """Every edge holds and no slot of the modulo reservation table is over
    its number of units."""
    if sorted(t) != list(range(n)) or min(t.values(), default=0) < 0:
        return False
    for u, v, delay, dist in edges:
        if t[v] + ii * dist < t[u] + delay:
            return False
    use = {}
    for v in range(n):
        for r, off in res[v]:
            key = (r, (t[v] + off) % ii)
            use[key] = use.get(key, 0) + 1
    return all(c <= machine[key[0]] for key, c in use.items())


def flat_ok(n, res, edges, machine, ii, t, iters):
    """Run iters overlapped iterations, iteration i from cycle i * II, and
    check every unit in every cycle and every dependence between iterations."""
    start = {(v, i): i * ii + t[v] for v in range(n) for i in range(iters)}
    busy = {}
    for (v, i), s in start.items():
        for r, off in res[v]:
            busy[(r, s + off)] = busy.get((r, s + off), 0) + 1
    if any(c > machine[r] for (r, _), c in busy.items()):
        return False
    for u, v, delay, dist in edges:
        for i in range(iters - dist):
            if start[(v, i + dist)] < start[(u, i)] + delay:
                return False
    return True


def oracle_res_mii(n, res, machine):
    best = 0
    for r in machine:
        uses = sum(1 for v in range(n) for x, _ in res[v] if x == r)
        best = max(best, ceil_div(uses, machine[r]))
    return best


def oracle_rec_mii(n, edges):
    """max over simple cycles of ceil(delay / distance), by enumeration of
    the simple cycles from their least vertex."""
    out = [[] for _ in range(n)]
    for u, v, delay, dist in edges:
        out[u].append((v, delay, dist))
    best = 0

    def walk(start, x, on, delay, dist):
        nonlocal best
        for y, d1, d2 in out[x]:
            if y == start:
                assert dist + d2 >= 1
                best = max(best, ceil_div(delay + d1, dist + d2))
            elif y > start and y not in on:
                on.add(y)
                walk(start, y, on, delay + d1, dist + d2)
                on.discard(y)

    for s in range(n):
        walk(s, s, {s}, 0, 0)
    return best


def feasible(n, res, edges, machine, ii):
    """Exact test: is there any legal modulo schedule at ii? Enumerate the
    slots k(v) = t(v) mod ii that fit the table; then t(v) = k(v) + ii q(v)
    and the edges are difference constraints on the integers q(v)."""
    k = [0] * n
    use = {}

    def diff_ok():
        cons = [(u, v, ceil_div(delay - ii * dist - k[v] + k[u], ii)) for u, v, delay, dist in edges]
        q = [0] * n
        for _ in range(n + 1):
            changed = False
            for u, v, c in cons:
                if q[u] + c > q[v]:
                    q[v] = q[u] + c
                    changed = True
            if not changed:
                return True
        return False

    def rec(j):
        if j == n:
            return diff_ok()
        for x in range(ii):
            keys = [(r, (x + off) % ii) for r, off in res[j]]
            for key in keys:
                use[key] = use.get(key, 0) + 1
            if all(use[key] <= machine[key[0]] for key in keys):
                k[j] = x
                if rec(j + 1):
                    for key in keys:
                        use[key] -= 1
                    return True
            for key in keys:
                use[key] -= 1
        return False

    return rec(0)


def random_loop(rng, n):
    machine = {"mem": 1, "alu": rng.choice([1, 2]), "mul": 1}
    res = []
    for _ in range(n):
        r = rng.choice(["mem", "alu", "mul"])
        if r == "mul" and rng.random() < 0.3:
            res.append([("mul", 0), ("mul", 1)])
        else:
            res.append([(r, 0)])
    edges = []
    for _ in range(rng.randint(0, 2 * n)):
        u, v = rng.randrange(n), rng.randrange(n)
        dist = 0 if u < v and rng.random() < 0.6 else rng.randint(1, 3)
        edges.append((u, v, rng.randint(-1, 4), dist))
    return n, res, edges, machine


def test_example():
    n = len(NAMES)
    assert ims.res_mii(n, RES, MACHINE) == 2
    assert ims.rec_mii(n, EDGES) == 3
    assert ims.height_r(n, EDGES, 3) == [4, 4, 2, 2, 0, 2]
    log = []
    ii, t, mii = ims.modulo_schedule(n, RES, EDGES, MACHINE, log=log)
    assert (ii, mii) == (3, 3)
    assert {NAMES[v]: s for v, s in t.items()} == {"lx": 0, "ly": 1, "m1": 6, "m2": 4, "a": 8, "inc": 1}
    steps = [(NAMES[v], e, s, [NAMES[w] for w in out]) for v, e, s, out in log[1:]]
    assert steps == [
        ("lx", 0, 0, []), ("ly", 0, 1, []), ("m1", 0, 0, []), ("m2", 3, 4, []), ("inc", 1, 1, []),
        ("a", 6, 6, ["m1"]), ("m1", 4, 5, ["a"]), ("a", 7, 8, ["m1"]), ("m1", 6, 6, []),
    ]
    assert ims.stages(t, ii) == ({0: 0, 1: 0, 2: 2, 3: 1, 4: 2, 5: 0}, 3)
    assert legal(n, RES, EDGES, MACHINE, ii, t)
    assert flat_ok(n, RES, EDGES, MACHINE, ii, t, 6)
    assert not feasible(n, RES, EDGES, MACHINE, 2) and feasible(n, RES, EDGES, MACHINE, 3)


def test_random_loops_against_oracles():
    rng = random.Random(21)
    for _ in range(600):
        n, res, edges, machine = random_loop(rng, rng.randint(1, 7))
        rm = ims.res_mii(n, res, machine)
        cm = ims.rec_mii(n, edges)
        assert rm == oracle_res_mii(n, res, machine)
        assert cm == oracle_rec_mii(n, edges)
        ii, t, mii = ims.modulo_schedule(n, res, edges, machine)
        assert mii == max(1, rm, cm) and ii >= mii
        assert legal(n, res, edges, machine, ii, t)
        _, sc = ims.stages(t, ii)
        assert flat_ok(n, res, edges, machine, ii, t, sc + 3)


def test_mii_bounds_the_optimum():
    rng = random.Random(22)
    hit = 0
    for _ in range(150):
        n, res, edges, machine = random_loop(rng, rng.randint(1, 5))
        ii, t, mii = ims.modulo_schedule(n, res, edges, machine)
        best = next(x for x in range(1, ii + 1) if feasible(n, res, edges, machine, x))
        assert mii <= best <= ii
        if not feasible(n, res, edges, machine, mii):
            assert best > mii
        hit += ii == best
    assert hit >= 140


def test_small_budget_still_legal():
    rng = random.Random(23)
    worse = 0
    for _ in range(200):
        n, res, edges, machine = random_loop(rng, rng.randint(2, 7))
        ii, t, mii = ims.modulo_schedule(n, res, edges, machine, budget_ratio=1)
        assert ii >= mii and legal(n, res, edges, machine, ii, t)
        worse += ii > ims.modulo_schedule(n, res, edges, machine)[0]
    assert worse > 0


def test_self_conflicting_table():
    # a divide that holds the multiplier in cycles 0 and 2 cannot run at II = 2
    res = [[("mul", 0), ("mul", 2)], [("alu", 0)]]
    machine = {"mul": 1, "alu": 1}
    assert ims.res_mii(2, res, machine) == 2
    assert ims.iterative_schedule(2, res, [], machine, 2, 6) is None
    ii, t, _ = ims.modulo_schedule(2, res, [], machine)
    assert ii == 3 and legal(2, res, [], machine, 3, t)
    assert not feasible(2, res, [], machine, 2)


def test_rounding_up():
    # three loads on two memory ports: II = 1 would need three ports
    res = [[("mem", 0)]] * 3
    machine = {"mem": 2}
    assert ims.res_mii(3, res, machine) == 2
    assert not feasible(3, res, [], machine, 1)
    # a recurrence of delay 5 over distance 2 needs II = 3, not 2
    edges = [(0, 1, 3, 0), (1, 0, 2, 2)]
    assert ims.rec_mii(2, edges) == 3
    assert not feasible(2, [[("alu", 0)], [("alu", 0)]], edges, {"alu": 2}, 2)


def test_input_checks():
    with pytest.raises(ValueError):
        ims.modulo_schedule(2, [[("alu", 0)], [("alu", 0)]], [(0, 1, 1, 0), (1, 0, 1, 0)], {"alu": 1})
    with pytest.raises(ValueError):
        ims.modulo_schedule(1, [[("alu", 0)]], [(0, 0, 1, 0)], {"alu": 1})
    with pytest.raises(ValueError):
        ims.modulo_schedule(1, [[("fpu", 0)]], [], {"alu": 1})
    with pytest.raises(ValueError):
        ims.modulo_schedule(1, [[("alu", 0)]], [(0, 0, 1, -1)], {"alu": 1})
    assert ims.modulo_schedule(0, [], [], {"alu": 1}) == (1, {}, 1)
    ii, t, _ = ims.modulo_schedule(1, [[("alu", 0)]], [(0, 0, 4, 1)], {"alu": 1})
    assert (ii, t) == (4, {0: 0})

History

Rau and Glaeser (1981) scheduled one iteration at a fixed interval with resources reserved modulo that interval, for a machine designed to make this easy. Lam (1988) built modulo scheduling into the compiler of the Warp machine, with bounds from resources and recurrences and modulo variable expansion. At Cydrome, Rau and others built the Cydra 5 and its compiler around modulo scheduling with rotating registers. Huff (1993) added slack scheduling to keep lifetimes short. Rau (1994) gave iterative modulo scheduling, with HeightR, the budget and the displacement of operations, and a long journal version in 1996. Llosa and others gave swing modulo scheduling in 1996, and Zhang and Liu carried the modulo reservation table into high-level synthesis in 2013.

References

  1. B. Ramakrishna Rau, Iterative modulo scheduling, an algorithm for software pipelining loops, Proceedings of the 27th Annual International Symposium on Microarchitecture, 1994, 63-74, the bounds ResMII and RecMII with the MinDist matrix, the priority HeightR, and the procedures IterativeSchedule and FindTimeSlot with the earliest start Estart and a budget of BudgetRatio times the number of operations
  2. B. Ramakrishna Rau, Iterative modulo scheduling, International Journal of Parallel Programming 24(1), 1996, 3-64, the journal version of the algorithm with its measurements
  3. Monica Lam, Software pipelining, an effective scheduling technique for VLIW machines, Proceedings of the ACM SIGPLAN Conference on Programming Language Design and Implementation, 1988, 318-328, modulo scheduling with lower bounds from resources and recurrences, the scheduling of strongly connected components first, and modulo variable expansion
  4. Richard A. Huff, Lifetime-sensitive modulo scheduling, Proceedings of the ACM SIGPLAN Conference on Programming Language Design and Implementation, 1993, 258-267, MinDist as all-pairs longest paths with arc costs of latency minus distance times II, and slack scheduling that places operations early or late to keep lifetimes short
  5. Josep Llosa, Antonio González, Eduard Ayguadé and Mateo Valero, Swing modulo scheduling, a lifetime-sensitive approach, Proceedings of the Conference on Parallel Architectures and Compilation Techniques, 1996, 80-86, the order of the operations by recurrences and the placement of each operation next to its scheduled neighbors
  6. Vicki H. Allan, Reese B. Jones, Randall M. Lee and Stephen J. Allan, Software pipelining, ACM Computing Surveys 27(3), 1995, 367-432, the survey of modulo scheduling methods, with iterative modulo scheduling among them

Where this leads

About this page

The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.

LadderLevelWhat the next level needs
Human proofH1 sketch
  • a full proof of time.worst
  • a full proof of space.extra
LeanL0 no Lean part
  • name a Lean module in the lean field (07)
Code (python)I0 not checked yet
  • the tests did not run in this build
VisualV0 none
  • add viz/scene.ts or a figure (10)
WritingW2 basic
  • a scene preset for the example