The trace-replay checker
Kernel.replay and its soundness, for every program (MojoProof/Sem/Replay.lean).
The checker
Kernel.replay prog fn L args m ch oracle fuel phases obs R, for a decidable R:
Grid.start prog fn L args m ch oracle. If the start faults, the result isunknown.Replay.run L c fuel phases g. This isGrid.run(MojoProof/Sem/Grid.lean), except that a stop keeps whatGrid.rundrops (Replay.Stop):fault g n fire e: the gridgand the threadnwhose step (fire = false) or collective call (fire = true) is the faulte;deadlock g: the grid after a phase that completed nothing with a thread not returned;out msg: out of fuel or phases.
Replay.found obs R. A fault.ubgivesub n msg. An.unsupportedfault givesunknown, and so doesout. A deadlock givesstuck. For a final gridgthe checks run in order:race? g.mem.trace: an access and the earlier access it races with givesrace a e;- then
broken? g.mem.trace: a frozen read (an!invariant.loadthat neither writes nor is anatomicrmw's) and an access that writes for the core'skept(a write or anatomicrmw's read) that touches its bytes givebroken r w; - then
obs g.mem:nonegivespost none, ayfailingRgivespost (some y), and aysatisfyingRgivespass y.
Found.bad is true exactly for ub, race, broken, stuck and post.
Statements
For every launch L, contexts c, grid g, fuel, phases, observation obs and decidable R:
Replay.run_eq:(Replay.run L c fuel phases g).mapError Stop.toFault = g.run L c fuel phases.Replay.run_stop: if the replay stops withs, thens.Holds L c g:- for
fault g' n b e,g'is reachable fromgand its step or collective call ise; - for
deadlock g',g'is reachable, not done, and has no step.
- for
Replay.found_bad:(found obs R (run L c fuel phases g)).bad = true → ¬ Grid.Sound L c g obs R, for a grid with at most the launch's number of threads every grid reachable from which has the premises ofracy_iff(Grid.Fits;Grid.start_reach_fitsat a start's grid).Grid.run_ub:g.run L c fuel phases = .error (.ub msg)gives a reachable grid that faults (the core'sGPUProof.Faultsatsig), or one that is not done and has no step.
For every program, kernel, launch, arguments, memory, choice, oracle, fuel, phases and adm with
adm ch oracle:
Kernel.replay_sound: a violation refutesKernel.Sound prog fn L args m adm obs R.Kernel.replay_unsafe: a violation for the trivial observationfun _ => some ()and relationfun _ => TruerefutesKernel.Soundfor every observation and relation.Kernel.replay_block: supposeRon the blocks fixes blockoutofmtof x, wherexism's block. Then a violation of the replay comparing blockout's final bytes (Replay.bytes?) withf x's refutesKernel.Soundforfun m => some m.blocksandR.
Proofs
run_eq. By induction on fuel, on the list of threads and on phases, following the definitions: each stop is mapped to the faultGrid.runthrows.bind_eqpasses the agreement through>>=. The two done tests use different matchers, so eachifis split on both sides, and the mixed cases are contradictions.run_stop.- Fault: the stop's grid is reached by the steps taken before it. Those are
advancesteps inthread, the earlier threads' runs inall(Grid.runThread_reach), and the earlier completions infire. Lift withStop.Holds.back. - Deadlock: a phase ran every thread until it stopped running (
thread_ok,all_ok).advance_framegives that a step of one thread leaves the others unchanged. So no thread of the grid after the phase runs (Replay.Idle), andadvance_idlegives noadvancestep. - Deadlock, continued:
fire_falsesays no collective call completed, so everyfireisnone. This covers threads outside the grid too (fire_none). So the grid has no step.
- Fault: the stop's grid is reached by the steps taken before it. Those are
found_bad. Case on the result:- a
.ubfault contradictssafeat the reachable grid; - a deadlock contradicts
progress; - for a final grid (reachable and done by
run_ok, fromGrid.run_reachandGrid.run_done):- a race contradicts
raceFree(racy_of_raceviaAccess.races_of_raceWith); - a broken promise contradicts
kept(kept_of_broken); postcontradicts the fieldpost.
- a race contradicts
- a
replay_sound. Unfold the start and applyfound_badto the started grid.replay_unsafe. UseGrid.Sound.unit: the first six fields give soundness for the trivial observation.replay_block. UseKernel.Sound.mapwithf B := bytes? (B out).
Probes
The probes of an output from its cells' bytes (wrong outputs the checker must refuse: one cell
omitted, no cell stored, two cells swapped, every cell zero, the input copied): Probe.drop k, Probe.stale, Probe.swap i j,
Probe.zero w n and Probe.copy l t enc x n.
Scope
Every program, for the checker and its soundness. The instances in MojoProofTest/Replay.lean cover
vector_addition only, on one launch (L23), memories mem5 and mem4, choice ch₀ and oracle
ω₀:
controlpasses;- the canaries are refuted:
omit_cell,stale_out,swap_cells,zero_out,input_copy; pre_refutesgives the same refutations with the preconditionMap2.Pre, bypre5;short_found,short_unsafeandshort_reachgive the fault at thread 4 onmem4.
Kernel evaluation of one replay of L23 takes about 3 s.
What a replay does not give:
- A
passis evidence for that one execution only, with no soundness claim. - An
unknownis never a violation.