TRANSCRIPTEnglish

Lecture 4d. Loop-independent vs. loop-carried dependences

9m 0s1,454 words254 segmentsEnglish

FULL TRANSCRIPT

0:01

in this video we want to talk about loop

0:03

independent versus loop carried

0:04

dependencies

0:06

this will help us decide which

0:07

iterations of which loops can be

0:09

executed

0:10

in parallel a loop carried dependence

0:13

means that dependence exists

0:14

across iterations if you take out the

0:17

for statement before the loop

0:19

then the dependence no longer exists

0:22

for a loop independent dependence the

0:24

dependence exists within an iteration

0:27

so if you take out the loop the

0:29

dependence would not change at all it

0:31

would still be there

0:32

we've got an example over here with

0:35

three

0:36

nested loops the first loop has two

0:38

statements in it

0:39

there's a loop carried dependence of

0:41

state of the i

0:42

plus first iteration of this

0:46

of this two statement loop with the i

0:48

federation

0:49

the reason for this is that a value

0:52

that's used on the i

0:53

plus first iteration is in fact

0:56

calculated

0:56

on the i federation that's because each

0:59

iteration uses

1:00

the value of a or uses an element of a

1:04

that was calculated on the previous

1:05

iteration also we see that a sub i is

1:09

computed here

1:10

and used there so this means that

1:13

statement s2 is dependent upon statement

1:16

s1 finishing before it but this is a

1:19

loop independent dependence because if

1:21

you take out the for statement

1:23

it's still there you still need to

1:25

finish s1 before you can overwrite the

1:27

value of

1:28

a sub i now in s3 notice that there is a

1:31

subscript of j

1:33

on the left hand side and a subscript of

1:35

j minus 1 on the right hand side

1:37

this means there's a loop carry

1:39

dependence on j

1:40

because the value that's written in the

1:42

j minus first

1:44

iteration is going to be used on the jth

1:46

iteration

1:48

but there are no dependencies in the i

1:50

direction one iteration

1:52

the i federation the i throw does not

1:54

depend upon the i plus first row or the

1:57

i

1:57

minus first row so we could actually

2:00

compute all of the rows

2:01

in parallel here in the fourth statement

2:05

which

2:05

is actually in the third loop there's no

2:07

loop carried dependence on j

2:09

because j doesn't change the subscript j

2:12

doesn't change

2:13

from the right hand side to the left

2:14

hand side of the statement

2:16

but there is a loop carry dependence on

2:18

the foreign loop

2:20

because the i throw depends upon values

2:23

computed in the i minus first row

2:25

and so we could do all the columns of

2:28

this loop in parallel

2:30

but we can't do the rows in parallel

2:32

because of that dependence

2:34

two kinds of graphs can help us see

2:36

these relationships

2:38

first is the iteration space traversal

2:40

graph or itg

2:42

it shows the order of traversal from one

2:45

iteration to another

2:47

here a node represents a point in the

2:49

iteration space in other words a node

2:51

represents

2:52

a set of i value and a j value like

2:55

i equals one j equals two and a directed

2:59

edge

2:59

indicates the next point that will be

3:01

encountered after the current point is

3:02

traversed

3:04

so here we see statement s3 which says a

3:07

sub ij

3:07

equals a sub i j minus 1 plus 1.

3:11

well actually as far as the

3:15

iteration space traversal graph is

3:17

concerned

3:18

what matters is not what's in s3 but

3:21

rather what's in the four statements

3:23

i goes from 1 to 4 but while i is going

3:27

from 1 to 4

3:28

j is going from 1 to 4 for each value of

3:31

i

3:32

so we start out with a with i equal 1 j

3:35

equal 1 and then we go to i equal 1 j

3:38

equal to 2

3:39

i and j are 1 and 3 respectively now i

3:42

and j

3:42

are 2 and 1 in the next iteration of the

3:45

loop and it just goes on like that

3:47

a loop carried dependence graph shows

3:50

the various dependence relationships

3:52

graphically

3:52

again a node is a point in the iteration

3:55

space in other words in this

3:56

two-dimensional

3:57

graph it's a point in the i j space

4:01

value of i and a value of j a directed

4:04

edge represents the dependence

4:06

what this shows us is that the iteration

4:09

1 comma 2 for i and j is dependent upon

4:12

the iteration 1 comma 1.

4:14

and that's because n1 comma 2 with i

4:17

equal to 1 and j equal to 2

4:20

we use a value that's computed in the

4:23

ij equal 1 1 iteration where we're

4:26

looking at

4:27

a sub 1 j sub 1. so that's why we have

4:31

this edge from 1 1 to 1 2. and this is a

4:34

true dependence because the value that

4:36

was computed in the previous iteration

4:38

of j

4:39

will be used in the current iteration of

4:41

j

4:42

so we see dependencies in this direction

4:46

we don't see any dependents from 1 3 to

4:49

2 1

4:50

because we don't have any dependencies

4:52

there the dependencies are all

4:54

along the rows they're between the

4:56

columns and the rows

4:57

there are no dependencies between this

4:59

row and this row

5:01

here we have another example involving

5:03

two nested loops

5:04

the first loop is a 4i 4j loop

5:07

that has a four point iteration

5:09

statement in the middle of it

5:11

in other words what this does is

5:13

computes the value of a sub i j

5:16

by summing up all the neighboring points

5:18

the ones above and below

5:19

and to the left and to the right because

5:22

this is the same

5:23

4i4j pattern that we saw before because

5:26

we have the same 4i4j pattern that we

5:28

did before

5:29

theater race and space traversal graph

5:31

is exactly the same

5:33

we do the 1 1 iteration followed by the

5:35

1 2 iteration

5:36

followed by dot dot the 1n iteration

5:40

followed by the 2 1 iteration and so

5:42

forth

5:43

now let's look at the dependence

5:45

relationship so we can draw the loop

5:47

dependence graph

5:49

as far as true dependences are concerned

5:51

there are two of them

5:53

the value of s one i j is used as an

5:56

operand in computing

5:58

s one of i j plus one note this

6:01

subscript here the j minus one subscript

6:05

indicates

6:06

that it's using the value that was

6:08

computed in the previous iteration of j

6:11

there are no output dependences because

6:14

there's only one statement in the loop

6:16

and the anti-dependences actually are

6:18

exactly the same

6:20

and the reason for that is that we have

6:21

these j plus one sub

6:23

which means we've got to be sure that we

6:25

don't overwrite

6:26

the next value the the value at the

6:29

point to the right

6:30

before we use it in our current

6:32

computation so one

6:34

thing that's interesting to note is that

6:36

the true dependencies

6:37

have exactly the same form as the

6:39

corresponding antidependences

6:41

only that these have a t there and these

6:45

have an a

6:46

and that means that when we actually

6:47

look at the loop dependence graph

6:50

we will find that each edge represents

6:53

both true and anti-dependences in other

6:55

words the

6:56

the iteration point to the right is

6:59

dependent

7:00

in both the true dependence and

7:01

antidependence on the point to the left

7:04

as is the point below okay so this

7:06

raises an interesting question

7:08

suppose we dropped off the first half of

7:11

statement s1

7:12

so we have what's shown below a sub i j

7:15

equals a

7:16

sub i minus 1 j plus a i

7:19

plus 1 j if we did that which of the

7:22

dependencies would still exist

7:25

and then let's do the same thing

7:26

removing the last half of the statement

7:34

then let's go on to the second loop nest

7:36

right here

7:37

the value of a sub i j that's computed

7:39

in s2

7:41

is used in the next the j the next j

7:44

iteration

7:44

of s3 so that's the true dependence

7:48

as shown here the anti-dependence again

7:51

is that b sub ij is used here

7:55

and written there so this read has to

7:58

occur

7:59

before that right the loop dependence

8:02

graph is pretty easy

8:03

because there are dependencies only in

8:05

the jth iteration

8:07

no dependences between the various rows

8:10

which means that all of the rows could

8:11

be

8:12

executed in parallel so

8:15

why are there no vertical edges in this

8:16

graph

8:18

well that's because there are no

8:20

dependencies involving i

8:22

so we could do the i the rows i in

8:25

parallel

8:27

why is the anti-dependence not shown on

8:29

the

8:30

note that the graph shows only the the

8:32

true dependence here

8:34

well the reason for that is because the

8:36

anti-dependence

8:37

is not loop carry and because it's not

8:40

loop parry

8:41

carried it does not appear in the ldg

8:44

because nodes represent all statements

8:48

in the loop body and so

8:51

if there is a dependence between two of

8:53

those statements the dependence is

8:54

within the node

8:56

not across nodes

UNLOCK MORE

Sign up free to access premium features

INTERACTIVE VIEWER

Watch the video with synced subtitles, adjustable overlay, and full playback control.

SIGN UP FREE TO UNLOCK

AI SUMMARY

Get an instant AI-generated summary of the video content, key points, and takeaways.

SIGN UP FREE TO UNLOCK

TRANSLATE

Translate the transcript to 100+ languages with one click. Download in any format.

SIGN UP FREE TO UNLOCK

MIND MAP

Visualize the transcript as an interactive mind map. Understand structure at a glance.

SIGN UP FREE TO UNLOCK

CHAT WITH TRANSCRIPT

Ask questions about the video content. Get answers powered by AI directly from the transcript.

SIGN UP FREE TO UNLOCK

GET MORE FROM YOUR TRANSCRIPTS

Sign up for free and unlock interactive viewer, AI summaries, translations, mind maps, and more. No credit card required.