SentryWard: Formal Verification of Warp-Specialized GPU Kernels
For a long time, GPU kernels were uniform data-parallel programs: every thread in a block ran the same code on its own part of the data. On modern architectures such as NVIDIA’s Hopper and Blackwell, matrix multiplication and data movement run on specialized units, the tensor cores and the Tensor Memory Accelerator (TMA), and these units work asynchronously: a thread only starts an operation, and the unit finishes it later.
To reach peak performance, a kernel must keep these units busy at the same time, loading the next tile while computing on the current one. High-performance kernels therefore give different warps different roles, such as loading, computing, and storing results. This style is called warp specialization, and the warps coordinate through barriers that wait for asynchronous operations to finish.
Such a kernel is a concurrent program, and its behavior can differ across schedules. A synchronization error may corrupt the output only under particular schedules, and random testing, which samples only the schedules that occur at run time, may miss it. Moreover, even with correct synchronization, a kernel can compute the wrong function because of a logic error.
SentryWard is a verifier for warp-specialized GPU kernels. Given a kernel’s PTX, a launch configuration, and an optional PyTorch reference, it can establish the following properties for that configuration and within its model:
- Synchronization and deadlock freedom. Barriers and mbarriers, including TMA byte counts, behave consistently across schedules, and no execution deadlocks.
- Data-race freedom. Conflicting accesses to global, shared, and tensor memory are ordered, including asynchronous copies and tensor-core operations.
- Resource lifetime safety. Tensor memory and barriers are never used after they are freed or invalidated.
- Mathematical correctness. When a reference is provided, the kernel computes the same function as the PyTorch reference in real arithmetic.
- Safe synchronization removal. After a candidate synchronization operation is removed, SentryWard can verify that the modified kernel still satisfies the required correctness properties for the specified input shape and launch configuration.
SentryWard found issues in popular kernel libraries; we describe three of them below. Across 44 kernels, removing synchronization that it shows to be redundant cuts kernel time by a median of 3–7.5%, depending on the input size. In this post, we look at how warp-specialized kernels synchronize, what can go wrong, and how SentryWard checks them.
Inside a warp-specialized kernel
Mbarrier operations
A block-wide barrier such as __syncthreads() makes all threads of a block wait for each other, but it does not wait for asynchronous copies or matrix multiplications to finish. Warp-specialized kernels therefore synchronize through mbarriers, barrier objects in shared memory with two counters: the pending arrivals and the pending bytes that the barrier still expects. Threads arrive on the barrier, and asynchronous copies report the bytes they deliver. When both counters reach zero, the current phase completes: the threads waiting for it proceed, and the barrier starts the next phase with its counters reset. We write a barrier’s state as (pending arrivals, pending bytes). For example, a barrier that expects one arrival starts at (1, 0); after a thread announces 32 KB and arrives, it is at (0, 32 KB), and once copies have delivered all 32 KB, it reaches (0, 0) and the phase completes.
The table below specifies each operation in our pseudocode, writing \(p\) for the phase number, \(n\) for the expected arrivals per phase, \(a\) for the pending arrivals, and \(b\) for the pending bytes (announced minus completed). It follows NVIDIA’s mbarrier, TMA copy, and tcgen05.commit specifications, without scope qualifiers and fences.
| Interface | Specification |
|---|---|
init(bar, n) | Initialize the barrier with a positive arrival count \(n\), setting \((p,a,b)=(0,n,0)\). Initialization must happen before any other use. |
arrive(bar) | With \(a>0\), record one arrival: \(a \leftarrow a-1\). The caller continues without waiting for the phase to complete. |
expect_tx(bar, bytes) | Announce additional bytes: \(b \leftarrow b+\mathit{bytes}\). This neither records an arrival nor initiates a transfer. |
arrive.expect_tx(bar, bytes) | With \(a>0\), announce \(\mathit{bytes}\), then record one arrival. The byte expectation is added before the arrival can complete the phase. |
wait(bar, parity) | Wait for completion of the phase identified by \(\mathit{parity}=p_{\mathrm{target}}\bmod 2\). This is a loop over PTX parity tests, not a single blocking instruction; it changes neither counter. |
tma_load(dst ← src, bar) | Issue an asynchronous copy from global to shared memory. As the copy completes, the hardware subtracts the transferred bytes from \(b\) via completion notifications. Expected bytes must be announced separately; the copy does not decrement \(a\). |
tcgen05.commit(bar) | Arrange one asynchronous arrival after this thread’s preceding mbarrier-tracked tcgen05 operations complete—the MMA in our example. The notification decrements \(a\) by one; issuing the commit does not wait for completion. |
A running example
Our running example is a small warp-specialized kernel on a Blackwell GPU that computes one tile of a matrix multiplication \(C = AB\). A large matrix multiplication is usually split into such tiles, one per thread block. Each thread block computes its \(M \times N\) tile of \(C\) in a loop over the shared dimension \(K\), multiplying a block of \(A\) by a block of \(B\) in each iteration. The loop is software-pipelined: while the tensor core operates on the current blocks, the TMA prefetches those for subsequent iterations. After the loop, the epilogue stores the accumulated tile to \(C\) in global memory. Our example runs a single iteration, with \(M = N = 128\) and \(K = 64\); with 16-bit elements, each input tile is 16 KB.
The kernel runs 128 threads in four warps. Warp 0 loads the input tiles, and warp 1 issues the matrix multiply-accumulate (MMA) instruction. Running the two jobs in separate warps allows them to overlap. All four warps then run the epilogue. We call the three roles the producer, the consumer, and the epilogue. A single thread issues each copy or MMA. First, thread 0 (warp 0) asks the TMA to copy the input tiles into the shared-memory buffers sA and sB. When both copies have landed, the barrier full completes, and thread 32 (warp 1) issues the MMA; the tensor core executes it and writes the product to acc in tensor memory. When the product is ready, the barrier mma_done completes, and all 128 threads copy acc to \(C\) in global memory, one row per thread.
// 128 threads (4 warps), thread index t.
if t == 0:
init(full, 1)
init(mma_done, 1)
syncthreads()
// Main loop: a real kernel repeats it for every block of K;
// here K is a single block, so it runs once.
if t == 0: // producer
arrive.expect_tx(full, 32 KB) 1
tma_load(sA ← A, full) 2 3
tma_load(sB ← B, full) 2 3
if t == 32: // consumer
wait(full, 0) 4
tcgen05.mma(acc ← sA * sB) 5
tcgen05.commit(mma_done) 6
// Epilogue
wait(mma_done, 0) 7
r = tcgen05.ld(acc[t, :]) 8
tcgen05.wait::ld()
st.global(C[t, :] ← r) 8
The kernel is correct only because of the order its barriers enforce: step 4 keeps the multiplication from reading sA and sB too early, and step 7 keeps the threads from loading the accumulator too early.
A bug that depends on the schedule
Now suppose the epilogue forgets its wait, step 7:
wait(mma_done, 0)// epilogue (buggy) r = tcgen05.ld(acc[t, :]) tcgen05.wait::ld() st.global(C[t, :] ← r)
Both barriers still count exactly as before: the copies complete phase 0 of full, and the commit’s arrival completes phase 0 of mma_done. But nothing orders the epilogue’s loads after the multiplication any more. Whether the epilogue reads acc before or after the tensor core writes it depends on the schedule:
mma_done (pending arrivals, pending bytes) after each update. The barrier behaves the same way in both; they differ only in whether the epilogue reads acc before or after the tensor core writes it.In this small kernel, the missing wait is easy to spot. In real kernels, with many more roles, pipeline stages, and asynchronous operations, it is not. The results below include a closely related missing wait in CUTLASS.
A test observes only the schedules that happen to occur, and so does a dynamic race detector such as Compute Sanitizer. Enumerating all schedules quickly becomes infeasible, since their number grows exponentially with the number of threads and asynchronous operations. We need an argument that covers every schedule without exhaustively enumerating them.
SentryWard
To prove a kernel correct, SentryWard checks three properties in turn: that the barriers behave the same way in every schedule, that no schedule has a data race or uses a resource after it is freed, and that the kernel computes the same function as the reference. The first property is well-synchronization, introduced for named barriers [1] and implemented in the WEFT verifier; SentryWard extends the definition and its algorithms to mbarriers. Each check relies on the guarantee of the one before it, and every guarantee covers all schedules of the configured launch under the modeled semantics. When a check identifies a violation, SentryWard reports a witness, such as the two unordered accesses of a race.
Program representation
SentryWard analyzes kernels with static control flow: their branches and loop bounds may depend on the launch configuration, but not on the data. It first specializes the kernel for the launch configuration: it resolves branches and unrolls loops, so that each thread executes a finite sequence of instructions. It then records the program in two views: the event view, a graph of events, and the value view, which records what each thread loads, stores, and computes. An instruction that takes effect at once, such as a store or a barrier update, is a single event. An asynchronous instruction starts with an issue event, after which the hardware performs the rest. Program-order edges record the order that each thread’s code imposes.
Synchronization analysis
Program order covers each thread on its own; across threads, the order comes from barriers. An mbarrier goes through a sequence of phases. During each phase, it counts pending arrivals and pending bytes: arrive decrements the pending-arrival count, expect_tx announces bytes, and a TMA copy subtracts its bytes when its transfer completes. When both counters reach zero, the phase completes, and the next phase starts with the counters reset. A thread waits for a phase to complete with wait; in our example, every wait is for phase 0.
Which updates does a wait observe? Those of the phase it waits for. But the schedule can change which phase an update joins. In one schedule, an update happens before phase 0 completes, so it joins phase 0. In another schedule, phase 0 completes first, so the same update joins phase 1. SentryWard focuses on kernels in which the schedule never changes what a wait observes. Formally, it requires the kernel to be well-synchronized: every barrier update and every wait belongs to the same phase in every execution.
Caveat. Some correct kernels are not well-synchronized, so they are outside SentryWard’s scope. Programmers, however, usually intend each wait to observe one particular phase, and in practice we find this scope sufficient: only one kernel in our benchmark fails SentryWard’s well-synchronization check.
Following WEFT, SentryWard first simulates one trace of the kernel, along any schedule that completes, and records the phase of every barrier update and every wait. From this trace it builds a candidate graph with a completion vertex for each phase. It then certifies that every schedule agrees with the trace. WEFT does this by checking that every update comes after the previous phase of its barrier completes. If certification succeeds, the candidate graph is the kernel’s happens-before graph: its orderings hold in every execution, and no execution deadlocks.
The hard part is the byte counter, for which WEFT’s check is not enough. A named barrier counts only arrivals, so a phase cannot complete before its last arrival. Pending bytes, however, go up as well as down, so a phase can reach (0, 0) before all of its updates have happened. It then completes early: the threads waiting for it proceed without the remaining updates, which join the next phase instead. To see this, consider a different mistake from the one above: the producer announces each tile’s 16 KB separately, just before starting its copy.
if t == 0: // producer (another bug) arrive.expect_tx(full, 16 KB) tma_load(sA ← A, full) expect_tx(full, 16 KB) tma_load(sB ← B, full)
If copy A lands before the second announcement, phase 0 completes early, and the second announcement joins phase 1. Unlike the missing wait, this kernel is not well-synchronized: the phase that the second announcement joins depends on the schedule. To catch such kernels, SentryWard checks that no phase can complete early. It looks for updates that can happen before the rest of their phase and already bring both counters to zero, like the first announcement and copy A here.
full in phase 0. When a copy completes, it subtracts its bytes from full with a complete_tx update, and an arrow points from an update to one that must come after it. (a) With separate announcements, the first announcement and copy A’s complete_tx can happen before the other two and already bring full from (1, 0) to (0, 0), so phase 0 completes early (red); the gray updates then fall into phase 1. (b) In the correct kernel, the single announcement comes first, so only all three updates together complete the phase.The buggy kernel with the missing wait passes the well-synchronization check, since its barriers count exactly as in the correct kernel. But without the epilogue’s wait, its happens-before graph has no path from the MMA’s execution to the epilogue’s loads (see the “Buggy kernel” tab in Figure 5).
Race freedom and serialization
With the happens-before graph, checking races becomes a question about paths. Two accesses conflict if their footprints may overlap and at least one of them writes, and SentryWard requires every conflicting pair to be ordered. Footprints follow exact layouts, including swizzled shared-memory tiles, and an SMT solver decides overlap when addresses are symbolic.
acc and the load of row \(t\) are ordered in the correct kernel but race in the buggy kernel.In the buggy kernel, nothing orders the MMA’s store to acc before the epilogue’s loads, so SentryWard reports a race, with the two accesses as its witness. Uses after free are checked the same way: every use of a resource, such as tensor memory, must be ordered before the resource is freed.
Within this model, a kernel that passes these checks behaves like a sequential program. On a given input, every execution has the same effect as running its events one at a time, in any order that the happens-before graph allows: every read and every write accesses the same addresses with the same values, and the final memory is the same.
Compact representation
An explicit per-thread, per-scalar representation does not scale: a block has hundreds of threads, and a single \(128 \times 256\) output tile with \(K = 4096\) involves about \(1.3 \times 10^8\) multiply-accumulates. Most of this size comes from repetition, and SentryWard compresses two kinds of it.
Templates for repeated threads and data. Many threads run the same code on different data, and many data elements are processed in the same way. SentryWard represents each such family by a single template, indexed by the thread or the element, and analyzes the template directly. Threads that take the same branches, for example, share one template.
Folds for reductions. A reduction repeats one operation over an index range. Instead of a chain of operations, SentryWard stores it as a Fold, given by its operator \(\oplus\), its index range, its initial value \(z\), and the term \(e(k)\) at each index:
A Fold’s size does not depend on the length of its range. In the running example, the MMA computes each element of its accumulator as
SentryWard builds Folds from MMA instructions and from repeated updates in the code, and the equivalence check below works on them directly, without unrolling them.
Equivalence checking
A kernel can be well-synchronized and race-free and still compute the wrong function because of a logic error. Since a race-free kernel behaves like a sequential program, SentryWard analyzes its computation on a single serialization, in two steps. It first eliminates loads and stores by symbolically executing the serialization, which turns each output into a pure expression over the inputs, and then proves that these expressions are equivalent to the reference’s.
Eliminating loads and stores via symbolic execution
Symbolic execution follows the serialization and keeps a memory state: the expression last stored at each address. Each store updates the state at its address, and each load is replaced by the expression that the state holds at its address, or by an input if nothing was stored there. The buffers in between, here sA, sB, and acc, drop out, and each output element becomes an expression built only from the inputs.
| Event | Loads and stores | After symbolic execution |
|---|---|---|
| copy A | load A[t, k], store sA[t, k] | sA[t, k] \(\leftarrow A[t, k]\) |
| copy B | load B[k, j], store sB[k, j] | sB[k, j] \(\leftarrow B[k, j]\) |
| MMA | load sA[t, k], load sB[k, j], store acc[t, j] | acc[t, j] \(\leftarrow \sum_k A[t, k] \cdot B[k, j]\) |
| epilogue, thread \(t\) | load acc[t, j], store C[t, j] | C[t, j] \(\leftarrow \sum_k A[t, k] \cdot B[k, j]\) |
A[t, k], holds an input.Proving equivalence to the reference
This step takes two pure expressions over the same inputs: the kernel’s, from load/store elimination, and the reference’s. They are rarely identical, because an optimized kernel computes its reductions differently from the reference: it may split a reduction into parts, combine the parts in a different order, or rescale them. To prove the two expressions equal, SentryWard uses the reference as a guide: it relates the kernel’s expression, part by part, to the reference’s intermediate results.
Figure 9 shows an example: attention for one query \(q\) and four keys of dimension four, with a scalar value \(v_j\) for each key \(j\). The reference computes the scores \(s_j\), the sum \(Z\) of their exponentials, and the weighted sum \(U\) (a sum is a Fold with \(\oplus = +\) and \(z = 0\)). The optimized kernel splits each score between two threads, one for the even \(k\) and one for the odd \(k\). It processes the keys in two blocks with online softmax: within a block, it subtracts the block’s largest score before taking exponentials, and the merge rescales both blocks to the overall largest score \(m\). To show that the kernel’s output \(p / \ell\) equals \(U / Z\), SentryWard proves five equalities, in order.
In each step, SentryWard writes a part of the kernel’s expression as \(c \cdot \sum_{k \in S} e(k) + r\): a common factor \(c\) times terms \(e(k)\) of a reference sum, plus a residual \(r\). If \(S\) covers every index exactly once, the part equals \(c\) times the reference sum plus \(r\), and later steps use that equality. If the merge forgot to rescale one block, the two blocks would have different factors, and no proof would be found. SentryWard checks coverage on a compact representation of index sets (their generating functions), without listing the indices, so it also handles large and strided index ranges. SentryWard compares parts without reductions by canonicalizing both sides into exponential polynomials [2], and handles operations such as square roots separately.
Figure 9 is simplified: it merges just two blocks, while real kernels merge many blocks in a loop. SentryWard proves such loops correct by induction, with an invariant that relates the loop’s state to the reference. Its support for induction is limited: it relies on predefined invariants for a few patterns, such as online softmax and Welford statistics, and does not synthesize invariants beyond these patterns.
The check treats floating-point values as real numbers, so equivalence holds in real arithmetic. It is also incomplete: finding no proof does not mean the kernel is wrong.
Results
Issues found in popular kernel libraries
Real kernels can contain mistakes similar to those in our running example, hidden among many more threads, pipeline stages, and barriers. Below we describe three of the issues that SentryWard flagged in kernels from popular libraries. The first, in PyTorch, had already been fixed upstream; we reported the other two, in TileLang and CUTLASS, as potential ordering issues.
Caveat. SentryWard’s model of the hardware follows our interpretation of the PTX documentation. The documentation does not specify every detail, so our model may differ from how the hardware actually behaves. The model is mostly confined to how SentryWard builds the event graph, so changing it does not affect the analyses that run on the graph. We welcome feedback and will refine the model where it differs from the hardware.
PyTorch: a bug that was already fixed. We analyzed an older release, PyTorch 2.8.0, and SentryWard flagged a race in its MultiMarginLoss backward kernel. The kernel splits a row of gradients among the threads of a block: thread 0 writes the gradient of the target class, and then every thread scales its part of the row. With no barrier in between, the thread that owns the target class may scale a stale value. The bug had already been reported and fixed upstream, independently of us, in PyTorch 2.9.0. It provides a validation case: an independently confirmed bug that SentryWard also detects.
// one block per row; thread t owns columns t, t + blockDim, ... for each of my columns i ≠ target: gradInput[i] = h(i) // 0 if the margin holds buffer[t] -= h(i) __syncthreads() if t == 0: gradInput[target] = sum(buffer) // thread 0 writes the target entry__syncthreads()// missing; PyTorch 2.9.0 adds it for each of my columns i: gradInput[i] *= gradOutput // the owner of target scales it
__syncthreads() at the dashed line.TileLang: a buffer reused too early. Our second example comes from a compiler. TileLang turns tile-level Python into GPU kernels and pipelines the loads automatically. With two pipeline stages, tiles \(k\) and \(k + 2\) share a buffer, so the copy of tile \(k + 2\) must wait until the multiplication of tile \(k\) has finished reading. The planner orders the copy after the MMA instruction, but the tensor core executes that instruction asynchronously and keeps reading the buffer until a later wait. Under this model, the copy can overwrite operands in the middle of a multiplication, and SentryWard reports a potential race between that write and that read.
# TileLang program for k in T.Pipelined(num_tiles, num_stages=2): T.copy(A[k], A_shared) T.copy(B[k], B_shared) T.tcgen05_gemm(A_shared, B_shared, C_tmem, mbar=mbar) T.mbarrier_wait_parity(mbar, k % 2) // generated loop body, iteration k, stage s = k % 2 tcgen05.mma(acc += sA[s] * sB[s]) // the tensor core reads stage s tcgen05.commit(mbar) __syncthreads() // does not wait for the tensor core // the copies of tile k + 2 overwrite stage s cp.async(sA[s] ← A[k + 2]) cp.async(sB[s] ← B[k + 2]) wait(mbar, k % 2) // MMA k is known to be done only here
CUTLASS: a signal sent too early. Our third example is a close relative of the running example. In CUTLASS’s Blackwell attention kernel, the softmax warpgroup writes row statistics to tensor memory and then tells the correction warpgroup that they are ready. But the write is asynchronous, and the signal goes out without waiting for it with tcgen05.wait::st. In the analyzed model, the correction warpgroup may then read the statistics before they land. The upstream investigation did not reproduce stale reads in B200 stress tests.
// softmax warpgroup, once per tile of keys tcgen05.st(stats ← old_max, new_max)tcgen05.wait::st()// missing arrive(stats_ready) // tells the correction warpgroup ... tcgen05.st(P ← probabilities) tcgen05.wait::st() // here the kernel does wait arrive(p_ready) // tells the MMA warp // correction warpgroup wait(stats_ready, phase) r = tcgen05.ld(stats) // may read stale statistics scale = exp(r.old_max - r.new_max)
Removing redundant synchronization
Because SentryWard checks every schedule, it can also identify synchronization that is unnecessary: if a kernel still verifies after we remove a synchronization operation, that operation is redundant for the given input shapes and launch configuration, under SentryWard’s hardware model. We apply this test greedily to each verified kernel, one operation at a time, and keep each removal that passes it.
We tried this on 44 kernels from our benchmark, each at two input sizes: the inputs of our examples, and larger inputs at which every pipeline buffer is reused (Figure 13). At the example inputs, 48.6% of the synchronization operations we tried turned out to be unnecessary, and removing them made 35 of the kernels faster on a B200, with a median reduction in kernel time of 7.5%. At the larger inputs, 42.4% were unnecessary, 37 kernels got faster, and the median reduction was 3.0%. Larger inputs thus leave less to remove, and a reduction found at one input may be wrong at another: at the larger inputs, SentryWard rejects 35 of the 44 reductions found at the example inputs, and 34 of those hang or fault on a B200. As an additional check, we also ran randomized tests: every reduced kernel produced exactly the same output as the original, over 500,000 launches at the example inputs and 20,000 at the larger ones.
Limitations and future work
SentryWard’s current scope has several limits, each a direction for future work. The results page shows which of our benchmark kernels fall outside it, and why.
- Symbolic input shapes. SentryWard currently fixes the problem sizes and the launch configuration. With symbolic shapes, one proof could cover a specified range of sizes.
- Data-dependent control flow and addressing. By default, branches, loop bounds, and addresses cannot depend on values loaded from tensors. Supporting such dependence in general would cover many more kernels.
- Weak memory model. SentryWard currently assumes that a write is visible to all threads once it happens: it models the ordering that barriers and asynchronous completion provide, but not fences. Supporting the full PTX memory model would cover kernels that synchronize with fences.
- Floating-point semantics. Numerics matter in LLM training and inference. Low precision loses accuracy, large values overflow, and different summation orders give different results, for example across batch sizes or between training and inference. Extending SentryWard from real arithmetic to floating-point semantics would help reason about these issues.
References
- Rahul Sharma, Michael Bauer, and Alex Aiken. Verification of Producer-Consumer Synchronization in GPU Programs. In PLDI, 2015. doi:10.1145/2737924.2737962
- Jiatu Li and Mengdi Wu. Identity Testing for Circuits with Exponentiation Gates. In ITCS, 2026. doi:10.4230/LIPIcs.ITCS.2026.95