Docsity

Data Dependence Testing: Determining Loop Interdependence, Exams of Computer Science

Toggle sidebar
bg1
1 of 14
Computing Data Dependence
Consider the loop:
do i1=0,U1
do i2=0,U2
...
do id=0,Ud
Sv: ...X(f1(i1,i2,...,id), f2(i), ... fs(i))...
Sw: ...X(g1(i1,i2,...,id), g2(i), ...,gs(i))...
These loops are normalized. that is, the
increment is always 1. If the loop header
were
do i
k
=L
k
,U
k
,N
k
then we would
replace it with index
j
k
which related to
i
k
by the formula
i
k
=j
k
N
k
+L
k
. The normalized
index
j
k
satisfies the inequality
0
≤
j
k
≤
(U
k
-L
k
)/N
k
and has increment of 1.
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe

Partial preview of the text

Download Data Dependence Testing: Determining Loop Interdependence and more Exams Computer Science in PDF only on Docsity!

Computing Data Dependence

Consider the loop:

do i 1 =0,U (^1)

do i 2 =0,U (^2) ... do i (^) d=0,U (^) d S (^) v : ...X(f 1 (i 1 ,i 2 ,...,id ), f 2 (i), ... fs (i))...

S (^) w : ...X(g 1 (i 1 ,i 2 ,...,id ), g 2 (i), ...,gs (i))...

These loops are normalized. that is, the

increment is always 1. If the loop header

were do i k=L k,Uk,Nk then we would

replace it with index jk which related to ik

by the formula ik=jkNk+L k. The normalized

index jksatisfies the inequality

0 ≤ jk ≤ (U k-Lk)/Nk

and has increment of 1.

We will test simultaneously for Sv δ

Sw and

S w δ

Sv where δ

stands for flow, anti- and

output dependence. the particular

dependence is determined by whether the

variable references are on the left-hand side

or the right-hand side, and the direction of the

dependence.

(,)**

(<,) (=,)*^ (<,)

Direction vector hierarchy for dependence testing

Data dependence algorithms

We will assume that

for 1 ≤ m ≤ s.

Given a direction vector (ψ 1 ,ψ 2 ,...,ψd), we can

apply a simple test known as the GCD test to

try to break the dependence.

f (^) m ( ) i a 0 a (^) k i (^) k

k = 1

d

g (^) m ( ) i b 0 b (^) k i (^) k

k = 1

d

Linear diophantine equations

Theorem. Let n≥0 and a 1 ,a 2 ,...,an be integers not

all 0. Then gcd{a i,i=1,...,n}=min{z | z=a 1 x 1 +...anxn,

xi (i=1,...,n) integers, and z>0}.

Proof. We present the proof for n=2. A simple

induction would complete the proof of the theorem.

Let M={a 1 x+a 2 y, x and y integers} and let z 0 be the

mininimum of all positive elements of M.

Clearly, z 0 exists. Assume that z 0 =a 1 u+a 2 v.

We can now prove that z 0 divides a 1. Assume it

does not. Then a 1 =z 0 q+r with 0<r<z 0. Therefore,

r=a 1 -z 0 q=a 1 (1-uq)+a 2 (-vq) and r is a (positive)

element of M that is less than z 0. This contradicts

the assumption that z 0 was the smallest positive

element of M.

Similarly, we can prove that z 0 divides a 2.

Clearly (1) gcd(a 1 ,a 2 ) divides z 0 because

z 0 =a 1 u+a 2 v. Furthermore,(2) z 0 is common divisor

of a 1 and a 2. Therefore gcd(a 1 ,a 2 )≥z 0.

Combining(1) and (2) we get that gcd(a 1 ,a 2 )=z 0.

Theorem. The diophantine equation

a 1 x 1 +...anx n=c has a solution iff gcd{ai ,i=1,...,n}

divides c.

Proof. Assume ther is a solution to the equation

x 1 =s 1 , ..., xn=sn. Then c=a 1 s 1 +...a nsn.

gcd{a i,i=1,...,n} divides the right hand sideof this

equation and therefore divides c.

Assume now that gcd{ai,i=1,...,n} divides c. From

the previous Theorem,we know that

gcd{a i,i=1,...,n}=a 1 v 1 +...a nvn for some integers v i.

Then m×gcd{ai ,i=1,...,n}=c and, therefore (m×v i) is

a solution because a 1 (mv 1 )+...a n(mvn)=c.

or, equivalently:

If either

or

hold then the fundtions cannot intersect

under the constraint of the direction vector.

The values of the upper bounds and lower

bounds are as follows:

LB

k=(a

k - bk)

(Uk - 1)+bk

UB

k=(a

k - bk)

(Uk - 1)+bk

LB

k=(ak - bk)

(Uk)

UB

k=(ak - bk)

(Uk)

LB

ψ k

k = 1

d

b 0 – a 0 UB

ψ k

k = 1

d

LB

ψ k

k = 1

d

b 0 – a 0

b 0 – a 0 UB

ψ k

k = 1

d

LB

k=(ak - b

k )

(Uk - 1)+ak

UB

k=(ak - b

k)

(Uk -1)+ak

LB*k =(a

k - b

k ) (Uk)

UB*k=(a

k - b

k) (Uk)

Here a

is equal to a if a is positive and zero

otherwise. Similarly, a

is equal to a if a is

negative and zero otherwise.

To prove these equations, all that is needed

are the following two observations:

min {ax | 0≤x≤U}=a

U and

max {ax | 0≤x≤U}=a

U.

To prove

LB*k =(a

k - b

k ) (Uk)^ and^ UB*k=(a

k - b

k) (Uk)

we just notice that since any direction is

possible, we can deal separately with each

term in

Therefore:

LB

=min(a ki’ k-bki” k)=min(a ki’ k)-max(bki” k)=a

kU^ k-b^

kU^ k

and

UB

=max(aki’k-b (^) ki”k)=max(a (^) ki’ (^) k)-min(b (^) ki”k)=a

kUk-b

  • kUk
LB

( a (^) k i ′ k – b (^) k i ″ k ) UB

≤ ≤

Finally, to prove that

LB

k=(a

k - bk)

(Uk - 1)+bk

and

UB

k=(a

k - bk)

(Uk - 1)+bk

we use the fact that 0≤i’k<i”k≤Uk which is a

direct consequence of the direction (<). From

and from max(aki’k)=a

k(i”k-1) (since the

maximum value of i’k is i” k-1) we get that

UB <=max(a (^) ki’ (^) k-b (^) ki” (^) k)=max(ak+(i” (^) k-1)-bki” (^) k)=

=max(a (^) k+(i” (^) k-1)-bk(i”k-1)+bk)=max(ak+(i” (^) k-1)-b (^) k(i”k-1))+b (^) k=

=(a+k - bk) +^ (Uk - 1)+bk

LB<=min(a (^) ki’ (^) k-bki”k)=min(ak-(i”k-1)-bki”k)=

=min(a (^) k-(i”k-1)-bk(i” (^) k-1)+bk)=min(ak-(i” (^) k-1)-b (^) k(i”k-1))+bk=

=(a-k - bk) -^ (Uk - 1)+bk

LB

< a k

i ′ k

b k

i ″ k

( – ) UB

< ≤ ≤