The gemv kernels in the block checker: what each block needs (a plan)
Lean: proved, for every program, the lane number in the block checker (exec_laneid,
MojoProof/Sym/Exec.lean; the node SNode.call, MojoProof/Sym/Term.lean; the case of
SState.stmt, MojoProof/Sym/Checker.lean), the casts castV evaluates (castOk, which is
castV's cases by castOk_iff, MojoProof/Sym/Exec.lean; the node SNode.castAt and its value
SNode.eval_castAt, MojoProof/Sym/Term.lean; the step exec_cast in SState.stmt_sound), and
the value of a bitcast between scalar types of the same width (SNode.eval_bitcast, by
bitcast_bits). Instances and twins at the two kernels: MojoProofTest/SymLane.lean
(call_laneid, gevm_lane, gevm_entry, gemv_entry, loops_contract, reductions_refused)
and MojoProofTest/SymCast.lean (gemv_shfl, gemv_bitcast; bf16_fpext and bf16_blocks at
the bfloat16 naive matrix product), and the refusals of fptosi, fptoui and inttoptr
(casts_refused, MojoProofTest/SymCastOk.lean). Proved too, for every program, the summary of
a segment of a block that ends at a barrier or a warp shuffle (summarizeTo and Seg.sound,
MojoProof/Sym/Segment.lean), with the segments of both warp reductions as tests
(MojoProofTest/SymSeg.lean, item 3), and the pointer of a global named at a statement's
operand (SNode.globalAt and its value SNode.eval_globalAt, MojoProof/Sym/Term.lean, item 5),
and the checker's steps for insertvalue, extractelement, insertelement and a
getelementptr with two indices (exec_insertvalue, exec_extractelement,
exec_insertelement, exec_gep, MojoProof/Sym/Exec.lean, item 6), with gemv_kernel's entry
block from statement 3 as a test (gemv_segs), and a block's allocas with the checker's
alloca flag (SNode.fresh, SEff.alloca, exec_alloca, Block.soundAt, item 6), with
hand-built kernels and the run of gemv_kernel's three allocas as tests
(MojoProofTest/SymAlloca.lean). Everything after the section "What the checker
takes" is a plan, not a proof, but for items 1 to 3, item 5's node and item 6's done parts:
the constructs each block of the two kernels uses that the checker refuses, the summaries that
would take them, and the order of the work. The runs proved: gevm_kernel's thread from its
entry to ret at every launch with 1024 threads a block, for every K and N with K % 32 = 0
and K * N < 2 ^ 29 (whole, MojoProofTest/OblGevmWhole.lean), and gemv_kernel's thread at
one context, frame and memory (item 6); no run of gemv_kernel at every launch.
The kernels
tests/corpus/gemv/gemv_f32.mojo launches the two float32 kernels of max/kernels/src/linalg/gemv.mojo with blocks of 1024 threads (32 warps). The line numbers below are those of the two IR files in tests/corpus/gemv/.
gemv_kernel (gemv_f32_gemv_kernel_float32_float32_float32_False_b79a852b.nvptx.ll), arguments
%0 (the output c), %1 (the matrix a, M × K), %2 (the vector b), %3 = M, %4 = N,
%5 = K, grid ⌈M / 32⌉. One warp computes one row:
- block
%6(lines 8-56): the row%20 = (ctaid.x · ntid.x + tid.x) / 32; lane 0's row is sent to the warp by twoshfl.sync.idxwith source lane 0 (lines 22-26: the row as<2 x i32>, one shuffle per half); each half goes through a stack slot (alloca,store,lifetime.*, lines 8-10 and 27-48: the two halves' slots, a[2 x ptr]of their addresses, loads back through it);%36(line 49) is the row again, now lane 0's; the output cell%37 = c + %36(line 50), the row's offset%38 = %36 · K, the lane%40(lines 52-53), the test%41 = (%40 = 0), and the guard%36 ≥ M(line 55), which returns; - the loop
%44to%77(lines 61-109):⌈K / 32⌉rounds; roundiaddsa[%38 + 32 i + l] · b[32 i + l](fmul contract,fadd contract, lines 98-101, loads with!invariant.load) to lanel's sum when32 i + l < K(line 94); - block
%78(lines 111-133): five butterfly rounds (bitcast floattoi32,shfl.sync.bflywith offsets 16, 8, 4, 2, 1,bitcastback,fadd contract); lane 0 stores the result to%37(line 136).
gevm_kernel (gemv_f32_gevm_kernel_float32_float32_float32_1024_1308aaae.nvptx.ll), the same
arguments (a the vector of K, b the matrix K × N), grid ⌈N / 32⌉, a shared array of 1024
floats (line 6). Thread (w, l) (warp %11 = tid.x / 32, lane %13) of block β:
- block
%6(lines 10-42): the column%17 = 32 β + l, the output cell%29 = c + ⌊(β · ntid.x + tid.x) / 32⌋, the trip count%38 = ⌈K / 32⌉; - the loop
%39to%58(lines 44-70): roundiaddsa[32 i + w] · b[(32 i + w) · N + %17]to the thread's sum, with no guard on32 i + w < Kor on%17 < N; - block
%59(lines 72-112): the thread stores its sum to the shared cell32 l + w(lines 74-78), the block meets at the barrier (line 79), the thread loads the shared celltid.x = 32 w + l(lines 80-82), which holds the sum of thread(l, w)(column32 β + w, rows≡ lmod 32), the warp runs the same five butterfly rounds (lines 83-102), and lane 0 stores the column's total to%29(line 115).
What the checker takes
#mojo_info on both files (its summarize is the checker without fmul contract), with the
lane number and the casts in the fragment:
| block | statements | verdict |
|---|---|---|
gemv_kernel %6 |
48 | refused at statement 0, alloca [2 x ptr] (gemv_entry); with the alloca flag, statements 0 to 16 run (gemv_allocas) and the getelementptr at 30 is refused (gemv_allocas_twin); from statement 3, as eleven segments ending at the shuffles and the lifetime markers (items 3 and 6): all in the fragment (gemv_segs) |
gemv_kernel %43, %44, %54, %58, %59, %60, %75, %76, %100 to %103 |
in the fragment | |
gemv_kernel %70 |
4 | fmul contract: in the fragment of coversC (loops_contract) |
gemv_kernel %78 |
21 | whole: refused at statement 2, the first shfl.sync.bfly (reductions_refused, gemv_shfl); as six segments ending at the shuffles (item 3): all in the fragment (gemv_segments) |
gevm_kernel %6 |
32 | in the fragment, the lane number at statement 5 (gevm_entry) |
gevm_kernel %39, %43, %44, %97 to %99 |
in the fragment | |
gevm_kernel %45 |
13 | fmul contract: in the fragment of coversC (loops_contract) |
gevm_kernel %59 |
39 | whole: refused at statement 6, the barrier (reductions_refused); as seven segments ending at the barrier and the shuffles (item 3): all in the fragment, the first two with the shared global's pointer (item 5, gevm_segments, gevm_after_barrier) |
So both loops, every segment of the reductions and every block after them are in the fragment;
what is left is gemv_kernel's entry block's three allocas in its paths (the block checker
and the segments take them, item 6) and the schedule through the reductions' collectives (item 4).
The constructs, and the summaries that would take them
- The lane number (done).
llvm.nvvm.read.ptx.sreg.laneid, with no arguments and no fast-math flags, before or after a store: the nodeSNode.call lbl pc, whose value is the context'slaneidunder the declaration's return attributes (withAttrs), the stepexec_laneid.gevm_kernel's%6(line 15) andgemv_kernel's%6(line 52). - Casts of the same size (
bitcast float↔i32,gemv_kernel's lines 113-131 andgevm_kernel's lines 83-101;bitcast i64↔<2 x i32>,gemv_kernel's lines 22 and 49). Done: the nodeSNode.castAt lbl pc n anames its statement, asgetelementptrandloadnodes do (so thatSNodeholds noTy, whose derived equality the kernel does not reduce); its value iscastVat that statement's operator and types and the oracle of stepn(SNode.eval_castAt), so every castcastVevaluates is covered, not onlybitcast; the step isexec_cast. The checker takes a cast only at the operator and types thatcastOkadmits, andcastOkis false exactly wherecastVfaults with its unsupported-cast message on every operand (castOk_iff, for every layout, memory and choice), sofptoui,fptosi,inttoptrand an ill-typed cast are refused (casts_refused, with#mojo_info's line pinned, and its twinsitofp_taken, MojoProofTest/SymCastOk.lean); no file of tests/corpus/ uses the three.ptrtoint, which reads the addresses, is taken after a store too, since a store keeps every block's address and size (SEff.run_shape). Done too: a scalarbitcastbetween types of the same width keeps a word (.bits w x:bitcast_bitsfor every layout,SNode.eval_bitcastfor every node; at%78's statements 1 and 3,gemv_bitcast). Done in Sem: the evaluation lemma for the vectors, thatbitcast i64to<2 x i32>gives its two halves, low first, and back (castV_split,castV_joinandcastV_halves, MojoProof/Sem/Eval.lean, for every layout; test MojoProofTest/Bitcast.leanhalves57). -
Collective calls as the end of a segment (
gemv_kernel'sshfl.synccalls at lines 25-26 and 114-130;gevm_kernel's barrier at line 79 and shuffles at lines 84-100). A thread's step at a collective is.wait i args fn, and the grid resumes it with a value (Thread.resume: the call's register,pc + 1,k + 1). Done, in MojoProof/Sym/Segment.lean:summarizeTo P fn lbl p0 p1is the summary (SegSummary, a new structure, soExitandSummarykeep their constructors) of the statementsp0top1 - 1, by the checker's statement case, with, as its end, the collective call atp1(SState.waitAt: the barrier or a warp shuffle,Coll, called with no flags or attributes) and its arguments as terms. Its theoremSeg.sound, for every program: from a valuation meeting the summary's obligations (among them that each argument term evaluates), the thread's steps run the segment and its step atp1is the.waitof the collective on the arguments' values (Waits). The resumed thread is atp1 + 1with the same function, block,allocablocks and caller's register (Thread.resume_at), where the next segment starts:summarizeToagain, or, after the last collective, the existingsummarize P fn lbl (p1 + 1)andBlock.sound, which start inside a block. Tests (MojoProofTest/SymSeg.lean):gemv_kernel's%78is six segments, the five to its shuffles and the one from statement 19 to the branch, with their shapes pinned (gemv_segments);gevm_kernel's%59is seven segments, to the barrier at 6, to the shuffles at 11, 15, 19, 23 and 27 and from statement 28 to the branch, all in the fragment with item 5 (gevm_segments);gemv_first_waitruns the first segment of%78on a thread to its wait and its resume at statement 3, andgevm_after_barrier_waitthe segment of%59after the barrier to its wait at 11 and its resume at 12, each one line ofSeg.resume(for every program: from the summary's collective and length, the steps to the.waitand the resumed frame atp1 + 1, bySeg.soundandThread.resume_at). The resumed frame has at every register but the call's result the summary's value (Seg.resume_regs, for every program, byThread.resume_regs); atgevm_kernel's barrier, which has no result, every register (gevm_barrier_regs).gemv_kernel's%6from statement 3 is eleven segments, to its two shuffles and its lifetime markers, and the summary to its branch (gemv_segs, item 6).A block's segments on one thread, done in MojoProof/Sym/Segment.lean.
summarizeSegs P fn lbl p0 psfoldssummarizeToover the positionspsof the block's collective calls, each segment starting after the previous call, and ends withsummarizeafter the last call: the list of segment summaries and the summary of the rest.Seg.Throughis the run of that list on one thread, with the collectives' values as parameters:w iis the value thei-th call delivers and the memory the thread resumes on (the schedule, item 4, supplies them). If a segment's obligations hold at the entry valuation of its start frame, the thread reaches the call's wait with the facts ofWaits, and the thread resumed withw i(Thread.resume) runs the rest of the list; after the last call, if the rest's obligations hold, the block ends (Ends).Seg.through, for every program, is the fold ofSeg.sound,Thread.resume_atand, at the end,Block.sound: whensummarizeSegsgives the summaries,Seg.Throughholds for every thread atp0and everyw. Each segment's obligations stay a premise at its own start frame, whose registers the earlier segments set (Waits). The testgevm_through(MojoProofTest/SymSeg.lean) runs%59from statement 1 with its collectives at 6, 11, 15, 19, 23 and 27, at symbolic values: 5, 4, 3, 3, 3 and 3 statements before the calls, then 11 to the conditional branch. The obligations stay premises there; discharging them is left to the specification (item 7). -
A schedule through the collectives.
Seq(MojoProof/Sym/Sched.lean) runs threads in turn, each to its end, with no collective. The kernel theorem needs one completed run (Grid.start_sound), so a schedule is enough: for each block, every thread runs to the barrier, the barrier fires; then for each warp, its lanes run in turn to the nextshfl.syncand it fires (Grid.fire: lanejreceives the operand of laneshflSource mode j b c), five times forgemv_kernel's%78(two for its%6); then the lanes run to their end. This is the phase structure of the evaluatorGrid.run(Grid.runAll, thenGrid.fireAll, both reachable byGrid.Step:Grid.runAll_reach,Grid.fireAll_reach). Done for every program (docs/proofs/kernel.md, "Through collective calls", items 7 to 10):Sched(phases ofSeq.ToWaitand theirFires, thenSeq),Sched.start_sound,Fires.barriers,Fires.shflsandbflyRoundsAt_of_shfl; left is building the phases from a kernel's segments for every thread. The values fromshflSource: lane 0 foridxwith lane operand 0 and clamp 31,l ^^^ mforbfly(shflSource_bfly, MojoProof/Sem/Bfly.lean). The five rounds' values are thenbflyRoundsof the lanes' sums, whose tree, depth and error bound are proved (eval_bflyTree,bfly_warp_error). - A global as an operand (
gevm_kernel's%64and%66, lines 77 and 81:getelementptron the shared array). Done, in MojoProof/Sym/Term.lean: the context gives each block's globals (Ctx.globals, set byGrid.startper block), andSNode.globalAt lbl pc iis the pointer of the global named at operandiof the statement at positionpcof blocklbl, naming the statement, not the string; its evaluation lemmaSNode.eval_globalAt, for every valuation, says it is the context's address of the global. The checker'sgetelementptron a global is two nodes, the global's pointer and thegetelementptron it (SState.stmt), withSState.stmt_sound's case for it; aloadorstorewhose pointer operand is the global itself is the global's node at that operand (0 for aload, 1 for astore), then theloadorstoreon it, with their cases ofSState.stmt_sound(the layernorm kernels'storeandloadof their shared array:ln_store,ln_store_ends,ln_load). The node is skeleton (SNode.pay): the two-run theorems take one table of globals (hgofvals_skelandSummary.oblivious_skel;Valuation.Relhas it), so the oblivious checkSummary.oblivioustakes a summary with one (ln_store_oblivious). The loads after the barrier start a new segment (item 3), so they are before that segment's first store. Tests (MojoProofTest/SymSeg.lean):gevm_after_barrierpins the table of the segment after the barrier, andgevm_sharedevaluates the global's nodes at statements 4 and- Race freedom across the barrier is
racy_tpose(docs/proofs/warp-dot.md, "The transposition through shared memory"),racy_eq_false_of_phasedat the tilingTiling.tpose 32 4 β: before the barrier thread(w, l)owns shared cell32 l + w = tpose 32 (32 w + l)(Launch.tpose_env, the instance at 32 warps ofLaunch.warps_env), after it threadtreads cellt. On a run the pattern, for every cell map injective on a block of threads, isGrid.sound_cells(docs/proofs/barrier-owned.md, "On a run"), with the instancesound1024attpose 32on every valid launch withntid.x = 1024, ofsound_tpose(every valid launch and cell width; MojoProofTest/Transpose.lean). The kernel's two rounds meetGrid.sound_roundswith the loop's reads, the start's arrival at%59and the last memory's owners as premises (gevm_sound, MojoProofTest/GevmTrace.lean; docs/proofs/barrier-owned.md, "A whole trace of rounds").
- Race freedom across the barrier is
- The stack round trip (
gemv_kernel's%6, lines 8-10 and 27-48), the largest item:alloca: done in the block checker, for every program, with itsallocaflag (SState.alloca;summarizeAt true,coversAt true): the nodeSNode.freshfor the new block's pointer and the effectSEff.allocathat makes the block, whose run is the obligation that its number is fresh (Mem.freshof the thread at the statement's step count; MojoProof/Sym/Term.lean), the stepexec_alloca(MojoProof/Sym/Exec.lean), and the block's endEndsAt true, with the frame'sallocasthe summary's blocks (SEff.blocks) followed by the entry's (Block.soundAt,Block.sound_alloca, MojoProof/Sym/Block.lean;Block.soundis its instance with the flag off). Tests (MojoProofTest/SymAlloca.lean): kernels of one to threeallocas (allocs_sound,two_sound), the twins without the flag and at a used number (allocs_twin,alloc_used), andgemv_kernel's%6, whose threeallocas and the statements to the shuffle at 17 run with three effects (gemv_allocas). After analloca,getelementptr,icmpandptrtointhave nodes on the memory the effects before them make (SNode.gepAfter,SNode.gepNAfter,SNode.icmpAfter,SNode.castAfter; MojoProof/Sym/Term.lean), as the entry memory has no block where theallocamade one; testreadK(reads_covers,reads_sound, and the mutant with the entry memory's node,reads_mutant). The segments take the flag too (summarizeTo,summarizeLifeandsummarizePieceswithallocaset;Seg.sound,Seg.lifeandPiece.throughfor every program, the frame'sallocasthe segment's blocks followed by the entry's):gemv_segs_alloca(MojoProofTest/SymSeg.lean) summarizes%6from statement 0 to its branch, the first segment, to the shuffle at 17, with the threeallocas' effects; its mutantsgemv_segs_alloca_mutant. The paths and the loops take the flag too (coversPathAt,Runs.of_retAt, MojoProof/Sym/Path.lean and MojoProof/Sym/Loop.lean;coversChainsAt,Runs.of_chainsAt, MojoProof/Sym/Loop.lean):tail_coversandtail_runs(MojoProofTest/SymGemvTail.lean) take%6from statement 41, after its last marker, through%43to%103'sretwith the flag, and a thread at statement 41 on one context and memory runs to its end. The two-block alloca path of MojoProofTest/SymAlloca.lean (pathText, parsed and checked, no id defined twice) is accepted with the flag (path_covers), meetsWalkWithandRetWithat one launch of one thread (path_walk,path_retWith) and runs to its end with bothallocablocks dead (path_dead), as the interpreter's steps do (path_steps); on a memory that already has the first block's number, the premises fail (path_used). The loop at%54with both flags: a round through either arm of%60is accepted (loop_rounds), and so is the chain of two loops at one header, the%70rounds then the%75rounds, the order gemv's rounds take (loop_arms, with the path out cut after%59); with its path out through%78the chain is refused (loop_refused), because%78's five shuffles are collectives the block checker does not summarize. A chain whose last path out stops after its last edge, into a block at a position, takes the thread to the frame there (ChainWith.enter, byChainWith.reachandBackWith.enter, MojoProof/Sym/Loop.lean;BackWith.enteris a path's run through its last edge, and each ofBlock.sound_loop's rounds), and a continuation from that frame joins it (RunsVia.of_chain, MojoProof/Sym/OblSeg.lean). The run from statement 0:Piece.ThroughTo(MojoProof/Sym/Segment.lean) is the segments' run continued at the frame after the last one into any continuation (Piece.Throughis its instance that ends at the block's end,EndsAt),Piece.throughToproves it for every program, andRunsVia.of_fires(MojoProof/Sym/OblSeg.lean) takes the segments' premises from the BooleanPiece.fires.gemv_runs(MojoProofTest/SymGemvTail.lean): on one context (one block of one thread), the frameframeS 0at statement 0 andmem0, with the two shuffles delivering 0 onmemW, the thread runs through the threeallocas, the shuffles and the nine markers to statement 41 and from there toreton the%43branch; the kernel decidesPiece.fires, and refuses the row count 1 and deliveries onmem0(gemv_runs_mutant). For thisfill(MojoProof/Sem/Eval.lean) is by structural recursion: the kernel did not unfold the well-founded one at[2 x ptr] undef. On the%44branch (MojoProofTest/SymGemvTail.lean): the segment checker summarizes%78from position 1 at its fiveshfl.sync.bflys, and the path checker with both flags takes the path after the last one through%100'sstoretoret(bfly_covers);bfly_at, for every thread at statement 41 and every memory of the deliveries, runs the chain through%44and the loop with no round, stopping after%59's edge into%78(RunsVia.of_chain,chainB), then%78's segments through the five shuffles and the path toret;gemv_loop_runsrunsframeS 1(row count 1,K = 0) from statement 0 through%6's segments andbfly_at, the seven waits joined byRunsVia.of_fireswith the waits after the block's (ws). The deliveries are premises, their memories too (memW, the memory at%6's first shuffle, at all seven); mutantsbfly_mutant;lifetime.startandlifetime.endon a block the thread owns: done as the end of a segment (summarizeLife,Seg.lifetime), the next segment starting after the marker on the memoryMem.setLivemakes;insertvalueintoundef(lines 34-35),insertelementintoundef(lines 41, 45) andextractelement(lines 23-24): done, for every program. The nodesSNode.insert,SNode.eltAtandSNode.insEltAt(MojoProof/Sym/Term.lean) evaluate asinsertV,extractEandinsertE; anundef,poisonorzeroinitializeroperand to insert into is itsSNode.constAtnode (fill .undef tforundef); the steps areexec_insertvalue,exec_extractelementandexec_insertelement(MojoProof/Sym/Exec.lean), inSState.stmt_sound(MojoProof/Sym/Block.lean);getelementptrwith two indices (line 38): done, for every program, on a base that is not a global: the nodeSNode.gepN(its indices evaluated one by one,SState.ops_eval), the stepexec_gep; on a global with other than one index the checker still refuses. With these,gemv_segs(MojoProofTest/SymSeg.lean) summarizes%6from statement 3, after itsallocas, as eleven segments, to its two shuffles and nine lifetime markers, and the summary of statements 41 to 47 to its branch; on a thread at statement 3, the thread runs the block through them (Piece.through). Its open twingemv_segs_twin: the checker refuses statement 0, the firstalloca;- loads after stores (lines 39-44). The load
node that carries the effects before it is done:
SNode.loadAfter(MojoProof/Sym/Term.lean), which the checker makes of aloadafter the block's firststore(on a global, on itsSNode.globalAtnode), with its case ofSState.stmt_sound; its value one effect at a time (MojoProof/Sym/LoadAfter.lean, for every valuation): after astoreat a pointer of the same value, type, space and alignment, the stored value's decoding (SNode.eval_loadAfter_store, byMem.load_store); after astoreapart from it, its value without thestore(SNode.eval_loadAfter_apart, byMem.load_store_apart); aloadeffect leaves it (SNode.eval_loadAfter_log). Tests at layernorm's%453(MojoProofTest/SymSeg.lean):ln_after,ln_twin,ln_apart,ln_reload. Left: the values of%6's loads, which need the codec form for thei32slots (Mem.load_store_codec, MojoProof/Sem/Confluence.lean) and an element lemma for the[2 x ptr]stored whole (line 37) and read one pointer at a time: the summary has the loads' nodes (SNode.loadAfterover thestores), not their values. Then%36is lane 0's%20(items 2, 3, 4).
- The kernel clause and the specification. With items 1 to 6, each thread of
gemv_kernelis a path through%6's segments, the loop and%78's segments; ofgevm_kernel, through%6, the loop and%59's segments. The store is lane 0's, to its row's (column's) cell. Each warp's value iswarpDotof its column's pairs once the threads' loop sums are stored (warpDot_tpose).
The order of the work
- The lane number (item 1): done.
- Same-size casts (item 2): the node, the step and the scalar evaluation lemma are done;
%78is now refused at its first shuffle, not at thebitcastbefore it. The vector evaluation lemma is done too (castV_split,castV_join). - Segments at collectives (item 3): done,
%78's six segments and, with item 5,%59's seven are in the fragment, a segment's wait and resume are one line ofSeg.resume, and a block's segments run in a row on one thread (Seg.through). The schedule (item 4) is proved for every program; its phases from the segments are left. With items 2 to 4,%78ofgemv_kernelis covered, and with item 5%59ofgevm_kernel, sogevm_kernelhas every block covered beforegemv_kerneldoes (whose entry block needs item 6): it is the first kernel to prove. - Globals (item 5): done; the ownership across the barrier is left (
gevm_kernel), and aloadwhose pointer operand is a global, after the segment's firststore, is still refused. - The obligations of
gevm_kernel's%6and its loop by mojo_obl, at every launch withntid.x = 1024: done (MojoProofTest/OblGevm.lean); forKnot divisible by 32 the last round reads pastxandB(rounds_open). - The stack round trip (item 6):
gemv_kernel's entry block. The loads after stores are done (SNode.loadAfter, its value lemmas in MojoProof/Sym/LoadAfter.lean), a lifetime call ends a segment (Seg.lifetime), and the vector and aggregate nodes and the two-indexgetelementptrare done, so%6from statement 3 is in the fragment (gemv_segs). Theallocain the block checker is done (statements 0 to 2: its node and effect, the freshness obligation, andEndsAtwith the frame'sallocas,Block.soundAt). The segments with the flag are done, so%6is in the fragment from statement 0 (gemv_segs_alloca), and so are the paths with the flag from statement 41 (tail_runs), and the segments' run continued into the path toreton the%43branch, at one context, frame and memory (gemv_runs), and on the%44branch with no round of the loop at%54, through%78's five shuffles (gemv_loop_runs). Left, in this order: rounds of the loop on that run (K > 0, the%70then the%75rounds ofloop_arms, whose invariantchainBdoes not state); deliveries whose memory is the thread's at each wait, which needs the valuation after a block's segments as a function (Piece.firescomputes it and returns only its check); the schedule's deliveries (item 4); then the values of the loads through the stored[2 x ptr]and of thei32slots (the element lemma andMem.load_store_codec), which the kernel theorem needs. - The kernel theorems (item 7), first
gevm_kernel's.
The specifications' premises
The kernels' guards fix the premises of a specification:
gemv_kernel:ntid.xa multiple of 32. Otherwise each block's last warp is partial: its lanes past the block are not threads, so a butterfly partner is missing and its operand is poison (Grid.fire); and the rows(β · ntid.x + 32 w) / 32of two warps of consecutive blocks can be equal (withntid.x = 48, warp 1 of block 0 and warp 0 of block 1 both get row 1), so their lanes 0 store to the same cell, a race. The rows pastMreturn at the guard (line 56) and the columns pastKare skipped (line 95).gevm_kernel:ntid.x = 1024(the shared array has 1024 cells, and the transposition through it pairs warpwwith lanew),KandNmultiples of 32: its loop reads row32 i + wfor everyi < ⌈K / 32⌉and column32 β + lwith no guard againstKorN.- Both: the output's block apart from the inputs' (the loads carry
!invariant.loadingemv_kernel).
The value stored is the butterfly tree over the 32 lanes of each lane's strided loop sum, not
the sequential dot product of TorchLean.Tensor.matVecLoop: the specification is warpDot
(docs/proofs/warp-dot.md), with an error bound against the exact row (column) product:
warpDot_error, warpDot_matVec and warpDot_vecMat, and the contraction-off word
warpDot_eq. The float rule gemv's Kernel.Sound will be stated against: gemv's word per row,
groupDot 5, meets the rule of GPUProof.Spec.matVec (GPUProof.laneVecGrade 32 5 fun n => ⌈n /
32⌉) (MojoProof.Tile.groupDot_holds, docs/proofs/dot.md); the kernel theorem is not proved.
Scope
exec_laneid, exec_alloca, Block.soundAt, SNode.eval_castAt, SNode.eval_bitcast,
bitcast_bits, castOk_iff,
SNode.eval_globalAt, the cast, getelementptr, load and store cases of
SState.stmt_sound (with a load after a store, and the insertvalue, extractelement,
insertelement and two-index getelementptr cases), Seg.sound, Thread.resume_at,
Thread.resume_regs, Seg.resume, Seg.resume_regs, Seg.through, Seg.lifetime,
Seg.lifetime_ptr, Piece.throughTo, Piece.through, RunsVia.of_fires, BackWith.enter,
ChainWith.enter, RunsVia.of_chain and the value lemmas of SNode.loadAfter cover every
program; the tests cover the seven blocks named above
of the two kernels, two blocks of the bfloat16 naive matrix product, five one-statement blocks
built on a block of vector_addition (MojoProofTest/SymCastOk.lean), three hand-built blocks
of allocas (MojoProofTest/SymAlloca.lean), the segments of the two reductions and two blocks
of a layernorm kernel (MojoProofTest/SymSeg.lean), and two runs of one thread of gemv_kernel
from statement 0 of %6 to ret, one on the %43 branch (gemv_runs) and one through %44,
the loop at %54 with no round and %78's five shuffles (gemv_loop_runs). That
gevm_kernel's trace meets racy_tpose's (on a run, Grid.sound_cells's) premises (item 5),
item 6's loaded values and the loop's rounds on a run, and items 4 and 7 are a plan: no
statement of them is proved, and the item numbers are this file's own.