interplane.Get Omega
Read in your language

omega-bridge

Omega-first language interoperability: checked conversion backends and native language bindings

Brought by drakestapleton

branch main Branches Tags History

omega-bridge / pytorch / kernels / linear.om

21 lines · 666 bytes Raw Blame History
1note linear: o[M,N] = c[N] + a[M,K] @ w[N,K]^T, the addmm of a torch.nn.Linear whose weight transpose
2note (aten.permute [1,0]) feeds only this addmm; w is read in place, nothing is copied. Each sum starts
3note at the bias, is summed in f64 and rounded once to f32. Consts M K N MK NK MN come first.
4fn lindot c view f32 N a view f32 MK w view f32 NK i ulong j ulong to f64
5s = f64 get c j
6ia = mul i K
7iw = mul j K
8for k ulong K
9s = add s mul f64 get a ia f64 get w iw
10ia = add ia 1
11iw = add iw 1
12end
13ret s
14end
15fn linear c view f32 N a view f32 MK w view f32 NK o edit f32 MN to void
16for i ulong M
17for j ulong N
18put o add mul i N j f32 lindot c a w i j
19end
20end
21end