aquinas hobor and cristian gherghina (national university of singapore) texpoint fonts used in emf....

35
Aquinas Hobor and Cristian Gherghina (National University of Singapore)

Upload: oswald-clarke

Post on 29-Dec-2015

223 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Aquinas Hobor and Cristian Gherghina (National University of Singapore) TexPoint fonts used in EMF. Read the TexPoint manual before you delete this box.:

Aquinas Hobor and Cristian Gherghina(National University of Singapore) 

Page 2: Aquinas Hobor and Cristian Gherghina (National University of Singapore) TexPoint fonts used in EMF. Read the TexPoint manual before you delete this box.:

BarriersBarriers:

Mechanism for synchronizing multiple parties at specific synchronization points

2

A B C

time

Page 3: Aquinas Hobor and Cristian Gherghina (National University of Singapore) TexPoint fonts used in EMF. Read the TexPoint manual before you delete this box.:

BarriersWhy barriers?

We looked at PARSEC Leading benchmark for shared memory systems Provides representative sample of parallel

programs workloads

Out of 13 PARSEC applications 5 (38%) use barriers

Fields like: financial analysis, computer vision, engineering, animation, data mining

3

Page 4: Aquinas Hobor and Cristian Gherghina (National University of Singapore) TexPoint fonts used in EMF. Read the TexPoint manual before you delete this box.:

BarriersWhy barriers?

not easy to reduce to other synchronization mechanisms like locks or channels

have an interesting property : They are a multiparty stateful synchronization mechanism

4

Page 5: Aquinas Hobor and Cristian Gherghina (National University of Singapore) TexPoint fonts used in EMF. Read the TexPoint manual before you delete this box.:

Barriers in Concurrent Separation Logic(CSL)Aims:

Extend CSL with rules for modularly reasoning about barriers

Define the necessary side conditions

Proof the soundness of the barrier rules (mechanically verify the proof in Coq)

5

Page 6: Aquinas Hobor and Cristian Gherghina (National University of Singapore) TexPoint fonts used in EMF. Read the TexPoint manual before you delete this box.:

OverviewExample of barrier use: Video compression

algorithm

Notation description

Key observations, translation to side conditions

Hoare Rules and side conditions

Comments about the soundness proof6

Page 7: Aquinas Hobor and Cristian Gherghina (National University of Singapore) TexPoint fonts used in EMF. Read the TexPoint manual before you delete this box.:

Example of Barrier UsageParallel video encoding:

Divide the frame into n parts, one per threadEach frame depends on the previousMore so, each part of a frame does depend on

the entire previous frame (e.g.. Moving objects)

Sounds like a good place for a barrier!

7

Page 8: Aquinas Hobor and Cristian Gherghina (National University of Singapore) TexPoint fonts used in EMF. Read the TexPoint manual before you delete this box.:

Ridiculously simplified…• We have two threads, and four shared data

memory cells, divided into pairs (x1, x2) and (y1, y2)

• Each thread computes one cell of the “current” pair using both cells from the “previous” pair

• They synchronize with barrier b

• Memory cell i, the frame count is also shared

8

Page 9: Aquinas Hobor and Cristian Gherghina (National University of Singapore) TexPoint fonts used in EMF. Read the TexPoint manual before you delete this box.:

9

Synchronize

Write new frame Y

Read old frame X

Synchronize

Synchronize

Read frame Y

Write new XCounter ++

Code example

Page 10: Aquinas Hobor and Cristian Gherghina (National University of Singapore) TexPoint fonts used in EMF. Read the TexPoint manual before you delete this box.:

10

Code exampleState 0

State 2

State 3

State 1

State 0

State 1

State 2

State 3

Page 11: Aquinas Hobor and Cristian Gherghina (National University of Singapore) TexPoint fonts used in EMF. Read the TexPoint manual before you delete this box.:

11

Barrier state machineState 0 0

State 11

State 2

2

State 33

Call @ 1

Call @ 16

Call @ 7

Call @ 13

Page 12: Aquinas Hobor and Cristian Gherghina (National University of Singapore) TexPoint fonts used in EMF. Read the TexPoint manual before you delete this box.:

ObservationsBarrier use is inherently statefull

For each thread, each state is characterized by reads from specific cells and writes to specific cells

From state to state and from thread to thread these permission requirements change

The transitions do not always mirror the control flow graph

State changes and permission reshuffling are tightly linked to the barrier calls

12

Page 13: Aquinas Hobor and Cristian Gherghina (National University of Singapore) TexPoint fonts used in EMF. Read the TexPoint manual before you delete this box.:

Prerequisites ( extensions to Separation Logic)

“maps-to” assertions : e1 e2

mean the current thread owns the memory location pointed to by e1 with ¼ permission and that location currently contains e2.

π can be either: Full, ¥ (reading and writing allowed) Empty, ¤ (nothing allowed) Or partial, i.e., ¤ < ¼ < ¥ (read only)

the symbols and indicate two distinct partial shares

With: © = ¥13

¼

Page 14: Aquinas Hobor and Cristian Gherghina (National University of Singapore) TexPoint fonts used in EMF. Read the TexPoint manual before you delete this box.:

x1 i

Explaining a notation

14

PRECONDITIONS

POSTCONDITIONS

Page 15: Aquinas Hobor and Cristian Gherghina (National University of Singapore) TexPoint fonts used in EMF. Read the TexPoint manual before you delete this box.:

barrier (b, ¼, n)

The “is-a-barrier” assertion:

Means the current thread owns the (nonempty) share ¼ of the barrier b, currently in state n

15

Prerequisites ( extensions to Separation Logic)

Page 16: Aquinas Hobor and Cristian Gherghina (National University of Singapore) TexPoint fonts used in EMF. Read the TexPoint manual before you delete this box.:

x1 i b-state

Explaining a notation

16

Page 17: Aquinas Hobor and Cristian Gherghina (National University of Singapore) TexPoint fonts used in EMF. Read the TexPoint manual before you delete this box.:

Barriers in CSLProblem:

Encoding the reshuffling of permissions and the staging associated with barrier calls

Solution:State diagram with labeled transitions

Labels consist of pairs of pre/post conditions

17

Page 18: Aquinas Hobor and Cristian Gherghina (National University of Singapore) TexPoint fonts used in EMF. Read the TexPoint manual before you delete this box.:

18

Page 19: Aquinas Hobor and Cristian Gherghina (National University of Singapore) TexPoint fonts used in EMF. Read the TexPoint manual before you delete this box.:

Key Restrictions on Barrier Definitions

1. A barrier reshuffles It does not create resources Translated: For a given transition, the total

preconditions and postconditions must be equal modulo the barrier state change

19

x1 i b-state

Page 20: Aquinas Hobor and Cristian Gherghina (National University of Singapore) TexPoint fonts used in EMF. Read the TexPoint manual before you delete this box.:

Key Restrictions on Barrier Definitions

1. Threads always agree on the barrier stateDirections must be mutually exclusive:

one thread cannot go left while the other goes right

20

Page 21: Aquinas Hobor and Cristian Gherghina (National University of Singapore) TexPoint fonts used in EMF. Read the TexPoint manual before you delete this box.:

Hoare RulesThere are other technical restrictions on

barrier definitions but they are less interesting

Instead, we will present our Hoare rules

Actually, almost all of our rules are standardSkip, If, Sequence, While , Assign,

Consequence, Frame, Store, Load, New, Free

21

Page 22: Aquinas Hobor and Cristian Gherghina (National University of Singapore) TexPoint fonts used in EMF. Read the TexPoint manual before you delete this box.:

Barrier Rule

Lookup_move finds a pre/postcondition in the barrier state diagram

Actually, this rule is so simple that it seems false:

cs, ns, and ln seem free in the premises!

22

ns ln

Page 23: Aquinas Hobor and Cristian Gherghina (National University of Singapore) TexPoint fonts used in EMF. Read the TexPoint manual before you delete this box.:

Barrier Rule

This is not true: cs and ns are uniquely determined (the barrier is in some state, and recall mutual exclusion)

ln is not determined, but if more than one is possible, then the barrier will never end!

23

ns ln

Page 24: Aquinas Hobor and Cristian Gherghina (National University of Singapore) TexPoint fonts used in EMF. Read the TexPoint manual before you delete this box.:

24

Page 25: Aquinas Hobor and Cristian Gherghina (National University of Singapore) TexPoint fonts used in EMF. Read the TexPoint manual before you delete this box.:

25

Page 26: Aquinas Hobor and Cristian Gherghina (National University of Singapore) TexPoint fonts used in EMF. Read the TexPoint manual before you delete this box.:

The barrier call from line 13

26

bn {Q}

Γ(bn) = b

Page 27: Aquinas Hobor and Cristian Gherghina (National University of Singapore) TexPoint fonts used in EMF. Read the TexPoint manual before you delete this box.:

27

Page 28: Aquinas Hobor and Cristian Gherghina (National University of Singapore) TexPoint fonts used in EMF. Read the TexPoint manual before you delete this box.:

The barrier call from line 13

28

Page 29: Aquinas Hobor and Cristian Gherghina (National University of Singapore) TexPoint fonts used in EMF. Read the TexPoint manual before you delete this box.:

29

Page 30: Aquinas Hobor and Cristian Gherghina (National University of Singapore) TexPoint fonts used in EMF. Read the TexPoint manual before you delete this box.:

The barrier call from line 13

30

Page 31: Aquinas Hobor and Cristian Gherghina (National University of Singapore) TexPoint fonts used in EMF. Read the TexPoint manual before you delete this box.:

31

P

Q

Page 32: Aquinas Hobor and Cristian Gherghina (National University of Singapore) TexPoint fonts used in EMF. Read the TexPoint manual before you delete this box.:

The barrier call from line 13

32

Page 33: Aquinas Hobor and Cristian Gherghina (National University of Singapore) TexPoint fonts used in EMF. Read the TexPoint manual before you delete this box.:

SoundnessGiven:

a concurrent machineAn operational semantics defined for that

machineA Hoare rule is sound if:

Whenever a Hoare triple {P}c{Q} holds and Q is enough to ensure safety after c then all states satisfying P are safe

A state is safe if in none of the successor states, the machine blocks

33

Page 34: Aquinas Hobor and Cristian Gherghina (National University of Singapore) TexPoint fonts used in EMF. Read the TexPoint manual before you delete this box.:

Coq development

34

3,352

16,598

Page 35: Aquinas Hobor and Cristian Gherghina (National University of Singapore) TexPoint fonts used in EMF. Read the TexPoint manual before you delete this box.:

Take awayCommon barrier usage makes them an

implicitly statefull multiparty synchronization mechanism

We have introduced an amazingly simple Hoare rule for dealing with barrier calls

We have proven sound the Hoare rules

35