arXiv:2611.04447cs.AINov 2026

Manuscript Offprint

arXiv:2611.04447

Formalizing PTX in Lean to Prove GPU Kernel Correctness

Luk Koska, Tom Koska, Ben Koska

Abstract

We present an approach to mathematically formalizing PTX, an approach that allows modeling and reasoning about patterns common in GPU kernels for Deep Learning, including acquire-release, tensor cores, proxies, async operations, multi-kernel pipelines and data-dependent control flow. We implement it in Lean and use it to prove the correctness of simple implementations of a WGMMA GEMM kernel, FlashAttention, and a 3-kernel MoE pipeline.

1 Introduction

The correctness of GPU kernels is becoming increasingly critical in the age of AI. Furthermore, as more and more kernels are written by LLMs, it is desirable to reduce human review burden, letting them trust outputs without extensive manual review.

A long line of work aims to verify the functional correctness of specific classes of GPU kernels. For example, Volta [11] checks equivalence of GPU kernels, supporting __syncthreads(), __syncwarp() and synchronous tensor-core operations, but requires statically determined control flow and excludes certain aspects of the PTX memory model.

Instead of focusing on specific classes of kernels, we mathematically model the possible executions of a given PTX kernel in Lean, an approach that allows reasoning about many patterns used in modern GPU kernels, including acquire-release synchronization and data-dependent control flow. This approach lets LLMs write correctness proofs in a verifiable manner: only the mathematical specification of what the kernel should compute, the preconditions, our formalization and parsing of PTX in Lean and the Lean kernel, but not the LLM's outputs, need to be trusted. Furthermore, it allows formalizing and checking human intuition for why a given kernel is correct.