Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-mv/blob/main/seed/ng/front/runs/linear-s.om # omega-mv Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance. Brought by drakestapleton Sign in to star 1 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-mv / seed / ng / front / runs / linear-s.om` 72 lines ยท 1962 bytes Raw Blame History 1 note linear-s: kernels/linear.om with 2 passes (was 40), for ngrun in gate-front-ir. linear: 2 note the torch.nn.Linear addmm kernel of omega-bridge pytorch/kernels/linear.om (main `d8174edd`, 3 note blob `f7d5231a`) at M 64, K 256, N 256, verbatim below the consts, plus a bench main: 40 passes, the 4 note bias changes by 1.0 at one column before each pass, and every pass folds the f32 bits of all 5 note outputs into one ulong checksum, printed as one decimal line. 6 const M ulong 64 7 const K ulong 256 8 const N ulong 256 9 const MK ulong 16384 10 const NK ulong 65536 11 const MN ulong 16384 12 note linear: o[M,N] = c[N] + a[M,K] @ w[N,K]^T, the addmm of a torch.nn.Linear whose weight transpose 13 note (aten.permute [1,0]) feeds only this addmm; w is read in place, nothing is copied. Each sum starts 14 note at the bias, is summed in f64 and rounded once to f32. Consts M K N MK NK MN come first. 15 fn lindot c view f32 N a view f32 MK w view f32 NK i ulong j ulong to f64 16 s = f64 get c j 17 ia = mul i K 18 iw = mul j K 19 for k ulong K 20 s = add s mul f64 get a ia f64 get w iw 21 ia = add ia 1 22 iw = add iw 1 23 end 24 ret s 25 end 26 fn linear c view f32 N a view f32 MK w view f32 NK o edit f32 MN to void 27 for i ulong M 28 for j ulong N 29 put o add mul i N j f32 lindot c a w i j 30 end 31 end 32 end 33 global out uchar 32 34 fn putnum v ulong to void 35 put out 31 10 36 p = ulong 31 37 x = v 38 while gt x 9 39 p = sub p 1 40 put out p uchar add rem x 10 48 41 x = div x 10 42 end 43 p = sub p 1 44 put out p uchar add x 48 45 w = write 1 out p sub 32 p 46 end 47 fn main to int 48 c = new f32 256 0.0f32 49 a = new f32 16384 0.0f32 50 w = new f32 65536 0.0f32 51 o = new f32 16384 0.0f32 52 for i ulong 256 53 put c i div f32 sub long rem mul i 5 11 5 4.0f32 54 end 55 for i ulong 16384 56 put a i div f32 sub long rem mul i 7 13 6 8.0f32 57 end 58 for i ulong 65536 59 put w i div f32 sub long rem mul i 3 17 8 16.0f32 60 end 61 s = ulong 0 62 for r ulong 2 63 q = rem r 256 64 put c q add get c q 1.0f32 65 linear c a w o 66 for i ulong 16384 67 s = add s mul ulong bitcast uint get o i add i 1 68 end 69 end 70 putnum s 71 ret 0 72 end