LAWS.bend open laws/TODOs
raw source on the hub · import bend-gpu-kernels@0.1.0.0/LAWS.bend as LAWS
bend-gpu-kernels: the laws about lanes.bend, the index arithmetic every kernel writes through. They are checks at literal values: the real shapes of a 2048 x 2048 diffusion transformer (rows of 5,376, 7,168 and 14,336 cells in 7 segments, 4,422 rows, 16,384 lanes) and small cases taken whole. Base has no theory of U32 division or overflow yet, so no law here covers every input. Laws: share_small, share_real, seg_cells, seg_rows.
2 imports
import Base import ./lanes.bend as L
Laws
law seg_cells provedin PROOF.bendsource · line 50 · raw
Pair({0x9ee7342e5aba51ed171798b850c1c311/lanes.cell(30953, 768) == U32.add(U32.mul(0x9ee7342e5aba51ed171798b850c1c311/lanes.row(30953, 7), 0x9ee7342e5aba51ed171798b850c1c311/lanes.width(768, 7)), 0x9ee7342e5aba51ed171798b850c1c311/lanes.col(30953, 768, 7)) : U32}, Pair({0x9ee7342e5aba51ed171798b850c1c311/lanes.cell(30953, 1024) == U32.add(U32.mul(0x9ee7342e5aba51ed171798b850c1c311/lanes.row(30953, 7), 0x9ee7342e5aba51ed171798b850c1c311/lanes.width(1024, 7)), 0x9ee7342e5aba51ed171798b850c1c311/lanes.col(30953, 1024, 7)) : U32}, Pair({0x9ee7342e5aba51ed171798b850c1c311/lanes.cell(30953, 2048) == U32.add(U32.mul(0x9ee7342e5aba51ed171798b850c1c311/lanes.row(30953, 7), 0x9ee7342e5aba51ed171798b850c1c311/lanes.width(2048, 7)), 0x9ee7342e5aba51ed171798b850c1c311/lanes.col(30953, 2048, 7)) : U32}, Pair({U32.div(0x9ee7342e5aba51ed171798b850c1c311/lanes.cell(30954, 2048), 2048) == 30954 : U32}, Pair({U32.div(0x9ee7342e5aba51ed171798b850c1c311/lanes.cell(123816, 4422), 4422) == 123816 : U32}, {U32.div(0x9ee7342e5aba51ed171798b850c1c311/lanes.cell(4838400, 8), 8) == 4838400 : U32})))))Guarantees: for rows of 768, 1,024 and 2,048 cells a segment (7 segments a row), the last of 30,954 items starts at the cell its row and column give (row * row width + column), and the cell just past the last item, 30,954 * seg, is computed without wrapping; so is the cell past the last softmax row (123,816 rows of 4,422) and past the adaLN output (4,838,400 items of 8). Item i owns cells i * seg .. i * seg + seg - 1, so no two items share a cell. Why it matters: a kernel writes an item's cells at i * seg but reads its weights and modulation by row and column; if those disagreed it would apply the wrong weights, and a wrapped index would write over the start of the array.
law seg_rows provedin PROOF.bendsource · line 58 · raw
Pair({0x9ee7342e5aba51ed171798b850c1c311/lanes.leads(0, 7) == True{} : Bool}, Pair({0x9ee7342e5aba51ed171798b850c1c311/lanes.leads(6, 7) == False{} : Bool}, Pair({0x9ee7342e5aba51ed171798b850c1c311/lanes.first(6, 7) == 0 : U32}, Pair({0x9ee7342e5aba51ed171798b850c1c311/lanes.row(6, 7) == 0 : U32}, Pair({0x9ee7342e5aba51ed171798b850c1c311/lanes.leads(30947, 7) == True{} : Bool}, Pair({0x9ee7342e5aba51ed171798b850c1c311/lanes.leads(30948, 7) == False{} : Bool}, Pair({0x9ee7342e5aba51ed171798b850c1c311/lanes.leads(30953, 7) == False{} : Bool}, Pair({0x9ee7342e5aba51ed171798b850c1c311/lanes.first(30947, 7) == 30947 : U32}, Pair({0x9ee7342e5aba51ed171798b850c1c311/lanes.first(30953, 7) == 30947 : U32}, Pair({0x9ee7342e5aba51ed171798b850c1c311/lanes.row(30947, 7) == 4421 : U32}, {0x9ee7342e5aba51ed171798b850c1c311/lanes.row(30953, 7) == 4421 : U32}))))))))))Guarantees: in the first row (items 0 .. 6) and the last (30,947 .. 30,953) of 7 segments, the first item leads its row and the others do not, and every item finds the row's partials at its first item (0, 30,947) and the row's per-row values at its row (0, 4,421). Why it matters: the row scale of int8 quantization is written by the leading item only; two leaders would race on it, and an item reading another row's partials would normalize with the wrong row's sum.
Definitions
def hits source · line 12 · raw
@cnt:Nat -> @+r:Nat -> @+t:Nat -> @+l:Nat -> Nat
how many of the items 0 .. cnt - 1 are congruent to t mod l, walking them with their residue r (an obvious count, with no division)
def agree source · line 20 · raw
@k:Nat -> @+t:Nat -> @+n:Nat -> @+l:Nat -> Bool
whether leaves t .. t + k - 1 each get share() equal to that count, for n items on l leaves