dependence testing

69
Dependence Testing Optimizing Compilers for Modern Architectures, Chapter 3 Allen and Kennedy Presented by Rachel Tzoref and Rotem Oshman Part II

Upload: draco

Post on 10-Feb-2016

77 views

Category:

Documents


9 download

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 Presentation

TRANSCRIPT

Page 1: Dependence Testing

Dependence TestingOptimizing Compilers for Modern

Architectures, Chapter 3Allen and Kennedy

Presented by Rachel Tzoref and Rotem Oshman

Part II

Page 2: Dependence Testing

Roadmap Single Subscript Tests:

SIV tests MIV tests

GCD Test Banerjee Inequality Trapezoidal Banerjee Inequality

Testing in coupled groups: Delta Test Empirical results

Page 3: Dependence Testing

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

Page 4: Dependence Testing

MIV Subscripts We will assume that

Page 5: Dependence Testing

MIV Subscripts Rearranging, we get

?

Page 6: Dependence Testing

GCD Test Theorem: the equation

has a solution iff

No solution ) no dependence!

divides

Page 7: Dependence Testing

GCD Test: drawbacks Doesn’t take into account loop bounds The most common GCD is… 1

Page 8: Dependence Testing

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

Page 9: Dependence Testing

The Banerjee Inequality (cont’d)

Define

Let R be the region defined by

Page 10: Dependence Testing

The Banerjee Inequality (cont’d)

Does h(x1, …, xn, y1, … yn) = 0 have a solution in the region R?

iff

Page 11: Dependence Testing

The Banerjee Inequality (cont’d)

Recall:

Define:

Page 12: Dependence Testing

The Banerjee Inequality (cont’d)

The problem is reduced to:

Page 13: Dependence Testing

Finding is a plane:

Page 14: Dependence Testing

Finding Define

Page 15: Dependence Testing

Finding

Page 16: Dependence Testing

What about the direction vector?

?

Page 17: Dependence Testing

Lemma

Page 18: Dependence Testing

Lemma: proof

Page 19: Dependence Testing

Finding

Page 20: Dependence Testing

The Banerjee Inequality We have:

Page 21: Dependence Testing

The Banerjee Inequality Similarly, we obtain:

Page 22: Dependence Testing

The Banerjee Inequality:Wrap-up

Dependency exists in direction D

Page 23: Dependence Testing

Example Example:DO i = 1, 100DO j = 1, i - 1

A(j) = A(i + j - 1) + CENDDO

ENDDO

D = ( = , = )

Page 24: Dependence Testing

Example:DO i = 1, 100DO j = 1, i - 1

A(j) = A(i + j - 1) + CENDDO

ENDDO

Example (cont’d)

D = ( = , = )

Dependence!

Page 25: Dependence Testing

Upon closer examination…DO i = 1, 100DO j = 1, i - 1

A(j) = A(i + j - 1) + CENDDO

ENDDO

Example (cont’d)

No dependence!

Page 26: Dependence Testing

Trapezoidal Banerjee Inequality Assume linear bounds:

Page 27: Dependence Testing

Trapezoidal Banerjee Inequality Recall:

Dependence Old strategy:

Minimize / maximize each separately:

Calculate for each independently.

Page 28: Dependence Testing

Trapezoidal Banerjee Inequality (cont’d)

New strategy:

We would like to do:

.

.

.

.

.

.

min

max

Page 29: Dependence Testing

Trapezoidal Banerjee Inequality (cont’d)

The problem: ‘s bounds depend on outer indices:

We can use H- and H+, but we will get

Page 30: Dependence Testing

Trapezoidal Banerjee Inequality (cont’d)

Step 1:

Obtain:

Rinse and repeat

Page 31: Dependence Testing

Trapezoidal Banerjee Inequality (cont’d)

Algorithm:

Page 32: Dependence Testing

Trapezoidal Banerjee Inequality (cont’d)

A closer look:

Suppose Di = “*”. We want to use:

xj or yj ?

source sink

Page 33: Dependence Testing

Trapezoidal Banerjee Inequality (cont’d)

To prove the bound for Di = “*“, we use

Lemma:

Page 34: Dependence Testing

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

Page 35: Dependence Testing

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.

Page 36: Dependence Testing

Using the Banerjee Inequality

Banerjee Inequality

2 array referencesLoop boundsDirection vector

Dependenceexists(yes / no)

?2 array referencesLoop bounds

Set ofdirectionvectors

The desired test:

Page 37: Dependence Testing

Testing For All Direction Vectors

Naïve approach (brute force):

Page 38: Dependence Testing

Testing For All Direction Vectors

Burke & Cytron’s algorithm:

(*, *, *) ?(<, *, *) (=, *, *) (>, *, *)? ?(=, <, *) (=, =, *) (=, >, *)

Page 39: Dependence Testing

Testing For All Direction Vectors

Burke & Cytron’s algorithm: D: current directionvector

k: currentcoordinate

dvlist: set ofvectors foundin prev. calls

Page 40: Dependence Testing

Roadmap Single Subscript Tests:

ZIV SIV MIV

Testing in coupled groups: Delta Test Empirical results

Page 41: Dependence Testing

Reminder Coupled group:

DO i = 1, 100DO j = 1, 100 A(i + 10, j) = A(i, i - 5)

ENDDOi + 10 ij i - 5

, ,< > < >

coupled

Page 42: Dependence Testing

Motivation

Delta

TestDirectionvectors

CoupledSubscriptgroup

Page 43: Dependence Testing

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

Page 44: Dependence Testing

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.

Page 45: Dependence Testing

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.

Page 46: Dependence Testing

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.

Page 47: Dependence Testing

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

Page 48: Dependence Testing

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!

Page 49: Dependence Testing

What can be?

Constraints Maintain a constraint vector

constraints for the ith indexDO i1 = 1, 100DO i2 = 1, 100

Page 50: Dependence Testing

Constraint Types Initially: <none>

Eventually (we hope): ; Independence

Page 51: Dependence Testing

Constraint Types What constraints can we infer from a SIV

test?

Strong SIV

d

Weak SIV

Page 52: Dependence Testing

Constraint Types

Page 53: Dependence Testing

Constraint Propagation What can we do with constraints? Example 1:

MIV

SIV

Page 54: Dependence Testing

Constraint Propagation What can we do with constraints? Example 2:

MIV

SIV

Page 55: Dependence Testing

Constraint Propagation Can we always eliminate an index? Example 3:

MIV

Page 56: Dependence Testing

Constraint Propagation Can we always eliminate an index?

Answer: no. May still gain information.

Page 57: Dependence Testing

Constraint Propagation

DO iDO j

A(i, 2*j + i) = A(i, 2*j – i + 5)ENDDO

ENDDO

Dependence

Page 58: Dependence Testing

Constraint Propagation

DO iDO j

A(i, 2*j + i) = A(i, 2*j – i + 5)ENDDO

ENDDO

No dependence

Page 59: Dependence Testing

The Delta Test: Summary

Page 60: Dependence Testing

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:

Page 61: Dependence Testing

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

Page 62: Dependence Testing

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:

Page 63: Dependence Testing

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

Page 64: Dependence Testing

Delta Test: Example

DO iDO j

DO kA(j, i+1, k) = A(j–1, i, k+1)

ENDDOENDDO

ENDDO

Test untested SIV subscripts:

Page 65: Dependence Testing

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

Page 66: Dependence Testing

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

Page 67: Dependence Testing

Roadmap Single Subscript Tests:

ZIV SIV MIV

Testing in coupled groups: Delta Test Empirical results

Page 68: Dependence Testing

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%

Page 69: Dependence Testing

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