70 likes | 85 Views
Dependence Analysis. Important and difficult Parallelize Optimize memory hierarchy Loop --- and non-loops ? Application to program transformation Should yield “better” code Should NOT alter code semantics . Which Loop(s) Parallelizable ?. 1) Do I = 1, n
E N D
Dependence Analysis • Important and difficult • Parallelize • Optimize memory hierarchy • Loop --- and non-loops ? • Application to program transformation • Should yield “better” code • Should NOT alter code semantics
Which Loop(s) Parallelizable ? 1) Do I = 1, n A[I] = 5 * B[I] + A[I] Enddo 2) Do I = 1, n A[I-1] = 5 * B[I] + A[I] Enddo 3) Do I = 1, n temp = 5 * B[I] A[I] = temp Enddo 4) Do I = 1, n A[I+1] = 5 * B[I] + A[I] Enddo
Data Dependence • Statement S2 is dependent on S1 iff • S2 follows S1 in execution • S2, S1 access same memory location, M • One of S2 or S1 write to M • Dependence “types” • True (or flow) -- S2 reads M set by S1 • Anti- -- S2 writes M read by S1 • Output -- S1 and S2 write M • Dependence Graph
Example S1: a = 3.14 S2: b = 5.0 S3: c = a * b * b S1 S2 S3
Example S1: a = 3.14 S2: b = 5.0 S3: c = a * b * b S4: b = a * c S1 S2 S3 S4
Program Order, Dependence • Sequential order of imperative programs is too restrictive • Partial order of dependences needed to ensure “correctness” • Reordering transformations should not violate dependence • Can we always determine dependence?
Dependence in Loops • Parameterize stmts by loop iterations • Loop nesting level: number of surrounding loops + 1 • Iteration number: value of iteration (index) variable • Iteration vector,I, of loop isthe value of all index variables for outerloop(s) for a particular iteration of innermost loop • Iteration space is set of all possible iteration vectors for a statement