Docs / Proofs

The tile layer

This document describes the tile layer of MojoProof/Tile/ (namespace MojoProof.Tile): a small language of tile programs over tensor cells, its interpreter, and the theorems that relate a kernel's compiled code to a tile program. The Lean statements are the reference; the instances and the tests are in MojoProofTest/Tile.lean, MojoProofTest/TileNaive.lean, MojoProofTest/TileGrade.lean, MojoProofTest/TileMatVec.lean and MojoProofTest/TileLanes.lean.

1. What the layer is

The answer of a float choice is the raw oracle number, which the program decodes as the LLVM semantics does: it delivers a NaN result at the number divided by 3 (Sem's deliver, the same function the LLVM semantics applies to a float operation's result), and the remainder modulo 3 chooses a contraction (dotStep). So the tile oracle that a kernel's oracle gives is the kernel's oracle at the site's thread and the computed step, unchanged, and a tile program and the kernel deliver a NaN from the same number in the same way.

2. The value type

Prog's values are concrete: a cell holds a value of the type V (FloatLib's Model ft.fmt for a float buffer), and the events answer concrete values. They are not symbolic terms.

The reason: a tile program then runs, so a program can be evaluated on concrete inputs by decide +kernel or #eval, and a wrong program is refused by evaluation (section 5). The generality is in the theorems instead: they quantify over every input tensor, every count and every oracle. A symbolic value type would need a second evaluator of terms, next to the one that already checks the compiled code (MojoProof/Sym/), and there is to be one semantics of LLVM.

3. What is proved

4. Trust

The tile layer is not in the trusted base. Its programs and its interpreter are definitions that a theorem relates to the LLVM semantics: a statement about a kernel holds of the kernel's compiled code whether or not the tile program is the intended one, and the headline theorems about kernels remain stated against Kernel.Obs and TorchLean tensors. A wrong tile program makes map2_refines or mat_refines inapplicable (its premises fail), not a wrong theorem true.

5. Tests

MojoProofTest/Tile.lean: the three instances, each applied at 6 and at 2 threads; the computed step of each kernel's operation (23, by decide +kernel); map2 .fadd run on concrete inputs at two counts and two numbers of threads, its values and access log evaluated by decide +kernel and its values by #eval; two faults (a count past the inputs' length, and frem, which has no IEEE operation); a program written with do; and the refusal of a wrong program: vector_addition's paths have no fsub step (siteStep? is none), and the subtraction program's output at a concrete input differs from the addition program's.

The matrix product: dot_meets at the 2 × 3 binary32 matrices tA and tB of MojoProofTest/Matmul.lean with the placement by rows (byRows) at two sizes, all 3 columns (meets_tA3) and the first 2 (meets_tA2); the run of dot false on them evaluated by decide +kernel at both sizes (with all 3 columns the cells are TorchLean's tA tBᵀ) and by #eval; a count past the matrices' columns, which faults; and the placement by rows. MojoProofTest/TileNaive.lean: naive_tile at the compiled kernel's strides, one launch of 2 × 2 threads and memory at two sizes, K = 768 and K = 4, its graded clause at K = 768, and that launch's placement evaluated; naive_holds, mat_holds at the family with one column. MojoProofTest/TileGrade.lean: the graded clause at the inputs' own values (meets_exact), at sizes 3 × 4 and 5 × 7 over generated binary32 matrices whose entries' finiteness is evaluated by the kernel, and a grade one ulp tighter refused at a cell of a run (tile_mutant). MojoProofTest/TileMatVec.lean: the product by rows with one column meets the matrix-vector spec's rule at sizes 3 × 4 and 5 × 7 (holds_3x4, holds_5x7), and the spec graded one ulp tighter is not met (rowLoops_mutant). MojoProofTest/TileLanes.lean: the strided lanes at 3 lanes and length 7 along a tree of depth 2, the butterfly at 4 lanes and length 10 (lane 0 and lane 3, whose trees are evaluated), their words computed by the kernel, and the grade at depth 0 refused on four binary32 pairs (depth_mutant).

6. Scope and what is not done