Docs / Proofs

fmul contract in the block checker (coversC, Block.soundC)

Lean: MojoProof/Sym/Term.lean (the node SNode.fbinP), MojoProof/Sym/Checker.lean (the checker coversC) and MojoProof/Sym/Block.lean (the proof). Tests: MojoProofTest/SymContract.lean, on the naive matmul kernel's latch.

Scope. Every program, function, block, entry position, condition list and summary that coversC accepts, every context of the program and every thread whose innermost frame runs the function at the block's position, with any memory and caller frames, whenever the conditions hold at the entry valuation. The same for paths and loops (MojoProof/Sym/Path.lean, MojoProof/Sym/Loop.lean): every path and loop sequence that the checkers with a contract flag accept, from every thread at its first block whose premises hold (see "Paths and loops with fmul contract").

Why covers refuses fmul contract

exec of fmul contract records the operands of the product in the frame (f.prods r = some (x, y)), and a later fadd contract or fsub contract on register r reads them (floatBin may fuse the two, by its oracle number). Ends, the conclusion of the frozen Block.sound, says that the frame's products at the block's end are regProd V S.regs, which is none for every register the block sets; and the frozen .fbin case of SNode.eval reads a product only from an entry register (SVal.prods), none for a node. Both are false after an fmul contract whose register the block sets, so covers keeps refusing it, and the new checker is a second instance of the same functions.

Statement

Definitions.

Theorems.

Proof

A (Rel). The relation between the symbolic state and the frame says that the frame's products are regProdIn V vs σ.nodes σ.regs (Rel.prods, on the values vs of the final table), and that the factors of the table's nodes refer to nodes of the table (Rel.fwf). Rel.defP appends a node nd and sets the frame's register with products pr, when nd's factors refer to nodes of the table and evaluate to pr (prodVal). Rel.def is its instance for a node without factors (pr = none).

B (exec_fbinC). exec of any float operator: the result is floatBin lane by lane with the operands' recorded products, and the register's products are the operands' values when the statement is fmul contract. exec_fbin is its instance for the other operators.

C (SState.stmt_sound). In the float case an operand's products in the frame are x.prodsWith V (vals V σ.nodes) (x.factors σ.nodes) (A at the operand's register: the factors refer to nodes before the new one, by Rel.fwf, so their values on the final table are those on the table before the node), which is what fbinOf's value reads (SNode.eval_fbinOf). For fmul contract the node's factors are its operand terms (SNode.factors_fbinOf), whose values are the operands', so Rel.defP applies with exec's pair.

D. SState.run_ptrs, SState.run_sound and Block.soundAt are the earlier proofs with the flag passed through; Block.sound_withAt is Block.soundAt with either flag, then Ends.of_C when the flag is off.

Tests

MojoProofTest/SymContract.lean, on the latch %52 of the naive matmul kernel (%65 = fmul contract float %60, %64, %66 = fadd contract float %48, %65):

The edge and a path with fmul contract

MojoProof/Sym/Path.lean, for every program, path and thread:

Tests:

Paths and loops with fmul contract

MojoProof/Sym/Path.lean and MojoProof/Sym/Loop.lean, for every program, function, path, loop sequence and thread. Each definition below takes a flag contract and checks every block with coversWith … contract, or enters every block after the first with Valuation.intoWith contract. The path's checker, premises and last valuation have no other form: where the flag is off they are written coversPathWith false, WalkWith false and Valuation.lastWith false. The other definitions' cases without the flag are named in parentheses below; each is defined as its With form at false.

Definitions.

Theorems, each proved once for both values of the flag.

The cases without the flag:

Test (MojoProofTest/SymNaive.lean): the naive kernel's loop %46 → %50 → %52, as a LoopSeg round (naiveL), is accepted by LoopSeg.coversRoundWith true and refused by LoopSeg.coversRound (the latch's fmul contract; naiveL_covers). At one concrete thread at %46's position 2 (frameL: %47 = 0, %48 = 0.0, %16 = 2) and one memory (mem0), its rounds' premises (RoundWith true) hold for two rounds, by decide +kernel (loop_rounds), so Block.sound_loop with contract = true runs the thread through two rounds to %46 again, at the second iterate of Valuation.roundWith true, where %47 = 2 and %48 = 1.0 (loop_regs, loop_two). This covers one thread, one memory and the trip count 2.