def gemm_any3
import bend-ml-tensor-array@0.1.19.0/main.bend as BendMlTensorArrayimport Base
1152# one row (matrix · vector): the scalar loop at every depth; two or more rows: cells of 8. Up to 0.1.11.0 one row in
1153# parallel ran gemm_par_cols, which clones both operands at every node of the fork tree: a 50,257 x 768 weight matrix at
1154# depth 4 ran out of the default heap (5.1 GB) and 8192 x 2048 took 124 ms against 10 ms sequentially. Packing the
1155# matrix into cells of 8 instead costs more than the product, which reads each weight once (64 ms against 24 at
1156# 50,257 x 768). Matrix · vector in parallel is Bands.matvec. Measured 2026-10-16 (NOTES.md).
1157def gemm_any3(+ac: Bool, one: Bool, d: Nat, +n: Nat, +m: Nat, +k: Nat, +arow: U32, +sa: U32, +sb: U32, +bcol: U32, a: Array<F32>, b: Array<F32>, c: Array<F32>) -> G:
1158 match one:
1159 case True{}:
1160 gemm_ac(ac, n, m, k, arow, sa, sb, bcol, a, b, c)
1161 case False{}:
1162 gemm_t8_ac(ac, d, n, m, k, arow, sa, sb, bcol, a, b, c)