# Program Transformations in the Polca Project Jan Kuper April 6, - PowerPoint PPT Presentation

## Program Transformations in the Polca Project Jan Kuper April 6, 2016 partially funded by the European Comission under FP7-ICT-2014.3.4 contract number 610686 Polca Program Transformations in the Polca Project 1/11 Partners POLCA: Programming

1. Program Transformations in the Polca Project Jan Kuper April 6, 2016 partially funded by the European Comission under FP7-ICT-2014.3.4 contract number 610686 Polca Program Transformations in the Polca Project 1/11

2. Partners POLCA: Programming Large Scale Heterogeneous Infrastructures Partners: – University of Ulm (Germany) – University of Stuttgart (Germany) – University of Twente (Enschede, The Netherlands) – CETIC (Charleroi, Belgium) – IMDEA Software (Madrid, Spain) – Maxeler Technologies (London, UK) – Recore Systems (Enschede, The Netherlands) Polca Program Transformations in the Polca Project 2/11

3. Main idea Parallelization of legacy code by: – annotating the code by a mathematical formula which expresses the algorithmic structure, – apply transformations on this formula for partitioning, – generate code that realizes the new formula. Polca Program Transformations in the Polca Project 3/11

4. Main idea Parallelization of legacy code by: – annotating the code by a mathematical formula which expresses the algorithmic structure, – apply transformations on this formula for partitioning, – generate code that realizes the new formula. Apply dataflow techniques to evaluate effect on performance Polca Program Transformations in the Polca Project 3/11

5. Main idea Parallelization of legacy code by: – annotating the code by a mathematical formula which expresses the algorithmic structure, – apply transformations on this formula for partitioning, – generate code that realizes the new formula. Apply dataflow techniques to evaluate effect on performance Use Haskell as mathematical language: computer readable, simulates Polca Program Transformations in the Polca Project 3/11

6. Algorithmic structures for (i = 0; i < n; i++) z[i] = f(x[i]); w = a; for (i = 0; i < n; i++) w = w ⋆ x[i]; Polca Program Transformations in the Polca Project 4/11

7. Algorithmic structures x 0 x 1 x 2 x 3 x 4 for (i = 0; i < n; i++) f f f f f z[i] = f(x[i]); z 0 z 1 z 2 z 3 z 4 w = a; x 0 x 3 x 1 x 2 x 4 for (i = 0; i < n; i++) a ⋆ ⋆ ⋆ ⋆ ⋆ w w = w ⋆ x[i]; Polca Program Transformations in the Polca Project 4/11

8. Algorithmic structures x 0 x 1 x 2 x 3 x 4 for (i = 0; i < n; i++) map f xs f f f f f z[i] = f(x[i]); z 0 z 1 z 2 z 3 z 4 w = a; x 0 x 3 x 1 x 2 x 4 for (i = 0; i < n; i++) foldl f a xs a ⋆ ⋆ ⋆ ⋆ ⋆ w w = w ⋆ x[i]; Polca Program Transformations in the Polca Project 4/11

9. Algorithmic structures x 0 x 1 x 2 x 3 x 4 for (i = 0; i < n; i++) map f xs f f f f f z[i] = f(x[i]); z 0 z 1 z 2 z 3 z 4 w = a; x 0 x 3 x 1 x 2 x 4 for (i = 0; i < n; i++) foldl f a xs a ⋆ ⋆ ⋆ ⋆ ⋆ w w = w ⋆ x[i]; Higher Order Functions Polca Program Transformations in the Polca Project 4/11

10. Higher Order Functions f a ⇒ a ′ itn z = itn f a n a z f f f f f zs = itnscan f a n itnscan a f a ⇒ z f f f f f z 0 z 1 z 2 z 3 z 4 z 5 x 0 x 1 x 2 x 3 x 4 map f x ⇒ z zs = map f xs f f f f f z 0 z 1 z 2 z 3 z 4 x 0 y 0 x 1 y 1 x 2 y 2 x 3 y 3 x 4 y 4 zipWith ⋆ ⋆ ⋆ ⋆ ⋆ x ⋆ y ⇒ z zs = zipWith ( ⋆ ) xs ys z 0 z 1 z 2 z 3 z 4 x 0 x 1 x 2 x 3 x 4 a ⋆ x ⇒ a ′ w = foldl ( ⋆ ) a xs foldl a ⋆ ⋆ ⋆ ⋆ ⋆ w x 0 x 1 x 2 x 3 x 4 scanl a ⋆ x ⇒ z zs = scanl ( ⋆ ) a xs a ⋆ ⋆ ⋆ ⋆ ⋆ z 0 z 1 z 2 z 3 z 4 z 5 x 0 x 1 x 2 x 3 x 4 f a x ⇒ ( a ′ , z ) mapAccumL ( w , zs ) = mapAccumL f a xs a f f f f f w z 0 z 1 z 2 z 3 z 4 Polca Program Transformations in the Polca Project 5/11

11. Transformations on HOFs x 0 x 1 x 2 x 3 x 4 x 5 x 6 x 7 x 8 x 9 x 10 x 11 foldl (+) 0 xs + + + + + + + + + + + + 0 total total = 0; for (i = 0; i < n; i++) total = total + x[i]; Polca Program Transformations in the Polca Project 6/11

12. Transformations on HOFs x 0 x 1 x 2 x 3 x 4 x 5 x 6 x 7 x 8 x 9 x 10 x 11 foldl (+) 0 xs + + + + + + + + + + + + 0 total x 0 x 1 x 2 x 3 x 4 x 5 x 6 x 7 x 8 x 9 x 10 x 11 foldl (foldl (+)) 0 xss 0 + + + + + + + + + + + + total total = 0; for (i = 0; i < n; i++) total = total + x[i]; Polca Program Transformations in the Polca Project 6/11

13. Transformations on HOFs x 0 x 1 x 2 x 3 x 4 x 5 x 6 x 7 x 8 x 9 x 10 x 11 foldl (+) 0 xs + + + + + + + + + + + + 0 total x 0 x 1 x 2 x 3 x 4 x 5 x 6 x 7 x 8 x 9 x 10 x 11 foldl (foldl (+)) 0 xss 0 + + + + + + + + + + + + total total = 0; Z = 0; for (i = 0; i < n; i++) for (i0...) { total = total + x[i]; for (i1...) { Z = Z + xss[i0][i1]; } ; } ; Polca Program Transformations in the Polca Project 6/11

14. Transformations on HOFs x 0 x 1 x 2 x 3 x 4 x 5 x 6 x 7 x 8 x 9 x 10 x 11 foldl (+) 0 xs + + + + + + + + + + + + 0 total total = 0; for (i = 0; i < n; i++) total = total + x[i]; Polca Program Transformations in the Polca Project 7/11

15. Transformations on HOFs x 0 x 1 x 2 x 3 x 4 x 5 x 6 x 7 x 8 x 9 x 10 x 11 foldl (+) 0 xs + + + + + + + + + + + + 0 total x 0 x 1 x 2 x 3 x 4 x 5 x 6 x 7 x 8 x 9 x 10 x 11 0 0 0 0 foldl (+) 0 (map (foldl (+) 0) xss) + + + + + + + + + + + + + + + + 0 total total = 0; for (i = 0; i < n; i++) total = total + x[i]; Polca Program Transformations in the Polca Project 7/11

16. Transformations on HOFs x 0 x 1 x 2 x 3 x 4 x 5 x 6 x 7 x 8 x 9 x 10 x 11 foldl (+) 0 xs + + + + + + + + + + + + 0 total x 0 x 1 x 2 x 3 x 4 x 5 x 6 x 7 x 8 x 9 x 10 x 11 0 0 0 0 foldl (+) 0 (map (foldl (+) 0) xss) + + + + + + + + + + + + + + + + 0 total for (i0...) { total = 0; v0[i0] = 0; for (i = 0; i < n; i++) for (i1...) { total = total + x[i]; v0[i0] = v0[i0] + xss[i0][i1]; } ; } ; Z = 0; for (i2...) { Z = Z + v0[i2]; } ; Polca Program Transformations in the Polca Project 7/11

17. Transformations on HOFs x 0 x 1 x 2 x 3 x 4 x 5 x 6 x 7 x 8 x 9 x 10 x 11 foldl (+) 0 xs + + + + + + + + + + + + 0 total total = 0; for (i = 0; i < n; i++) total = total + x[i]; Polca Program Transformations in the Polca Project 8/11

18. Transformations on HOFs x 0 x 1 x 2 x 3 x 4 x 5 x 6 x 7 x 8 x 9 x 10 x 11 foldl (+) 0 xs + + + + + + + + + + + + 0 total total = 0; for (i = 0; i < n; i++) 0 0 0 x 0 x 1 x 2 total = total + x[i]; + + + x 3 x 4 x 5 + + + x 6 x 7 x 8 + + + x 9 x 10 x 11 + + + + + + 0 total foldl (+) 0 (foldl (zipWith (+)) zs xss) Polca Program Transformations in the Polca Project 8/11

19. Transformations on HOFs x 0 x 1 x 2 x 3 x 4 x 5 x 6 x 7 x 8 x 9 x 10 x 11 foldl (+) 0 xs + + + + + + + + + + + + 0 total total = 0; for (i = 0; i < n; i++) 0 0 0 x 0 x 1 x 2 total = total + x[i]; + + + x 3 x 4 x 5 + + + x 6 x 7 x 8 v0 = zs; + + + for (i0...) { x 9 x 10 x 11 for (i1...) { v0[i1] = v0[i1] + xss[i0][i1]; + + + } ; + + + 0 total } ; Z = 0; foldl (+) 0 (foldl (zipWith (+)) zs xss) for (i2...) { Z = Z + v0[i2]; } ; Polca Program Transformations in the Polca Project 8/11

20. Dot product y = � n − 1 � x • � i = 0 x i y i = x 0 y 0 + x 1 y 1 + · · · + x n − 1 y n − 1 Polca Program Transformations in the Polca Project 9/11

21. Dot product y = � n − 1 � x • � i = 0 x i y i = x 0 y 0 + x 1 y 1 + · · · + x n − 1 y n − 1 x 0 y 0 x 1 y 1 · · · x n − 1 y n − 1 · · · ∗ ∗ ∗ w 0 w 1 w n − 1 0 · · · z + + + Polca Program Transformations in the Polca Project 9/11

22. Dot product y = � n − 1 � x • � i = 0 x i y i = x 0 y 0 + x 1 y 1 + · · · + x n − 1 y n − 1 x 0 y 0 x 1 y 1 · · · x n − 1 y n − 1 vxv xs ys = foldl (+) 0 ( zipWith ( ∗ ) xs ys ) · · · ∗ ∗ ∗ w 0 w 1 w n − 1 0 · · · z + + + Polca Program Transformations in the Polca Project 9/11

23. Dot product y = � n − 1 � x • � i = 0 x i y i = x 0 y 0 + x 1 y 1 + · · · + x n − 1 y n − 1 x 0 y 0 x 1 y 1 · · · x n − 1 y n − 1 vxv xs ys = foldl (+) 0 ( zipWith ( ∗ ) xs ys ) · · · ∗ ∗ ∗ for (i0...) { w 0 w 1 w n − 1 v0[i0] = xs[i0] * ys[i0]; } ; 0 · · · z + + + Z = 0; for (i1...) { Z = Z + v0[i1]; } ; Polca Program Transformations in the Polca Project 9/11

24. Dot product y = � n − 1 � x • � i = 0 x i y i = x 0 y 0 + x 1 y 1 + · · · + x n − 1 y n − 1 x 0 y 0 x 1 y 1 · · · x n − 1 y n − 1 vxv xs ys = foldl (+) 0 ( zipWith ( ∗ ) xs ys ) · · · ∗ ∗ ∗ for (i0...) { w 0 w 1 w n − 1 v0[i0] = xs[i0] * ys[i0]; } ; 0 · · · z + + + Z = 0; for (i1...) { Z = Z + v0[i1]; } ; Polca Program Transformations in the Polca Project 9/11

25. Dot product y = � n − 1 x • � � i = 0 x i y i = x 0 y 0 + x 1 y 1 + · · · + x n − 1 y n − 1 x 0 y 0 x 1 y 1 · · · x n − 1 y n − 1 vxv xs ys = foldl (+) 0 ( zipWith ( ∗ ) xs ys ) · · · ∗ ∗ ∗ for (i0...) { w 0 w 1 w n − 1 v0[i0] = xs[i0] * ys[i0]; } ; 0 · · · z + + + Z = 0; for (i1...) { Z = Z + v0[i1]; } ; x 0 y 0 x 1 y 1 · · · x n − 1 y n − 1 · · · ∗ ∗ ∗ w 0 w 1 w n − 1 · · · z 0 + + + Polca Program Transformations in the Polca Project 9/11

Recommend

More recommend