32
Implementing Sequentially Consistent Programs on Processor Consistent Platforms Lisa Higham and Jalal Kawash University of Calgary, Canada American University of Sharjah, UAE

Implementing Sequentially Consistent Programs on Processor Consistent Platforms Lisa Higham and Jalal Kawash University of Calgary, Canada American University

Embed Size (px)

Citation preview

Page 1: Implementing Sequentially Consistent Programs on Processor Consistent Platforms Lisa Higham and Jalal Kawash University of Calgary, Canada American University

Implementing Sequentially Consistent Programson Processor Consistent Platforms

Lisa Higham and Jalal Kawash

University of Calgary, Canada

American University of Sharjah, UAE

Page 2: Implementing Sequentially Consistent Programs on Processor Consistent Platforms Lisa Higham and Jalal Kawash University of Calgary, Canada American University

Outline

• Memory consistency models– Sequential consistency

– P-RAM

– Coherence

– PC-G

• Compiling from SC to PC-G– Good news

– Bad news

– Proof

Page 3: Implementing Sequentially Consistent Programs on Processor Consistent Platforms Lisa Higham and Jalal Kawash University of Calgary, Canada American University

Multi-Processor’s Computation

P P P P..……

Oo1o1o1o1

o2o2o2o2

o3o3o3o3

……

……..…..…

Page 4: Implementing Sequentially Consistent Programs on Processor Consistent Platforms Lisa Higham and Jalal Kawash University of Calgary, Canada American University

Sequential Consistency

P P P P..……

Switch

SharedMemory

Page 5: Implementing Sequentially Consistent Programs on Processor Consistent Platforms Lisa Higham and Jalal Kawash University of Calgary, Canada American University

Sequential Consistency: Example

P P P

x y

r(y) 4r(x) 2

w(x, 2)w(y, 1)

w(x, 3)w(y, 4)

w(x, 3)

w(y, 4)

r(y) 4

w(x, 2)

w(y, 1)

r(x) 2

0 0 0 0 0 03 42 1

Page 6: Implementing Sequentially Consistent Programs on Processor Consistent Platforms Lisa Higham and Jalal Kawash University of Calgary, Canada American University

Sequential Consistency: Definition

• A computation is sequentially consistent iff

a valid total order on O such that

(O, ) (O, )prog

Page 7: Implementing Sequentially Consistent Programs on Processor Consistent Platforms Lisa Higham and Jalal Kawash University of Calgary, Canada American University

P-RAM

Copies ofMemory

P

P

P

P

FIFOChannels

x y z x y z

x y z x y z

Page 8: Implementing Sequentially Consistent Programs on Processor Consistent Platforms Lisa Higham and Jalal Kawash University of Calgary, Canada American University

P-RAM: Example

w(x, 1)x 1x 1x 1

w(y, 2)

y 2y 2y 2P P

PP

P P P P

r(y) 2r(x) 0

r(x) 1r(y) 0

w(y, 2)w(x, 1)

0 0 0 021

0 0 0 021

0 0 0 021

0 0 0 021

r(x) 1r(y) 0r(y) 2r(x) 0

x y x y

x y x y

Page 9: Implementing Sequentially Consistent Programs on Processor Consistent Platforms Lisa Higham and Jalal Kawash University of Calgary, Canada American University

P-RAM Definition

A computation is P-RAM iff for each process p, a valid total order such that

(O|p O|w, ) (O|p O|w, )

Lp

∩prog

∩Lp

Page 10: Implementing Sequentially Consistent Programs on Processor Consistent Platforms Lisa Higham and Jalal Kawash University of Calgary, Canada American University

Coherence

x zy

P P P P…...

Page 11: Implementing Sequentially Consistent Programs on Processor Consistent Platforms Lisa Higham and Jalal Kawash University of Calgary, Canada American University

x 2 y 3

Coherence: Example

0 0

x y

P P P P

w(x, 2)r(y) 0 r(x) 0

w(y, 3)

2 3

w(x, 2)

r(y) 0

r(x) 0

w(y, 3)

P

Page 12: Implementing Sequentially Consistent Programs on Processor Consistent Platforms Lisa Higham and Jalal Kawash University of Calgary, Canada American University

Coherence: Definition

A computation is Coherent iff for each variable x, a valid total order such that

(O|x , ) (O|x , ) prog x

x

Page 13: Implementing Sequentially Consistent Programs on Processor Consistent Platforms Lisa Higham and Jalal Kawash University of Calgary, Canada American University

PC-G: P-RAM and Coherence

P-RAM CoherencePC-G

Page 14: Implementing Sequentially Consistent Programs on Processor Consistent Platforms Lisa Higham and Jalal Kawash University of Calgary, Canada American University

P-CG Definition

A computation is P-CG iff for each process p, a valid total order such that

– (O|p O|w, ) (O|p O|w, )

processes q, and variable x:

• (O|w ∩ O|x, ) = (O|w ∩ O|x, )

Lp

∩ prog∩

Lp

Lp Lq

Page 15: Implementing Sequentially Consistent Programs on Processor Consistent Platforms Lisa Higham and Jalal Kawash University of Calgary, Canada American University

P-CG vs. SC

• Algorithms are designed for SC machines

• Some of them work directly when run on

P-CG (e.g. Peterson 2)

• Most of the SC algorithms do not work on P-CG machines (e.g. test&set and Bakery algorithm)

Page 16: Implementing Sequentially Consistent Programs on Processor Consistent Platforms Lisa Higham and Jalal Kawash University of Calgary, Canada American University

• Can we transform an SC algorithm to an equivalent P-CG algorithm?

• Can we find a compiler that transforms any SC algorithm to an equivalent P-CG algorithm?

Page 17: Implementing Sequentially Consistent Programs on Processor Consistent Platforms Lisa Higham and Jalal Kawash University of Calgary, Canada American University

Program Transformation and Interpretation

ProgramP

Programα(P)

Transformationα Interpretation

D

C= {Computations of P on SC machines}D= {Computations of α(P) on M machines}E = {Interpretations of D on SC machines}

C EExecute P

on SC

Execute α(P)

on PC-G

Page 18: Implementing Sequentially Consistent Programs on Processor Consistent Platforms Lisa Higham and Jalal Kawash University of Calgary, Canada American University

Program Implementation

ProgramP

Programα(P)

Transformationα

C E

Interpretation

D

C= {SC Computations of P}D= {P-CG Computations of α(P)}E = {Interpretations of D}

If program P, α implements P, then α is a compiler from SC to PC-G

Execute P

on SC

Execute α(P)

on PC-G

Page 19: Implementing Sequentially Consistent Programs on Processor Consistent Platforms Lisa Higham and Jalal Kawash University of Calgary, Canada American University

Transformation Function α

m: a new multi-writer variable

Instruction α(Instruction)

write(sy, val) write(m, id(y)); write(sy, val); write(m, id(y))

read(sy) read(sy)

Page 20: Implementing Sequentially Consistent Programs on Processor Consistent Platforms Lisa Higham and Jalal Kawash University of Calgary, Canada American University

Results

• Claim 1: implements Lamport’s Bakery algorithm for

2 processes on PC-G

• Claim 2: is a compiler from SC to PC-G for any

program provided:• Only 2 processes• Only single-writer variables

Page 21: Implementing Sequentially Consistent Programs on Processor Consistent Platforms Lisa Higham and Jalal Kawash University of Calgary, Canada American University

Transformation Example

P P

w(x, 1)

r(y)

w(y, 4)

w(y, 2)

r(x)

Program

Under SC: if r(y) returns 4, then r(x) returns 1

Possible PC-G Views

P P

w(x, 1)w(y, 4)r(y) 4w(y, 2)

w(y, 4)w(y, 2)r(x) 0w(x, 1)

Under PC-G: r(y) returns 4 and r(x) may return 0

Page 22: Implementing Sequentially Consistent Programs on Processor Consistent Platforms Lisa Higham and Jalal Kawash University of Calgary, Canada American University

Transformation ExampleProgram(Program)

P P

w(x, 1)

r(x)

w(y, 4)

r(y)w(y, 2)w4(m, P)

w1(m, P)

w2(m, P)

w1(m, P)

w2(m, P)w3(m, P)

Page 23: Implementing Sequentially Consistent Programs on Processor Consistent Platforms Lisa Higham and Jalal Kawash University of Calgary, Canada American University

Transformation ExampleP P

r(x)

r(x) must return 1

w(x, 1) w(y, 4)

w(y, 2)

View for View for

w1(m, P)

w2(m, P)

w3(m, P)

w4(m, P)

w1(m, P)

w2(m, P)

If r(y) returns 4

w(x, 1) w(y, 4)

w(y, 2)

w1(m, P)

w2(m, P)

w3(m, P)

w4(m, P)

w1(m, P)

w2(m, P)

r(y)

Page 24: Implementing Sequentially Consistent Programs on Processor Consistent Platforms Lisa Higham and Jalal Kawash University of Calgary, Canada American University

m

m

m

m

m

m

Proof Sketch

P P

w1w

w2

..…

..…m1

m5

m2

m3

m4

m6

Program

P P

PC-G Views

m1

m5

m2

m3

m4

m6

ww1

w2

System View

m1

m5

m2

m3

m4

m6

ww1

w2

…..

m2

m3

m4

m6

m1

m5

Page 25: Implementing Sequentially Consistent Programs on Processor Consistent Platforms Lisa Higham and Jalal Kawash University of Calgary, Canada American University

Proof Sketch

• System view– Contains all reads and writes by both processes– Maintains program order– Is valid

Page 26: Implementing Sequentially Consistent Programs on Processor Consistent Platforms Lisa Higham and Jalal Kawash University of Calgary, Canada American University

Summary

Compiler:

• Only one additional variable

• Only writes to that variable

Provided:

• Two processors

• Single writer variables

Page 27: Implementing Sequentially Consistent Programs on Processor Consistent Platforms Lisa Higham and Jalal Kawash University of Calgary, Canada American University

Impossibilities

For more than 2 processors, there is no compiler from SC to PC-G that:

• Only adds write instructions (with any number of variables)

nor• Uses only one additional variable (with any

number of reads and writes)

Page 28: Implementing Sequentially Consistent Programs on Processor Consistent Platforms Lisa Higham and Jalal Kawash University of Calgary, Canada American University

Pros and Cons

• Restricted– 2 processes– Only single writer variables

• Valuable– ME Lamport’s Bakery algorithm– Wait-free test&set had no known solutions in

weak memory consistency

Page 29: Implementing Sequentially Consistent Programs on Processor Consistent Platforms Lisa Higham and Jalal Kawash University of Calgary, Canada American University

Wait-Free Test&setDefine test&set<(Ω, i)>

if (si = you and sj ≠ rst) the return 1

repeat

si choose

case sj is:

you, rst:

si me

me :

si you

choose:

si random (me, you)

end case

until (si ≠ sj)

if (si = me) then return 0

else return 1

m i

m i

m i

m i

m i

m i

m i

m i

Define reset<(Ω, i)>

si rst

Page 30: Implementing Sequentially Consistent Programs on Processor Consistent Platforms Lisa Higham and Jalal Kawash University of Calgary, Canada American University

Conclusions

• α works for any two-process program withsingle-writer variables

• α works for particular programs with > 2 processes (randomized wait-free n-process test&set)

• If there is a transformation that work for other cases, it must be more complicated:– Cannot be write-adding– Must use more than one additional variable

Page 31: Implementing Sequentially Consistent Programs on Processor Consistent Platforms Lisa Higham and Jalal Kawash University of Calgary, Canada American University

Thank You

?

Page 32: Implementing Sequentially Consistent Programs on Processor Consistent Platforms Lisa Higham and Jalal Kawash University of Calgary, Canada American University

m

m

m

m

m

m

Proof Sketch

P P

w1w

w2

..…

..…m1

m5

m2

m3

m4

m6

Program

P P

PC-G Views

m1

m5

m2

m3

m4

m6

..

m2

m3

m4

m6

m1

m5

w

w1

w2

System View

m1

m5

m2

m3

m4

m6

ww1

w2