~/bend-docscommunity

main.bend relies on unsafe/foreign

raw source on the hub · import bend-ml-tensor-gpu@0.1.5.4/main.bend as Main

bend-ml-tensor-gpu: tensor-array's products on the GPU, with tensor-array's bits.

import ../tensor-array/main.bend as TA import bend-ml-tensor-gpu@0.1.5.4/main.bend as TG TG.matmul(n, k, m, par, a, b) # the same arguments, result type and bits as TA.Mat.matmul

The six products (matmul, matmul_nt, matmul_tn and their accumulating forms) take tensor-array's Mat values and return its result types; par is ignored (the GPU decides the split). Each product is one ! call (a bang): a balanced fork tree whose leaves each compute a 4 x 4 tile of C, every node sharing A, B and C through Base's Array.fork (two handles to one block, no copy), as upstream's one-block pattern does (bendlang/bend tests/run/stencil3d.bend). On a machine without a GPU, or with +RTS --gpu off -RTS, the same bang runs on the CPU threads.

The bits: a cell of C is computed in tensor-array's order. Product p of a dot goes to partial sum p mod 4, in increasing p, each sum starting at +0.0, and the four sums are combined by TA.t8_comb with rot = k mod 4, as tensor-array's dotr and t8_dot do; an accumulating product adds the cell to C once with TA.cwr. The loop takes four steps of k a turn; the steps past k in the last turn add +0.0, which leaves a sum unchanged (a sum that starts at +0.0 is never -0.0). Bend builds the device code with --fmad=false, so no multiply-add is fused. tests/bits.bend checks the bits against tensor-array on many shapes, on the GPU and the CPU.

Counter-based random numbers (fill_uniform, fill_gauss, uniform_mat, gauss_mat and their _at forms; the last section): n uniforms or Gaussians of a counter made in one bang, each a pure function of (counter, index), with the same bits on every lane.

Not proved, and marked so: Array.fork and Array.join are @unsafe in Base, so the defs below that call them, or take a shared array, are @unsafe, and bend main.bend names every def that relies on them. Nothing checks that a leaf writes only its own tile of C, or never writes A or B; the tiles are disjoint by construction (leaf t writes tile t). All of it is Bend: no foreign code. Written by bend-ml's scripts/gen_tensor_gpu.py (4 x 4 tiles). bend-lint: disable-file bend-lint-rules/performance/gpu_fit -- the bangs carry the arrays to the device by design; that is the package not-expected-because: products timed on the GPU against 16 CPU threads (8.4 against 12.2 ms, 11-13 against 55-56 ms, NOTES 2026-10-18); a caller whose kernel does not win runs the same bang on the CPU threads

2 imports
import Base
import bend-ml-tensor-array@0.1.22.0/main.bend as TA

Types

type E source · line 34 · raw

Data

the sizes and strides of one product: C[i][j] = sum_p A[oa + i*arow + p*sa] * B[ob + p*sb + j*bcol], n x m, k steps (oa, ob: 0 except for matmul_precise's blocks)

type GR source · line 44 · raw

Type

the values of one turn: A's 4 rows and B's 4 columns at four consecutive steps, read through the arrays in order

type T source · line 180 · raw

Type

the tile's cells after the four sums are combined, row by row

type ABC source · line 249 · raw

Type

type O2 source · line 368 · raw

Type

type O3 source · line 371 · raw

Type

type O4 source · line 374 · raw

Type

type R1 source · line 377 · raw

Type

type R2 source · line 380 · raw

Type

type R3 source · line 383 · raw

Type

type R4 source · line 386 · raw

Type

type SC source · line 657 · raw

Data

the result of rng_sc: sin and cos of one angle

type FE source · line 697 · raw

Data

the counter, the first index and the number of cells, the same for every leaf

Definitions

def pk source · line 38 · raw

@ok:Bool -> @+x:F32 -> F32

a product that counts only when its step is inside k (the last turn's steps past k add +0.0)

def gr_31 source · line 47 · raw

@+ia:U32 -> @+ib:U32 -> @+arow:U32 -> @+sa:U32 -> @+sb:U32 -> @+bcol:U32 -> @+x0_0:F32 -> @+x0_1:F32 -> @+x0_2:F32 -> @+x0_3:F32 -> @+x1_0:F32 -> @+x1_1:F32 -> @+x1_2:F32 -> @+x1_3:F32 -> @+x2_0:F32 -> @+x2_1:F32 -> @+x2_2:F32 -> @+x2_3:F32 -> @+x3_0:F32 -> @+x3_1:F32 -> @+x3_2:F32 -> @+x3_3:F32 -> @+y0_0:F32 -> @+y0_1:F32 -> @+y0_2:F32 -> @+y0_3:F32 -> @+y1_0:F32 -> @+y1_1:F32 -> @+y1_2:F32 -> @+y1_3:F32 -> @+y2_0:F32 -> @+y2_1:F32 -> @+y2_2:F32 -> @+y2_3:F32 -> @+y3_0:F32 -> @+y3_1:F32 -> @+y3_2:F32 -> @a:Array<F32> -> @rv:Pair(Array<F32>, F32) -> GR

def gr_30 source · line 51 · raw

@+ia:U32 -> @+ib:U32 -> @+arow:U32 -> @+sa:U32 -> @+sb:U32 -> @+bcol:U32 -> @+x0_0:F32 -> @+x0_1:F32 -> @+x0_2:F32 -> @+x0_3:F32 -> @+x1_0:F32 -> @+x1_1:F32 -> @+x1_2:F32 -> @+x1_3:F32 -> @+x2_0:F32 -> @+x2_1:F32 -> @+x2_2:F32 -> @+x2_3:F32 -> @+x3_0:F32 -> @+x3_1:F32 -> @+x3_2:F32 -> @+x3_3:F32 -> @+y0_0:F32 -> @+y0_1:F32 -> @+y0_2:F32 -> @+y0_3:F32 -> @+y1_0:F32 -> @+y1_1:F32 -> @+y1_2:F32 -> @+y1_3:F32 -> @+y2_0:F32 -> @+y2_1:F32 -> @+y2_2:F32 -> @+y2_3:F32 -> @+y3_0:F32 -> @+y3_1:F32 -> @a:Array<F32> -> @rv:Pair(Array<F32>, F32) -> GR

def gr_29 source · line 55 · raw

@+ia:U32 -> @+ib:U32 -> @+arow:U32 -> @+sa:U32 -> @+sb:U32 -> @+bcol:U32 -> @+x0_0:F32 -> @+x0_1:F32 -> @+x0_2:F32 -> @+x0_3:F32 -> @+x1_0:F32 -> @+x1_1:F32 -> @+x1_2:F32 -> @+x1_3:F32 -> @+x2_0:F32 -> @+x2_1:F32 -> @+x2_2:F32 -> @+x2_3:F32 -> @+x3_0:F32 -> @+x3_1:F32 -> @+x3_2:F32 -> @+x3_3:F32 -> @+y0_0:F32 -> @+y0_1:F32 -> @+y0_2:F32 -> @+y0_3:F32 -> @+y1_0:F32 -> @+y1_1:F32 -> @+y1_2:F32 -> @+y1_3:F32 -> @+y2_0:F32 -> @+y2_1:F32 -> @+y2_2:F32 -> @+y2_3:F32 -> @+y3_0:F32 -> @a:Array<F32> -> @rv:Pair(Array<F32>, F32) -> GR

def gr_28 source · line 59 · raw

@+ia:U32 -> @+ib:U32 -> @+arow:U32 -> @+sa:U32 -> @+sb:U32 -> @+bcol:U32 -> @+x0_0:F32 -> @+x0_1:F32 -> @+x0_2:F32 -> @+x0_3:F32 -> @+x1_0:F32 -> @+x1_1:F32 -> @+x1_2:F32 -> @+x1_3:F32 -> @+x2_0:F32 -> @+x2_1:F32 -> @+x2_2:F32 -> @+x2_3:F32 -> @+x3_0:F32 -> @+x3_1:F32 -> @+x3_2:F32 -> @+x3_3:F32 -> @+y0_0:F32 -> @+y0_1:F32 -> @+y0_2:F32 -> @+y0_3:F32 -> @+y1_0:F32 -> @+y1_1:F32 -> @+y1_2:F32 -> @+y1_3:F32 -> @+y2_0:F32 -> @+y2_1:F32 -> @+y2_2:F32 -> @+y2_3:F32 -> @a:Array<F32> -> @rv:Pair(Array<F32>, F32) -> GR

def gr_27 source · line 63 · raw

@+ia:U32 -> @+ib:U32 -> @+arow:U32 -> @+sa:U32 -> @+sb:U32 -> @+bcol:U32 -> @+x0_0:F32 -> @+x0_1:F32 -> @+x0_2:F32 -> @+x0_3:F32 -> @+x1_0:F32 -> @+x1_1:F32 -> @+x1_2:F32 -> @+x1_3:F32 -> @+x2_0:F32 -> @+x2_1:F32 -> @+x2_2:F32 -> @+x2_3:F32 -> @+x3_0:F32 -> @+x3_1:F32 -> @+x3_2:F32 -> @+x3_3:F32 -> @+y0_0:F32 -> @+y0_1:F32 -> @+y0_2:F32 -> @+y0_3:F32 -> @+y1_0:F32 -> @+y1_1:F32 -> @+y1_2:F32 -> @+y1_3:F32 -> @+y2_0:F32 -> @+y2_1:F32 -> @+y2_2:F32 -> @a:Array<F32> -> @rv:Pair(Array<F32>, F32) -> GR

def gr_26 source · line 67 · raw

@+ia:U32 -> @+ib:U32 -> @+arow:U32 -> @+sa:U32 -> @+sb:U32 -> @+bcol:U32 -> @+x0_0:F32 -> @+x0_1:F32 -> @+x0_2:F32 -> @+x0_3:F32 -> @+x1_0:F32 -> @+x1_1:F32 -> @+x1_2:F32 -> @+x1_3:F32 -> @+x2_0:F32 -> @+x2_1:F32 -> @+x2_2:F32 -> @+x2_3:F32 -> @+x3_0:F32 -> @+x3_1:F32 -> @+x3_2:F32 -> @+x3_3:F32 -> @+y0_0:F32 -> @+y0_1:F32 -> @+y0_2:F32 -> @+y0_3:F32 -> @+y1_0:F32 -> @+y1_1:F32 -> @+y1_2:F32 -> @+y1_3:F32 -> @+y2_0:F32 -> @+y2_1:F32 -> @a:Array<F32> -> @rv:Pair(Array<F32>, F32) -> GR

def gr_25 source · line 71 · raw

@+ia:U32 -> @+ib:U32 -> @+arow:U32 -> @+sa:U32 -> @+sb:U32 -> @+bcol:U32 -> @+x0_0:F32 -> @+x0_1:F32 -> @+x0_2:F32 -> @+x0_3:F32 -> @+x1_0:F32 -> @+x1_1:F32 -> @+x1_2:F32 -> @+x1_3:F32 -> @+x2_0:F32 -> @+x2_1:F32 -> @+x2_2:F32 -> @+x2_3:F32 -> @+x3_0:F32 -> @+x3_1:F32 -> @+x3_2:F32 -> @+x3_3:F32 -> @+y0_0:F32 -> @+y0_1:F32 -> @+y0_2:F32 -> @+y0_3:F32 -> @+y1_0:F32 -> @+y1_1:F32 -> @+y1_2:F32 -> @+y1_3:F32 -> @+y2_0:F32 -> @a:Array<F32> -> @rv:Pair(Array<F32>, F32) -> GR

def gr_24 source · line 75 · raw

@+ia:U32 -> @+ib:U32 -> @+arow:U32 -> @+sa:U32 -> @+sb:U32 -> @+bcol:U32 -> @+x0_0:F32 -> @+x0_1:F32 -> @+x0_2:F32 -> @+x0_3:F32 -> @+x1_0:F32 -> @+x1_1:F32 -> @+x1_2:F32 -> @+x1_3:F32 -> @+x2_0:F32 -> @+x2_1:F32 -> @+x2_2:F32 -> @+x2_3:F32 -> @+x3_0:F32 -> @+x3_1:F32 -> @+x3_2:F32 -> @+x3_3:F32 -> @+y0_0:F32 -> @+y0_1:F32 -> @+y0_2:F32 -> @+y0_3:F32 -> @+y1_0:F32 -> @+y1_1:F32 -> @+y1_2:F32 -> @+y1_3:F32 -> @a:Array<F32> -> @rv:Pair(Array<F32>, F32) -> GR

def gr_23 source · line 79 · raw

@+ia:U32 -> @+ib:U32 -> @+arow:U32 -> @+sa:U32 -> @+sb:U32 -> @+bcol:U32 -> @+x0_0:F32 -> @+x0_1:F32 -> @+x0_2:F32 -> @+x0_3:F32 -> @+x1_0:F32 -> @+x1_1:F32 -> @+x1_2:F32 -> @+x1_3:F32 -> @+x2_0:F32 -> @+x2_1:F32 -> @+x2_2:F32 -> @+x2_3:F32 -> @+x3_0:F32 -> @+x3_1:F32 -> @+x3_2:F32 -> @+x3_3:F32 -> @+y0_0:F32 -> @+y0_1:F32 -> @+y0_2:F32 -> @+y0_3:F32 -> @+y1_0:F32 -> @+y1_1:F32 -> @+y1_2:F32 -> @a:Array<F32> -> @rv:Pair(Array<F32>, F32) -> GR

def gr_22 source · line 83 · raw

@+ia:U32 -> @+ib:U32 -> @+arow:U32 -> @+sa:U32 -> @+sb:U32 -> @+bcol:U32 -> @+x0_0:F32 -> @+x0_1:F32 -> @+x0_2:F32 -> @+x0_3:F32 -> @+x1_0:F32 -> @+x1_1:F32 -> @+x1_2:F32 -> @+x1_3:F32 -> @+x2_0:F32 -> @+x2_1:F32 -> @+x2_2:F32 -> @+x2_3:F32 -> @+x3_0:F32 -> @+x3_1:F32 -> @+x3_2:F32 -> @+x3_3:F32 -> @+y0_0:F32 -> @+y0_1:F32 -> @+y0_2:F32 -> @+y0_3:F32 -> @+y1_0:F32 -> @+y1_1:F32 -> @a:Array<F32> -> @rv:Pair(Array<F32>, F32) -> GR

def gr_21 source · line 87 · raw

@+ia:U32 -> @+ib:U32 -> @+arow:U32 -> @+sa:U32 -> @+sb:U32 -> @+bcol:U32 -> @+x0_0:F32 -> @+x0_1:F32 -> @+x0_2:F32 -> @+x0_3:F32 -> @+x1_0:F32 -> @+x1_1:F32 -> @+x1_2:F32 -> @+x1_3:F32 -> @+x2_0:F32 -> @+x2_1:F32 -> @+x2_2:F32 -> @+x2_3:F32 -> @+x3_0:F32 -> @+x3_1:F32 -> @+x3_2:F32 -> @+x3_3:F32 -> @+y0_0:F32 -> @+y0_1:F32 -> @+y0_2:F32 -> @+y0_3:F32 -> @+y1_0:F32 -> @a:Array<F32> -> @rv:Pair(Array<F32>, F32) -> GR

def gr_20 source · line 91 · raw

@+ia:U32 -> @+ib:U32 -> @+arow:U32 -> @+sa:U32 -> @+sb:U32 -> @+bcol:U32 -> @+x0_0:F32 -> @+x0_1:F32 -> @+x0_2:F32 -> @+x0_3:F32 -> @+x1_0:F32 -> @+x1_1:F32 -> @+x1_2:F32 -> @+x1_3:F32 -> @+x2_0:F32 -> @+x2_1:F32 -> @+x2_2:F32 -> @+x2_3:F32 -> @+x3_0:F32 -> @+x3_1:F32 -> @+x3_2:F32 -> @+x3_3:F32 -> @+y0_0:F32 -> @+y0_1:F32 -> @+y0_2:F32 -> @+y0_3:F32 -> @a:Array<F32> -> @rv:Pair(Array<F32>, F32) -> GR

def gr_19 source · line 95 · raw

@+ia:U32 -> @+ib:U32 -> @+arow:U32 -> @+sa:U32 -> @+sb:U32 -> @+bcol:U32 -> @+x0_0:F32 -> @+x0_1:F32 -> @+x0_2:F32 -> @+x0_3:F32 -> @+x1_0:F32 -> @+x1_1:F32 -> @+x1_2:F32 -> @+x1_3:F32 -> @+x2_0:F32 -> @+x2_1:F32 -> @+x2_2:F32 -> @+x2_3:F32 -> @+x3_0:F32 -> @+x3_1:F32 -> @+x3_2:F32 -> @+x3_3:F32 -> @+y0_0:F32 -> @+y0_1:F32 -> @+y0_2:F32 -> @a:Array<F32> -> @rv:Pair(Array<F32>, F32) -> GR

def gr_18 source · line 99 · raw

@+ia:U32 -> @+ib:U32 -> @+arow:U32 -> @+sa:U32 -> @+sb:U32 -> @+bcol:U32 -> @+x0_0:F32 -> @+x0_1:F32 -> @+x0_2:F32 -> @+x0_3:F32 -> @+x1_0:F32 -> @+x1_1:F32 -> @+x1_2:F32 -> @+x1_3:F32 -> @+x2_0:F32 -> @+x2_1:F32 -> @+x2_2:F32 -> @+x2_3:F32 -> @+x3_0:F32 -> @+x3_1:F32 -> @+x3_2:F32 -> @+x3_3:F32 -> @+y0_0:F32 -> @+y0_1:F32 -> @a:Array<F32> -> @rv:Pair(Array<F32>, F32) -> GR

def gr_17 source · line 103 · raw

@+ia:U32 -> @+ib:U32 -> @+arow:U32 -> @+sa:U32 -> @+sb:U32 -> @+bcol:U32 -> @+x0_0:F32 -> @+x0_1:F32 -> @+x0_2:F32 -> @+x0_3:F32 -> @+x1_0:F32 -> @+x1_1:F32 -> @+x1_2:F32 -> @+x1_3:F32 -> @+x2_0:F32 -> @+x2_1:F32 -> @+x2_2:F32 -> @+x2_3:F32 -> @+x3_0:F32 -> @+x3_1:F32 -> @+x3_2:F32 -> @+x3_3:F32 -> @+y0_0:F32 -> @a:Array<F32> -> @rv:Pair(Array<F32>, F32) -> GR

def gr_16 source · line 107 · raw

@+ia:U32 -> @+ib:U32 -> @+arow:U32 -> @+sa:U32 -> @+sb:U32 -> @+bcol:U32 -> @+x0_0:F32 -> @+x0_1:F32 -> @+x0_2:F32 -> @+x0_3:F32 -> @+x1_0:F32 -> @+x1_1:F32 -> @+x1_2:F32 -> @+x1_3:F32 -> @+x2_0:F32 -> @+x2_1:F32 -> @+x2_2:F32 -> @+x2_3:F32 -> @+x3_0:F32 -> @+x3_1:F32 -> @+x3_2:F32 -> @+x3_3:F32 -> @a:Array<F32> -> @rv:Pair(Array<F32>, F32) -> GR

def gr_15 source · line 111 · raw

@+ia:U32 -> @+ib:U32 -> @+arow:U32 -> @+sa:U32 -> @+sb:U32 -> @+bcol:U32 -> @+x0_0:F32 -> @+x0_1:F32 -> @+x0_2:F32 -> @+x0_3:F32 -> @+x1_0:F32 -> @+x1_1:F32 -> @+x1_2:F32 -> @+x1_3:F32 -> @+x2_0:F32 -> @+x2_1:F32 -> @+x2_2:F32 -> @+x2_3:F32 -> @+x3_0:F32 -> @+x3_1:F32 -> @+x3_2:F32 -> @rv:Pair(Array<F32>, F32) -> @b:Array<F32> -> GR

def gr_14 source · line 115 · raw

@+ia:U32 -> @+ib:U32 -> @+arow:U32 -> @+sa:U32 -> @+sb:U32 -> @+bcol:U32 -> @+x0_0:F32 -> @+x0_1:F32 -> @+x0_2:F32 -> @+x0_3:F32 -> @+x1_0:F32 -> @+x1_1:F32 -> @+x1_2:F32 -> @+x1_3:F32 -> @+x2_0:F32 -> @+x2_1:F32 -> @+x2_2:F32 -> @+x2_3:F32 -> @+x3_0:F32 -> @+x3_1:F32 -> @rv:Pair(Array<F32>, F32) -> @b:Array<F32> -> GR

def gr_13 source · line 119 · raw

@+ia:U32 -> @+ib:U32 -> @+arow:U32 -> @+sa:U32 -> @+sb:U32 -> @+bcol:U32 -> @+x0_0:F32 -> @+x0_1:F32 -> @+x0_2:F32 -> @+x0_3:F32 -> @+x1_0:F32 -> @+x1_1:F32 -> @+x1_2:F32 -> @+x1_3:F32 -> @+x2_0:F32 -> @+x2_1:F32 -> @+x2_2:F32 -> @+x2_3:F32 -> @+x3_0:F32 -> @rv:Pair(Array<F32>, F32) -> @b:Array<F32> -> GR

def gr_12 source · line 123 · raw

@+ia:U32 -> @+ib:U32 -> @+arow:U32 -> @+sa:U32 -> @+sb:U32 -> @+bcol:U32 -> @+x0_0:F32 -> @+x0_1:F32 -> @+x0_2:F32 -> @+x0_3:F32 -> @+x1_0:F32 -> @+x1_1:F32 -> @+x1_2:F32 -> @+x1_3:F32 -> @+x2_0:F32 -> @+x2_1:F32 -> @+x2_2:F32 -> @+x2_3:F32 -> @rv:Pair(Array<F32>, F32) -> @b:Array<F32> -> GR

def gr_11 source · line 127 · raw

@+ia:U32 -> @+ib:U32 -> @+arow:U32 -> @+sa:U32 -> @+sb:U32 -> @+bcol:U32 -> @+x0_0:F32 -> @+x0_1:F32 -> @+x0_2:F32 -> @+x0_3:F32 -> @+x1_0:F32 -> @+x1_1:F32 -> @+x1_2:F32 -> @+x1_3:F32 -> @+x2_0:F32 -> @+x2_1:F32 -> @+x2_2:F32 -> @rv:Pair(Array<F32>, F32) -> @b:Array<F32> -> GR

def gr_10 source · line 131 · raw

@+ia:U32 -> @+ib:U32 -> @+arow:U32 -> @+sa:U32 -> @+sb:U32 -> @+bcol:U32 -> @+x0_0:F32 -> @+x0_1:F32 -> @+x0_2:F32 -> @+x0_3:F32 -> @+x1_0:F32 -> @+x1_1:F32 -> @+x1_2:F32 -> @+x1_3:F32 -> @+x2_0:F32 -> @+x2_1:F32 -> @rv:Pair(Array<F32>, F32) -> @b:Array<F32> -> GR

def gr_9 source · line 135 · raw

@+ia:U32 -> @+ib:U32 -> @+arow:U32 -> @+sa:U32 -> @+sb:U32 -> @+bcol:U32 -> @+x0_0:F32 -> @+x0_1:F32 -> @+x0_2:F32 -> @+x0_3:F32 -> @+x1_0:F32 -> @+x1_1:F32 -> @+x1_2:F32 -> @+x1_3:F32 -> @+x2_0:F32 -> @rv:Pair(Array<F32>, F32) -> @b:Array<F32> -> GR

def gr_8 source · line 139 · raw

@+ia:U32 -> @+ib:U32 -> @+arow:U32 -> @+sa:U32 -> @+sb:U32 -> @+bcol:U32 -> @+x0_0:F32 -> @+x0_1:F32 -> @+x0_2:F32 -> @+x0_3:F32 -> @+x1_0:F32 -> @+x1_1:F32 -> @+x1_2:F32 -> @+x1_3:F32 -> @rv:Pair(Array<F32>, F32) -> @b:Array<F32> -> GR

def gr_7 source · line 143 · raw

@+ia:U32 -> @+ib:U32 -> @+arow:U32 -> @+sa:U32 -> @+sb:U32 -> @+bcol:U32 -> @+x0_0:F32 -> @+x0_1:F32 -> @+x0_2:F32 -> @+x0_3:F32 -> @+x1_0:F32 -> @+x1_1:F32 -> @+x1_2:F32 -> @rv:Pair(Array<F32>, F32) -> @b:Array<F32> -> GR

def gr_6 source · line 147 · raw

@+ia:U32 -> @+ib:U32 -> @+arow:U32 -> @+sa:U32 -> @+sb:U32 -> @+bcol:U32 -> @+x0_0:F32 -> @+x0_1:F32 -> @+x0_2:F32 -> @+x0_3:F32 -> @+x1_0:F32 -> @+x1_1:F32 -> @rv:Pair(Array<F32>, F32) -> @b:Array<F32> -> GR

def gr_5 source · line 151 · raw

@+ia:U32 -> @+ib:U32 -> @+arow:U32 -> @+sa:U32 -> @+sb:U32 -> @+bcol:U32 -> @+x0_0:F32 -> @+x0_1:F32 -> @+x0_2:F32 -> @+x0_3:F32 -> @+x1_0:F32 -> @rv:Pair(Array<F32>, F32) -> @b:Array<F32> -> GR

def gr_4 source · line 155 · raw

@+ia:U32 -> @+ib:U32 -> @+arow:U32 -> @+sa:U32 -> @+sb:U32 -> @+bcol:U32 -> @+x0_0:F32 -> @+x0_1:F32 -> @+x0_2:F32 -> @+x0_3:F32 -> @rv:Pair(Array<F32>, F32) -> @b:Array<F32> -> GR

def gr_3 source · line 159 · raw

@+ia:U32 -> @+ib:U32 -> @+arow:U32 -> @+sa:U32 -> @+sb:U32 -> @+bcol:U32 -> @+x0_0:F32 -> @+x0_1:F32 -> @+x0_2:F32 -> @rv:Pair(Array<F32>, F32) -> @b:Array<F32> -> GR

def gr_2 source · line 163 · raw

@+ia:U32 -> @+ib:U32 -> @+arow:U32 -> @+sa:U32 -> @+sb:U32 -> @+bcol:U32 -> @+x0_0:F32 -> @+x0_1:F32 -> @rv:Pair(Array<F32>, F32) -> @b:Array<F32> -> GR

def gr_1 source · line 167 · raw

@+ia:U32 -> @+ib:U32 -> @+arow:U32 -> @+sa:U32 -> @+sb:U32 -> @+bcol:U32 -> @+x0_0:F32 -> @rv:Pair(Array<F32>, F32) -> @b:Array<F32> -> GR

def gr_0 source · line 171 · raw

@+ia:U32 -> @+ib:U32 -> @+arow:U32 -> @+sa:U32 -> @+sb:U32 -> @+bcol:U32 -> @rv:Pair(Array<F32>, F32) -> @b:Array<F32> -> GR

def turn source · line 176 · raw

@+ia:U32 -> @+ib:U32 -> @+arow:U32 -> @+sa:U32 -> @+sb:U32 -> @+bcol:U32 -> @a:Array<F32> -> @b:Array<F32> -> GR

the turn whose A values start at ia and B values at ib

def wr source · line 194 · raw

@ok:Bool -> @+ac:Bool -> @+idx:U32 -> @+x:F32 -> @c:Array<F32> -> Array<F32>

writes cell (i, j) of C when it is inside n x m

def e_ofo source · line 257 · raw

@+ac:Bool -> @+n:Nat -> @+m:Nat -> @+k:Nat -> @+arow:U32 -> @+sa:U32 -> @+sb:U32 -> @+bcol:U32 -> @+oa:U32 -> @+ob:U32 -> E

the product's sizes and strides

def e_of source · line 260 · raw

@+ac:Bool -> @+n:Nat -> @+m:Nat -> @+k:Nat -> @+arow:U32 -> @+sa:U32 -> @+sb:U32 -> @+bcol:U32 -> E

def tiles source · line 263 · raw

@+n:Nat -> @+m:Nat -> Nat

def mm_fin source · line 276 · raw

@-n:Nat -> @-k:Nat -> @-m:Nat -> @g:ABC -> 0x16d5cc503cc2ac0bbdd98ca927ac8989/main.MMul<n, k, m>

def mm_nt_fin source · line 280 · raw

@-n:Nat -> @-k:Nat -> @-m:Nat -> @g:ABC -> 0x16d5cc503cc2ac0bbdd98ca927ac8989/main.MMulNT<n, k, m>

def mm_tn_fin source · line 284 · raw

@-n:Nat -> @-k:Nat -> @-m:Nat -> @g:ABC -> 0x16d5cc503cc2ac0bbdd98ca927ac8989/main.MMulTN<n, k, m>

def depth2 source · line 351 · raw

@big:Bool -> @+n:Nat -> Nat

def depth source · line 357 · raw

@+n:Nat -> Nat

leaves for n cells: 2^14 when there are that many, else the fewest powers of two that cover them

def share source · line 361 · raw

@+t:U32 -> @+n:U32 -> @+l:U32 -> Nat

how many of the cells t, t + l, t + 2l, .. lie below n

def none source · line 365 · raw

@u:Unit -> Array<F32>

an array of one cell, for an unused input

def blk_len source · line 546 · raw

@+bi:U32 -> @+k:U32 -> Nat

def rng_word source · line 596 · raw

@x:F32 -> U32

def rng_f32 source · line 600 · raw

@x:U32 -> F32

def rng_mix source · line 605 · raw

@+z:U32 -> U32

mlbend-generative's mix32: xor-shift 16, multiply, xor-shift 13, multiply, xor-shift 16, over U32 that wraps

def rng_hash source · line 613 · raw

@+s:U32 -> @+i:U32 -> U32

the hash of index i of counter s

def rng_uniform source · line 617 · raw

@+s:U32 -> @+i:U32 -> F32

the uniform of index i of counter s, in (0, 1]: the hash's low 24 bits plus one, over 2^24 (exact)

def rng_ln_m source · line 621 · raw

@+ex:F32 -> @+m:F32 -> F32

ln m for m in [sqrt(1/2), sqrt(2)], from s = (m - 1) / (m + 1): ln m = 2 (s + s^3/3 + s^5/5 + s^7/7 + s^9/9)

def rng_ln_w source · line 632 · raw

@+w:U32 -> F32

ln x for a positive normal x: x = m * 2^ex with m in [sqrt(1/2), sqrt(2)) read from the bits (a mantissa above sqrt(2)'s, 0x3504F3, is halved and the exponent raised by one); ex * ln 2 in two parts, the first exact

def rng_ln source · line 637 · raw

@x:F32 -> F32

def rng_sin source · line 641 · raw

@+x:F32 -> F32

sin x and cos x for x in [0, pi/4], Taylor to x^9 and x^10 (the next terms are below 2^-28)

def rng_cos source · line 648 · raw

@+x:F32 -> F32

def rng_sc_q source · line 661 · raw

@+q:U32 -> @+sx:F32 -> @+cx:F32 -> SC

sin and cos of a quarter turn's first eighth (x) or second (pi/2 - x, the two swapped), then turned by q quarters

def rng_sc_x source · line 664 · raw

@+q:U32 -> @+hi:Bool -> @+x:F32 -> SC

def rng_sc_w source · line 671 · raw

@+q:U32 -> @+w:U32 -> SC

sin and cos of 2 pi v / 2^24 (v < 2^24): the quarter q is v's top 2 bits, w the rest; past the eighth (2^21) the angle is taken from the quarter's end (2^22 - w, exact), so the polynomial only sees [0, pi/4]

def rng_sc source · line 675 · raw

@+v:U32 -> SC

def rng_pair source · line 678 · raw

@+r:F32 -> @a:SC -> Pair(F32, F32)

def rng_gauss2 source · line 684 · raw

@+s:U32 -> @+p:U32 -> Pair(F32, F32)

the Gaussians of cells 2p and 2p + 1 of counter s (Box-Muller). The angle's 24 bits are u_b's (its hash plus one, mod 2^24), so the angle is 2 pi u_b exactly before rounding

def rng_pick source · line 688 · raw

@+odd:Bool -> @g:Pair(F32, F32) -> F32

def rng_gauss source · line 693 · raw

@+s:U32 -> @+i:U32 -> F32

the Gaussian of cell i alone (fill_gauss's cell i)

def fu_go source · line 700 · raw

@k:Nat -> @+i:U32 -> @+l:U32 -> @+s:U32 -> @+i0:U32 -> @o:Array<F32> -> Array<F32>

def fu_leaf source · line 706 · raw

@+t:U32 -> @+l:U32 -> @+e:FE -> @x1:Array<F32> -> @x2:Array<F32> -> @x3:Array<F32> -> @x4:Array<F32> -> @o:Array<F32> -> Array<F32>

leaf t writes the cells t, t + l, .. below n, cell k the uniform of index i0 + k

def fg_if source · line 712 · raw

@ok:Bool -> @+i:U32 -> @+x:F32 -> @o:Array<F32> -> Array<F32>

writes cell i when it is below n (the cell before the first of an odd i0, which wraps to 2^32 - 1, and the cell after the last are not written)

def fg_put source · line 717 · raw

@+i:U32 -> @+n:U32 -> @g:Pair(F32, F32) -> @o:Array<F32> -> Array<F32>

def fg_go source · line 722 · raw

@k:Nat -> @+j:U32 -> @+l:U32 -> @+s:U32 -> @+q:U32 -> @+h:U32 -> @+n:U32 -> @o:Array<F32> -> Array<F32>

pair j of the slice is the global pair q + j (q = i0 / 2), cells 2j - h and 2j - h + 1 of the output (h = i0 mod 2)

def fg_pairs source · line 728 · raw

@+i0:U32 -> @+n:U32 -> U32

the number of global pairs that cells i0 .. i0 + n - 1 touch: (i0 mod 2 + n + 1) / 2

def fg_leaf source · line 732 · raw

@+t:U32 -> @+l:U32 -> @+e:FE -> @x1:Array<F32> -> @x2:Array<F32> -> @x3:Array<F32> -> @x4:Array<F32> -> @o:Array<F32> -> Array<F32>

leaf t writes the pairs t, t + l, .. of the slice's pairs, each into the cells of it that lie in the slice

def r1_out source · line 736 · raw

@r:R1 -> Array<F32>

Unsafe

unsafe mm source · line 186 · raw

@kg:Nat -> @+ia:U32 -> @+ib:U32 -> @+arow:U32 -> @+sa:U32 -> @+sb:U32 -> @+bcol:U32 -> @+rem:U32 -> @+rot:Nat -> @+s0_0_0:F32 -> @+s1_0_0:F32 -> @+s2_0_0:F32 -> @+s3_0_0:F32 -> @+s0_0_1:F32 -> @+s1_0_1:F32 -> @+s2_0_1:F32 -> @+s3_0_1:F32 -> @+s0_0_2:F32 -> @+s1_0_2:F32 -> @+s2_0_2:F32 -> @+s3_0_2:F32 -> @+s0_0_3:F32 -> @+s1_0_3:F32 -> @+s2_0_3:F32 -> @+s3_0_3:F32 -> @+s0_1_0:F32 -> @+s1_1_0:F32 -> @+s2_1_0:F32 -> @+s3_1_0:F32 -> @+s0_1_1:F32 -> @+s1_1_1:F32 -> @+s2_1_1:F32 -> @+s3_1_1:F32 -> @+s0_1_2:F32 -> @+s1_1_2:F32 -> @+s2_1_2:F32 -> @+s3_1_2:F32 -> @+s0_1_3:F32 -> @+s1_1_3:F32 -> @+s2_1_3:F32 -> @+s3_1_3:F32 -> @+s0_2_0:F32 -> @+s1_2_0:F32 -> @+s2_2_0:F32 -> @+s3_2_0:F32 -> @+s0_2_1:F32 -> @+s1_2_1:F32 -> @+s2_2_1:F32 -> @+s3_2_1:F32 -> @+s0_2_2:F32 -> @+s1_2_2:F32 -> @+s2_2_2:F32 -> @+s3_2_2:F32 -> @+s0_2_3:F32 -> @+s1_2_3:F32 -> @+s2_2_3:F32 -> @+s3_2_3:F32 -> @+s0_3_0:F32 -> @+s1_3_0:F32 -> @+s2_3_0:F32 -> @+s3_3_0:F32 -> @+s0_3_1:F32 -> @+s1_3_1:F32 -> @+s2_3_1:F32 -> @+s3_3_1:F32 -> @+s0_3_2:F32 -> @+s1_3_2:F32 -> @+s2_3_2:F32 -> @+s3_3_2:F32 -> @+s0_3_3:F32 -> @+s1_3_3:F32 -> @+s2_3_3:F32 -> @+s3_3_3:F32 -> @g:GR -> T

kg more full turns; g holds the current turn's values. The last call (kg = 0) adds the turn that holds the steps past the last full turn (rem = k mod 4 of them), counting only those, and combines the sums.

unsafe put source · line 201 · raw

@+ac:Bool -> @+n:U32 -> @+m:U32 -> @+i0:U32 -> @+j0:U32 -> @c:Array<F32> -> @t:T -> Array<F32>

the tile at rows i0.., columns j0.. of C, from the loop's result; A and B are dropped (the caller holds them)

unsafe tile source · line 207 · raw

@+e:E -> @+i0:U32 -> @+j0:U32 -> @+a:Array<F32> -> @+b:Array<F32> -> @c:Array<F32> -> Array<F32>

unsafe leaf_if source · line 214 · raw

@ok:Bool -> @+e:E -> @+t:U32 -> @+tcols:U32 -> @+a:Array<F32> -> @+b:Array<F32> -> @c:Array<F32> -> Array<F32>

leaf t computes tile t (row-major over the tiles); leaves past the last tile write nothing

unsafe leaf source · line 220 · raw

@+e:E -> @+t:U32 -> @+a:Array<F32> -> @+b:Array<F32> -> @c:Array<F32> -> Array<F32>

unsafe tree source · line 226 · raw

@+e:E -> @d:Nat -> @+t:U32 -> @+a:Array<F32> -> @+b:Array<F32> -> @+c:Array<F32> -> Array<F32>

unsafe tree_new source · line 237 · raw

@+e:E -> @d:Nat -> @+a:Array<F32> -> @+b:Array<F32> -> @+cd:Nat -> Array<F32>

C made inside the bang: the root of the ! call allocates it on the device. Made on the host instead, a new C often reuses a block whose pages sit on the device, so zeroing it on the host pulls them back over PCIe and the bang moves them again (a 256 x 1536 product: 9.2 ms against 6.0, measured 2026-10-18). The leaves write every cell of C.

unsafe bang_new source · line 241 · raw

@+e:E -> @d:Nat -> @+a:Array<F32> -> @+b:Array<F32> -> @+cd:Nat -> Array<F32>

unsafe bang source · line 246 · raw

@+e:E -> @d:Nat -> @+a:Array<F32> -> @+b:Array<F32> -> @c:Array<F32> -> Array<F32>

one bang over the tiles; A and B are shared with every leaf and come back unchanged

unsafe run_e source · line 253 · raw

@+e:E -> @+tiles:U32 -> @+a:Array<F32> -> @+b:Array<F32> -> @c:Array<F32> -> ABC

unsafe gemm_new source · line 268 · raw

@+n:Nat -> @+m:Nat -> @+k:Nat -> @+arow:U32 -> @+sa:U32 -> @+sb:U32 -> @+bcol:U32 -> @+a:Array<F32> -> @+b:Array<F32> -> ABC

C (n x m) = A · B with k steps into a new C made on the device

unsafe gemm source · line 273 · raw

@+ac:Bool -> @+n:Nat -> @+m:Nat -> @+k:Nat -> @+arow:U32 -> @+sa:U32 -> @+sb:U32 -> @+bcol:U32 -> @a:Array<F32> -> @b:Array<F32> -> @c:Array<F32> -> ABC

C (n x m) = A · B with k steps, or C + A · B when ac, C[i][j] = sum_p A[i*arow + p*sa] * B[p*sb + j*bcol]

unsafe matmul source · line 290 · raw

@+n:Nat -> @+k:Nat -> @+m:Nat -> @par:Nat -> @a:0x16d5cc503cc2ac0bbdd98ca927ac8989/main.Mat<n, k> -> @b:0x16d5cc503cc2ac0bbdd98ca927ac8989/main.Mat<k, m> -> 0x16d5cc503cc2ac0bbdd98ca927ac8989/main.MMul<n, k, m>

C = A · B (n x k) · (k x m), tensor-array's TA.Mat.matmul bits

unsafe matmul_acc source · line 297 · raw

@+n:Nat -> @+k:Nat -> @+m:Nat -> @par:Nat -> @a:0x16d5cc503cc2ac0bbdd98ca927ac8989/main.Mat<n, k> -> @b:0x16d5cc503cc2ac0bbdd98ca927ac8989/main.Mat<k, m> -> @c:0x16d5cc503cc2ac0bbdd98ca927ac8989/main.Mat<n, m> -> 0x16d5cc503cc2ac0bbdd98ca927ac8989/main.MMul<n, k, m>

C + A · B, into C (n x m)

unsafe matmul_nt source · line 304 · raw

@+n:Nat -> @+k:Nat -> @+m:Nat -> @par:Nat -> @a:0x16d5cc503cc2ac0bbdd98ca927ac8989/main.Mat<n, k> -> @b:0x16d5cc503cc2ac0bbdd98ca927ac8989/main.Mat<m, k> -> 0x16d5cc503cc2ac0bbdd98ca927ac8989/main.MMulNT<n, k, m>

C = A · Bᵀ (n x k) · (m x k)ᵀ: for weights stored with one row per output

unsafe matmul_nt_acc source · line 311 · raw

@+n:Nat -> @+k:Nat -> @+m:Nat -> @par:Nat -> @a:0x16d5cc503cc2ac0bbdd98ca927ac8989/main.Mat<n, k> -> @b:0x16d5cc503cc2ac0bbdd98ca927ac8989/main.Mat<m, k> -> @c:0x16d5cc503cc2ac0bbdd98ca927ac8989/main.Mat<n, m> -> 0x16d5cc503cc2ac0bbdd98ca927ac8989/main.MMulNT<n, k, m>

C + A · Bᵀ, into C (n x m)

unsafe matmul_tn source · line 318 · raw

@+n:Nat -> @+k:Nat -> @+m:Nat -> @par:Nat -> @a:0x16d5cc503cc2ac0bbdd98ca927ac8989/main.Mat<k, n> -> @b:0x16d5cc503cc2ac0bbdd98ca927ac8989/main.Mat<k, m> -> 0x16d5cc503cc2ac0bbdd98ca927ac8989/main.MMulTN<n, k, m>

C = Aᵀ · B (k x n)ᵀ · (k x m): weight gradient, Xᵀ · dY

unsafe matmul_tn_acc source · line 325 · raw

@+n:Nat -> @+k:Nat -> @+m:Nat -> @par:Nat -> @a:0x16d5cc503cc2ac0bbdd98ca927ac8989/main.Mat<k, n> -> @b:0x16d5cc503cc2ac0bbdd98ca927ac8989/main.Mat<k, m> -> @c:0x16d5cc503cc2ac0bbdd98ca927ac8989/main.Mat<n, m> -> 0x16d5cc503cc2ac0bbdd98ca927ac8989/main.MMulTN<n, k, m>

C + Aᵀ · B, into C (n x m): dW += Xᵀ · dY

unsafe join2 source · line 390 · raw

@x:O2 -> @y:O2 -> O2

unsafe join3 source · line 395 · raw

@x:O3 -> @y:O3 -> O3

unsafe join4 source · line 400 · raw

@x:O4 -> @y:O4 -> O4

unsafe tree1 source · line 405 · raw

@-E:Data -> @-f:(@+t:U32 -> @+l:U32 -> @+e:E -> @_:Array<F32> -> @_:Array<F32> -> @_:Array<F32> -> @_:Array<F32> -> @_:Array<F32> -> Array<F32>) -> @+d:Nat -> @+t:U32 -> @+l:U32 -> @+e:E -> @+x1:Array<F32> -> @+x2:Array<F32> -> @+x3:Array<F32> -> @+x4:Array<F32> -> @+oa:Array<F32> -> Array<F32>

unsafe root1 source · line 413 · raw

@-E:Data -> @-f:(@+t:U32 -> @+l:U32 -> @+e:E -> @_:Array<F32> -> @_:Array<F32> -> @_:Array<F32> -> @_:Array<F32> -> @_:Array<F32> -> Array<F32>) -> @+d:Nat -> @+e:E -> @+x1:Array<F32> -> @+x2:Array<F32> -> @+x3:Array<F32> -> @+x4:Array<F32> -> @oa:Array<F32> -> Array<F32>

unsafe root1_new source · line 417 · raw

@-E:Data -> @-f:(@+t:U32 -> @+l:U32 -> @+e:E -> @_:Array<F32> -> @_:Array<F32> -> @_:Array<F32> -> @_:Array<F32> -> @_:Array<F32> -> Array<F32>) -> @+d:Nat -> @+e:E -> @+x1:Array<F32> -> @+x2:Array<F32> -> @+x3:Array<F32> -> @+x4:Array<F32> -> @+ca:Nat -> Array<F32>

unsafe go1 source · line 421 · raw

@-E:Data -> @-f:(@+t:U32 -> @+l:U32 -> @+e:E -> @_:Array<F32> -> @_:Array<F32> -> @_:Array<F32> -> @_:Array<F32> -> @_:Array<F32> -> Array<F32>) -> @+d:Nat -> @+e:E -> @+x1:Array<F32> -> @+x2:Array<F32> -> @+x3:Array<F32> -> @+x4:Array<F32> -> @oa:Array<F32> -> R1

unsafe go1_new source · line 425 · raw

@-E:Data -> @-f:(@+t:U32 -> @+l:U32 -> @+e:E -> @_:Array<F32> -> @_:Array<F32> -> @_:Array<F32> -> @_:Array<F32> -> @_:Array<F32> -> Array<F32>) -> @+d:Nat -> @+e:E -> @+x1:Array<F32> -> @+x2:Array<F32> -> @+x3:Array<F32> -> @+x4:Array<F32> -> @+ca:Nat -> R1

unsafe run1 source · line 430 · raw

@-E:Data -> @-f:(@+t:U32 -> @+l:U32 -> @+e:E -> @_:Array<F32> -> @_:Array<F32> -> @_:Array<F32> -> @_:Array<F32> -> @_:Array<F32> -> Array<F32>) -> @+d:Nat -> @+e:E -> @x1:Array<F32> -> @x2:Array<F32> -> @x3:Array<F32> -> @x4:Array<F32> -> @oa:Array<F32> -> R1

one bang over 2^d leaves with 1 output written in place

unsafe run1_new source · line 435 · raw

@-E:Data -> @-f:(@+t:U32 -> @+l:U32 -> @+e:E -> @_:Array<F32> -> @_:Array<F32> -> @_:Array<F32> -> @_:Array<F32> -> @_:Array<F32> -> Array<F32>) -> @+d:Nat -> @+e:E -> @x1:Array<F32> -> @x2:Array<F32> -> @x3:Array<F32> -> @x4:Array<F32> -> @+ca:Nat -> R1

one bang over 2^d leaves with 1 new output of 2^c.. cells, made on the device

unsafe tree2 source · line 439 · raw

@-E:Data -> @-f:(@+t:U32 -> @+l:U32 -> @+e:E -> @_:Array<F32> -> @_:Array<F32> -> @_:Array<F32> -> @_:Array<F32> -> @_:O2 -> O2) -> @+d:Nat -> @+t:U32 -> @+l:U32 -> @+e:E -> @+x1:Array<F32> -> @+x2:Array<F32> -> @+x3:Array<F32> -> @+x4:Array<F32> -> @+oa:Array<F32> -> @+ob:Array<F32> -> O2

unsafe root2 source · line 447 · raw

@-E:Data -> @-f:(@+t:U32 -> @+l:U32 -> @+e:E -> @_:Array<F32> -> @_:Array<F32> -> @_:Array<F32> -> @_:Array<F32> -> @_:O2 -> O2) -> @+d:Nat -> @+e:E -> @+x1:Array<F32> -> @+x2:Array<F32> -> @+x3:Array<F32> -> @+x4:Array<F32> -> @oa:Array<F32> -> @ob:Array<F32> -> O2

unsafe root2_new source · line 451 · raw

@-E:Data -> @-f:(@+t:U32 -> @+l:U32 -> @+e:E -> @_:Array<F32> -> @_:Array<F32> -> @_:Array<F32> -> @_:Array<F32> -> @_:O2 -> O2) -> @+d:Nat -> @+e:E -> @+x1:Array<F32> -> @+x2:Array<F32> -> @+x3:Array<F32> -> @+x4:Array<F32> -> @+ca:Nat -> @+cb:Nat -> O2

unsafe go2 source · line 455 · raw

@-E:Data -> @-f:(@+t:U32 -> @+l:U32 -> @+e:E -> @_:Array<F32> -> @_:Array<F32> -> @_:Array<F32> -> @_:Array<F32> -> @_:O2 -> O2) -> @+d:Nat -> @+e:E -> @+x1:Array<F32> -> @+x2:Array<F32> -> @+x3:Array<F32> -> @+x4:Array<F32> -> @oa:Array<F32> -> @ob:Array<F32> -> R2

unsafe go2_new source · line 459 · raw

@-E:Data -> @-f:(@+t:U32 -> @+l:U32 -> @+e:E -> @_:Array<F32> -> @_:Array<F32> -> @_:Array<F32> -> @_:Array<F32> -> @_:O2 -> O2) -> @+d:Nat -> @+e:E -> @+x1:Array<F32> -> @+x2:Array<F32> -> @+x3:Array<F32> -> @+x4:Array<F32> -> @+ca:Nat -> @+cb:Nat -> R2

unsafe run2 source · line 464 · raw

@-E:Data -> @-f:(@+t:U32 -> @+l:U32 -> @+e:E -> @_:Array<F32> -> @_:Array<F32> -> @_:Array<F32> -> @_:Array<F32> -> @_:O2 -> O2) -> @+d:Nat -> @+e:E -> @x1:Array<F32> -> @x2:Array<F32> -> @x3:Array<F32> -> @x4:Array<F32> -> @oa:Array<F32> -> @ob:Array<F32> -> R2

one bang over 2^d leaves with 2 outputs written in place

unsafe run2_new source · line 469 · raw

@-E:Data -> @-f:(@+t:U32 -> @+l:U32 -> @+e:E -> @_:Array<F32> -> @_:Array<F32> -> @_:Array<F32> -> @_:Array<F32> -> @_:O2 -> O2) -> @+d:Nat -> @+e:E -> @x1:Array<F32> -> @x2:Array<F32> -> @x3:Array<F32> -> @x4:Array<F32> -> @+ca:Nat -> @+cb:Nat -> R2

one bang over 2^d leaves with 2 new outputs of 2^c.. cells, made on the device

unsafe tree3 source · line 473 · raw

@-E:Data -> @-f:(@+t:U32 -> @+l:U32 -> @+e:E -> @_:Array<F32> -> @_:Array<F32> -> @_:Array<F32> -> @_:Array<F32> -> @_:O3 -> O3) -> @+d:Nat -> @+t:U32 -> @+l:U32 -> @+e:E -> @+x1:Array<F32> -> @+x2:Array<F32> -> @+x3:Array<F32> -> @+x4:Array<F32> -> @+oa:Array<F32> -> @+ob:Array<F32> -> @+oc:Array<F32> -> O3

unsafe root3 source · line 481 · raw

@-E:Data -> @-f:(@+t:U32 -> @+l:U32 -> @+e:E -> @_:Array<F32> -> @_:Array<F32> -> @_:Array<F32> -> @_:Array<F32> -> @_:O3 -> O3) -> @+d:Nat -> @+e:E -> @+x1:Array<F32> -> @+x2:Array<F32> -> @+x3:Array<F32> -> @+x4:Array<F32> -> @oa:Array<F32> -> @ob:Array<F32> -> @oc:Array<F32> -> O3

unsafe root3_new source · line 485 · raw

@-E:Data -> @-f:(@+t:U32 -> @+l:U32 -> @+e:E -> @_:Array<F32> -> @_:Array<F32> -> @_:Array<F32> -> @_:Array<F32> -> @_:O3 -> O3) -> @+d:Nat -> @+e:E -> @+x1:Array<F32> -> @+x2:Array<F32> -> @+x3:Array<F32> -> @+x4:Array<F32> -> @+ca:Nat -> @+cb:Nat -> @+cc:Nat -> O3

unsafe go3 source · line 489 · raw

@-E:Data -> @-f:(@+t:U32 -> @+l:U32 -> @+e:E -> @_:Array<F32> -> @_:Array<F32> -> @_:Array<F32> -> @_:Array<F32> -> @_:O3 -> O3) -> @+d:Nat -> @+e:E -> @+x1:Array<F32> -> @+x2:Array<F32> -> @+x3:Array<F32> -> @+x4:Array<F32> -> @oa:Array<F32> -> @ob:Array<F32> -> @oc:Array<F32> -> R3

unsafe go3_new source · line 493 · raw

@-E:Data -> @-f:(@+t:U32 -> @+l:U32 -> @+e:E -> @_:Array<F32> -> @_:Array<F32> -> @_:Array<F32> -> @_:Array<F32> -> @_:O3 -> O3) -> @+d:Nat -> @+e:E -> @+x1:Array<F32> -> @+x2:Array<F32> -> @+x3:Array<F32> -> @+x4:Array<F32> -> @+ca:Nat -> @+cb:Nat -> @+cc:Nat -> R3

unsafe run3 source · line 498 · raw

@-E:Data -> @-f:(@+t:U32 -> @+l:U32 -> @+e:E -> @_:Array<F32> -> @_:Array<F32> -> @_:Array<F32> -> @_:Array<F32> -> @_:O3 -> O3) -> @+d:Nat -> @+e:E -> @x1:Array<F32> -> @x2:Array<F32> -> @x3:Array<F32> -> @x4:Array<F32> -> @oa:Array<F32> -> @ob:Array<F32> -> @oc:Array<F32> -> R3

one bang over 2^d leaves with 3 outputs written in place

unsafe run3_new source · line 503 · raw

@-E:Data -> @-f:(@+t:U32 -> @+l:U32 -> @+e:E -> @_:Array<F32> -> @_:Array<F32> -> @_:Array<F32> -> @_:Array<F32> -> @_:O3 -> O3) -> @+d:Nat -> @+e:E -> @x1:Array<F32> -> @x2:Array<F32> -> @x3:Array<F32> -> @x4:Array<F32> -> @+ca:Nat -> @+cb:Nat -> @+cc:Nat -> R3

one bang over 2^d leaves with 3 new outputs of 2^c.. cells, made on the device

unsafe tree4 source · line 507 · raw

@-E:Data -> @-f:(@+t:U32 -> @+l:U32 -> @+e:E -> @_:Array<F32> -> @_:Array<F32> -> @_:Array<F32> -> @_:Array<F32> -> @_:O4 -> O4) -> @+d:Nat -> @+t:U32 -> @+l:U32 -> @+e:E -> @+x1:Array<F32> -> @+x2:Array<F32> -> @+x3:Array<F32> -> @+x4:Array<F32> -> @+oa:Array<F32> -> @+ob:Array<F32> -> @+oc:Array<F32> -> @+od:Array<F32> -> O4

unsafe root4 source · line 515 · raw

@-E:Data -> @-f:(@+t:U32 -> @+l:U32 -> @+e:E -> @_:Array<F32> -> @_:Array<F32> -> @_:Array<F32> -> @_:Array<F32> -> @_:O4 -> O4) -> @+d:Nat -> @+e:E -> @+x1:Array<F32> -> @+x2:Array<F32> -> @+x3:Array<F32> -> @+x4:Array<F32> -> @oa:Array<F32> -> @ob:Array<F32> -> @oc:Array<F32> -> @od:Array<F32> -> O4

unsafe root4_new source · line 519 · raw

@-E:Data -> @-f:(@+t:U32 -> @+l:U32 -> @+e:E -> @_:Array<F32> -> @_:Array<F32> -> @_:Array<F32> -> @_:Array<F32> -> @_:O4 -> O4) -> @+d:Nat -> @+e:E -> @+x1:Array<F32> -> @+x2:Array<F32> -> @+x3:Array<F32> -> @+x4:Array<F32> -> @+ca:Nat -> @+cb:Nat -> @+cc:Nat -> @+cd:Nat -> O4

unsafe go4 source · line 523 · raw

@-E:Data -> @-f:(@+t:U32 -> @+l:U32 -> @+e:E -> @_:Array<F32> -> @_:Array<F32> -> @_:Array<F32> -> @_:Array<F32> -> @_:O4 -> O4) -> @+d:Nat -> @+e:E -> @+x1:Array<F32> -> @+x2:Array<F32> -> @+x3:Array<F32> -> @+x4:Array<F32> -> @oa:Array<F32> -> @ob:Array<F32> -> @oc:Array<F32> -> @od:Array<F32> -> R4

unsafe go4_new source · line 527 · raw

@-E:Data -> @-f:(@+t:U32 -> @+l:U32 -> @+e:E -> @_:Array<F32> -> @_:Array<F32> -> @_:Array<F32> -> @_:Array<F32> -> @_:O4 -> O4) -> @+d:Nat -> @+e:E -> @+x1:Array<F32> -> @+x2:Array<F32> -> @+x3:Array<F32> -> @+x4:Array<F32> -> @+ca:Nat -> @+cb:Nat -> @+cc:Nat -> @+cd:Nat -> R4

unsafe run4 source · line 532 · raw

@-E:Data -> @-f:(@+t:U32 -> @+l:U32 -> @+e:E -> @_:Array<F32> -> @_:Array<F32> -> @_:Array<F32> -> @_:Array<F32> -> @_:O4 -> O4) -> @+d:Nat -> @+e:E -> @x1:Array<F32> -> @x2:Array<F32> -> @x3:Array<F32> -> @x4:Array<F32> -> @oa:Array<F32> -> @ob:Array<F32> -> @oc:Array<F32> -> @od:Array<F32> -> R4

one bang over 2^d leaves with 4 outputs written in place

unsafe run4_new source · line 537 · raw

@-E:Data -> @-f:(@+t:U32 -> @+l:U32 -> @+e:E -> @_:Array<F32> -> @_:Array<F32> -> @_:Array<F32> -> @_:Array<F32> -> @_:O4 -> O4) -> @+d:Nat -> @+e:E -> @x1:Array<F32> -> @x2:Array<F32> -> @x3:Array<F32> -> @x4:Array<F32> -> @+ca:Nat -> @+cb:Nat -> @+cc:Nat -> @+cd:Nat -> R4

one bang over 2^d leaves with 4 new outputs of 2^c.. cells, made on the device

unsafe blocks_acc source · line 551 · raw

@nb:Nat -> @+bi:U32 -> @+n:Nat -> @+m:Nat -> @+k:U32 -> @+arow:U32 -> @+sa:U32 -> @+sb:U32 -> @+bcol:U32 -> @+a:Array<F32> -> @+b:Array<F32> -> @c:Array<F32> -> Array<F32>

the blocks after the first: nb more, from block bi, each added into C

unsafe precise_c source · line 557 · raw

@+n:Nat -> @+m:Nat -> @+k:Nat -> @+arow:U32 -> @+sa:U32 -> @+sb:U32 -> @+bcol:U32 -> @+a:Array<F32> -> @+b:Array<F32> -> Array<F32>

unsafe mm_precise3 source · line 561 · raw

@+n:Nat -> @+k:Nat -> @+m:Nat -> @+a:Array<F32> -> @+b:Array<F32> -> 0x16d5cc503cc2ac0bbdd98ca927ac8989/main.MMul<n, k, m>

unsafe mm_precise2 source · line 565 · raw

@long:Bool -> @+n:Nat -> @+k:Nat -> @+m:Nat -> @+par:Nat -> @a:0x16d5cc503cc2ac0bbdd98ca927ac8989/main.Mat<n, k> -> @b:0x16d5cc503cc2ac0bbdd98ca927ac8989/main.Mat<k, m> -> 0x16d5cc503cc2ac0bbdd98ca927ac8989/main.MMul<n, k, m>

unsafe matmul_precise source · line 572 · raw

@+n:Nat -> @+k:Nat -> @+m:Nat -> @+par:Nat -> @a:0x16d5cc503cc2ac0bbdd98ca927ac8989/main.Mat<n, k> -> @b:0x16d5cc503cc2ac0bbdd98ca927ac8989/main.Mat<k, m> -> 0x16d5cc503cc2ac0bbdd98ca927ac8989/main.MMul<n, k, m>

C = A · B with k summed in blocks of 1024: TA.Mat.matmul_precise's bits (opt-in)

unsafe fill_uniform_at source · line 743 · raw

@+s:U32 -> @+i0:U32 -> @+n:Nat -> @+c:Nat -> Array<F32>

n uniforms of counter s from index i0, cell k = rng_uniform(s, i0 + k) (mod 2^32), in a new array of 2^c cells made on the device (one bang)

unsafe fill_gauss_at source · line 749 · raw

@+s:U32 -> @+i0:U32 -> @+n:Nat -> @+c:Nat -> Array<F32>

n Gaussians of counter s from index i0, cell k = rng_gauss(s, i0 + k) (mod 2^32), in a new array of 2^c cells made on the device (one bang, a lane a global pair of cells; an odd i0 starts with the sine half of the pair (i0 - 1, i0))

unsafe fill_uniform source · line 754 · raw

@+s:U32 -> @+n:Nat -> @+c:Nat -> Array<F32>

n uniforms of counter s, cell i = rng_uniform(s, i), in a new array of 2^c cells made on the device (one bang)

unsafe fill_gauss source · line 760 · raw

@+s:U32 -> @+n:Nat -> @+c:Nat -> Array<F32>

n Gaussians of counter s, cell i = rng_gauss(s, i), in a new array of 2^c cells made on the device (one bang, a lane a pair of cells)

unsafe uniform_mat source · line 765 · raw

@+s:U32 -> @+r:Nat -> @+m:Nat -> 0x16d5cc503cc2ac0bbdd98ca927ac8989/main.Mat<r, m>

an r x m Mat of uniforms of counter s, row-major (cell i * m + j = rng_uniform(s, i * m + j))

unsafe gauss_mat source · line 770 · raw

@+s:U32 -> @+r:Nat -> @+m:Nat -> 0x16d5cc503cc2ac0bbdd98ca927ac8989/main.Mat<r, m>

an r x m Mat of Gaussians of counter s, row-major (cell i * m + j = rng_gauss(s, i * m + j))

unsafe uniform_mat_at source · line 776 · raw

@+s:U32 -> @+i0:U32 -> @+r:Nat -> @+m:Nat -> 0x16d5cc503cc2ac0bbdd98ca927ac8989/main.Mat<r, m>

an r x m Mat of uniforms of counter s from index i0 (cell i * m + j = rng_uniform(s, i0 + i * m + j)); rows b .. b + r - 1 of an R x m uniform_mat are uniform_mat_at(s, b * m, r, m)

unsafe gauss_mat_at source · line 782 · raw

@+s:U32 -> @+i0:U32 -> @+r:Nat -> @+m:Nat -> 0x16d5cc503cc2ac0bbdd98ca927ac8989/main.Mat<r, m>

an r x m Mat of Gaussians of counter s from index i0 (cell i * m + j = rng_gauss(s, i0 + i * m + j)); rows b .. b + r - 1 of an R x m gauss_mat are gauss_mat_at(s, b * m, r, m)