Programming a multicore architecture without coherency and atomic - - PowerPoint PPT Presentation

programming a multicore architecture without coherency
SMART_READER_LITE
LIVE PREVIEW

Programming a multicore architecture without coherency and atomic - - PowerPoint PPT Presentation

Programming a multicore architecture without coherency and atomic operations Jochem Rutgers , Marco Bekooij, Gerard Smit 2014-02-15 1 / 13 Parallel render example One master thread: data = read_3d_model_from_file(); 1 go = 1; 2 while


slide-1
SLIDE 1

Programming a multicore architecture without coherency and atomic operations

Jochem Rutgers, Marco Bekooij, Gerard Smit 2014-02-15

1 / 13

slide-2
SLIDE 2

Parallel render example

One master thread:

1

data = read_3d_model_from_file();

2

go = 1;

3

while(done!=N) sleep();

4

display_frame(frame);

N slave threads:

1

while(!go) sleep();

2

render_my_part_of_frame(data,frame);

3

done++;

2 / 13

slide-3
SLIDE 3

Parallel render Pthread example

One master thread:

1

data = read_3d_model_from_file();

2

pthread_barrier_wait();

3

pthread_barrier_wait();

4

display_frame(frame);

N slave threads:

1

pthread_barrier_wait();

2

render_my_part_of_frame(data,frame);

3

pthread_barrier_wait();

3 / 13

slide-4
SLIDE 4

programmers say. . . hardware architects say. . .

I want C, so I need

sequential execution

Can’t do, use parallel execution instead Hmm, then I need

shared memory to use

threads and pointers I’ll give you

distributed memory

Then at least supply hardware cache

coherency

Ok, but only with a

weak memory model

I can’t reason about state then, give me

atomic operations

Ok, but that’s ex- tremely expensive, so don’t use them

4 / 13

slide-5
SLIDE 5

Programming a multicore architecture

without

coherency and atomic operations

5 / 13

slide-6
SLIDE 6

Programming a multicore architecture

without

coherency and atomic operations . . . by starting from a functional language

5 / 13

slide-7
SLIDE 7

Dependency-only description

Program definition:

1

main h = cylinder 2 h

2

cylinder r = * (* π (sqr r))

3

sqr x = * x x

Evaluation sequence:

1

main (* 3 3)

2

cylinder 2 (* 3 3)

3

* (* π (sqr 2)) (* 3 3)

4

* (* π (* 2 2)) (* 3 3)

5

* (* π (4)) (* 3 3)

6

* (12.57...) (* 3 3)

7

* (12.57...) 9

8

113.10...

app

main

app app

* 3 3

6 / 13

slide-8
SLIDE 8

Dependency-only description

Program definition:

1

main h = cylinder 2 h

2

cylinder r = * (* π (sqr r))

3

sqr x = * x x

Evaluation sequence:

1

main (* 3 3)

2

cylinder 2 (* 3 3)

3

* (* π (sqr 2)) (* 3 3)

4

* (* π (* 2 2)) (* 3 3)

5

* (* π (4)) (* 3 3)

6

* (12.57...) (* 3 3)

7

* (12.57...) 9

8

113.10...

app

main

app app

* 3 3

6 / 13

slide-9
SLIDE 9

Dependency-only description

Program definition:

1

main h = cylinder 2 h

2

cylinder r = * (* π (sqr r))

3

sqr x = * x x

Evaluation sequence:

1

main (* 3 3)

2

cylinder 2 (* 3 3)

3

* (* π (sqr 2)) (* 3 3)

4

* (* π (* 2 2)) (* 3 3)

5

* (* π (4)) (* 3 3)

6

* (12.57...) (* 3 3)

7

* (12.57...) 9

8

113.10...

app

main

app app

* 3 3

app

cyl 2

6 / 13

slide-10
SLIDE 10

Dependency-only description

◮ Terms are constant ◮ Duplicates are identical ◮ No order in execution ◮ No memory/state ◮ No implicit behavior

. . . therefore. . .

◮ Parallel description ◮ Shortcuts in synchronization ◮ Lossy work distribution ◮ Only atomic pointer writes ◮ atomic free

app

main

app app

* 3 3

app

cyl 2

6 / 13

slide-11
SLIDE 11

A λ-term’s life

new

  • 1. Memory allocation
  • 2. Memory initialization (construction)
  • 3. Add to expression
  • 4. Replace with result (indirect)
  • 5. Die
  • 6. Garbage collect, free

7 / 13

slide-12
SLIDE 12

A λ-term’s life

init

  • 1. Memory allocation
  • 2. Memory initialization (construction)
  • 3. Add to expression
  • 4. Replace with result (indirect)
  • 5. Die
  • 6. Garbage collect, free

7 / 13

slide-13
SLIDE 13

A λ-term’s life

init

  • 1. Memory allocation
  • 2. Memory initialization (construction)
  • 3. Add to expression
  • 4. Replace with result (indirect)
  • 5. Die
  • 6. Garbage collect, free

7 / 13

slide-14
SLIDE 14

A λ-term’s life

init

  • 1. Memory allocation
  • 2. Memory initialization (construction)
  • 3. Add to expression
  • 4. Replace with result (indirect)
  • 5. Die
  • 6. Garbage collect, free

7 / 13

slide-15
SLIDE 15

A λ-term’s life

init

  • 1. Memory allocation
  • 2. Memory initialization (construction)
  • 3. Add to expression
  • 4. Replace with result (indirect)
  • 5. Die
  • 6. Garbage collect, free

7 / 13

slide-16
SLIDE 16

A λ-term’s life

  • 1. Memory allocation
  • 2. Memory initialization (construction)
  • 3. Add to expression
  • 4. Replace with result (indirect)
  • 5. Die
  • 6. Garbage collect, free

7 / 13

slide-17
SLIDE 17

A λ-term’s life

  • 1. Memory allocation

private

  • 2. Memory initialization (construction)

r/w access, private

  • 3. Add to expression

read-only, shared

  • 4. Replace with result (indirect)

pointer write, shared

  • 5. Die

private

  • 6. Garbage collect, free

private

7 / 13

slide-18
SLIDE 18

From phases to rules

  • 1. Memory allocation
  • 2. Memory initialization (construction)

Rule 1: construction must be completed; flush / fence

  • 3. Add to expression

Rule 2: pointer write is atomic, in total order; (flush) Rule 3: reads are in total order

  • 4. Replace with result (indirect)

(Rule 2 again)

  • 5. Die

Rule 4: all operations are completed; flush / fence

  • 6. Garbage collect, free

8 / 13

slide-19
SLIDE 19

From phases to rules to requirements

  • 1. Memory allocation
  • 2. Memory initialization (construction)

Rule 1: construction must be completed; flush / fence

  • 3. Add to expression

Rule 2: pointer write is atomic, in total order; (flush) Rule 3: reads are in total order

  • 4. Replace with result (indirect)

(Rule 2 again)

  • 5. Die

Rule 4: all operations are completed; flush / fence

  • 6. Garbage collect, free

8 / 13

slide-20
SLIDE 20

From phases to rules to requirements

  • 1. Memory allocation
  • 2. Memory initialization (construction)

Rule 1: construction must be completed; flush / fence

  • 3. Add to expression

Rule 2: pointer write is atomic, in total order; (flush) Rule 3: reads are in total order

  • 4. Replace with result (indirect)

(Rule 2 again)

  • 5. Die

Rule 4: all operations are completed; flush / fence

  • 6. Garbage collect, free

8 / 13

slide-21
SLIDE 21

From phases to rules to requirements

  • 1. Memory allocation
  • 2. Memory initialization (construction)

Rule 1: construction must be completed; flush / fence

  • 3. Add to expression

Rule 2: pointer write is atomic, in total order; (flush) Rule 3: reads are in total order

  • 4. Replace with result (indirect)

(Rule 2 again)

  • 5. Die

Rule 4: all operations are completed; flush / fence

  • 6. Garbage collect, free

8 / 13

slide-22
SLIDE 22

From phases to rules to requirements

  • 1. Memory allocation
  • 2. Memory initialization (construction)

Rule 1: construction must be completed; flush / fence

  • 3. Add to expression

Rule 2: pointer write is atomic, in total order; (flush) Rule 3: reads are in total order

  • 4. Replace with result (indirect)

(Rule 2 again)

  • 5. Die

Rule 4: all operations are completed; flush / fence

  • 6. Garbage collect, free

8 / 13

slide-23
SLIDE 23

λ-calculus in C++

◮ λ-terms implemented as C++ templates/classes ◮ gcc; ()-operator overloading gives FP-like syntax ◮ data type: (complex) doubles, large integers (GNU MP) ◮ one worker thread per core ◮ Haskell-like par and pseq ◮ local vs. global data and garbage collection ◮ mark–sweep GC (global GC is stop-the-world) ◮ ≈400 instructions in run-time per created λ-term ◮ ≈5500 LoC ◮ GPLv3 ◮ https://sites.google.com/site/jochemrutgers/lambdacpp

9 / 13

slide-24
SLIDE 24

I$ D$ 1 I$ D$ 2 I$ D$ i I$ D$ 31 I$ D$ in-order NoC DDR

10 / 13

slide-25
SLIDE 25

4 8 12 16 20 24 28 32 4 8 12 16 20 24 Number of processors Speedup (b) parfib

linear speedup ghc (x86) ghc (x86, hyperthreaded) LambdaC++ (x86) LambdaC++ (x86, hyperthreaded) LambdaC++ (MicroBlaze) LambdaC++ (x86), no mem bottleneck 11 / 13

slide-26
SLIDE 26

c

  • i

n s p a r f i b p a r t a k p r s a q u e e n s 0.2 0.4 0.6 0.8 1 Time spent (fraction of execution time) global GC local GC stalling on black hole idle running β-reduction

12 / 13

slide-27
SLIDE 27

Highlights

programmers say. . . hardware architects say. . . I want C, so I need

sequential execution

Can’t do, use parallel execution instead Hmm, then I need

shared memory to use

threads and pointers I’ll give you

distributed memory

Then at least supply hardware cache

coherency

Ok, but only with a

weak memory model

I can’t reason about state then, give me

atomic operations

Ok, but that’s ex- tremely expensive, so don’t use them

4 / 13

programmers say. . . hardware architects say. . . I want C, so I need sequential execution Can’t do, use parallel execution instead Hmm, then I need shared memory to use threads and pointers I’ll give you distributed memory Then at least supply hardware cache coherency Ok, but only with a weak memory model I can’t reason about state then, give me atomic operations Ok, but that’s ex- tremely expensive, so don’t use them 4 / 13 Dependency-only description ◮ Terms are constant ◮ Duplicates are identical ◮ No order in execution ◮ No memory/state ◮ No implicit behavior . . . therefore. . . ◮ Parallel description ◮ Shortcuts in synchronization ◮ Lossy work distribution ◮ Only atomic pointer writes ◮ atomic free app main app app * 3 3 app cyl 2 6 / 13 From phases to rules to requirements
  • 1. Memory allocation
  • 2. Memory initialization (construction)
Rule 1: construction must be completed; flush / fence
  • 3. Add to expression
Rule 2: pointer write is atomic, in total order; (flush) Rule 3: reads are in total order
  • 4. Replace with result (indirect)
(Rule 2 again)
  • 5. Die
Rule 4: all operations are completed; flush / fence
  • 6. Garbage collect, free
8 / 13 I$ D$ 1 I$ D$ 2 I$ D$ i I$ D$ 31 I$ D$ in-order NoC DDR 10 / 13

Thanks!

Jochem Rutgers j.h.rutgers@utwente.nl Programming a multicore architecture without coherency and atomic operations 15 / 13

◮ Accept the hardware trends ◮ Another programming model might be more suitable ◮ Extreme example: FP is hardware-friendly. . . ◮ . . . cache coherency and atomics are avoided

13 / 13

slide-28
SLIDE 28

Highlights

programmers say. . . hardware architects say. . . I want C, so I need sequential execution Can’t do, use parallel execution instead Hmm, then I need shared memory to use threads and pointers I’ll give you distributed memory Then at least supply hardware cache coherency Ok, but only with a weak memory model I can’t reason about state then, give me atomic operations Ok, but that’s ex- tremely expensive, so don’t use them 4 / 13

Dependency-only description

◮ Terms are constant ◮ Duplicates are identical ◮ No order in execution ◮ No memory/state ◮ No implicit behavior

. . . therefore. . .

◮ Parallel description ◮ Shortcuts in synchronization ◮ Lossy work distribution ◮ Only atomic pointer writes ◮ atomic free app main app app * 3 3 app cyl 2

6 / 13

Dependency-only description ◮ Terms are constant ◮ Duplicates are identical ◮ No order in execution ◮ No memory/state ◮ No implicit behavior . . . therefore. . . ◮ Parallel description ◮ Shortcuts in synchronization ◮ Lossy work distribution ◮ Only atomic pointer writes ◮ atomic free app main app app * 3 3 app cyl 2 6 / 13 From phases to rules to requirements
  • 1. Memory allocation
  • 2. Memory initialization (construction)
Rule 1: construction must be completed; flush / fence
  • 3. Add to expression
Rule 2: pointer write is atomic, in total order; (flush) Rule 3: reads are in total order
  • 4. Replace with result (indirect)
(Rule 2 again)
  • 5. Die
Rule 4: all operations are completed; flush / fence
  • 6. Garbage collect, free
8 / 13 I$ D$ 1 I$ D$ 2 I$ D$ i I$ D$ 31 I$ D$ in-order NoC DDR 10 / 13

Thanks!

Jochem Rutgers j.h.rutgers@utwente.nl Programming a multicore architecture without coherency and atomic operations 15 / 13

◮ Accept the hardware trends ◮ Another programming model might be more suitable ◮ Extreme example: FP is hardware-friendly. . . ◮ . . . cache coherency and atomics are avoided

13 / 13

slide-29
SLIDE 29

Highlights

programmers say. . . hardware architects say. . . I want C, so I need sequential execution Can’t do, use parallel execution instead Hmm, then I need shared memory to use threads and pointers I’ll give you distributed memory Then at least supply hardware cache coherency Ok, but only with a weak memory model I can’t reason about state then, give me atomic operations Ok, but that’s ex- tremely expensive, so don’t use them 4 / 13 Dependency-only description ◮ Terms are constant ◮ Duplicates are identical ◮ No order in execution ◮ No memory/state ◮ No implicit behavior . . . therefore. . . ◮ Parallel description ◮ Shortcuts in synchronization ◮ Lossy work distribution ◮ Only atomic pointer writes ◮ atomic free app main app app * 3 3 app cyl 2 6 / 13

From phases to rules to requirements

  • 1. Memory allocation
  • 2. Memory initialization (construction)

Rule 1: construction must be completed; flush / fence

  • 3. Add to expression

Rule 2: pointer write is atomic, in total order; (flush) Rule 3: reads are in total order

  • 4. Replace with result (indirect)

(Rule 2 again)

  • 5. Die

Rule 4: all operations are completed; flush / fence

  • 6. Garbage collect, free

8 / 13

From phases to rules to requirements
  • 1. Memory allocation
  • 2. Memory initialization (construction)
Rule 1: construction must be completed; flush / fence
  • 3. Add to expression
Rule 2: pointer write is atomic, in total order; (flush) Rule 3: reads are in total order
  • 4. Replace with result (indirect)
(Rule 2 again)
  • 5. Die
Rule 4: all operations are completed; flush / fence
  • 6. Garbage collect, free
8 / 13 I$ D$ 1 I$ D$ 2 I$ D$ i I$ D$ 31 I$ D$ in-order NoC DDR 10 / 13

Thanks!

Jochem Rutgers j.h.rutgers@utwente.nl Programming a multicore architecture without coherency and atomic operations 15 / 13

◮ Accept the hardware trends ◮ Another programming model might be more suitable ◮ Extreme example: FP is hardware-friendly. . . ◮ . . . cache coherency and atomics are avoided

13 / 13

slide-30
SLIDE 30

Highlights

programmers say. . . hardware architects say. . . I want C, so I need sequential execution Can’t do, use parallel execution instead Hmm, then I need shared memory to use threads and pointers I’ll give you distributed memory Then at least supply hardware cache coherency Ok, but only with a weak memory model I can’t reason about state then, give me atomic operations Ok, but that’s ex- tremely expensive, so don’t use them 4 / 13 Dependency-only description ◮ Terms are constant ◮ Duplicates are identical ◮ No order in execution ◮ No memory/state ◮ No implicit behavior . . . therefore. . . ◮ Parallel description ◮ Shortcuts in synchronization ◮ Lossy work distribution ◮ Only atomic pointer writes ◮ atomic free app main app app * 3 3 app cyl 2 6 / 13 From phases to rules to requirements
  • 1. Memory allocation
  • 2. Memory initialization (construction)
Rule 1: construction must be completed; flush / fence
  • 3. Add to expression
Rule 2: pointer write is atomic, in total order; (flush) Rule 3: reads are in total order
  • 4. Replace with result (indirect)
(Rule 2 again)
  • 5. Die
Rule 4: all operations are completed; flush / fence
  • 6. Garbage collect, free
8 / 13

I$ D$ 1 I$ D$ 2 I$ D$ i I$ D$ 31 I$ D$ in-order NoC DDR

10 / 13

I$ D$ 1 I$ D$ 2 I$ D$ i I$ D$ 31 I$ D$ in-order NoC DDR 10 / 13

Thanks!

Jochem Rutgers j.h.rutgers@utwente.nl Programming a multicore architecture without coherency and atomic operations 15 / 13

◮ Accept the hardware trends ◮ Another programming model might be more suitable ◮ Extreme example: FP is hardware-friendly. . . ◮ . . . cache coherency and atomics are avoided

13 / 13

slide-31
SLIDE 31

Highlights

programmers say. . . hardware architects say. . . I want C, so I need sequential execution Can’t do, use parallel execution instead Hmm, then I need shared memory to use threads and pointers I’ll give you distributed memory Then at least supply hardware cache coherency Ok, but only with a weak memory model I can’t reason about state then, give me atomic operations Ok, but that’s ex- tremely expensive, so don’t use them 4 / 13 Dependency-only description ◮ Terms are constant ◮ Duplicates are identical ◮ No order in execution ◮ No memory/state ◮ No implicit behavior . . . therefore. . . ◮ Parallel description ◮ Shortcuts in synchronization ◮ Lossy work distribution ◮ Only atomic pointer writes ◮ atomic free app main app app * 3 3 app cyl 2 6 / 13 From phases to rules to requirements
  • 1. Memory allocation
  • 2. Memory initialization (construction)
Rule 1: construction must be completed; flush / fence
  • 3. Add to expression
Rule 2: pointer write is atomic, in total order; (flush) Rule 3: reads are in total order
  • 4. Replace with result (indirect)
(Rule 2 again)
  • 5. Die
Rule 4: all operations are completed; flush / fence
  • 6. Garbage collect, free
8 / 13 I$ D$ 1 I$ D$ 2 I$ D$ i I$ D$ 31 I$ D$ in-order NoC DDR 10 / 13

Thanks!

Jochem Rutgers j.h.rutgers@utwente.nl

Programming a multicore architecture without coherency and atomic operations

15 / 13 Thanks!

Jochem Rutgers j.h.rutgers@utwente.nl Programming a multicore architecture without coherency and atomic operations 15 / 13

◮ Accept the hardware trends ◮ Another programming model might be more suitable ◮ Extreme example: FP is hardware-friendly. . . ◮ . . . cache coherency and atomics are avoided

13 / 13

slide-32
SLIDE 32

Part II Appendix

14 / 13

slide-33
SLIDE 33

Thanks!

Jochem Rutgers j.h.rutgers@utwente.nl

Programming a multicore architecture without coherency and atomic operations

15 / 13

slide-34
SLIDE 34

benchmark local applicationsa local constantsa globalsa coins 0.418 0.582 1.36 · 10−4 parfib 0.379 0.621 1.44 · 10−4 partak 0.351 0.648 5.47 · 10−4 prsa 0.412 0.583 4.97 · 10−3 queens 0.445 0.555 9.10 · 10−5

a Fraction of sum of all global and local terms

Table 2. Generated terms during evaluation (LambdaC++, x86, 12 cores)

16 / 13