arXiv:2611.02028cs.AINov 2026

Manuscript Offprint

arXiv:2611.02028

LARK: Lean-Assisted Reasoning for LLM-Generated GPU Kernels

Zixi Zhang, Jiayi Nie, Haoran Wu, Yujie Yan, Yann Herklotz, Rika Antonova, Robert Mullins, Yiren Zhao, George A. Constantinides, Jianyi Cheng

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

ABSTRACT

Efficient GPU kernels are typically low-level and hardware-specific, and LLM agents can now generate them faster than experts can verify. Existing approaches rely on testing, which provides evidence but not a guarantee of correctness. We introduce LARK, an agentic framework that automatically and formally verifies GPU kernels against their PyTorch reference implementations. LARK proves equivalence in functional and memory behavior under exact arithmetic and establishes a new trust boundary: human effort is only needed to verify operator-level Lean semantics ahead of kernel generation time, instead of checking every single line of generated code. LARK formalizes the GPU machine model and the semantics of each operation in Lean 4 once per target language, and the Lean 4 semantics of any incoming kernel is derived from these pre-built definitions. LLM agents then automate the proof in two steps. First, an agent decomposes the whole kernel semantics into smaller segments and Lean 4 verifies this segmentation, which addresses the intractability of proving equivalence for large kernels directly. Second, agents write Lean proofs that each kernel segment matches its high-level PyTorch counterpart. Together, the two steps give whole-program equivalence. We demonstrate that LARK can be used 1) to ensure correctness in existing code-generation agents and 2) to automatically verify human-written kernel libraries. On the KernelCraft GPU tasks, combined with a simple ReAct agent, LARK enables GLM 5.3 to fully verify 10 of 12 Level-1 kernels and Opus 5.5 all 5 Level-2 kernels. Moreover, over 10 production kernels randomly sampled from popular open-source LLM serving frameworks, LARK verifies 9 and identifies a new data race bug in the tenth. We believe LARK represents a significant step toward verifiable code generation in the agentic era.

1 INTRODUCTION

GPU kernels are where the cost of training and serving deep learning models is paid, and the fastest are hand-scheduled CUDA, PTX, or HIP written close to the metal (Wu et al., 2026; Dao et al., 2022; Tillet et al., 2019). Such code is increasingly written by LLM agents (Nie et al., 2026; Ouyang et al., 2025; Beel et al., 2025; Baronio et al., 2026), and a plausible kernel is not a correct one: the same models that write fluent code write fluent bugs (Lange et al., 2025; Chatterjee et al., 2026). Every regenerated kernel needs its own correctness check, at the pace of generation. Existing checks fall short on one count or the other (Fig-

ure 1, top). Tests on sampled inputs keep pace but give evidence, never a guarantee; human review reasons about all inputs but cannot keep pace; an LLM judge removes the human but not the problem. What a generated kernel needs is a proof of a precise equivalence statement, checked by a proof assistant such as Lean 4 (Moura & Ullrich, 2021), and formal tools do not provide one either: GPUVerify (Betts et al., 2012) proves race and divergence freedom, not the specification; a verified compiler (Leroy, 2009) certifies its own translation, not a generated kernel; a handwritten model (Armstrong et al., 2019) or proof (Klein et al., 2010) puts a human back where we want automation.

We present LARK (Lean-Assisted Reasoning for Kernels), an agentic framework in which LLM agents write both the model of the kernel and the proof, and Lean checks both. Once per target language, LARK formalizes in Lean a machine model of the GPU and the semantics of each operation and measures them against the hardware; the machine model is shared across languages, so a new target supplies only its operations and their semantics, and we instantiate LARK for PTX, CUDA, and AMD HIP. Given a PyTorch specification and a kernel from any generator, the kernel's

1^{1}Department of Electrical and Electronic Engineering, Imperial College London, London, United Kingdom 2^{2}Department of Computer Science and Technology, University of Cambridge, Cambridge, United Kingdom 3^{3}Quettaflop AI 4^{4}School of Informatics, University of Edinburgh, Edinburgh, United Kingdom 5^{5}Computer Science Department, EPFL, Lausanne, Switzerland. Correspondence to: George A. Constantinides <g(constantinides@imperial.ac.uk>, Jianyi Cheng jianyi.cheng@ed.ac.uk.

Preprint.

Figure

Figure 1. Where trust sits in LLM kernel generation. Top: existing pipelines check a generated kernel by sampled tests or review, so the whole kernel is taken on faith. Bottom: LARK fixes what is assumed (dashed) before the kernel is seen, the machine model and operation semantics formalized once per language and the task's interface; every property of the kernel is proved in Lean or the kernel is rejected, and the assumptions are reported with every result.

semantics is derived from these pinned parts, agents write the proofs, and Lean checks every step, so a wrong agent output is a failed proof, never a wrong theorem. This division of labor raises three challenges:

  1. Semantic gap. The kernel's Lean semantics is spelled out operation by operation over the machine model, while the PyTorch reference has a tensor-level semantics in Lean. LARK bridges the two by deriving a flat model of the kernel and having an LLM agent segment it, verifiably, into a segment-level model that a proof can induct on (Section 4.2).

  2. Fidelity versus tractability. The machine model must be sound for the hardware yet abstract enough to prove against. LARK's model computes over exact numbers, runs a phase's threads in sequence, and treats undefined behavior as a fault; what makes this sound, race freedom above all, is proved in Lean per kernel as obligations, and a kernel that can fault or race has no theorem (Sections 4.1 and 4.2).

  3. Trust boundaries. Any assumption the theorem depends on but Lean does not verify must be trusted by humans; we call this set the trust boundary. LARK keeps it small and fixed by the task, the hardware machine model, the fixed mapping from operation semantics to kernel semantics, and the formalized task specification, so it can be reviewed once in advance; every run produces a Lean certificate that any Lean project re-checks without repeating the LARK procedure (Section 4.3).

LARK tackles these three challenges, and we make the following contributions:

  • We present LARK, an agentic formal-verification work-

flow for GPU kernels in low-level, close-to-metal languages. To our knowledge, LARK is the first attempt at using agents to produce formally verified low-level GPU code for equivalence check.

  • We show how to formalize low-level GPU semantics in Lean 4 and prove functional equivalence between a GPU kernel and a PyTorch reference. LARK combines verified program segmentation with iterative agentic proof construction, and humans review the task's trust boundary only once, ahead of time in dependent of kernel inputs; every kernel generated afterwards is certified relative to those trusted assumptions.

  • We demonstrate that LARK can be integrated with agentic code-generation harnesses to certify their kernels and serves as an automated verifier for human-written kernels. On KernelCraft, GLM 5.3 certifies 10 of the 12 Level-1 kernels and Opus 5.5 all five fused Level-2 kernels, every semantics-breaking mutant is rejected, and nine of ten production kernels verify while the tenth is rejected for a real data race (Section 5).

References (39)