a relaxed criterion for loop tiling
play

A Relaxed Criterion for Loop Tiling Riyadh Baghdadi, Albert Cohen, - PowerPoint PPT Presentation

A Relaxed Criterion for Loop Tiling Riyadh Baghdadi, Albert Cohen, Sven Verdoolaege UPMC/INRIA/ENS September 22, 2015 1/22 Tiling Main benefit: enhance data locality 2/22 Tiling Main benefit: enhance data locality Useful in architectures


  1. A Relaxed Criterion for Loop Tiling Riyadh Baghdadi, Albert Cohen, Sven Verdoolaege UPMC/INRIA/ENS September 22, 2015 1/22

  2. Tiling Main benefit: enhance data locality 2/22

  3. Tiling Main benefit: enhance data locality Useful in architectures with a memory hierarchy 2/22

  4. Tiling Example for ( i = 0; i < n; i++) for ( j = 0; j < n; j++) C[i ][ j ] = A[j ] + B[j ]; j i : execution order 3/22

  5. Tiling Example for ( i = 0; i < n; i++) for ( j = 0; j < n; j++) C[i ][ j ] = A[j ] + B[j ]; j i : execution order 3/22

  6. Tiling Example for ( i = 0; i < n; i++) for ( j = 0; j < n; j++) C[i ][ j ] = A[j ] + B[j ]; j i : execution order 3/22

  7. Permutability Requirements To perform tiling we check for permutability 4/22

  8. Permutability Requirements To perform tiling we check for permutability Classical loop permutability criterion Each dependence is forward in each loop of the band 4/22

  9. Permutability Requirements To perform tiling we check for permutability Classical loop permutability criterion Each dependence is forward in each loop of the band A dependence is forward if it is oriented from earlier to later iterations 4/22

  10. Permutability Requirement Examples A[i ][ j ] = f(A[i − 1][j ], A[i ][ j − 1]); j i : dependence : execution order 5/22

  11. Permutability Requirement Examples A[i ][ j ] = f(A[i − 1][j ], A[i ][ j − 1]); j i : dependence : execution order 5/22

  12. Permutability Requirement Examples A[i ][ j ] = f(A[i − 1][j ], A[i ][ j − 1]); j i OK : dependence : execution order 5/22

  13. Permutability Requirement Examples A = f(A); j i : dependence (only some dependences shown) : execution order 5/22

  14. Permutability Requirement Examples A = f(A); j i : dependence (only some dependences shown) : execution order 5/22

  15. Permutability Requirement Examples A = f(A); j i NOT OK : dependence (only some dependences shown) : execution order 5/22

  16. Loop Transformation Legality A loop transformation is correct if live ranges do not interfere after the transformation 6/22

  17. Loop Transformation Legality A loop transformation is correct if live ranges do not interfere after the transformation 6/22

  18. True and Falce Dependence Types of dependences true dependences: write → read false dependences anti dependence: read → write output dependence: write → write 7/22

  19. True and Falce Dependence Types of dependences true dependences: write → read false dependences anti dependence: read → write output dependence: write → write False dependences are caused by memory reuse prevent live ranges from overlapping Iteration j Iteration j+1 s1(j) s1(j+1) WAR Live range s2(j) s2(j+1) 7/22

  20. True and Falce Dependence Types of dependences true dependences: write → read false dependences anti dependence: read → write output dependence: write → write False dependences are caused by memory reuse prevent live ranges from overlapping Iteration j Iteration j+1 s1(j) s1(j+1) WAR Live range s2(j) s2(j+1) Dependences adjacent to live ranges 7/22

  21. False Dependences prevent Tiling for ( i = 0; i < n; i++) for ( j = 0; j < n; j++) { S1: t = A[i ]; S2: B[i ][ j ] = t ; } j S1 S1 S1 S1 S1 S1 S1 S1 S2 S2 S2 S2 S2 S2 S2 S2 S1 S1 S1 S1 S1 S1 S1 S1 S2 S2 S2 S2 S2 S2 S2 S2 S1 S1 S1 S1 S1 S1 S1 S1 S2 S2 S2 S2 S2 S2 S2 S2 S1 S1 S1 S1 S1 S1 S1 S1 S2 S2 S2 S2 S2 S2 S2 S2 i 8/22

  22. False Dependences prevent Tiling for ( i = 0; i < n; i++) for ( j = 0; j < n; j++) { S1: t = A[i ]; S2: B[i ][ j ] = t ; } Classical tiling j S1 S1 S1 S1 S1 S1 S1 S1 criterion: S2 S2 S2 S2 S2 S2 S2 S2 not allowed S1 S1 S1 S1 S1 S1 S1 S1 S2 S2 S2 S2 S2 S2 S2 S2 S1 S1 S1 S1 S1 S1 S1 S1 S2 S2 S2 S2 S2 S2 S2 S2 S1 S1 S1 S1 S1 S1 S1 S1 S2 S2 S2 S2 S2 S2 S2 S2 i 8/22

  23. False Dependences prevent Tiling for ( i = 0; i < n; i++) for ( j = 0; j < n; j++) { S1: t = A[i ]; S2: B[i ][ j ] = t ; } Classical tiling j S1 S1 S1 S1 S1 S1 S1 S1 criterion: S2 S2 S2 S2 S2 S2 S2 S2 not allowed S1 S1 S1 S1 S1 S1 S1 S1 S2 S2 S2 S2 S2 S2 S2 S2 but tiling is S1 S1 S1 S1 S1 S1 S1 S1 possible S2 S2 S2 S2 S2 S2 S2 S2 S1 S1 S1 S1 S1 S1 S1 S1 S2 S2 S2 S2 S2 S2 S2 S2 i 8/22

  24. Relaxed Permutability Criterion Main idea a loop transformation is correct if it does not lead to live range interference 9/22

  25. Relaxed Permutability Criterion Main idea a loop transformation is correct if it does not lead to live range interference tiling only changes the order of execution of iterations 9/22

  26. Relaxed Permutability Criterion Main idea a loop transformation is correct if it does not lead to live range interference tiling only changes the order of execution of iterations if live ranges are local to an iteration then they are guaranteed not to interfer due to tiling 9/22

  27. Relaxed Permutability Criterion Classical Permutability Criterion Each dependence is forward in each loop of the band 10/22

  28. Relaxed Permutability Criterion Classical Permutability Criterion Each dependence is forward in each loop of the band Relaxed Permutability Criterion The same classical criterion except that we ignore anti-dependences that are adjacent to only local live ranges 10/22

  29. False Dependences prevent Tiling for ( i = 0; i < n; i++) for ( j = 0; j < n; j++) { S1: t = A[i ]; S2: B[i ][ j ] = t ; } Classical tiling j S1 S1 S1 S1 S1 S1 S1 S1 criterion: S2 S2 S2 S2 S2 S2 S2 S2 not allowed S1 S1 S1 S1 S1 S1 S1 S1 S2 S2 S2 S2 S2 S2 S2 S2 but tiling is S1 S1 S1 S1 S1 S1 S1 S1 possible S2 S2 S2 S2 S2 S2 S2 S2 S1 S1 S1 S1 S1 S1 S1 S1 S2 S2 S2 S2 S2 S2 S2 S2 i 11/22

  30. False Dependences prevent Tiling for ( i = 0; i < n; i++) for ( j = 0; j < n; j++) { S1: t = A[i ]; S2: B[i ][ j ] = t ; } Classical tiling j S1 S1 S1 S1 S1 S1 S1 S1 criterion: S2 S2 S2 S2 S2 S2 S2 S2 not allowed S1 S1 S1 S1 S1 S1 S1 S1 S2 S2 S2 S2 S2 S2 S2 S2 but tiling is S1 S1 S1 S1 S1 S1 S1 S1 possible S2 S2 S2 S2 S2 S2 S2 S2 S1 S1 S1 S1 S1 S1 S1 S1 S2 S2 S2 S2 S2 S2 S2 S2 i 11/22

  31. False Dependences prevent Tiling for ( i = 0; i < n; i++) for ( j = 0; j < n; j++) { S1: t = A[i ]; S2: B[i ][ j ] = t ; } Classical tiling j S1 S1 S1 S1 S1 S1 S1 S1 criterion: S2 S2 S2 S2 S2 S2 S2 S2 not allowed S1 S1 S1 S1 S1 S1 S1 S1 S2 S2 S2 S2 S2 S2 S2 S2 but tiling is S1 S1 S1 S1 S1 S1 S1 S1 possible S2 S2 S2 S2 S2 S2 S2 S2 Relaxed S1 S1 S1 S1 S1 S1 S1 S1 S2 S2 S2 S2 S2 S2 S2 S2 tiling i criterion: allowed 11/22

  32. Tilability of Selected PolyBench Benchmarks Original 3AC 3AC + relaxed criterion Expanded 3mm yes no yes yes dynprog yes no yes yes fdtd-2d yes no yes yes syr2k yes no yes yes fdtd-apml yes no yes yes bicg yes no yes yes symm no no yes yes cholesky no no yes yes 12/22

  33. Conclusion Relaxed permutability criterion Allows tiling in presence of false dependences No expansion or privatization required Future directions Combination with on-demand array expansion 13/22

  34. Outline Relaxed Permutability Criterion Conclusion PENCIL 14/22

  35. Outline Relaxed Permutability Criterion Conclusion PENCIL 15/22

  36. Motivation Programming accelerators: low level APIs (OpenCL, CUDA, . . . ) 16/22

  37. Motivation Programming accelerators: low level APIs (OpenCL, CUDA, . . . ) Problems of low level APIs: difficult to use, non portable code, . . . 16/22

  38. Motivation Programming accelerators: low level APIs (OpenCL, CUDA, . . . ) Problems of low level APIs: difficult to use, non portable code, . . . Solution Write code in a high level language Use a compiler for parallelization/optimization 16/22

  39. PENCIL 17/22

  40. P encil Intermediate Language Subset of C99 restrictions on pointer use goals: no write aliasing, constant array references, . . . 18/22

  41. P encil Intermediate Language Subset of C99 restrictions on pointer use goals: no write aliasing, constant array references, . . . restrictions: C99 VLA syntax for array declaration ( int A[m] instead of int ∗ A ) cannot read or write to a pointer except passing an array reference to a function: foo(A); 18/22

  42. P encil Intermediate Language Subset of C99 restrictions on pointer use goals: no write aliasing, constant array references, . . . restrictions: C99 VLA syntax for array declaration ( int A[m] instead of int ∗ A ) cannot read or write to a pointer except passing an array reference to a function: foo(A); no goto s Extensions (builtins and directives) __pencil_assume(expression) __pencil_kill(T) __pencil_reduce(...) #pragma pencil independent Summary functions 18/22

  43. Compiling P encil We use the PPCG polyhedral compiler Polyhedral moldel: an algebraic representation of programs (focus on loop nests). Static-affine control Static control: not data dependent ( if (A[i ]) ). loop bounds, conditionals and array subscripts should be affine with respect to the loop iterators and a set of symbolic constants. Affine: i + j ≥ 0. Non-affine: i ∗ i ≥ 0 19/22

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend