Title: Speculative N-Way Barriers
1Speculative N-Way Barriers
- Lukasz Ziarek, Suresh Jagannathan
- Purdue University
- Mathew Fluet, Umut Acar
- TTI Chicago
2Speculation
- 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?
3Programming 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
4Motivating 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
5Motivating Example All Pairs Shortest Path
2nd iteration
1st iteration
T1
T2
T1 dependant on T2,T3,T4
T3
T4
6Motivating 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
7Solution 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
8Representing N-Way Barriers
match(P) gt e
- Patterns (P)
- Rd(l) read of location l
- Wr(l) write of location l
- Wr(l, v) write of v to l
- Wr?(l, v) write of v to l
- if l does not already contain v
9Representing N-Way Barriers
match(P) gt e
- 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() gt e spawn (e)
10Speculative 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
11Example Program
T1 match(wr(x) wr(y)) gt !x !y !z
T2 x 1 T3 z
3 y 2 y 42
12Synchronous Execution
T1
T2
T3
z3
BLOCKED
T4
y2
Satisfied
!x 1 !y 2 !z 3
y42
13Speculative Execution
T1
T2
T3
sx-gt1, y-gt2, z-gt3
z3
!x 1 !y 2 !z 3
y2
T4
Validate
y42
14Speculative Execution Requiring Rollback
T1
T2
T3
sx-gt1, y-gt2, z-gt3
z3 y2
!x 1 !y 2 !z 3
y42
T4
Validate
15Potential for Self Satisfying Code
T1
match(wr(x) wr(y))gt !xy2!z
T2
!x y 2 !z
x1
Validate
16Time Travel
T3
T1
T2
match(wr(x) wr(y))
x2
match(wr(x) wr(y))
y4
Validate
!x y 2 !z
x1
T4
17So 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
18Formalization
- 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
19Related Work
- Compiler/Architecture Driven Speculation
- Safe Futures
- Software Transactions
- Join Calculus
- Fork/Join parallelism (Cilk)
20Conclusion
- Provided a Formal Definition of Unconstrained
Speculation in a Multithreaded Context - Proved Speculative Semantics Adhere to
Synchronous Semantics
21Questions?