720 likes | 924 Views
Dependence Testing. Part II. Optimizing Compilers for Modern Architectures, Chapter 3 Allen and Kennedy Presented by Rachel Tzoref and Rotem Oshman. Roadmap. Single Subscript Tests: SIV tests MIV tests GCD Test Banerjee Inequality Trapezoidal Banerjee Inequality
E N D
Dependence Testing Part II Optimizing Compilers for Modern Architectures, Chapter 3Allen and Kennedy Presented by Rachel Tzoref and Rotem Oshman
Roadmap • Single Subscript Tests: • SIV tests • MIV tests • GCD Test • Banerjee Inequality • Trapezoidal Banerjee Inequality • Testing in coupled groups: Delta Test • Empirical results
MIV Subscripts DO i1 = L1, U1 DO i2 = L2, U2 ... DO in = Ln, Un S1 A(f(i1, ..., in)) = ... S2 ... = A(g(i1, ..., in)) ENDDO ... ENDDO ENDDO
MIV Subscripts • We will assume that
MIV Subscripts • Rearranging, we get ?
GCD Test • Theorem: the equation has a solution iff • No solution ) no dependence! divides
GCD Test: drawbacks • Doesn’t take into account loop bounds • The most common GCD is… 1
The Banerjee Inequality • Input: • A pair of array references A(f(i1, ..., in)), A(g(i1, ..., in)) • Loop bounds L1, U1, …, Ln, Un • A direction vector D = (D1, …, Dn) • Output: whether or not a dependency exists in direction D
The Banerjee Inequality (cont’d) • Define • Let R be the region defined by
The Banerjee Inequality (cont’d) • Does h(x1, …, xn, y1, … yn) = 0 have a solution in the region R? iff
The Banerjee Inequality (cont’d) • Recall: • Define:
The Banerjee Inequality (cont’d) The problem is reduced to:
Finding • is a plane:
Finding • Define
Lemma: proof
The Banerjee Inequality • We have:
The Banerjee Inequality • Similarly, we obtain:
The Banerjee Inequality:Wrap-up Dependency exists in direction D
Example • Example: DO i = 1, 100 DO j = 1, i - 1 A(j) = A(i + j - 1) + C ENDDO ENDDO D = ( = , = )
Example (cont’d) • Example: DO i = 1, 100 DO j = 1, i - 1 A(j) = A(i + j - 1) + C ENDDO ENDDO D = ( = , = ) Dependence!
Example (cont’d) • Upon closer examination… DO i = 1, 100 DO j = 1, i - 1 A(j) = A(i + j - 1) + C ENDDO ENDDO No dependence!
Trapezoidal Banerjee Inequality • Assume linear bounds:
Trapezoidal Banerjee Inequality • Recall: Dependence • Old strategy: • Minimize / maximize each separately: • Calculate for each independently.
Trapezoidal Banerjee Inequality (cont’d) • New strategy: • We would like to do: . . . min . . . max
Trapezoidal Banerjee Inequality (cont’d) • The problem: • ‘s bounds depend on outer indices: • We can use H- and H+, but we will get
Trapezoidal Banerjee Inequality (cont’d) • Step 1: • Obtain: • Rinse and repeat
Trapezoidal Banerjee Inequality (cont’d) • Algorithm:
Trapezoidal Banerjee Inequality (cont’d) • A closer look: • Suppose Di= “*”. • We want to use: xj or yj ? sink source
Trapezoidal Banerjee Inequality (cont’d) • To prove the bound for Di= “*“, we use Lemma:
Trapezoidal Banerjee Inequality (cont’d) • To prove the bound for Di= “=“, we use Lemma: x’ s AND y’ s! x’s or y’s? sink source
Trapezoidal Banerjee Inequality (cont’d) • What happens if we choose wrong? • Bounds are still correct • … we gave the loop index “more freedom” than it has in reality • Bounds may not be tight ) the test is not precise.
Banerjee Inequality ? 2 array references Loop bounds Direction vector Dependence exists (yes / no) Set of direction vectors 2 array references Loop bounds Using the Banerjee Inequality The desired test:
Testing For All Direction Vectors • Naïve approach (brute force):
Testing For All Direction Vectors • Burke & Cytron’s algorithm: ? (*, *, *) ? (<, *, *) (=, *, *) (>, *, *) ? (=, <, *) (=, =, *) (=, >, *) …
Testing For All Direction Vectors • Burke & Cytron’s algorithm: D: current direction vector k: current coordinate dvlist: set of vectors found in prev. calls
Roadmap • Single Subscript Tests: • ZIV • SIV • MIV • Testing in coupled groups: Delta Test • Empirical results
Reminder • Coupled group: DO i = 1, 100 DO j = 1, 100 A(i + 10, j) = A(i, i - 5) ENDDO i + 10 j i i - 5 < > < > , , coupled
Delta Test Motivation Coupled Subscript group Direction vectors
Motivation • What happens if coupled subscripts are tested separately? • Result = “independent” really independent • Result = “dependent” not necessarily dependent • Goal: use information provided by other subscripts where the index appears DO i = 1, 5 A(i + 10, i) = A(i, i) ENDDO
Example 1 DO i = 1, 100 A(i + 1, i) = A(i, i + 1) + C ENDDO • Subscript 1: < • Subscript 2: > • No dependence. Some information can be gained by intersecting direction vectors.
Example 2 DO i = 1, 100 A(i + 1, i + 2) = A(i, i) + C ENDDO • Subscript 1: < • Subscript 2: < • Dependence with direction vector D = ( “<“ ) • … except not.
Example 2 (Take Two) DO i = 1, 100 A(i + 1, i + 2) = A(i, i) + C ENDDO • Subscript 1: d = 1 • Subscript 2: d = 2 • No dependence. More complete information can be gained by intersecting distance vectors.
The Delta Test • Main idea: • Test SIV subscripts (easiest), and get: • Independence, or • Constraint E.g., d = 1 • Apply constraints, hoping to: • Prove independence E.g., (d = 1) (d = 2) = or • Reduce MIV subscripts to SIV or ZIV
Example: Reducing Subscript Complexity DO i = 1, 100 DO j = 1, 100 A(i + 1, i + j) = A(i, i + j - 1) ENDDO ENDDO MIV Subscript!
Constraints • Maintain a constraint vector • constraints for the ith index DO i1 = 1, 100 DO i2 = 1, 100 … What can be?
Constraint Types • Initially: <none> • Eventually (we hope): ; Independence