dependence testing
DESCRIPTION
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 - PowerPoint PPT PresentationTRANSCRIPT
Dependence TestingOptimizing Compilers for Modern
Architectures, Chapter 3Allen and Kennedy
Presented by Rachel Tzoref and Rotem Oshman
Part II
Roadmap Single Subscript Tests:
SIV tests MIV tests
GCD Test Banerjee Inequality Trapezoidal Banerjee Inequality
Testing in coupled groups: Delta Test Empirical results
MIV SubscriptsDO 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 boundsL1, 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
Finding
What about the direction vector?
?
Lemma
Lemma: proof
Finding
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, 100DO j = 1, i - 1
A(j) = A(i + j - 1) + CENDDO
ENDDO
D = ( = , = )
Example:DO i = 1, 100DO j = 1, i - 1
A(j) = A(i + j - 1) + CENDDO
ENDDO
Example (cont’d)
D = ( = , = )
Dependence!
Upon closer examination…DO i = 1, 100DO j = 1, i - 1
A(j) = A(i + j - 1) + CENDDO
ENDDO
Example (cont’d)
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 ?
source sink
Trapezoidal Banerjee Inequality (cont’d)
To prove the bound for Di = “*“, we use
Lemma:
x’ s AND y’ s !x’s or y’s?
Trapezoidal Banerjee Inequality (cont’d)
To prove the bound for Di = “=“, we use
Lemma:
source sink
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.
Using the Banerjee Inequality
Banerjee Inequality
2 array referencesLoop boundsDirection vector
Dependenceexists(yes / no)
?2 array referencesLoop bounds
Set ofdirectionvectors
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 directionvector
k: currentcoordinate
dvlist: set ofvectors foundin prev. calls
Roadmap Single Subscript Tests:
ZIV SIV MIV
Testing in coupled groups: Delta Test Empirical results
Reminder Coupled group:
DO i = 1, 100DO j = 1, 100 A(i + 10, j) = A(i, i - 5)
ENDDOi + 10 ij i - 5
, ,< > < >
coupled
Motivation
Delta
TestDirectionvectors
CoupledSubscriptgroup
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
DO i = 1, 100A(i + 1, i) = A(i, i + 1) + C
ENDDO
Subscript 1: < Subscript 2: > No dependence.
Example 1
Some information can begained by intersectingdirection vectors.
Example 2
DO i = 1, 100A(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, 100A(i + 1, i + 2) = A(i, i) + C
ENDDO
Subscript 1: d = 1 Subscript 2: d = 2 No dependence.
More complete informationcan be gained byintersecting distancevectors.
The Delta Test Main idea:
Test SIV subscripts (easiest), and get: Independence, or Constraint
E.g., d = 1 Apply constraints, hoping to:
Prove independenceE.g., (d = 1) (d = 2) = or
Reduce MIV subscripts to SIV or ZIV
DO i = 1, 100DO j = 1, 100
A(i + 1, i + j) = A(i, i + j - 1)ENDDO
ENDDO
Example: Reducing Subscript Complexity
MIV Subscript!
What can be?
Constraints Maintain a constraint vector
constraints for the ith indexDO i1 = 1, 100DO i2 = 1, 100
…
Constraint Types Initially: <none>
Eventually (we hope): ; Independence
Constraint Types What constraints can we infer from a SIV
test?
Strong SIV
d
Weak SIV
Constraint Types
Constraint Propagation What can we do with constraints? Example 1:
MIV
SIV
Constraint Propagation What can we do with constraints? Example 2:
MIV
SIV
Constraint Propagation Can we always eliminate an index? Example 3:
MIV
Constraint Propagation Can we always eliminate an index?
Answer: no. May still gain information.
Constraint Propagation
DO iDO j
A(i, 2*j + i) = A(i, 2*j – i + 5)ENDDO
ENDDO
Dependence
Constraint Propagation
DO iDO j
A(i, 2*j + i) = A(i, 2*j – i + 5)ENDDO
ENDDO
No dependence
The Delta Test: Summary
Delta Test: Example
DO iDO j
DO kA(j–i, i+1, j+k) = A(j–i, i,
j+k)ENDDO
ENDDOENDDO
Test untested SIV subscripts:
Delta Test: Example
DO iDO j
DO kA(j–i, i+1, j+k) = A(j–i, i,
j+k)ENDDO
ENDDOENDDO
Propagate constraints:
j j - 1
Delta Test: Example
DO iDO j
DO kA(j, i+1, j+k) = A(j–1, i, j+k)
ENDDOENDDO
ENDDO
Test untested SIV subscripts:
Delta Test: Example
DO iDO j
DO kA(j, i+1, j+k) = A(j–1, i, j+k)
ENDDOENDDO
ENDDO
Propagate constraints:
k k+1
Delta Test: Example
DO iDO j
DO kA(j, i+1, k) = A(j–1, i, k+1)
ENDDOENDDO
ENDDO
Test untested SIV subscripts:
Delta Test
Is the Delta Test Exact?
Single
Subscript
Tests
Constraint
Propagation
Constraint
Intersection
??Imprecise whenan index can’tbe eliminated
Intersection of lines and points
Is the Delta Test Exact? Additional sources of imprecision:
Triangular or trapezoidal bounds Coupled MIV subscripts may remain:
DO iDO j
A(i + j, i – j) = A(2i + 3j, j – i)ENDDO
ENDDO
Roadmap Single Subscript Tests:
ZIV SIV MIV
Testing in coupled groups: Delta Test Empirical results
Empirical Results
SIV
ZIV Strong Weak-zero
Weak-crossing
Exact MIV Delta
Of all tests 45% 34% 7% 0.7% 0.1% 5.1% 8.4%
Of successful tests
31% 52% 8% 0.6% 0.2% 3% 6%
Of proved independencies
85% 5% 1.5% 0.1% 0% 2.7% 5.3%
Non-linear subscripts: 6%
DO i DO j DO k A(j, i+1, k) = A(j–1, i, k+1) ENDDO ENDDOENDDO
Strong SIV
dDO i = 1, 100
DO j = 1, 100 A(i + 10, j) = A(i, i
- 5)ENDDO
DO i = 1, 5 A(i + 10, i) = A(i, i)ENDDO
Weak SIV
DO i DO j A(i + j, i – j) = A(2i + 3j, j – i) ENDDOENDDO
DO i DO j A(i + j, i – j) = A(2i + 3j, j – i) ENDDOENDDO
THEEND
THEEND
DO j = 1, 100 A(j - 1, j) = A(j, i)ENDDO