MojoProof
Machine-checked proofs for compiled Mojo GPU kernels, in Lean.
mojo_kernel proves the kernel theorem against a spec stated with TorchLean.
The check mark: every proof is checked by Lean's kernel. Click a box to see its code.MojoProof proves things about the code the Mojo compiler actually emits, for every input and every launch of the shape a theorem states (one-dimensional, for the elementwise kernels), with floating point modelled bit for bit. It lives outside the compiler, so Mojo itself doesn't need to change, and every theorem says how far it reaches: every program, a family of kernels, or one kernel.
Why Mojo
I really like Mojo, for two reasons.
- One language, all the way down. The same language takes you from Python-style code to kernels on NVIDIA, AMD and Apple GPUs.
- One system instead of many. What makes PyTorch and JAX hard to verify is how heterogeneous they are. One model runs through Python, C++, CUDA or Triton kernels and a graph compiler, each with its own semantics. With Mojo there is one language and one open-source compiler, so there is one thing to give a semantics to.
Why verification
GPU kernels are easy to get quietly wrong, and testing can't cover them. A kernel that passes on the sizes you tried can still read out of bounds, race, or give a different answer at another size or under another thread schedule. A proof can cover every input, every launch size and every schedule at once. MojoProof proves things about the code the Mojo compiler actually emits, so the guarantee is about what runs, not about a hand-written model of it.
What is proved today
Schedule independence every program
From a memory whose pointers name only its own blocks, one run of a launch to its end with no fault, no data race and no broken invariant-load promise shows that every thread schedule of that launch is safe, race free, terminates and gives the same result.
A sound symbolic checker every program
A block, a path or a path to the kernel's return that the checker accepts runs as its summary says, whenever the path's conditions hold at its entry.
Elementwise kernels a family
A kernel with two input buffers, an output buffer and a count meets the kernel theorem when each thread takes a checked path, and each finite output cell below the count and the thread count is the float operation applied to the inputs' cells.
Three kernels, end to end three kernels
vector_addition from max/examples, a vector multiply and a vector subtraction, each proved by one mojo_kernel command from its spec, with no proof lines written by hand.
A kernel with a loop one kernel
Modular's naive matrix product meets the kernel theorem for every valid launch, size and input that meets the matmul precondition: each output cell inside the matrix holds the row-by-column dot loop. Its threads' runs are proved by hand from the library's lemmas, not yet generated by mojo_kernel.
Each result links to its Lean declaration. Every statement, with all its premises, is in What is proved, and what the proofs trust is in the trusted base.
The roadmap
Get involved
- Pick a card on the roadmap whose level can go up.
- Follow the guide, or hand AGENTS.md to your coding agent. Specs are always checked by a human.
- Open a pull request. CI checks it, and this site updates itself when it's merged.
I'd love help, and I'd love to hear which kernels you want proved. Come say hi on the Modular forum : )