Capable: Capabilities for Scalability Current state of design Elias - - PowerPoint PPT Presentation

capable capabilities for scalability
SMART_READER_LITE
LIVE PREVIEW

Capable: Capabilities for Scalability Current state of design Elias - - PowerPoint PPT Presentation

Capable: Capabilities for Scalability Current state of design Elias Castegren , Tobias Wrigstad forename.surname@it.uu.se IWACO 2014, Uppsala 1 / 22 Introduction Safe parallel programming using capabilities Scalability and performance


slide-1
SLIDE 1

Capable: Capabilities for Scalability

Current state of design Elias Castegren, Tobias Wrigstad forename.surname@it.uu.se IWACO 2014, Uppsala

1 / 22

slide-2
SLIDE 2

Introduction

◮ Safe parallel programming using capabilities ◮ Scalability and performance rather than verification

2 / 22

slide-3
SLIDE 3

Background

◮ Ownership types prescribe structure

3 / 22

slide-4
SLIDE 4

Background

◮ Ownership types prescribe structure

3 / 22

slide-5
SLIDE 5

Background

◮ Ownership types prescribe structure

3 / 22

slide-6
SLIDE 6

Background

◮ Ownership types prescribe structure ◮ Effect systems describe usage

3 / 22

slide-7
SLIDE 7

Background

◮ Ownership types prescribe structure ◮ Effect systems describe usage

3 / 22

slide-8
SLIDE 8

Background

◮ Ownership types prescribe structure ◮ Effect systems describe usage

3 / 22

slide-9
SLIDE 9

Background

◮ Ownership types prescribe structure ◮ Effect systems describe usage

3 / 22

slide-10
SLIDE 10

Background

◮ Ownership types prescribe structure ◮ Effect systems describe usage ◮ We’re aiming somewhere in-between:

Any structure is allowed as long as all aliases are non-interfering.

3 / 22

slide-11
SLIDE 11

Outline

◮ Introduction ◮ Background ◮ Capabilities ◮ Traits and classes ◮ Composition, splitting and merging ◮ Nesting and parametricity ◮ Composition as abstract memory layout specification

4 / 22

slide-12
SLIDE 12

Capabilities

◮ A capability governs access to some resource

Capability Exclusive Non-exclusive Unsafe Safe

Locks Transactions Immutable Lock-free ... 5 / 22

slide-13
SLIDE 13

Capabilities

◮ A capability governs access to some resource ◮ Capability ≃ (Reference, {allowed operations})

Capability Exclusive Non-exclusive Unsafe Safe

Locks Transactions Immutable Lock-free ... 5 / 22

slide-14
SLIDE 14

Capabilities

◮ A capability governs access to some resource ◮ Capability ≃ (Reference, {allowed operations})

Capability Capability Exclusive Non-exclusive Unsafe Safe

Locks Transactions Immutable Lock-free ... 5 / 22

slide-15
SLIDE 15

Capabilities

◮ A capability governs access to some resource ◮ Capability ≃ (Reference, {allowed operations})

Capability Exclusive Non-exclusive Capability Exclusive Non-exclusive Unsafe Safe

Locks Transactions Immutable Lock-free ... 5 / 22

slide-16
SLIDE 16

Capabilities

◮ A capability governs access to some resource ◮ Capability ≃ (Reference, {allowed operations})

Capability Exclusive Non-exclusive Unsafe Safe Capability Exclusive Non-exclusive Unsafe Safe

Locks Transactions Immutable Lock-free ... 5 / 22

slide-17
SLIDE 17

Capabilities

◮ A capability governs access to some resource ◮ Capability ≃ (Reference, {allowed operations})

Capability Exclusive Non-exclusive Unsafe Safe

Locks Transactions Immutable Lock-free ... 5 / 22

slide-18
SLIDE 18

Safety

◮ Orthogonal to the design of our system: Plug in your favorite

synchronization mechanism!

6 / 22

slide-19
SLIDE 19

Safety

◮ Orthogonal to the design of our system: Plug in your favorite

synchronization mechanism!

◮ Baseline:

◮ No write-write conflicts outside of unsafe capabilities ◮ Exclusive capabilities are (and remain) exclusive 6 / 22

slide-20
SLIDE 20

Safety

◮ Orthogonal to the design of our system: Plug in your favorite

synchronization mechanism!

◮ Baseline:

◮ No write-write conflicts outside of unsafe capabilities ◮ Exclusive capabilities are (and remain) exclusive

◮ Our focus: Lock-free capabilities with static support for

speculation and publication of values (see paper for more details)

6 / 22

slide-21
SLIDE 21

Traits

◮ Capabilities are introduced using traits:

safe trait Get{ require int value; int get(){ return this.value; } }

7 / 22

slide-22
SLIDE 22

Traits

◮ Capabilities are introduced using traits:

safe trait Get{ require int value; int get(){ return this.value; } }

◮ Traits are exclusive by default:

trait Set{ require int value; void set(int val){ this.value = val; } }

7 / 22

slide-23
SLIDE 23

Classes

trait Set{ require int value; void set(int val)... safe trait Get{ require int value; int get()...

◮ Classes are formed by composing traits:

class Cell = Set ⊕ Get∗{ provide int value; }

8 / 22

slide-24
SLIDE 24

Classes

trait Set{ require int value; void set(int val)... safe trait Get{ require int value; int get()...

◮ Classes are formed by composing traits:

class Cell = Set ⊕ Get∗{ provide int value; }

◮ Class types are composite capabilities:

Cell c = new Cell; c.set(42); c.get(); // = 42

8 / 22

slide-25
SLIDE 25

Composition and splitting

◮ A disjunction can be split into either of its components:

=

  • r

= ⊕ Cell Set Get* = and = ⊗ Pair Cell Cell

9 / 22

slide-26
SLIDE 26

Composition and splitting (Cell = Set ⊕ Get∗)

x = new Cell;

x x

42

x

42

x

42

y å p z f

10 / 22

slide-27
SLIDE 27

Composition and splitting (Cell = Set ⊕ Get∗)

x = new Cell;

x

x.set(42);

x

42

x

42

x

42

y å p z f

10 / 22

slide-28
SLIDE 28

Composition and splitting (Cell = Set ⊕ Get∗)

x = new Cell;

x

x.set(42);

x

42

x = (Get∗) consume x;

x

42

x

42

y å p z f

10 / 22

slide-29
SLIDE 29

Composition and splitting (Cell = Set ⊕ Get∗)

x = new Cell;

x

x.set(42);

x

42

x = (Get∗) consume x;

x

42

x

42

y å p z f

10 / 22

slide-30
SLIDE 30

Composition and splitting

◮ A disjunction can be split into either of its components:

=

  • r

= ⊕ Cell Set Get*

◮ A conjunction can be split into both of its components:

= and = ⊗ Pair Cell Cell

11 / 22

slide-31
SLIDE 31

Composition and splitting (Pair = Cell ⊗ Cell)

p = new Pair;

p p c1 c2 c1 c2

12 / 22

slide-32
SLIDE 32

Composition and splitting (Pair = Cell ⊗ Cell)

p = new Pair;

p

Cell c1, c2 = consume p;

p c1 c2 c1 c2

12 / 22

slide-33
SLIDE 33

Composition and splitting (Pair = Cell ⊗ Cell)

p = new Pair;

p

Cell c1, c2 = consume p;

p c1 c2

c1 and c2 are aliases, but can only access “their half” of the Pair:

c1 c2

12 / 22

slide-34
SLIDE 34

Splitting and merging

= and = ⊗ Pair Cell Cell

13 / 22

slide-35
SLIDE 35

Splitting and merging

and ⊗ Pair Cell Cell

13 / 22

slide-36
SLIDE 36

Splitting and merging

Pair Pair

13 / 22

slide-37
SLIDE 37

Merging

◮ Structured split and merge

Pair p = ...; split p into Cell c1, c2 in{ ... // p is invalidated } ... // p is reinstated

14 / 22

slide-38
SLIDE 38

Merging

◮ Structured split and merge

Pair p = ...; split p into Cell c1, c2 in{ ... // p is invalidated } ... // p is reinstated

◮ Unstructured split and merge

Pair p = ...; Cell c1, c2 = consume p; ... p = consume c1 ⊗ consume c2 ... // c1 and c2 are invalidated

14 / 22

slide-39
SLIDE 39

Merging

◮ Structured split and merge

Pair p = ...; split p into Cell c1, c2 in{ ... // p is invalidated } ... // p is reinstated

◮ Unstructured split and merge

Pair p = ...; Cell c1, c2 = consume p; ... p = consume c1 ⊗ consume c2 ← dynamic alias check! ... // c1 and c2 are invalidated

14 / 22

slide-40
SLIDE 40

Merging

◮ What about disjunction?

=

  • r

= ⊕ Cell Set Get*

15 / 22

slide-41
SLIDE 41

Merging

◮ What about disjunction?

= = Cell Set Get*

15 / 22

slide-42
SLIDE 42

Merging

◮ What about disjunction?

= = Cell Get* Set

15 / 22

slide-43
SLIDE 43

Merging

◮ What about disjunction?

= = Cell Get* Set

◮ The Get capability is lost!

15 / 22

slide-44
SLIDE 44

Splitting with Jails

◮ Cell = Set ⊕ Get∗ means Set and Get∗ may not be used

in parallel

=

  • r

= ⊕ Cell Set Get*

16 / 22

slide-45
SLIDE 45

Splitting with Jails

◮ Cell = Set ⊕ Get∗ means Set and Get∗ may not be used

in parallel

= = ⊗ Cell Set J<Get*> and

◮ A jailed capability is an alias with an empty interface

16 / 22

slide-46
SLIDE 46

Splitting with Jails

◮ Cell = Set ⊕ Get∗ means Set and Get∗ may not be used

in parallel

= = ⊗ Cell

◮ A jailed capability is an alias with an empty interface

16 / 22

slide-47
SLIDE 47

Splitting with Jails

◮ Cell = Set ⊕ Get∗ means Set and Get∗ may not be used

in parallel

= = ⊗ Cell

◮ A jailed capability is an alias with an empty interface ◮ Jails can turn any disjunction c1 ⊕ c2 into a conjunction

c1 ⊗ Jc2, which can be split and merged in a non-lossy way

16 / 22

slide-48
SLIDE 48

Recap

◮ Capabilities are either exclusive, safe or unsafe

17 / 22

slide-49
SLIDE 49

Recap

◮ Capabilities are either exclusive, safe or unsafe ◮ Traits specify behaviour and introduce capability types.

17 / 22

slide-50
SLIDE 50

Recap

◮ Capabilities are either exclusive, safe or unsafe ◮ Traits specify behaviour and introduce capability types. ◮ Classes introduce composite capability types

17 / 22

slide-51
SLIDE 51

Recap

◮ Capabilities are either exclusive, safe or unsafe ◮ Traits specify behaviour and introduce capability types. ◮ Classes introduce composite capability types

◮ A disjunction c1 ⊕ c2 can be split into either c1 or c2 17 / 22

slide-52
SLIDE 52

Recap

◮ Capabilities are either exclusive, safe or unsafe ◮ Traits specify behaviour and introduce capability types. ◮ Classes introduce composite capability types

◮ A disjunction c1 ⊕ c2 can be split into either c1 or c2 ◮ A conjunction c1 ⊗ c2 can be split into both c1 and c2 which

may be used in parallel

17 / 22

slide-53
SLIDE 53

Recap

◮ Capabilities are either exclusive, safe or unsafe ◮ Traits specify behaviour and introduce capability types. ◮ Classes introduce composite capability types

◮ A disjunction c1 ⊕ c2 can be split into either c1 or c2 ◮ A conjunction c1 ⊗ c2 can be split into both c1 and c2 which

may be used in parallel

◮ Merging can be used to regain composite capabilities in both

structured and unstructured ways

17 / 22

slide-54
SLIDE 54

Co-encapsulation through nesting

◮ Parametricity exposes internal details about a nested

capability class ListT = AddT ⊕ DelT ⊕ Nth∗T{ provide LinkT first; }

= = List<T> Add<T> Del<T> Nth*<T> ⊕ ⊕

  • r
  • r

List<Pair>

18 / 22

slide-55
SLIDE 55

Co-encapsulation through nesting

◮ Parametricity exposes internal details about a nested

capability class ListT = AddT ⊕ DelT ⊕ Nth∗T{ provide LinkT first; }

= = List<T> Add<T> Del<T> Nth*<T> ⊕ ⊕

  • r
  • r

List<Pair>

18 / 22

slide-56
SLIDE 56

Co-encapsulation through nesting

◮ Parametricity exposes internal details about a nested

capability class ListT = AddT ⊕ DelT ⊕ Nth∗T{ provide LinkT first; }

= = List<T> Add<T> Del<T> Nth*<T> ⊕ ⊕

  • r
  • r

List<Pair>

18 / 22

slide-57
SLIDE 57

Nesting and splitting

ListT = AddT ⊕ DelT ⊕ Nth∗T Pair = Cell ⊗ Cell

List<Pair> Nth*<Pair> Nth*<Cell> Nth*<Cell> ⊗ and

19 / 22

slide-58
SLIDE 58

Nesting and splitting

ListT = AddT ⊕ DelT ⊕ Nth∗T Pair = Cell ⊗ Cell

List<Pair>

Outer split:

Nth*<Pair> Nth*<Cell> Nth*<Cell> ⊗ and

19 / 22

slide-59
SLIDE 59

Nesting and splitting

ListT = AddT ⊕ DelT ⊕ Nth∗T Pair = Cell ⊗ Cell

List<Pair>

Outer split:

Nth*<Pair>

Inner split:

Nth*<Cell> Nth*<Cell> ⊗ and

19 / 22

slide-60
SLIDE 60

Composition as abstract memory layout specification

◮ Cache locality is good! Data accessed together by a single

thread should be on the same cache line

20 / 22

slide-61
SLIDE 61

Composition as abstract memory layout specification

◮ Cache locality is good! Data accessed together by a single

thread should be on the same cache line

◮ False sharing is bad! Disjoint data accessed in parallel should

be on separate cache lines

20 / 22

slide-62
SLIDE 62

Composition as abstract memory layout specification

◮ Cache locality is good! Data accessed together by a single

thread should be on the same cache line

◮ False sharing is bad! Disjoint data accessed in parallel should

be on separate cache lines

◮ Different splitting semantics suggest different access patterns:

c = c1 ⊕ c2 ⇒ c1 and c2 accessed together or separately

20 / 22

slide-63
SLIDE 63

Composition as abstract memory layout specification

◮ Cache locality is good! Data accessed together by a single

thread should be on the same cache line

◮ False sharing is bad! Disjoint data accessed in parallel should

be on separate cache lines

◮ Different splitting semantics suggest different access patterns:

c = c1 ⊕ c2 ⇒ c1 and c2 accessed together or separately Keep c1 and c2’s resources on the same cache line!

20 / 22

slide-64
SLIDE 64

Composition as abstract memory layout specification

◮ Cache locality is good! Data accessed together by a single

thread should be on the same cache line

◮ False sharing is bad! Disjoint data accessed in parallel should

be on separate cache lines

◮ Different splitting semantics suggest different access patterns:

c = c1 ⊕ c2 ⇒ c1 and c2 accessed together or separately Keep c1 and c2’s resources on the same cache line! c = c1 ⊗ c2 ⇒ c1 and c2 may be accessed in parallel

20 / 22

slide-65
SLIDE 65

Composition as abstract memory layout specification

◮ Cache locality is good! Data accessed together by a single

thread should be on the same cache line

◮ False sharing is bad! Disjoint data accessed in parallel should

be on separate cache lines

◮ Different splitting semantics suggest different access patterns:

c = c1 ⊕ c2 ⇒ c1 and c2 accessed together or separately Keep c1 and c2’s resources on the same cache line! c = c1 ⊗ c2 ⇒ c1 and c2 may be accessed in parallel Keep c1 and c2’s resources on different cache lines!

20 / 22

slide-66
SLIDE 66

What else?

◮ Merging non-exclusive capabilities ◮ Aliasing exclusive capabilities ◮ Lock-free capabilities

21 / 22

slide-67
SLIDE 67

What else?

◮ Merging non-exclusive capabilities ◮ Aliasing exclusive capabilities ◮ Lock-free capabilities ◮ See paper for more details

21 / 22

slide-68
SLIDE 68

Summary

◮ Safe aliasing through capability splitting (and merging) ◮ Capability composition hints efficient memory layout ◮ Lock-free capabilities for lock-free data structures

22 / 22

slide-69
SLIDE 69

Summary

◮ Safe aliasing through capability splitting (and merging) ◮ Capability composition hints efficient memory layout ◮ Lock-free capabilities for lock-free data structures

What now?

◮ Implementation and evaluation ◮ Extend the support for lock-free data structures ◮ Add high level abstractions (e.g. Reagents [Turon 12])

22 / 22

slide-70
SLIDE 70

Summary

◮ Safe aliasing through capability splitting (and merging) ◮ Capability composition hints efficient memory layout ◮ Lock-free capabilities for lock-free data structures

What now?

◮ Implementation and evaluation ◮ Extend the support for lock-free data structures ◮ Add high level abstractions (e.g. Reagents [Turon 12])

Thank you!

22 / 22