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