{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

lecture-13 - Dependence Analysis Friday Motivating question...

Info iconThis preview shows pages 1–11. Sign up to view the full content.

View Full Document Right Arrow Icon
Dependence Analysis Friday, November 18, 2011
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Motivating question Can the loops on the right be run in parallel? i.e. , can different processors run different iterations in parallel? What needs to be true for a loop to be parallelizable? Iterations cannot interfere with each other No dependence between iterations for (i = 1; i < N; i++) { a [i] = b [i]; c [i] = a [i - 1]; } for (i = 1; i < N; i++) { a [i] = b [i]; c [i] = a [i] + b [i - 1]; } Friday, November 18, 2011
Background image of page 2
Dependences A flow dependence occurs when one iteration writes a location that a later iteration reads for (i = 1; i < N; i++) { a [i] = b [i]; c [i] = a [i - 1]; } i = 1 W(a[1]) R(b[1]) W(c[1]) R(a[0]) i = 2 W(a[2]) R(b[2]) W(c[2]) R(a[1]) i = 3 W(a[3]) R(b[3]) W(c[3]) R(a[2]) i = 4 W(a[4]) R(b[4]) W(c[4]) R(a[3]) i = 5 W(a[5]) R(b[5]) W(c[5]) R(a[4]) Friday, November 18, 2011
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Running a loop in parallel If there is a dependence in a loop, we cannot guarantee that the loop will run correctly in parallel What if the iterations run out of order? Might read from a location before the correct value was written to it What if the iterations do not run in lock-step? Same problem! Friday, November 18, 2011
Background image of page 4
Other kinds of dependence Anti dependence – When an iteration reads a location that a later iteration writes (why is this a problem?) Output dependence – When an iteration writes a location that a later iteration writes (why is this a problem?) for (i = 1; i < N; i++) { a [i - 1] = b [i]; c [i] = a [i]; } for (i = 1; i < N; i++) { a [i] = b [i]; a [i + 1] = c [i]; } Friday, November 18, 2011
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Data dependence concepts Dependence source is the earlier statement (the statement at the tail of the dependence arrow) Dependence sink is the later statement (the statement at the head of the dependence arrow) Dependences can only go forward in time: always from an earlier iteration to a later iteration. i = 1 W(a[1]) R(b[1]) W(c[1]) R(a[0]) i = 2 W(a[2]) R(b[2]) W(c[2]) R(a[1]) i = 3 W(a[3]) R(b[3]) W(c[3]) R(a[2]) i = 4 W(a[4]) R(b[4]) W(c[4]) R(a[3]) i = 5 W(a[5]) R(b[5]) W(c[5]) R(a[4]) Friday, November 18, 2011
Background image of page 6
Using dependences If there are no dependences, we can parallelize a loop None of the iterations interfere with each other Can also use dependence information to drive other optimizations Loop interchange Loop fusion (We will discuss these later) Two questions: How do we represent dependences in loops? How do we determine if there are dependences? Friday, November 18, 2011
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Representing dependences Focus on flow dependences for now Dependences in straight line code are easy to represent: One statement writes a location (variable, array location, etc.) and another reads that same location Can figure this out using reaching definitions What do we do about loops? We often care about dependences between the same statement in different iterations of the loop! for (i = 1; i < N; i++) { a [i + 1] = a [i] + 2 } Friday, November 18, 2011
Background image of page 8
Iteration space graphs Represent each dynamic instance of a loop as a point in a graph Draw arrows from one point to another to represent dependences for (i = 0; i < N; i++) { a [i + 2] = a [i] } Friday, November 18, 2011
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Iteration space graphs Represent each dynamic instance of a loop as a point in a graph
Background image of page 10
Image of page 11
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}