210 likes | 301 Views
Speculative N-Way Barriers. Lukasz Ziarek, Suresh Jagannathan Purdue University Mathew Fluet, Umut Acar TTI Chicago. Speculation. Performance Tool for better utilization of multi-core processors Highly constrained Short lived Isolated Few side effects, if any Rarely formalized
E N D
Speculative N-Way Barriers Lukasz Ziarek, Suresh Jagannathan Purdue University Mathew Fluet, Umut Acar TTI Chicago
Speculation • Performance • Tool for better utilization of multi-core processors • Highly constrained • Short lived • Isolated • Few side effects, if any • Rarely formalized • Can we safely relax these limitations?
Programming Model • Higher Order Concurrent Language • References • N-way barriers • Synchronization point of n interacting threads • Fork/Join execution model • Threads operate over local heaps • Easier to reason about speculation • Heaps merged at join points (barriers) • N-way barriers server as a communication medium
Motivating Example –All Pairs Shortest Path • Utilizes a matrix representation for a DAG • Partitions the matrix into smaller units • Each worker thread operates on disjoint partitions • All workers synchronize on an n-way barrier
Motivating Example –All Pairs Shortest Path 2nd iteration 1st iteration T1 T2 T1 dependant on T2,T3,T4 T3 T4
Motivating Example –All Pairs Shortest Path • Observation : • Each thread is only dependant on the work done by a fix number of threads in a previous iteration • Solution 1: • Rewrite the algorithm • Algorithmic Complexity • Specialized Barriers and Counters • Results in ~6x more code
Solution 2 :Optimistic Concurrency • Utilize Speculation • Requires no change to the underlying core algorithm • Allows for the extraction of additional concurrency • Challenges • Maintaining a consistent view of memory • Interacting speculations
Representing N-Way Barriers • Patterns (P) • Rd(l) : read of location l • Wr(l) : write of location l • Wr(l, v) : write ofvto l • Wr?(l, v) : write of v to l if l does not already contain v match(P) => e
Representing N-Way Barriers • Barriers (match(…)) • Each thread that matches a base pattern blocks until the entire pattern is satisfied • Thread which creates the barrier does not block • Guarded Expressions (e) • e delayed until completion of pattern • Executed in separate thread of control • can be utilized to encode spawn • match() => e : spawn (e) match(P) => e
Speculative Execution Model • Allow Speculation Past Barriers • Execute guarded expression speculatively • Participating threads proceed • Speculate a thread local store • Validate When Last Thread Participates in the Barrier • Confirm thread local store
Example Program T1 = … match(wr(x) ^ wr(y)) => !x; !y; !z; … T2 = … x := 1; … T3 = … z := 3; y := 2; y := 42;
match(wr(x)^wr(y)) => !x;!y;!z x:=1; Synchronous Execution T1 T2 T3 z:=3; BLOCKED T4 y:=2; Satisfied !x; 1 !y; 2 !z; 3 y:=42;
match(wr(x)^wr(y))=> !x;!y;!z x:=1; Speculative Execution T1 T2 T3 σ[x->1, y->2, z->3 ] z:=3; !x; 1 !y; 2 !z; 3 y:=2; T4 Validate y:=42;
match(wr(x)^wr(y))=> !x;!y;!z x:=1; Speculative Execution Requiring Rollback T1 T2 T3 σ[x->1, y->2, z->3 ] z:=3; y:=2; !x; 1 !y; 2 !z; 3 y:=42; T4 Validate
Potential for Self Satisfying Code T1 match(wr(x) ^ wr(y))=> !x;y:=2;!z T2 !x; y:= 2; !z; x:=1; Validate
Time Travel T3 T1 T2 match(wr(x) ^ wr(y)) x:=2; match(wr(x) ^ wr(y)) y:=4; Validate !x; y:= 2; !z; x:=1; T4
So how DO we choose a store? • Observation 1 : • Only need to estimate what we need and what has changed • Observation 2 : • Each thread participating in the pattern contributes at least 1 value • Observation 3: • Patterns which specify a value for a location guide our choice • Observation 4: • The more threads blocked on a barrier the more we know about the speculation context
Formalization • Synchronous Semantics • Speculative Semantics • Trace • Allows for the bridging of the speculative and synchronous semantics • Speculative Semantics composed of a committed trace and a speculative trace • Validated speculative actions are committed • Validation is done one thread at a time
Related Work • Compiler/Architecture Driven Speculation • Safe Futures • Software Transactions • Join Calculus • Fork/Join parallelism (Cilk)
Conclusion • Provided a Formal Definition of Unconstrained Speculation in a Multithreaded Context • Proved Speculative Semantics Adhere to Synchronous Semantics