~/bend-docscommunity

main.bend relies on unsafe/foreign

raw source on the hub · import bend-ml-tensor-gpu@0.1.5.0/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.0/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).

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

Types

type E source · line 33 · 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 43 · 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 179 · raw

Type

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

type ABC source · line 248 · raw

Type

type O2 source · line 367 · raw

Type

type O3 source · line 370 · raw

Type

type O4 source · line 373 · raw

Type

type R1 source · line 376 · raw

Type

type R2 source · line 379 · raw

Type

type R3 source · line 382 · raw

Type

type R4 source · line 385 · raw

Type

type SC source · line 656 · raw

Data

the result of rng_sc: sin and cos of one angle

type FE source · line 696 · raw

Data

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

Definitions

def pk source · line 37 · 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 46 · 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 50 · 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 54 · 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 58 · 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 62 · 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 66 · 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 70 · 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 74 · 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 78 · 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 82 · 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 86 · 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 90 · 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 94 · 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 98 · 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 102 · 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 106 · 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 110 · 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 114 · 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 118 · 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 122 · 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 126 · 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 130 · 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 134 · 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 138 · 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 142 · 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 146 · 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 150 · 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 154 · 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 158 · 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 162 · 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 166 · 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 170 · 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 175 · 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 193 · 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 256 · 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 259 · raw

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

def tiles source · line 262 · raw

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

def mm_fin source · line 275 · raw

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

def mm_nt_fin source · line 279 · raw

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

def mm_tn_fin source · line 283 · raw

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

def depth2 source · line 350 · raw

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

def depth source · line 356 · 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 360 · 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 364 · raw

@u:Unit -> Array<F32>

an array of one cell, for an unused input

def blk_len source · line 545 · raw

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

def rng_word source · line 595 · raw

@x:F32 -> U32

def rng_f32 source · line 599 · raw

@x:U32 -> F32

def rng_mix source · line 604 · 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 612 · raw

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

the hash of index i of counter s

def rng_uniform source · line 616 · 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 620 · 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 631 · 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 636 · raw

@x:F32 -> F32

def rng_sin source · line 640 · 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 647 · raw

@+x:F32 -> F32

def rng_sc_q source · line 660 · 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 663 · raw

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

def rng_sc_w source · line 670 · 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 674 · raw

@+v:U32 -> SC

def rng_pair source · line 677 · raw

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

def rng_gauss2 source · line 683 · 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 687 · raw

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

def rng_gauss source · line 692 · raw

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

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

def fu_go source · line 699 · raw

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

def fu_leaf source · line 705 · 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 711 · 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 716 · raw

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

def fg_go source · line 721 · 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 727 · 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 731 · 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 735 · raw

@r:R1 -> Array<F32>

Unsafe

unsafe mm source · line 185 · 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 200 · 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 206 · raw

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

unsafe leaf_if source · line 213 · 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 219 · raw

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

unsafe tree source · line 225 · raw

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

unsafe tree_new source · line 236 · 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 240 · raw

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

unsafe bang source · line 245 · 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 252 · raw

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

unsafe gemm_new source · line 267 · 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 272 · 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 289 · raw

@+n:Nat -> @+k:Nat -> @+m:Nat -> @par:Nat -> @a:0xf4dfe0b415f12cd7b6b3e20aa7cc5aa0/main.Mat<n, k> -> @b:0xf4dfe0b415f12cd7b6b3e20aa7cc5aa0/main.Mat<k, m> -> 0xf4dfe0b415f12cd7b6b3e20aa7cc5aa0/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 296 · raw

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

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

unsafe matmul_nt source · line 303 · raw

@+n:Nat -> @+k:Nat -> @+m:Nat -> @par:Nat -> @a:0xf4dfe0b415f12cd7b6b3e20aa7cc5aa0/main.Mat<n, k> -> @b:0xf4dfe0b415f12cd7b6b3e20aa7cc5aa0/main.Mat<m, k> -> 0xf4dfe0b415f12cd7b6b3e20aa7cc5aa0/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 310 · raw

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

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

unsafe matmul_tn source · line 317 · raw

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

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

unsafe matmul_tn_acc source · line 324 · raw

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

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

unsafe join2 source · line 389 · raw

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

unsafe join3 source · line 394 · raw

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

unsafe join4 source · line 399 · raw

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

unsafe tree1 source · line 404 · 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 412 · 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 416 · 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 420 · 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 424 · 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 429 · 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 434 · 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 438 · 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 446 · 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 450 · 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 454 · 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 458 · 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 463 · 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 468 · 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 472 · 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 480 · 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 484 · 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 488 · 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 492 · 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 497 · 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 502 · 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 506 · 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 514 · 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 518 · 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 522 · 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 526 · 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 531 · 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 536 · 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 550 · 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 556 · 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 560 · raw

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

unsafe mm_precise2 source · line 564 · raw

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

unsafe matmul_precise source · line 571 · raw

@+n:Nat -> @+k:Nat -> @+m:Nat -> @+par:Nat -> @a:0xf4dfe0b415f12cd7b6b3e20aa7cc5aa0/main.Mat<n, k> -> @b:0xf4dfe0b415f12cd7b6b3e20aa7cc5aa0/main.Mat<k, m> -> 0xf4dfe0b415f12cd7b6b3e20aa7cc5aa0/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 742 · 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 748 · 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 753 · 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 759 · 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 764 · raw

@+s:U32 -> @+r:Nat -> @+m:Nat -> 0xf4dfe0b415f12cd7b6b3e20aa7cc5aa0/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 769 · raw

@+s:U32 -> @+r:Nat -> @+m:Nat -> 0xf4dfe0b415f12cd7b6b3e20aa7cc5aa0/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 775 · raw

@+s:U32 -> @+i0:U32 -> @+r:Nat -> @+m:Nat -> 0xf4dfe0b415f12cd7b6b3e20aa7cc5aa0/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 781 · raw

@+s:U32 -> @+i0:U32 -> @+r:Nat -> @+m:Nat -> 0xf4dfe0b415f12cd7b6b3e20aa7cc5aa0/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)