interplane.Get Omega
Read in your language

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

branch main Branches Tags History

omega-mv / seed / ng / front / runs / linear-s.om

72 lines · 1962 bytes Raw Blame History
1note linear-s: kernels/linear.om with 2 passes (was 40), for ngrun in gate-front-ir. linear:
2note the torch.nn.Linear addmm kernel of omega-bridge pytorch/kernels/linear.om (main d8174edd,
3note blob f7d5231a) at M 64, K 256, N 256, verbatim below the consts, plus a bench main: 40 passes, the
4note bias changes by 1.0 at one column before each pass, and every pass folds the f32 bits of all
5note outputs into one ulong checksum, printed as one decimal line.
6const M ulong 64
7const K ulong 256
8const N ulong 256
9const MK ulong 16384
10const NK ulong 65536
11const MN ulong 16384
12note linear: o[M,N] = c[N] + a[M,K] @ w[N,K]^T, the addmm of a torch.nn.Linear whose weight transpose
13note (aten.permute [1,0]) feeds only this addmm; w is read in place, nothing is copied. Each sum starts
14note at the bias, is summed in f64 and rounded once to f32. Consts M K N MK NK MN come first.
15fn lindot c view f32 N a view f32 MK w view f32 NK i ulong j ulong to f64
16s = f64 get c j
17ia = mul i K
18iw = mul j K
19for k ulong K
20s = add s mul f64 get a ia f64 get w iw
21ia = add ia 1
22iw = add iw 1
23end
24ret s
25end
26fn linear c view f32 N a view f32 MK w view f32 NK o edit f32 MN to void
27for i ulong M
28for j ulong N
29put o add mul i N j f32 lindot c a w i j
30end
31end
32end
33global out uchar 32
34fn putnum v ulong to void
35put out 31 10
36p = ulong 31
37x = v
38while gt x 9
39p = sub p 1
40put out p uchar add rem x 10 48
41x = div x 10
42end
43p = sub p 1
44put out p uchar add x 48
45w = write 1 out p sub 32 p
46end
47fn main to int
48c = new f32 256 0.0f32
49a = new f32 16384 0.0f32
50w = new f32 65536 0.0f32
51o = new f32 16384 0.0f32
52for i ulong 256
53put c i div f32 sub long rem mul i 5 11 5 4.0f32
54end
55for i ulong 16384
56put a i div f32 sub long rem mul i 7 13 6 8.0f32
57end
58for i ulong 65536
59put w i div f32 sub long rem mul i 3 17 8 16.0f32
60end
61s = ulong 0
62for r ulong 2
63q = rem r 256
64put c q add get c q 1.0f32
65linear c a w o
66for i ulong 16384
67s = add s mul ulong bitcast uint get o i add i 1
68end
69end
70putnum s
71ret 0
72end