Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "Implementing Sequentially Consistent Programs on Processor Consistent Platforms Lisa Higham and Jalal Kawash University of Calgary, Canada American University."— Presentation transcript:

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

2 Outline Memory consistency models –Sequential consistency –P-RAM –Coherence –PC-G Compiling from SC to PC-G –Good news –Bad news –Proof

3 Multi-Processor’s Computation PPPP..…… O o1o1 o1o1 o1o1 o1o1 o2o2 o2o2 o2o2 o2o2 o3o3 o3o3 o3o3 o3o3 ……..…

4 Sequential Consistency PPPP..…… Switch Shared Memory

5 Sequential Consistency: Example PPP xy r(y) 4 r(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 0000003421

6 Sequential Consistency: Definition A computation is sequentially consistent iff  a valid total order on O such that (O, )  (O, ) prog

7 P-RAM Copies of Memory P P P P FIFO Channels xyzxyz xyzxyz

8 P-RAM: Example w(x, 1) x  1 w(y, 2) y  2 P P P P PPPP r(y) 2 r(x) 0 r(x) 1 r(y) 0 w(y, 2)w(x, 1) 000021 000021 000021 000021 r(x) 1 r(y) 0 r(y) 2 r(x) 0 xy xy xy xy

9 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

10 Coherence x z y PPPP …...

11 x  2y  3 Coherence: Example 00 x y P PPP w(x, 2) r(y) 0r(x) 0 w(y, 3) 23 w(x, 2) r(y) 0 r(x) 0 w(y, 3) P

12 Coherence: Definition A computation is Coherent iff for each variable x,  a valid total order such that (O| x, )  (O| x, ) progx x

13 PC-G: P-RAM and Coherence P-RAM Coherence PC-G

14 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 Lq

15 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)

16 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?

17 Program Transformation and Interpretation Program P 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 E Execute P on SC Execute α(P) on PC-G

18 Program Implementation Program P 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

19 Transformation Function α m: a new multi-writer variable Instructionα(Instruction) write(s y, val)write(m, id(y)); write(s y, val); write(m, id(y)) read(s y )

20 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

21 Transformation Example PP 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 PP w(x, 1) w(y, 4) r(y) 4 w(y, 2) w(y, 4) w(y, 2) r(x) 0 w(x, 1) Under PC-G: r(y) returns 4 and r(x) may return 0

22 Transformation Example Program  (Program) PP w(x, 1) r(x) w(y, 4) r(y) w(y, 2) w 4 (m, P) w 1 (m, P) w 2 (m, P) w 1 (m, P) w 2 (m, P) w 3 (m, P)

23 Transformation Example P P r(x) r(x) must return 1 w(x, 1)w(y, 4) w(y, 2) View for w 1 (m, P) w 2 (m, P) w 3 (m, P) w 4 (m, P) w 1 (m, P) w 2 (m, P) If r(y) returns 4 w(x, 1)w(y, 4) w(y, 2) w 1 (m, P) w 2 (m, P) w 3 (m, P) w 4 (m, P) w 1 (m, P) w 2 (m, P) r(y)

24 m m m m m m Proof Sketch PP w1w1 w w2w2..… m1m1 m5m5 m2m2 m3m3 m4m4 m6m6 Program PP PC-G Views … m1m1 m5m5 m2m2 m3m3 m4m4 m6m6 w w1w1 w2w2 System View … m1m1 m5m5 m2m2 m3m3 m4m4 m6m6 w w1w1 w2w2 ….. m2m2 m3m3 m4m4 m6m6 m1m1 m5m5

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

26 Summary Compiler: Only one additional variable Only writes to that variable Provided: Two processors Single writer variables

27 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)

28 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

29 Wait-Free Test&set Define test&set if (s i = you and s j ≠ rst) the return 1 repeat s i  choose case s j is: you, rst: s i  me me : s i  you choose: s i  random (me, you) end case until (s i ≠ s j ) if (s i = me) then return 0 else return 1 m  i Define reset s i  rst

30 Conclusions α works for any two-process program with single-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

31 Thank You?Thank You?

32 m m m m m m Proof Sketch PP w1w1 w w2w2..… m1m1 m5m5 m2m2 m3m3 m4m4 m6m6 Program PP PC-G Views … m1m1 m5m5 m2m2 m3m3 m4m4 m6m6.. m2m2 m3m3 m4m4 m6m6 m1m1 m5m5 w w1w1 w2w2 System View … m1m1 m5m5 m2m2 m3m3 m4m4 m6m6 w w1w1 w2w2 …


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

Similar presentations


Ads by Google