Performance measurement · Research feature

New Tool Verifies Correctness of ML GPU Kernels Generated by Humans, LLMs, and Compilers

The researchers present the first equivalence checker for GPU kernels and use it to formally verify the correctness of machine learning (ML) kernels optimized by hand, by LLM, and by compiler.

Adapted from research by Benjamin Driscoll, Kshitij Dubey, Anjiang Wei and colleagues.

arXiv preprint revision · 2026-08-16 · Attribution & reuse
In this article
Editorial illustration of processor die.

Authors’ overview

With the rapid progress of deep learning and large language models (LLMs), companies spend enormous sums executing GPU kernels. These kernels have become prime targets for aggressive optimization. Recent efforts increasingly leverage LLMs to generate GPU kernels, but make no formal guarantees about the generated kernels. We present the first equivalence checker for GPU kernels and use it to formally verify the correctness of machine learning (ML) kernels optimized by hand, by LLM, and by compiler. We show that our equivalence checker is sound and, for a well-defined class of GPU kernels which includes many programs of interest, complete. Our implementation, Volta, can verify ML computations such as convolutions, matrix multiplications, and various attention mechanisms.

Introduction

Given two GPU kernels—a reference implementation and an optimized counterpart—our goal is to prove their extensional equivalence, i.e., that they produce identical outputs on all valid inputs, and, thereby, to verify the correctness of the optimized implementation. Equivalence checking has been extensively studied for over half a century and recent works, such as, have successfully proven the correctness of optimized CPU code. However, GPU programming introduces unique challenges arising from fine-grained synchronization among a massive number of threads and, to date, the literature proffers no equivalence checker for GPU programs.

GPU kernels execute thousands of threads in parallel on runtimes such as NVIDIA’s CUDA or AMD’s ROCm, which can introduce subtle concurrency errors that testing alone cannot reliably detect. One major source of such errors is data races, which may appear only in extremely rare executions or may remain latent when kernels rely on implicit synchronization that happens only for a specific version of the test runtime or the test hardware but that is not guaranteed to hold in general. For example, a widely cited GPU programming tutorial relies on warp-level synchronization that was removed after CUDA 9.0. Testing-based correctness checking is further complicated by floating-point arithmetic. GPU optimizations often reorder arithmetic operations, causing small numerical differences between the outputs of the reference and optimized implementations. Such variations are usually tolerated in tests, yet similar deviations can arise from genuine semantic bugs. For instance, an unsound optimization that omits a clipping operation may seem acceptable for some test inputs even though it reduces overall model accuracy. While compilers rarely introduce such mistakes, they are plausible when kernels are hand-optimized by human programmers or generated by agents.

State-of-the-art equivalence checking supports single-threaded integer programs and high-level tensor operations, but it is not obvious how to decompose the equivalence checking of GPU kernels into single-threaded sub-tasks. In an optimized kernel, there may be no one-to-one correspondence between its threads and the threads in the reference implementation. In addition, existing techniques have no support for synchronization among multiple threads.

Volta checks the identities output by its symbolic executor in less than 3 minutes on all evaluated benchmarks, including convolution, matrix multiplication, and attention (Section 6). Volta operates as a black-box equivalence checker, requiring no information about how an optimized kernel was produced; it verifies correctness solely from the assembly corresponding to the optimized program itself. In particular, Volta analyzes PTX assembly, the lowest documented level of the stack for NVIDIA GPUs. Operating at the PTX level enables our approach to handle various developer front-ends. For example, GPU programmers can write CUDA kernels or CUTLASS templates. NVIDIA’s nvcc compiler translates both into PTX.

The rest of the paper is as follows. Section 2 shows, at a high-level, how Volta verifies a motivating example. Section 3 provides background on GPU architecture, synchronization, and ML GPU kernels. Section 4 describes our symbolic execution algorithm formally. Section 4.3 establishes our main technical results. Section 5 describes Volta’s implementation and Section 6 evaluates it across a diverse set of GPU kernels, demonstrating its ability to verify realistic programs and detect bugs. Section 7 reviews related work and Section 8 concludes with directions for future research.

Motivating Example

Note that this representation is shown only for clarity of exposition. In fact, the actual implementation (Section 5) never constructs the fully expanded program, nor does it perform other AST transformations. It operates over the original program, requiring that values are sufficiently static such that the symbolic executor can resolve all control flow.

Background

We begin with necessary background on GPUs. To execute a task on a GPU, the CPU host launches a grid of cooperative thread arrays (CTAs), also known as thread-blocks. All CTAs share access to global memory (HBM), typically sized in gigabytes. Different CTAs in a grid usually write to disjoint regions of global memory due to the cost of inter-CTA synchronization, which was not even possible for many GPU generations. The GPU hardware schedules each CTA on a streaming multiprocessor (SM); a modern GPU may contain hundreds of SMs. The resources assigned to each SM are limited and hence each CTA is tasked to compute only a tile of the output tensor. Each CTA consists of 128 to 1024 threads, depending on the hardware generation. Within a CTA, threads are grouped into warps, each consisting of 32 threads. Every thread maintains its own registers for local storage, while shared memory serves as a software-managed cache accessible to all threads in the same CTA. To coordinate access to shared memory, threads must use explicit synchronization operations. Missing synchronization leads to data races and over synchronization leads to loss of performance. The shared memory available per CTA ranges from 48 KB to 256 KB, depending on the GPU architecture. In a typical CTA, threads first load data from global memory into shared memory, perform arithmetic operations while keeping intermediate values in registers or shared memory, and finally write the results back to global memory. Writing code for efficient CTAs is challenging because programmers must reason about massive thread-level parallelism and low-level hardware details. Volta aims to statically identify incorrect or unsafe optimizations. We next describe the synchronization mechanisms available on GPUs.

Synchronization Operations

NVIDIA GPUs support independent thread scheduling, meaning that in the absence of explicit synchronization, each thread executes independently. The fundamental synchronization primitive is syncthreads, a barrier that spans all threads within a CTA. Threads that reach the barrier earlier are suspended until all threads in the CTA arrive or exit, at which point execution resumes for all of the threads blocked at the barrier.

Another synchronization primitive is syncwarp, which operates on a user-specified subset of threads within a single warp. This mechanism is commonly used when programming tensor cores—CUDA intrinsics such as wmma::mma_sync synchronize all threads in a warp to perform matrix multiplication. Most prior verification techniques for GPU kernels support only syncthreads and therefore cannot reason about machine learning kernels that rely on warp-level synchronization. While syncthreads is deadlock free (per the CUDA documentation, it can only be placed under conditionals that evaluate uniformly across the entire CTA), syncwarp can introduce deadlocks.

In summary, the synchronization mechanisms we consider are barriers that block subsets of the available threads. Asynchronous producer-consumer-style primitives such as arrive are beyond the scope of this paper. The race checking mechanism of Volta could potentially be swapped out for a more general, if less efficient, mechanism such as a happens-before analysis in the style of, without disrupting the rest of the system, but we leave this for future work.

Why Structured-CTAs?

In this section, we discuss, at a high level, the assumptions that Volta makes about input kernels. We first state our assumptions, then motivate them. Note that these assumptions are checked: Volta raises an exception if a kernel does not satisfy our requirements (Section 5).

Structured-CTAs reflect well-established best practices for achieving high GPU performance, as supported by empirical study. A large-scale analysis of GPGPU kernels in the wild found that most memory accesses are control independent and data independent (59.5% of 2770 programs). Similarly, a study of the CUDA SDK showed that most programs exhibit access invariance, meaning that threads perform the same memory accesses for all inputs (52 out of 76). Weft, a race detector for scientific and cudaDMA kernels, makes all of the above assumptions—all 26 scientific computations studied by Weft fall into the aforementioned class.

Moreover, we are focused on the kernels that are performance bottlenecks in the training or inference of machine learning (ML) models, such as matrix multiplications, convolutions, and multi-head attention. In these workloads, the structure of the ML model is fixed: tensor entries depend on runtime inputs, but tensor sizes are statically known. Kernels are therefore specialized for particular tensor dimensions to achieve maximum performance. In fact, JAX, a popular ML framework, only permits tensors with fixed dimensions.

Once tensor shapes are known, loop bounds can also be determined, since the bounds in tensor operations depend only on tensor shapes. Volta can statically evaluate these loops to “flat” expressions that do not contain conditionals, effectively unrolling them. We also require that the targets of conditional branches can be statically resolved; note this restriction exploits the fact that efficient machine learning kernels do not make truly data dependent runtime decisions. Under these assumptions, the code executed by each individual thread can be represented as straight-line, no dynamic branches or loops. It is common for threads to branch on predicates of their thread index or of a loop index (counting up to some tensor dimension); however, such control flow still preserves the straight-line property for each thread’s execution. For example, causal masking in FlashAttention branches on whether an array index is above or below the diagonal, but this is a static condition given the tensor shape.

Efficient GPU kernels carefully orchestrate memory transfers by coalescing accesses to global memory and avoiding shared memory bank conflicts. As a result, GPU programmers typically define memory access patterns statically, making memory addresses independent of the tensor contents. Consequently, when a straight-line thread accesses an array element, both the base array and the exact index can be determined statically. This property allows the symbolic evaluator to record memory accesses precisely and to detect data races accurately.

Implementation

Volta currently assumes that CTAs behave uniformly and simply checks CTA 0 of the reference against CTA 0 of the optimized program. If the optimizations are intra-CTA, checking multiple CTAs is embarrassingly parallel, but it might become intractably expensive for real, multi-billion parameter models. It is worth noting that, while the number of CTAs grows, the per-CTA tensor size does not.

It is worth noting that Volta’s implementation is currently single-threaded. One could try to parallelize VC generation by simulating the CUDA parallel machine with a parallel machine. The decision procedure would be a more interesting task because of canonical form memoization, out of which the implementation gets quite a bit of mileage, as we shall see (Section 6.5). We leave parallelization to future work.

Finally, we give an inventory of the PTX operations Volta currently supports. It supports collective operations bar.sync, bar.warp.sync, shfl.sync, activemask, ldmatrix, mma.sync, and wmma. It can symbolically compute addition, multiplication, division, reciprocal, fused multiply-add, and exponentiation along with max and min, float-width conversions (modeled as the identity), and floating-point saturation and ReLU clamps (modeled via min/max). Some additional operations can be performed on statically known values. We do not support square root or trigonometric functions. These operations are tricky because they place requirements on their arguments, e.g., square root requires a positive argument. If the set of operations appearing in expressions grows sufficiently complex, an SMT solver might be necessary.

Evaluation

There are three main ways to create efficient GPU kernels for machine learning workloads: manual optimization (Section 6.1), generation by LLMs (Section 6.2), and compilation by domain-specific compilers (Section 6.3). Since our equivalence checker operates as a black box and makes no assumptions about the optimization process, it can verify the correctness of optimized kernels produced by all three approaches. We evaluate on reductions, matrix multiplications, convolutions, and various attention mechanisms. We report the time to generate the verification conditions (VCs), which includes symbolically executing both kernels (“VC Gen”), and the time to solve them (“VC Time”), measured on a machine with a 128-core 2.25 GHz AMD EPYC 7742 processor and 995 GB of RAM. We show that Volta scales to realistic machine learning workloads and effectively identifies correctness issues when they exist. In particular, Volta detects data races that have been previously reported in open-source GitHub repositories (Section 6.4).

LLM-generated Kernels

Through the course of this verification, we discovered interesting undocumented behaviors. For example, out-of-bounds reads from shared-memory arrays may not cause a crash and may also go undetected by NVIDIA’s Compute Sanitizer. The following code segment—which uses two warps (64 threads) to read 48 elements of the shared-memory array A into registers v—runs without raising any exceptions on the Ampere, Hopper, and Blackwell GPUs we tested on, even though it performs out-of-bounds accesses.

Although the two programs behave identically on current GPUs, there is no guarantee that future GPU hardware would continue to tolerate out-of-bounds reads to shared memory. The latter code segment is correct for future hardware as well and, hence, preferable. Thus, even though we focus on verifying correctness of optimizations in this paper, we believe Volta can also help improve code quality.

Data Race Detection Baseline

FaialAA cannot track the concrete value of x at line 2 and, therefore, models it as non-deterministic. Subsequently, line 3 is reported as a (spurious) data race. Since we use symbolic evaluation, and M[x] is constant (since tid is constant), we don’t report an error and declare the write in line 3 correctly as data race free.

Several existing approaches bound the worst-case numerical error in floating-point implementations. However, the worst-case errors when arithmetic operations are reordered in tensor computations (as in GPU optimization) are huge for contrived inputs and do not provide useful insights. For ensuring memory safety in floating-point programs, enforcing non-interference between floating-point and non-floating-point values has proven useful.

Lifting systems seek to translate code in low-level, typically general purpose, languages into code in higher-level, typically domain specific, languages so that code can be more easily maintained and better re-optimized, retargeted, or parallelized by compilers. C2TACO lifts C to TACO, as its name suggests, STNG lifts Fortran to a stencil DSL and then translates to Halide, Tenspiler lifts C, C++, or Python to a tensor IR and then translates to various backends, such as PyTorch, and LLMLift lifts C, C++, or Python to a custom Python DSL and then translates to a similar set of backends. C2TACO does not provide formal guarantees about its output, instead relying on random testing. However, the latter three systems do verify equivalence of the lifted code and the original code. The fact that these approaches rely on recovering a high-level IR complicates the kinds of VCs they must generate—all of them make non-trivial use of general purpose SMT solvers—and the process of generating the VCs itself, which is done, e.g., in the case of STNG, by counterexample-guided inductive synthesis. Moreover, these systems lift sequential code—C, C++, Fortran, or Python loop nests—whereas a GPU kernel comprises hundreds or thousands of concurrent threads. Applying lifting in our setting would additionally require modeling shared memory, barrier and warp-level synchronization, and the attendant possibility of data races and deadlocks.

Conclusion and Future Work

We have presented Volta, the first equivalence checker for ML GPU kernels. Volta operates directly on low-level PTX, taking advantage of known tensor sizes and thread IDs to simplify the space of expressions it must support. PTX is currently the lowest-level, public-facing language for NVIDIA GPUs and, therefore, the ultimate target of open-source compilation pipelines.

Volta interprets kernels to obtain a symbolic expression for each output tensor element and checks the implied verification conditions using a specialized canonicalization procedure. Soundness and completeness are guaranteed by virtue of the semantics given in this paper and the Agda-verified confluence theorem. We also prove the decidability of identities between certain polynomials with exponentials over the reals.