Docsity

Understanding Loop-Carried Dependences and DOALL Loops for Data Parallelization, Slides of Compilers

Partial preview of the text

Download Understanding Loop-Carried Dependences and DOALL Loops for Data Parallelization and more Slides Compilers in PDF only on Docsity!

Data Dependences and

Parallelization

Agenda

  • Introduction
  • Single Loop
  • Nested Loops
  • Data Dependence Analysis

Examples

for i = 11, 20 a[i] = a[i] + 3

Parallel

for i = 11, 20 a[i] = a[i-1] + 3 Parallel?

Examples

for i = 11, 20 a[i] = a[i] + 3

Parallel

for i = 11, 20 a[i] = a[i-1] + 3

for i = 11, 20 a[i] = a[i-10] + 3

Not parallel

Parallel?

Data Dependence of Scalar Variables

  • True dependence
  • Anti-dependence

a = = a

= a a =

 Output dependence

 Input dependence

a = a =

= a = a

Array Accesses in a Loop

for i= 2, 5 a[i] = a[i] + 3

a[2]

a[2]

a[3]

a[3]

a[4]

a[4]

a[5]

a[5]

read

write

Array True-dependence

for i= 2, 5 a[i] = a[i-2] + 3

a[0]

a[2]

a[1]

a[3]

a[2]

a[4]

a[3]

a[5]

read

write

Dynamic Data Dependence

  • Let o and o’ be two (dynamic) operations
  • Data dependence exists from o to o’, iff
    • either o or o’ is a write operation
    • o and o’ may refer to the same location
    • o executes before o’

Recognizing DOALL Loops

  • Find data dependences in loop
  • Definition: a dependence is loop-carried if it crosses an iteration boundary
  • If there are no loop-carried dependences then loop is parallelizable

Compute Dependence

  • There is a dependence between a[i] and a[i-2] if - There exist two iterations ir and iw within the loop bounds such that iterations ir and iw read and write the same array element, respectively - There exist i (^) r, i (^) w , 2 ≤ i (^) r, iw ≤ 5, i (^) r = i (^) w -

for i= 2, 5 a[i-2] = a[i] + 3

Parallelization

  • Is there a loop-carried dependence

between a[i] and a[i-2]?

  • Is there a loop-carried dependence

between a[i-2] and a[i-2]?

for i= 2, 5 a[i-2] = a[i] + 3

Agenda

  • Introduction
  • Single Loops
  • Nested Loops
  • Data Dependence Analysis

Iteration Space

  • An abstraction for loops
  • Iteration is represented as coordinates in iteration space.

for i1 = 0, 5 for i2 = 0, 3 a[i1,i2] = 3

i

i

Execution Order

  • Sequential execution order of iterations: Lexicographic order [0,0], [0,1], …[0,3], [1,0], [1,1], …[1,3], [2,0]…
  • Let I = (i 1 ,i 2 ,… i (^) n). I is lexicographically less than I’, I<I’, iff there exists k such that (i 1 ,… i (^) k-1) = (i’ 1 ,… i’ (^) k-1) and i (^) k < i’ (^) k i (^1)

i (^2)