Algorithm Search⌘K

Definitioncore

Dependence distance vector

Also called distance vector.

The difference between the iteration vectors of the sink and the source of a dependence in a loop nest.

The distance vector of a data dependence in a loop nest is the iteration vector of the sink minus the iteration vector of the source. If the sink T(j⃗)T(\vec{j}) depends on the source S(i⃗)S(\vec{i}), the distance is d⃗=j⃗−i⃗\vec{d} = \vec{j} - \vec{i}. It says how many iterations of each loop lie between the two accesses. Its first nonzero entry gives the loop that carries the dependence, and the distances of all dependences decide which reorderings of the loops are legal. When the distance is not one fixed vector, compilers keep only its signs, the direction vector.

Definition

Let SS and TT have kk common loops, and let a dependence go from S(i⃗)S(\vec{i}) to T(j⃗)T(\vec{j}), where i⃗,j⃗∈Zk\vec{i}, \vec{j} \in \mathbb{Z}^k are the parts of the iteration vectors for these loops. The distance vector of this pair of instances is

d⃗=j⃗−i⃗∈Zk.\vec{d} = \vec{j} - \vec{i} \in \mathbb{Z}^k.

The distance set of the dependence S→TS \to T of one kind is the set of all such vectors,

Δ(S,T)={ j⃗−i⃗:S(i⃗)→T(j⃗) }.\Delta(S, T) = \{\, \vec{j} - \vec{i} : S(\vec{i}) \to T(\vec{j}) \,\}.

In the isl notation, this is the set of deltas of the dependence relation: for { S[i, j] -> S[i + 1, j - 1] : ... } the deltas are { [1, -1] }. The dependence is uniform, or has a constant distance, when Δ(S,T)\Delta(S, T) has one element.

Lexicographic sign. Each distance vector is lexicographically positive or zero, d⃗⪰0⃗\vec{d} \succeq \vec{0}. The source runs first, so i⃗⪯j⃗\vec{i} \preceq \vec{j} on the common loops: either i⃗=j⃗\vec{i} = \vec{j}, or at the first index ll where they differ, il<jli_l < j_l. In the first case d⃗=0⃗\vec{d} = \vec{0}; in the second, d1=⋯=dl−1=0d_1 = \dots = d_{l-1} = 0 and dl>0d_l > 0. A pair of accesses with j⃗−i⃗≺0⃗\vec{j} - \vec{i} \prec \vec{0} is a dependence in the other direction, from T(j⃗)T(\vec{j}) to S(i⃗)S(\vec{i}), and its distance is i⃗−j⃗\vec{i} - \vec{j}.

The zero vector. d⃗=0⃗\vec{d} = \vec{0} means that the source and the sink run in the same iteration. Such a dependence is loop independent, not carried by any loop. It exists only between two different statements, with the source first in the body.

Index values against iteration numbers. The definition uses the values of the loop indices. For a loop with step s≠1s \ne 1, these values differ by multiples of ss. Most texts first normalize each loop to start at 0 or 1 with step 1, and then measure distances in iterations. Say which one a table uses.

When the distance is constant

Let SS access X[Fi⃗+f⃗]X[F\vec{i} + \vec{f}] and TT access X[Gj⃗+g⃗]X[G\vec{j} + \vec{g}], with integer matrices FF and GG of size m×km \times k. A dependence needs Fi⃗+f⃗=Gj⃗+g⃗F\vec{i} + \vec{f} = G\vec{j} + \vec{g}.

  • If F=GF = G (the two references are uniformly generated), then Fd⃗=f⃗−g⃗F\vec{d} = \vec{f} - \vec{g}. If moreover FF has full column rank, this has at most one solution d⃗\vec{d}, so the distance is constant whenever a dependence exists. In one dimension this is the case of the strong SIV test: ai+c1=aj+c2a i + c_1 = a j + c_2 gives d=(c1−c2)/ad = (c_1 - c_2)/a, see practical dependence tests.
  • If F=GF = G but FF has a nonzero kernel, the distances form the solutions of Fd⃗=f⃗−g⃗F\vec{d} = \vec{f} - \vec{g} that fit in the bounds: one solution plus the kernel vectors. A loop index that the subscript does not use has every distance within its bounds.
  • If F≠GF \ne G, the distance usually changes from one pair to the next.

Examples and non-examples

A constant distance

for i = 1 to n:
  for j = 1 to n:
    S: A[i][j] = A[i-1][j] + A[i][j-1]

S(i,j)S(i, j) writes A[i][j]A[i][j]. S(i+1,j)S(i+1, j) reads it as A[i][j]A[i][j] through the first read, and S(i,j+1)S(i, j+1) reads it through the second. So there are two flow dependences, with distances (1,0)(1, 0) and (0,1)(0, 1). There is no anti dependence: each element is read only after it is written. Both distances have nonnegative entries, so the two loops are fully permutable: interchange is legal, and so is tiling. The time function π(i,j)=i+j\pi(i, j) = i + j has π⋅d⃗=1>0\pi \cdot \vec{d} = 1 > 0 for both distances, so all points on one line i+j=ci + j = c can run at the same time (wavefront parallelism, the hyperplane method).

A distance that changes

for i = 1 to 8:
  S1: A[2*i] = B[i]
  S2: C[i] = A[i]

S1(i)S1(i) writes A[2i]A[2i], and S2(i′)S2(i') reads it when i′=2i≤8i' = 2i \le 8. The flow dependence has the distances i′−i=ii' - i = i for i=1,2,3,4i = 1, 2, 3, 4, so Δ(S1,S2)={1,2,3,4}\Delta(S1, S2) = \{1, 2, 3, 4\}. There is no anti dependence, since S2(i′)S2(i') would have to read A[2i]A[2i] before S1(i)S1(i) writes it, which needs 2i<i2i < i. The dependence is not uniform. Its direction vector is (<)(<).

A subscript that does not use a loop index

for i = 1 to n:
  for j = 1 to m:
    S: A[i] = A[i-1] + B[i][j]

The read A[i−1]A[i-1] of S(i′,j′)S(i', j') meets the write A[i]A[i] of S(i,j)S(i, j) when i′=i+1i' = i + 1, for any jj and j′j'. The flow distances are (1,δ)(1, \delta) for all δ\delta with 1−m≤δ≤m−11 - m \le \delta \le m - 1. Each is lexicographically positive, also those with a negative second entry. The output dependence of SS on itself has the distances (0,δ)(0, \delta) for 1≤δ≤m−11 \le \delta \le m - 1: all writes of one row go to A[i]A[i]. No single vector describes either set; the direction vectors are (<,∗)(<, *) and (=,<)(=, <).

Legality with distances

For a unimodular transformation TT of a perfect nest, the new distance of each dependence is Td⃗T\vec{d}, and TT is legal if Td⃗≻0⃗T\vec{d} \succ \vec{0} for each nonzero distance. Take d⃗=(1,−1)\vec{d} = (1, -1) from A[i][j] = A[i-1][j+1]:

transformation matrix Td⃗T\vec{d} legal
interchange (0110)\begin{pmatrix} 0 & 1 \\ 1 & 0 \end{pmatrix} (−1,1)(-1, 1) no
skewing of jj by ii (1011)\begin{pmatrix} 1 & 0 \\ 1 & 1 \end{pmatrix} (1,0)(1, 0) yes
skewing, then interchange (1110)\begin{pmatrix} 1 & 1 \\ 1 & 0 \end{pmatrix} (0,1)(0, 1) yes

Non-examples

  • d⃗=(0,−1)\vec{d} = (0, -1) is never the distance of a dependence: its first nonzero entry is negative. If a test finds a solution with j⃗−i⃗=(0,−1)\vec{j} - \vec{i} = (0, -1), it has found a dependence from TT to SS with distance (0,1)(0, 1).
  • Two references to different arrays that cannot overlap have no dependence, so no distance set; an empty distance set is not the same as the distance 0⃗\vec{0}.
  • Direction vector. The vector of signs of d⃗\vec{d}, written with <<, == and >>; it summarizes a distance set that has more than one element. See dependence direction vector.
  • Level of a dependence. The index of the first nonzero entry of d⃗\vec{d}. See loop-carried dependence.
  • Reuse vector. The same subtraction on two accesses that both read a location gives a reuse vector, used for locality (Wolf-Lam locality algorithm); it is not a dependence.
  • Dependence cone and polyhedron. In the polyhedral model, the exact set of pairs is kept as a polyhedron, and the distances are a projection of it.

References

  1. Randy Allen and Ken Kennedy, Optimizing Compilers for Modern Architectures, a Dependence-Based Approach, Morgan Kaufmann, 2002 (copyright 2001), Chapter 2 (distance and direction vectors, and the rule that the leftmost nonzero entry of a legal distance vector is positive)
  2. Michael E. Wolf and Monica S. Lam, A loop transformation theory and an algorithm to maximize parallelism, IEEE Transactions on Parallel and Distributed Systems 2(4), 1991, the representation of dependences by distance vectors, the legality condition for unimodular transformations, and fully permutable loops
  3. Leslie Lamport, The parallel execution of DO loops, Communications of the ACM 17(2), 1974, the sets of iteration differences of a loop nest and the hyperplane method that uses them
  4. Michael Wolfe, High Performance Compilers for Parallel Computing, Addison-Wesley, 1996, the chapter on data dependence (distance vectors and direction vectors in loop nests)

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 proofH0 no proof
  • add a proof in proofs/ (06.5)
LeanL0 no Lean part
  • name a Lean module in the lean field (07)
VisualV0 none
  • add viz/scene.ts or a figure (10)
WritingW4 complete
  • a review of the text: no review record reviews/0X40N7/text.yaml