Algorithm Search⌘K

Definitioncore

Dependence direction vector

Also called direction vector.

The signs of the components of the distance vectors of a dependence, written with less, equal and greater, when exact distances are unknown.

The direction vector of a data dependence in a loop nest gives, for each common loop, the sign of the distance between the sink and the source iterations. It is the summary that compilers keep when the distance is not one fixed vector, which is common: a dependence can hold between many pairs of iterations at many distances. The direction vector still tells which loop carries the dependence and which loop permutations are legal. It cannot decide transformations that need the size of a distance, such as skewing.

Definition

Notation

This page uses Wolfe's notation with the symbols <<, == and >>. Each symbol compares the source index with the sink index:

symbol on this page meaning sign of dl=jl−ild_l = j_l - i_l Aho, Lam, Sethi and Ullman
<< il<jli_l < j_l dl>0d_l > 0 ++
== il=jli_l = j_l dl=0d_l = 0 00
>> il>jli_l > j_l dl<0d_l < 0 −-

So "<<" means that the sink runs in a later iteration of loop ll. The two notations run in opposite visual directions: << goes with ++. Unions of symbols are also used: ≤\le for {<,=}\{<, =\}, ≥\ge for {>,=}\{>, =\}, ≠\ne for {<,>}\{<, >\}, and ∗* for all three.

Direction vector of a pair and of a dependence

Let S(i⃗)→T(j⃗)S(\vec{i}) \to T(\vec{j}) be a dependence with kk common loops, and d⃗=j⃗−i⃗\vec{d} = \vec{j} - \vec{i}. Its direction vector is ψ⃗=(ψ1,…,ψk)\vec{\psi} = (\psi_1, \dots, \psi_k) with ψl=<\psi_l = {<}, ={=} or >{>} as dl>0d_l > 0, dl=0d_l = 0 or dl<0d_l < 0.

The direction vectors of the dependence S→TS \to T form the set Ψ(S,T)={ψ⃗(d⃗):d⃗∈Δ(S,T)}\Psi(S, T) = \{\vec{\psi}(\vec{d}) : \vec{d} \in \Delta(S, T)\}, which has at most 3k3^k elements. A vector with union symbols, such as (<,∗)(<, *), stands for the set of all plain vectors it contains, here (<,<)(<, <), (<,=)(<, =) and (<,>)(<, >).

Every distance vector satisfies d⃗⪰0⃗\vec{d} \succeq \vec{0} (see distance vector). So every direction vector of a dependence has one of two shapes:

  • the leftmost entry that is not == is <<: the dependence is carried at the level of that entry;
  • all entries are ==: the dependence is loop independent, and the source statement comes before the sink statement in the body.

A vector whose leftmost non-== entry is >> cannot belong to a dependence from SS to TT. When a test finds solutions with such a vector, they belong to the dependence from TT to SS, whose direction vector has each entry reversed.

Direction vectors as constraints

A dependence test can take a direction vector as an extra constraint: it adds il<jli_l < j_l, il=jli_l = j_l or il>jli_l > j_l for each level and asks if a solution remains. Testing (∗,…,∗)(*, \dots, *) first, and refining one ∗* into <<, == and >> only when the test does not rule out the coarser vector, finds the set Ψ\Psi with far fewer tests than all 3k3^k vectors in the usual case. The Banerjee test and the practical tests work this way.

Examples and non-examples

A recurrence read in reverse

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

The write of S(i)S(i) and the read of S(i′)S(i') touch the same element when i=i′+1i = i' + 1. In the pair (write, read), the read iteration i′i' is smaller, so the sign is >>: this is not a flow dependence from the write to the read. Reversed, it is an anti dependence from the read S(i′)S(i') to the write S(i′+1)S(i' + 1), with direction (<)(<) and distance 11. The value read is the old value of A[i′+1]A[i'+1].

Directions of a dependence with many distances

for i = 1 to 3:
  for j = 1 to 3:
    S: X[i+j] = X[i+j-1] + 1

The flow distances are (0,1)(0, 1), (1,0)(1, 0) and (2,−1)(2, -1), so the flow direction vectors are (=,<)(=, <), (<,=)(<, =) and (<,>)(<, >). The output distances (1,−1)(1, -1) and (2,−2)(2, -2) give (<,>)(<, >), and the anti distance (1,−2)(1, -2) gives (<,>)(<, >).

Interchange

Loop interchange of two loops swaps the two entries of each direction vector. It is legal if each swapped vector still has the legal shape. In the example above, (<,>)(<, >) becomes (>,<)(>, <), which is not legal, so the interchange is illegal. The vectors (<,<)(<, <), (<,=)(<, =) and (=,<)(=, <) swap to (<,<)(<, <), (=,<)(=, <) and (<,=)(<, =), all legal. So in a two-deep nest, interchange is legal exactly when no dependence has the direction vector (<,>)(<, >).

What a direction vector cannot tell

The dependence d⃗=(1,−1)\vec{d} = (1, -1) has the direction vector (<,>)(<, >), and so does d⃗′=(1,−2)\vec{d}' = (1, -2). Skewing the inner loop by the outer one, (i,j)↦(i,i+j)(i, j) \mapsto (i, i + j), maps them to (1,0)(1, 0) and (1,−1)(1, -1). The first becomes (<,=)(<, =), the second stays (<,>)(<, >). So the same direction vector can need a different skew factor, and only the distances say which one. Skewing by 2i2i maps both to vectors with a nonnegative second entry: (1,1)(1, 1) and (1,0)(1, 0).

Non-examples

  • (>,<)(>, <) is not the direction vector of any dependence. It is the reverse of (<,>)(<, >).
  • (=,=)(=, =) is not the direction vector of a dependence of a statement on itself, because an instance does not depend on itself. It is the direction vector of a loop-independent dependence between two different statements.
  • Distance vector. The exact difference j⃗−i⃗\vec{j} - \vec{i}; the direction vector is its sign. See dependence distance vector.
  • Level. The position of the leftmost << when all earlier entries are ==. See loop-carried dependence.
  • Legality. A loop permutation is legal if it maps each direction vector of each dependence to a vector of the legal shape; this is a special case of the legality theorem. For general unimodular transformations the test needs distances, or a direction vector with enough information to bound the signs of Td⃗T\vec{d}.
  • Loop reversal. Running loop ll backward swaps << and >> at position ll in every vector.

References

  1. Michael Wolfe, High Performance Compilers for Parallel Computing, Addison-Wesley, 1996, the chapter on data dependence (direction vectors with the symbols less, equal and greater, and their use for interchange)
  2. Randy Allen and Ken Kennedy, Optimizing Compilers for Modern Architectures, a Dependence-Based Approach, Morgan Kaufmann, 2002 (copyright 2001), Chapter 2 (direction vectors and the rule that the leftmost non-equal entry of the direction vector of a dependence is less) and Chapter 3 (direction vectors computed by the dependence tests)
  3. David J. Kuck, Robert H. Kuhn, David A. Padua, Bruce Leasure and Michael Wolfe, Dependence graphs and compiler optimizations, POPL 1981, pp. 207 to 218 (dependence graphs with direction information on the arcs, and the transformations they allow)
  4. Alfred V. Aho, Monica S. Lam, Ravi Sethi and Jeffrey D. Ullman, Compilers, Principles, Techniques, and Tools, second edition, Addison-Wesley, 2007, Chapter 11 (Section 11.6 on array data-dependence analysis, where signs of distances are written with plus, zero and minus)

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/CQ8RHA/text.yaml