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 / protocol / aien-protocols / specs / aienet / jobpath / matmul_u32_recompute.om

145 lines · 3737 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0
2note matmul_u32_recompute.om: the Spark verifier's independent recompute of the Aienet-0 allowlisted
3note job matmul_u32 (task layout copied by reference from aien-sovereign-core PR #662,
4note crates/aien-hetjob/src/task.rs at 3606d041: KIND_MATMUL_U32, splitmix64 inputs, MATMUL_DOMAIN).
5note This file is not a unit on its own: build.sh appends it to the pinned OM-2 SHA-256 unit
6note omega-mv om/sha256/sha256-om2.om (sha256 pinned in build.sh), which supplies om2, shactx and
7note sha256_hash. The worker computes C = A x B in i-k-j order in Rust; this recompute is a different
8note language, compiler and loop order (i-j-k dot products).
9note stdin: the 15-byte task payload kind 0x01, m, k, n (u16 big endian), seed (u64 big endian).
10note stdout: 64 lowercase hex characters of SHA-256(domain, m, k, n, seed, C as u32 big endian), newline.
11note exit 0 ok; 2 payload is not 15 bytes; 3 kind is not matmul_u32; 4 a dimension is 0 or above 256;
12note 5 a write to stdout failed.
13
14text dom "AIEN-HETJOB-MATMUL-U32-V1"
15text hexd "0123456789abcdef"
16
17note splitmix64, one step: st[0] is the state.
18fn smix st edit ulong 1 to ulong
19s = add get st 0 0x9e3779b97f4a7c15
20put st 0 s
21z = xor s shr s 30
22z = mul z 0xbf58476d1ce4e5b9
23z = xor z shr z 27
24z = mul z 0x94d049bb133111eb
25ret xor z shr z 31
26end
27
28note cnt elements of the stream, low 32 bits each (Rust: splitmix64(&mut s) as u32).
29fn gen a edit uint 65536 cnt ulong st edit ulong 1 to void
30for i ulong cnt
31put a i uint and smix st 0xffffffff
32end
33end
34
35note Row i of A (offset ia = i*k) dotted with column j of B, wrapping mod 2^32.
36fn dot a view uint 65536 b view uint 65536 ia ulong k ulong n ulong j ulong to uint
37acc = uint 0
38q = j
39for p ulong k
40x = get a add ia p
41acc = add acc mul x get b q
42q = add q n
43end
44ret acc
45end
46
47note C[i][j] = sum over p of A[i][p] * B[p][j], i-j-k order (one dot product per element).
48fn mm a view uint 65536 b view uint 65536 c edit uint 65536 m ulong k ulong n ulong to void
49o = ulong 0
50for i ulong m
51for j ulong n
52put c o dot a b mul i k k n j
53o = add o 1
54end
55end
56end
57
58note C as u32 big endian into pre from byte 39.
59fn ser c view uint 65536 pre edit uchar 262183 cnt ulong to void
60v = uint 0
61q = ulong 39
62for i ulong cnt
63v = get c i
64put pre q uchar shr v 24
65put pre add q 1 uchar and shr v 16 0xff
66put pre add q 2 uchar and shr v 8 0xff
67put pre add q 3 uchar and v 0xff
68q = add q 4
69end
70end
71
72fn dim b view uchar 16 o ulong to ulong
73ret or shl ulong get b o 8 ulong get b add o 1
74end
75
76note SHA-256 of domain, payload[1..15) and C; 65 bytes of hex and newline to stdout.
77fn emit buf view uchar 16 c view uint 65536 cnt ulong to int
78pre = new uchar 262183 0
79for i ulong 25
80put pre i get dom i
81end
82for i ulong 14
83put pre add 25 i get buf add 1 i
84end
85ser c pre cnt
86d = new uchar 32 0
87sha256_hash part pre 0 add 39 shl cnt 2 d
88o = new uchar 65 0
89for i ulong 32
90put o shl i 1 get hexd shr get d i 4
91put o add shl i 1 1 get hexd and get d i 15
92end
93put o 64 10
94w = write 1 o 0 65
95if ne w 65
96ret 5
97end
98ret 0
99end
100
101note The payload in buf is 15 bytes of kind 1; checks the dimensions, computes and emits.
102fn job buf view uchar 16 to int
103m = dim buf 1
104k = dim buf 3
105n = dim buf 5
106if or or eq m 0 eq k 0 eq n 0
107ret 4
108end
109if or or gt m 256 gt k 256 gt n 256
110ret 4
111end
112st = new ulong 1 0
113for i ulong 8
114put st 0 or shl get st 0 8 ulong get buf add 7 i
115end
116a = new uint 65536 0
117b = new uint 65536 0
118c = new uint 65536 0
119gen a mul m k st
120gen b mul k n st
121mm a b c m k n
122ret emit buf c mul m n
123end
124
125fn main to int
126buf = new uchar 16 0
127got = ulong 0
128r = long 1
129while gt r 0
130if ge got 16
131ret 2
132end
133r = read 0 buf got sub 16 got
134if gt r 0
135got = add got ulong r
136end
137end
138if ne got 15
139ret 2
140end
141if ne get buf 0 1
142ret 3
143end
144ret job buf
145end