Researchers from Columbia University and CertiK have developed TensorLean, a Lean-based framework for formally verifying GPU kernels at the PTX assembly level against tensor-level mathematical specifications written using Lean's Mathlib and PyTorch-style operators. The verification pipeline operates in seven stages: compiling unmodified source code to PTX, loading a formal PTX semantics, constructing a happens-before graph to prove race freedom and termination, symbolically executing kernels to derive schedule-independent final memory states, lowering tensor specifications to the PTX memory level, and discharging proof obligations using Lean's kernel alongside the Z3 and cvc5 SMT solvers. Key scalability techniques include reducing concurrency verification to sequential reasoning via symbolic happens-before graphs covering all CTAs and threads, employing loop invariants over semirings to handle tiled accumulation loops like online softmax with a single SMT query per loop, separating algebraic error (proven zero) from round-off error (bounded independently), and reusing proved developer-inserted assertions as hints. Evaluated on a 16-core workstation against kernels compiled for A100, H100, and B200 GPUs, the 1,800-line PTX parser verified 149 kernel instances—including all FlashAttention-2, -3, -4 and DeepGEMM kernels—with specifications totaling 10,278 lines against 151,285 lines of source (approximately 15:1 ratio). The tool proved 83 instances fully correct across four properties (race freedom, termination, numerical tolerance, memory safety) and uncovered 38 distinct bugs across six projects, 23 in FlashAttention alone. Bug categories comprise 19 memory access errors, 13 numerical issues, 7 data races (including one in FlashAttention-4 undetected in 17,760 test runs), 5 uninitialized reads, 5 undefined behaviors, 3 algorithmic errors, 2 miscompilations, and 1 deadlock. Median verification time is approximately 10 minutes, scaling to 50 minutes maximum. Unlike equivalence checkers such as Volta that unroll loops for concrete configurations, TensorLean uses symbolic parameters to cover configuration spaces comprehensively.

Read original