Show HN: Warpspec – TLA+ model checking on a GPU, 4,600× faster than TLC Developer Praveen Perera released warpspec, an Apache-2.0 TLA+ model checker that compiles a spec and its TLC config into a bit-packed no_std Rust state machine and searches the state graph on an NVIDIA GPU or across CPU cores, reporting 0.121 s on EWD998 (N = 4) versus 401.5 s for TLC on 24 workers. On LamportMutex (N = 4, maxClock = 5) warpspec ran in 0.473 s against TLC's 1,824 s, and on PaxosCommit (RM = 3) in 3.65 s against TLC's 4 h 40 min, with warpspec reporting identical distinct-state, generated-state and search-depth counts to TLC on every model both checkers finished. Across the 191 exhaustive-search configs in tlaplus/Examples, warpspec compiles 152 with no wrong counts or verdicts against TLC and refuses the other 39 at compile time. I’ve been looking for workloads outside AI where a single desktop GPU makes a real difference, and TLA+ model checking stood out. Checking a distributed protocol spec means exploring millions or billions of reachable states, and most of that work is parallel. I built warpspec https://github.com/praveenperera/warpspec to test whether putting it on a GPU actually works. It compiles a TLA+ spec and its TLC config into a fixed-size, bit-packed no std Rust state machine, then searches the state graph on an NVIDIA GPU or across every core of a CPU. Both run the exact same generated code, print TLC-format counterexample traces on safety or deadlock failures, and on the CPU check temporal liveness and fairness too. It’s Apache-2.0 licensed. My rule from the start was that speed doesn’t count unless the answers match TLC. For every model both checkers finished, warpspec reports the exact same number of distinct states, generated states, and search depth. | Model | Distinct states | TLC 24 workers | Generated CPU 24 threads | RTX 5090 | |---|---|---|---|---| | EWD998, N = 4 | 248,006,200 | 401.5 s | 5.93 s | 0.121 s | | LamportMutex, N = 4, maxClock = 5 | 561,679,480 | 1,824 s | 16.55 s | 0.473 s | | PaxosCommit, RM = 3 | 1,357,590,081 | 4 h 40 min | 74.9 s | 3.65 s | | KeyValueStore MCKVSSafetyLarge | 594,616,815 | not run | not run | 3.93 s | | EWD998, N = 4, pending ≤ 5 | 2,127,805,446 | not run | not run | 3.91 s | The CPU and GPU columns are search time; TLC’s are its reported totals with its default fingerprint set switching TLC to its off-heap fingerprint set brings EWD998 N = 4 down to 330.1 s . I didn’t run TLC on the last two rows, and they don’t fit in the CPU checker’s memory on this machine. I explain how their counts were checked below fitting-2-billion-states-in-32-gb . Two things surprised me while building this. First, the flat state layout does a huge part of the work before a GPU is even involved: packing each state into a few 64-bit integers makes the generated code 13× to 73× faster than tla-mc ’s compiled Rust checker on the same 24 CPU cores. Second, the obvious GPU kernel was way too slow only 3.6× over 24 CPU cores on LamportMutex until I changed its structure. Now each thread first works out which actions can fire, then builds those next states one at a time and passes every one through the same short piece of code that hashes and stores it. That jumped it to 26.9×. Across the 191 exhaustive-search configs in tlaplus/Examples , warpspec compiles 152 with no wrong counts or verdicts against TLC, and refuses the other 39 at compile time. Table of Contents Where model checkers spend their time At a high level, TLC runs breadth-first search. It computes the starting states, then walks through the state graph one level at a time. For each state, it runs Next to find every possible next state, checks the invariants on each new one, and stores a 64-bit hash fingerprint in a set of states already seen. It stops when a level produces nothing new. The graph search itself is cheap. Almost all the time goes into evaluating the spec. TLC interprets TLA+ over dynamically typed values, where any variable can hold a nested mix of sets, records, functions, and sequences. That flexibility lets TLC check almost any spec you write without asking for types. On EWD998 with N = 4, a Java Flight Recorder profile of TLC on 24 workers showed 76% of samples in computing next states and 22% in hashing and checking the seen-states set. The state queue was 0.4%. tla-mc https://github.com/ddalton/tla-mc compiles TLA+ to Rust, which gets rid of the interpreter. It’s much faster than TLC: 76.7 s against 401.5 s on EWD998 N = 4, and 36.3 s against 101 s on PaxosCommit with four acceptors. everystate https://github.com/mattzcarey/everystate , a Rust TLA+ checker that runs directly with no compile step and ships on npm with no Java needed , beats TLC too: 280.2 s against 401.5 s on EWD998 N = 4, and 88.3 s against 101 s on PaxosCommit with four acceptors. Both still keep a dynamic value representation so they can run general TLA+, and that sets their speed ceiling. I profiled tla-mc and warpspec on PaxosCommit with RM = 2 the tlaplus/Examples config, 1,321,761 distinct states on a single thread. tla-mc took 26.9 s, everystate 0.4.6 took 25.8 s, and warpspec’s generated CPU code took about 0.5 s. Under callgrind, tla-mc ran 424.0 billion instructions to the generated code’s 4.82 billion, about 27,800 instructions per next state versus 284. Here’s where tla-mc’s instructions went inclusive, so the rows overlap : | Work | Share | What tla-mc does | What warpspec’s code does | |---|---|---|---| | Hashing next states | 31.9% | Walks the whole value tree, including every record in the message set, about 5,460 instructions per call | Hashes three 64-bit integers | | Set membership | 18.8% | Linear scan comparing values across the message set | Tests one bit | | Checking PCTypeOK | 15.0% | Walks nested functions and records | Checks bit-packed fields | | Building new values | about 18% | Allocates records, merges sets, and updates copies | Sets bits in a copy of the state | | Storing states | about 14% | Encodes and decodes dynamic values for the state store | Copies three integers | Memory allocation is 8.3% of the total and sits mostly inside the value-building work. There’s no single slow function you could patch away. PaxosCommit’s msgs variable is a set of records that grows as the protocol runs, so hashing, membership checks, and copying all get slower as it grows. A bitset does each of those in a few CPU instructions. warpspec gives up checking every TLA+ spec so each state fits in a fixed number of 64-bit integers. Packing a spec into fixed integers The generator, tla-gpu-gen , takes a TLA+ spec and a TLC config and writes one Rust file. It reuses tla-mc’s lexer, parser, and module loader; everything after the syntax tree is new. First, it evaluates every constant from the config file ahead of time. With RM = {r1, r2, r3} and Ballot = {0, 1} , a set like PaxosCommit’s Message turns into a fixed, finite list of records the generator can number. Next, it needs a fixed type for every variable. It pulls that from a TypeOK invariant the v \in S lines most TLC users already write . If there isn’t one, it starts from the values in Init and expands them with whatever Next assigns until they stop growing. PaxosCommit’s type invariant looks like this: php PCTypeOK == /\ rmState \in RM - {"working", "prepared", "committed", "aborted"} /\ aState \in RM - Acceptor - mbal : Ballot, bal : Ballot \cup {-1}, val : {"prepared", "aborted", "none"} /\ msgs \in SUBSET Message Each type turns into a fixed-width field: - Integers are shifted to start at zero and packed into just enough bits for their range in TypeOK , Init , or a CONSTRAINT . If one end has no bound, warpspec reserves 5 bits by default --int-bits and checks every write at runtime. Anything out of range stops the run with encoding overflow instead of wrapping silently. - Model values and strings from a finite set become enums. - Records and fixed-key functions flatten into one field per key. - Finite sets become bitsets with one bit per possible member. - Sequences need a length bound like Len s <= k and turn into a length field plus k packed slots. The generator packs those fields, largest first, into an array of 64-bit integers u64 words . For PaxosCommit with two resource managers, Message has 144 possible records, so msgs is a 144-bit bitset and the entire state fits in three 64-bit words. The generator writes the layout as a comment at the top of each generated file: Layout, 3 words: - word 0 bit 0: msgs set bits 0..64 : 64 bits - word 1 bit 0: msgs set bits 64..128 : 64 bits - word 2 bit 0: msgs set bits 128..144 : 16 bits - word 2 bit 16: rmState r1 : 2 bits - word 2 bit 18: rmState r2 : 2 bits - word 2 bit 20: aState r1 a1 .bal: 2 bits - word 2 bit 22: aState r1 a1 .val: 2 bits ... - word 2 bit 49: aState r2 a3 .mbal: 1 bits With three resource managers, Message has 215 members and the state is five words, 40 bytes total. Adding a known message to msgs is one bitwise OR, and checking whether it’s already there is one bitwise AND. EWD998 with three nodes fits in 35 bits of a single 64-bit integer. Its counters have no lower bound in the spec, so the generator reserves room down to -28 and checks for overflow on every update: - word 0 bit 0: counter 0 : 5 bits - word 0 bit 5: counter 1 : 5 bits - word 0 bit 10: counter 2 : 5 bits - word 0 bit 15: token.q: 5 bits - word 0 bit 20: pending 0 : 2 bits ... - word 0 bit 34: token.color: 1 bits LamportMutex was the trickiest benchmark state to pack. Its network variable is a nested map of FIFO channels, one per pair of nodes, each holding type, clock records. With BoundedNetwork capping each channel at three messages, each channel packs into 17 bits, and the whole N = 4 state fits in six words, 48 bytes. When I laid it out by hand earlier, I needed eight words. Once the layout is fixed, the generator evaluates each action ahead of time with only the current state left as a runtime input. Anything constant disappears, and what’s left compiles down to plain Rust bit math over the state array. It also tracks the min and max possible value of each integer as it goes, so any comparison whose answer is already known gets dropped too. Here is part of EWD998’s PassToken 1 builder: js 1 = 'b: { let v48: u64 = s 0 15 & 0x1f; let v49: i64 = v48 as i64 + -22; let v54: u64 = s 0 5 & 0x1f; let v55: i64 = v54 as i64 + -28; let v58: i64 = v49.wrapping add v55 ; // ... if v58 <= 9 { break 'b 1 << 2 | CONSTRAINED; } if v51 = 0 && v51 <= 2 && v58 = -22 { break 'b 1 << 2 | OVERFLOW; } t 0 = t 0 & 0xf8000 | v58 - -22 as u64 << 15 ; // ... } The builders never allocate, and every function is inline always . Each state is just a Copy array, u64; W . That same generated file compiles for both the CPU driver and the GPU kernel crate. Matching TLC’s generated-state count turned out to be trickier than matching distinct states. When a TLA+ action branches on \/ , \E , x' \in S , IF , or CASE , TLC counts a next state once for every branch that produces it, even if two branches produce the exact same state. My first PaxosCommit model matched TLC’s distinct states and depth, but generated 16,375,079 states against TLC’s 16,959,159. TLC even forks on an \E nested inside an \A in an action. When a branch only checks a condition and doesn’t assign any next-state x' variables, the generator now turns it into a check plus a branch count, and emits that next state once per matching branch so the totals match TLC. The same code on the CPU The CPU driver runs that same generated file on std threads, using the same flat hash table design as the GPU. On the same 24 cores, against tla-mc’s compiled checker check time only : | Model | tla-mc compiled | Generated CPU | Ratio | |---|---|---|---| | EWD998, N = 4 | 76.7 s | 5.93 s | 13× | | LamportMutex, N = 4, maxClock = 5 | 402.9 s | 16.55 s | 24× | | PaxosCommit, RM = 2, 4 acceptors | 36.3 s | 0.717 s | 51× | | PaxosCommit, RM = 3 | 5,460 s | 74.9 s | 73× | The gap is smallest on EWD998, which has no sets in its state, and largest on PaxosCommit, where msgs dominates. tla-mc agrees with TLC on distinct states and depth for all of these. Its generated-state count is lower on PaxosCommit and EWD998 because it doesn’t count the extra branches TLC forks on. That’s just a counting difference and doesn’t change which states get explored. I also timed everystate https://github.com/mattzcarey/everystate 0.4.6 -workers 24 , wall time on this same 24-core machine. It matched TLC’s exact distinct, generated, and depth counts on every run with no compile step: | Model | Distinct states | everystate 24w | warpspec CPU 24t | warpspec RTX 5090 | |---|---|---|---|---| | EWD998, N = 4 | 248,006,200 | 280.2 s 11.8 GiB | 5.93 s 47× | 0.121 s 2,316× | | PaxosCommit, RM = 2, 4 acceptors | 21,180,165 | 88.3 s 22.9 GiB | 0.717 s 123× | 0.018 s 4,900× | | LamportMutex, N = 4, maxClock = 4 | 37,706,250 | 46.6 s 4.4 GiB | 0.858 s 54× | 0.0345 s 1,350× | Because everystate keeps its multi-worker fingerprints and shared values in memory 40 to 65 bytes per distinct state, plus shared values, which hit 22.9 GiB on 21.2M-state PaxosCommit and crossed 30 GiB partway through 562M-state LamportMutex , the larger runs don’t fit comfortably in this machine’s 56 GB of RAM. On models that do fit, compiling down to flat integers puts warpspec 47× to 123× ahead on the same 24 CPU cores and 1,350× to 4,900× ahead on the RTX 5090 the LamportMutex maxClock = 4 warpspec times above are from the hand-written model in the next section; the generated layout is smaller and faster . Why the obvious GPU kernel was slow I wrote the first GPU kernels before the generator existed, against hand-written models of EWD998 and LamportMutex. The whole point was to see whether a GPU would stay far enough ahead of the exact same compiled code running on 24 CPU cores. The kernels are written in Rust and compiled to PTX NVIDIA’s GPU assembly with cuda-oxide https://github.com/NVIDIA/cuda-rust from NVIDIA/cuda-rust . Each GPU thread takes one state from the current frontier and expands it. For every next state it finds, it computes the fingerprint, tries to insert it into a hash table with a 64-bit compare-and-swap, and if the state is new, checks the invariants and appends it to the next frontier. On EWD998 at N = 4, the GPU was 48× faster than the hand-compiled CPU code on 24 threads. My hand-written N = 4 EWD998 state fit in 61 bits of a single integer, though, so it could act as its own hash key with no hashing and no multi-word memory reads. Before building a full compiler, I set a kill bar on LamportMutex, with its 64-byte state and channels of records: if the GPU couldn’t beat 24 CPU cores by at least 10×, I’d stop. The first LamportMutex kernel ran the hash, table-insert, and append code directly inside each of the 28 action branches. That’s the natural way to write it for a CPU. On N = 4, maxClock = 4, the GPU was only 3.8× faster than the CPU. Profiling with Nsight Compute ncu made the problem obvious: duplicating that insert code across all 28 actions blew out the GPU’s instruction cache. Warps spent about 95% of their time stalled waiting to fetch instructions, fewer than 4 of the 32 threads in a warp were active on average, and memory bandwidth sat under 2%. The fix was to split each step in two and funnel every next state through one shared output path. First, each thread checks which actions can fire and packs the results into a bitmask. Then it loops over the set bits, builds each next state in registers, and passes it to a single piece of code that hashes and stores it. That’s the shape the generator writes: php pub fn successors