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

program transformations in the polca project jan kuper
SMART_READER_LITE
LIVE PREVIEW

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


slide-1
SLIDE 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

slide-2
SLIDE 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

slide-3
SLIDE 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

slide-4
SLIDE 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

slide-5
SLIDE 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

slide-6
SLIDE 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

slide-7
SLIDE 7

Algorithmic structures

for (i = 0; i < n; i++) z[i] = f(x[i]);

x0 f z0 x1 f z1 x2 f z2 x3 f z3 x4 f z4

w = a; for (i = 0; i < n; i++) w = w ⋆ x[i];

⋆ x0 ⋆ x1 ⋆ x2 ⋆ x3 ⋆ x4 a w

Polca Program Transformations in the Polca Project 4/11

slide-8
SLIDE 8

Algorithmic structures

for (i = 0; i < n; i++) z[i] = f(x[i]);

x0 f z0 x1 f z1 x2 f z2 x3 f z3 x4 f z4

map f xs

w = a; for (i = 0; i < n; i++) w = w ⋆ x[i];

⋆ x0 ⋆ x1 ⋆ x2 ⋆ x3 ⋆ x4 a w

foldl f a xs

Polca Program Transformations in the Polca Project 4/11

slide-9
SLIDE 9

Algorithmic structures

for (i = 0; i < n; i++) z[i] = f(x[i]);

x0 f z0 x1 f z1 x2 f z2 x3 f z3 x4 f z4

map f xs

w = a; for (i = 0; i < n; i++) w = w ⋆ x[i];

⋆ x0 ⋆ x1 ⋆ x2 ⋆ x3 ⋆ x4 a w

foldl f a xs

Higher Order Functions

Polca Program Transformations in the Polca Project 4/11

slide-10
SLIDE 10

Higher Order Functions

itn

f f f f f a z

f a ⇒ a′ z = itn f a n itnscan

f z1 f z2 f z3 f z4 f z5 a z0

f a ⇒ z zs = itnscan f a n map

x0 f z0 x1 f z1 x2 f z2 x3 f z3 x4 f z4

f x ⇒ z zs = map f xs zipWith

⋆ x0y0 z0 ⋆ x1y1 z1 ⋆ x2y2 z2 ⋆ x3y3 z3 ⋆ x4y4 z4

x ⋆ y ⇒ z zs = zipWith (⋆) xs ys foldl

⋆ x0 ⋆ x1 ⋆ x2 ⋆ x3 ⋆ x4 a w

a ⋆ x ⇒ a′ w = foldl (⋆) a xs scanl

⋆ x0 z1 ⋆ x1 z2 ⋆ x2 z3 ⋆ x3 z4 ⋆ x4 z5 a z0

a ⋆ x ⇒ z zs = scanl (⋆) a xs mapAccumL

f x0 z0 f x1 z1 f x2 z2 f x3 z3 f x4 z4 a w

f a x ⇒ (a′, z) (w, zs) = mapAccumL f a xs

Polca Program Transformations in the Polca Project 5/11

slide-11
SLIDE 11

Transformations on HOFs

+ x0 + x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10 + x11 total

foldl (+) 0 xs total = 0; for (i = 0; i < n; i++) total = total + x[i];

Polca Program Transformations in the Polca Project 6/11

slide-12
SLIDE 12

Transformations on HOFs

+ x0 + x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10 + x11 total

foldl (+) 0 xs total = 0; for (i = 0; i < n; i++) total = total + x[i];

+ x0 + x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10 + x11 total

foldl (foldl (+)) 0 xss

Polca Program Transformations in the Polca Project 6/11

slide-13
SLIDE 13

Transformations on HOFs

+ x0 + x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10 + x11 total

foldl (+) 0 xs total = 0; for (i = 0; i < n; i++) total = total + x[i];

+ x0 + x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10 + x11 total

foldl (foldl (+)) 0 xss Z = 0; for (i0...) { for (i1...) { Z = Z + xss[i0][i1]; }; };

Polca Program Transformations in the Polca Project 6/11

slide-14
SLIDE 14

Transformations on HOFs

+ x0 + x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10 + x11 total

foldl (+) 0 xs total = 0; for (i = 0; i < n; i++) total = total + x[i];

Polca Program Transformations in the Polca Project 7/11

slide-15
SLIDE 15

Transformations on HOFs

+ x0 + x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10 + x11 total

foldl (+) 0 xs total = 0; for (i = 0; i < n; i++) total = total + x[i];

+ x0 + x1 + x2 + + x3 + x4 + x5 + + x6 + x7 + x8 + + x9 + x10 + x11 +

total

foldl (+) 0 (map (foldl (+) 0) xss)

Polca Program Transformations in the Polca Project 7/11

slide-16
SLIDE 16

Transformations on HOFs

+ x0 + x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10 + x11 total

foldl (+) 0 xs total = 0; for (i = 0; i < n; i++) total = total + x[i];

+ x0 + x1 + x2 + + x3 + x4 + x5 + + x6 + x7 + x8 + + x9 + x10 + x11 +

total

foldl (+) 0 (map (foldl (+) 0) xss) for (i0...) { v0[i0] = 0; for (i1...) { v0[i0] = v0[i0] + xss[i0][i1]; }; }; Z = 0; for (i2...) { Z = Z + v0[i2]; };

Polca Program Transformations in the Polca Project 7/11

slide-17
SLIDE 17

Transformations on HOFs

+ x0 + x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10 + x11 total

foldl (+) 0 xs total = 0; for (i = 0; i < n; i++) total = total + x[i];

Polca Program Transformations in the Polca Project 8/11

slide-18
SLIDE 18

Transformations on HOFs

+ x0 + x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10 + x11 total

foldl (+) 0 xs total = 0; for (i = 0; i < n; i++) total = total + x[i];

+ x0 + x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10 + x11 + + +

total

foldl (+) 0 (foldl (zipWith (+)) zs xss)

Polca Program Transformations in the Polca Project 8/11

slide-19
SLIDE 19

Transformations on HOFs

+ x0 + x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10 + x11 total

foldl (+) 0 xs total = 0; for (i = 0; i < n; i++) total = total + x[i];

+ x0 + x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10 + x11 + + +

total

foldl (+) 0 (foldl (zipWith (+)) zs xss) v0 = zs; for (i0...) { for (i1...) { v0[i1] = v0[i1] + xss[i0][i1]; }; }; Z = 0; for (i2...) { Z = Z + v0[i2]; };

Polca Program Transformations in the Polca Project 8/11

slide-20
SLIDE 20

Dot product

  • x •

y = n−1

i=0 xiyi = x0y0 + x1y1 + · · · + xn−1yn−1

Polca Program Transformations in the Polca Project 9/11

slide-21
SLIDE 21

Dot product

  • x •

y = n−1

i=0 xiyi = x0y0 + x1y1 + · · · + xn−1yn−1

x0 x1 · · · xn−1 y0 y1 yn−1 ∗ ∗ · · · ∗ + + · · · + z

w0 w1 wn−1

Polca Program Transformations in the Polca Project 9/11

slide-22
SLIDE 22

Dot product

  • x •

y = n−1

i=0 xiyi = x0y0 + x1y1 + · · · + xn−1yn−1

x0 x1 · · · xn−1 y0 y1 yn−1 ∗ ∗ · · · ∗ + + · · · + z

w0 w1 wn−1

vxv xs ys = foldl (+) 0 (zipWith (∗) xs ys)

Polca Program Transformations in the Polca Project 9/11

slide-23
SLIDE 23

Dot product

  • x •

y = n−1

i=0 xiyi = x0y0 + x1y1 + · · · + xn−1yn−1

x0 x1 · · · xn−1 y0 y1 yn−1 ∗ ∗ · · · ∗ + + · · · + z

w0 w1 wn−1

vxv xs ys = foldl (+) 0 (zipWith (∗) xs ys)

for (i0...) { v0[i0] = xs[i0] * ys[i0]; }; Z = 0; for (i1...) { Z = Z + v0[i1]; };

Polca Program Transformations in the Polca Project 9/11

slide-24
SLIDE 24

Dot product

  • x •

y = n−1

i=0 xiyi = x0y0 + x1y1 + · · · + xn−1yn−1

x0 x1 · · · xn−1 y0 y1 yn−1 ∗ ∗ · · · ∗ + + · · · + z

w0 w1 wn−1

vxv xs ys = foldl (+) 0 (zipWith (∗) xs ys)

for (i0...) { v0[i0] = xs[i0] * ys[i0]; }; Z = 0; for (i1...) { Z = Z + v0[i1]; };

Polca Program Transformations in the Polca Project 9/11

slide-25
SLIDE 25

Dot product

  • x •

y = n−1

i=0 xiyi = x0y0 + x1y1 + · · · + xn−1yn−1

x0 x1 · · · xn−1 y0 y1 yn−1 ∗ ∗ · · · ∗ + + · · · + z

w0 w1 wn−1

vxv xs ys = foldl (+) 0 (zipWith (∗) xs ys)

for (i0...) { v0[i0] = xs[i0] * ys[i0]; }; Z = 0; for (i1...) { Z = Z + v0[i1]; };

x0 x1 · · · xn−1 y0 y1 yn−1 ∗ ∗ · · · ∗ + + · · · + z

w0 w1 wn−1

Polca Program Transformations in the Polca Project 9/11

slide-26
SLIDE 26

Dot product

  • x •

y = n−1

i=0 xiyi = x0y0 + x1y1 + · · · + xn−1yn−1

x0 x1 · · · xn−1 y0 y1 yn−1 ∗ ∗ · · · ∗ + + · · · + z

w0 w1 wn−1

vxv xs ys = foldl (+) 0 (zipWith (∗) xs ys)

for (i0...) { v0[i0] = xs[i0] * ys[i0]; }; Z = 0; for (i1...) { Z = Z + v0[i1]; };

x0 x1 · · · xn−1 y0 y1 yn−1 ∗ ∗ · · · ∗ + + · · · + z

w0 w1 wn−1

vxv′ xs ys = foldl ((+) ⊳ (∗)) 0 (zip xs ys)

Polca Program Transformations in the Polca Project 9/11

slide-27
SLIDE 27

Dot product

  • x •

y = n−1

i=0 xiyi = x0y0 + x1y1 + · · · + xn−1yn−1

x0 x1 · · · xn−1 y0 y1 yn−1 ∗ ∗ · · · ∗ + + · · · + z

w0 w1 wn−1

vxv xs ys = foldl (+) 0 (zipWith (∗) xs ys)

for (i0...) { v0[i0] = xs[i0] * ys[i0]; }; Z = 0; for (i1...) { Z = Z + v0[i1]; };

x0 x1 · · · xn−1 y0 y1 yn−1 ∗ ∗ · · · ∗ + + · · · + z

w0 w1 wn−1

vxv′ xs ys = foldl ((+) ⊳ (∗)) 0 (zip xs ys)

Z = 0; for (i0...) { Z = Z + x * y; };

Polca Program Transformations in the Polca Project 9/11

slide-28
SLIDE 28

Dot product

  • x •

y = n−1

i=0 xiyi = x0y0 + x1y1 + · · · + xn−1yn−1

x0 x1 · · · xn−1 y0 y1 yn−1 ∗ ∗ · · · ∗ + + · · · + z

w0 w1 wn−1

vxv xs ys = foldl (+) 0 (zipWith (∗) xs ys)

x0 x1 · · · xn−1 y0 y1 yn−1 ∗ ∗ · · · ∗ + + · · · + z

w0 w1 wn−1

vxv′ xs ys = foldl ((+) ⊳ (∗)) 0 (zip xs ys)

Polca Program Transformations in the Polca Project 9/11

slide-29
SLIDE 29

Work in Progress

– More complex transformation rules, combining various HOFs – More complex examples: Conjugate Gradient, Gaussian Filtering – Generating native code for various platform (OpenCL, Xentium IS, VHDL) – Generating dataflow graphs from annotations – Applying dataflow analysis techniques for discovering bottlenecks (in term sof time, area, energy)

Polca Program Transformations in the Polca Project 10/11

slide-30
SLIDE 30

Thank you

Polca Program Transformations in the Polca Project 11/11