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
omega-mv / seed / helix / extract_q36_kernels.om
| 1 | note SPDX-License-Identifier: Apache-2.0 |
| 2 | note seed/helix/extract_q36_kernels.om: Extracts real production SM121 SASS binaries |
| 3 | note directly from om/gpu/q36/emit_fast.om (31 kernels, modes 97..127) and |
| 4 | note om/gpu/q36/head/emit_head.om (5 kernels, modes 97..101) so Strand B Predator + |
| 5 | note Strand A Monk + 12-Antibody Immune System verify all 36 production Qwen 3.6 35B GB10 kernels! |
| 6 | note Compose after: |
| 7 | note om/encoder/bw_enc_sm121.om |
| 8 | note om/gpu/q36/emit_fast.om |
| 9 | note om/gpu/q36/head/emit_head.om |
| 10 | note |
| 11 | note Usage: |
| 12 | note extract_q36_kernels MODE OUT_BIN |
| 13 | note MODE: single ASCII char ('a'..'~'), decimal numeric ID (97..127, fixing ASCII 127=DEL |
| 14 | note on qBf16Gemv1R), or head mode ('h97'..'h101' / 'ha'..'he'). |
| 15 | note extract_q36_kernels --all OUT_DIR |
| 16 | note Extracts all 31 emit_fast (fast_097.bin..fast_127.bin) + 5 emit_head (head_097.bin..head_101.bin). |
| 17 | |
| 18 | global exOut uchar 65536 |
| 19 | global exPath uchar 1024 |
| 20 | global exDir uchar 1024 |
| 21 | global exMode uchar 32 |
| 22 | |
| 23 | text exUse "usage: extract_q36_kernels MODE OUT_BIN | --all OUT_DIR\n" |
| 24 | text exOk "EXTRACTED q36_kernel mode=" |
| 25 | text exBy " bytes=" |
| 26 | text exIn " insns=" |
| 27 | text exNl "\n" |
| 28 | text exAllOk "EXTRACTED_ALL fast=31 head=5 total=36\n" |
| 29 | text exFastPfx "/fast_" |
| 30 | text exHeadPfx "/head_" |
| 31 | text exBinSfx ".bin" |
| 32 | text exHeadCh "h" |
| 33 | |
| 34 | fn q36Write w view ulong 4 to void |
| 35 | end |
| 36 | |
| 37 | fn qhWrite w view ulong 4 to void |
| 38 | end |
| 39 | |
| 40 | fn exDumpFast cnt ulong to ulong |
| 41 | for pc ulong cnt bound 2048 |
| 42 | for k ulong 4 |
| 43 | exWd = get q36Buf add mul pc 4 k |
| 44 | base = add mul pc 16 mul k 4 |
| 45 | put exOut base uchar and exWd 255 |
| 46 | put exOut add base 1 uchar and shr exWd 8 255 |
| 47 | put exOut add base 2 uchar and shr exWd 16 255 |
| 48 | put exOut add base 3 uchar and shr exWd 24 255 |
| 49 | end |
| 50 | end |
| 51 | ret mul cnt 16 |
| 52 | end |
| 53 | |
| 54 | fn exDumpHead cnt ulong to ulong |
| 55 | for pc ulong cnt bound 2048 |
| 56 | for k ulong 4 |
| 57 | exWd = get qhBuf add mul pc 4 k |
| 58 | base = add mul pc 16 mul k 4 |
| 59 | put exOut base uchar and exWd 255 |
| 60 | put exOut add base 1 uchar and shr exWd 8 255 |
| 61 | put exOut add base 2 uchar and shr exWd 16 255 |
| 62 | put exOut add base 3 uchar and shr exWd 24 255 |
| 63 | end |
| 64 | end |
| 65 | ret mul cnt 16 |
| 66 | end |
| 67 | |
| 68 | fn exNum v ulong to void |
| 69 | b = new uchar 24 0 |
| 70 | p = ulong 24 |
| 71 | x = v |
| 72 | while true bound 24 |
| 73 | p = sub p 1 |
| 74 | put b p uchar add 48 rem x 10 |
| 75 | x = div x 10 |
| 76 | if eq x 0 |
| 77 | break |
| 78 | end |
| 79 | end |
| 80 | r = write 1 b p sub 24 p |
| 81 | end |
| 82 | |
| 83 | fn exWritePath plen ulong n ulong to bool |
| 84 | fd = fopen exPath 0 plen 577 420 |
| 85 | if lt fd 0 |
| 86 | ret false |
| 87 | end |
| 88 | pos = ulong 0 |
| 89 | while lt pos n bound 256 |
| 90 | ch = sub n pos |
| 91 | if gt ch 4096 |
| 92 | ch = ulong 4096 |
| 93 | end |
| 94 | w = write int fd exOut pos ch |
| 95 | if ne w long ch |
| 96 | z = fclose int fd |
| 97 | ret false |
| 98 | end |
| 99 | pos = add pos ch |
| 100 | end |
| 101 | z = fclose int fd |
| 102 | ret true |
| 103 | end |
| 104 | |
| 105 | fn exParseDec off ulong m ulong to ulong |
| 106 | v = ulong 0 |
| 107 | if ge off m |
| 108 | ret 0 |
| 109 | end |
| 110 | for i ulong sub m off bound 16 |
| 111 | c = get exMode add off i |
| 112 | if or lt c 48 gt c 57 |
| 113 | ret 0 |
| 114 | end |
| 115 | v = add mul v 10 ulong sub c 48 |
| 116 | end |
| 117 | ret v |
| 118 | end |
| 119 | |
| 120 | fn exEmitOne isHead bool id ulong plen ulong to bool |
| 121 | n = ulong 0 |
| 122 | if isHead |
| 123 | put qhPc 0 0 |
| 124 | put qhGuard 0 0 |
| 125 | if not qhKernel uchar id |
| 126 | ret false |
| 127 | end |
| 128 | qhDone |
| 129 | cnt = get qhPc 0 |
| 130 | if or eq cnt 0 gt cnt 2048 |
| 131 | ret false |
| 132 | end |
| 133 | n = exDumpHead cnt |
| 134 | else |
| 135 | put q36Pc 0 0 |
| 136 | put q36Guard 0 0 |
| 137 | if not q36Kernel uchar id |
| 138 | ret false |
| 139 | end |
| 140 | q36Done |
| 141 | cnt = get q36Pc 0 |
| 142 | if or eq cnt 0 gt cnt 2048 |
| 143 | ret false |
| 144 | end |
| 145 | n = exDumpFast cnt |
| 146 | end |
| 147 | if not exWritePath plen n |
| 148 | ret false |
| 149 | end |
| 150 | r = write 1 exOk 0 len exOk |
| 151 | if isHead |
| 152 | r = write 1 exHeadCh 0 1 |
| 153 | end |
| 154 | exNum id |
| 155 | r = write 1 exBy 0 len exBy |
| 156 | exNum n |
| 157 | r = write 1 exIn 0 len exIn |
| 158 | exNum div n 16 |
| 159 | r = write 1 exNl 0 len exNl |
| 160 | ret true |
| 161 | end |
| 162 | |
| 163 | fn exBuildName dlen ulong isHead bool id ulong to ulong |
| 164 | p = ulong 0 |
| 165 | for i ulong dlen bound 900 |
| 166 | put exPath p get exDir i |
| 167 | p = add p 1 |
| 168 | end |
| 169 | if isHead |
| 170 | for i ulong len exHeadPfx bound 16 |
| 171 | put exPath p get exHeadPfx i |
| 172 | p = add p 1 |
| 173 | end |
| 174 | else |
| 175 | for i ulong len exFastPfx bound 16 |
| 176 | put exPath p get exFastPfx i |
| 177 | p = add p 1 |
| 178 | end |
| 179 | end |
| 180 | put exPath p uchar add 48 div id 100 |
| 181 | p = add p 1 |
| 182 | put exPath p uchar add 48 rem div id 10 10 |
| 183 | p = add p 1 |
| 184 | put exPath p uchar add 48 rem id 10 |
| 185 | p = add p 1 |
| 186 | for i ulong len exBinSfx bound 8 |
| 187 | put exPath p get exBinSfx i |
| 188 | p = add p 1 |
| 189 | end |
| 190 | ret p |
| 191 | end |
| 192 | |
| 193 | fn exIsAll m ulong to bool |
| 194 | if ne m 5 |
| 195 | ret false |
| 196 | end |
| 197 | if ne get exMode 0 45 |
| 198 | ret false |
| 199 | end |
| 200 | if ne get exMode 1 45 |
| 201 | ret false |
| 202 | end |
| 203 | if ne get exMode 2 97 |
| 204 | ret false |
| 205 | end |
| 206 | if ne get exMode 3 108 |
| 207 | ret false |
| 208 | end |
| 209 | ret eq get exMode 4 108 |
| 210 | end |
| 211 | |
| 212 | fn main to int |
| 213 | if ne argcnt 3 |
| 214 | r = write 1 exUse 0 len exUse |
| 215 | ret 90 |
| 216 | end |
| 217 | m = argread 1 exMode 0 31 |
| 218 | k = argread 2 exPath 0 1023 |
| 219 | if or lt m 1 lt k 1 |
| 220 | ret 90 |
| 221 | end |
| 222 | um = ulong m |
| 223 | uk = ulong k |
| 224 | if exIsAll um |
| 225 | for i ulong uk bound 1024 |
| 226 | put exDir i get exPath i |
| 227 | end |
| 228 | for id ulong 31 |
| 229 | mid = add 97 id |
| 230 | pl = exBuildName uk false mid |
| 231 | if not exEmitOne false mid pl |
| 232 | ret 2 |
| 233 | end |
| 234 | end |
| 235 | for id ulong 5 |
| 236 | mid = add 97 id |
| 237 | pl = exBuildName uk true mid |
| 238 | if not exEmitOne true mid pl |
| 239 | ret 2 |
| 240 | end |
| 241 | end |
| 242 | r = write 1 exAllOk 0 len exAllOk |
| 243 | ret 0 |
| 244 | end |
| 245 | isHead = false |
| 246 | mid = ulong 0 |
| 247 | c0 = get exMode 0 |
| 248 | if and eq c0 104 gt um 1 |
| 249 | isHead = true |
| 250 | c1 = get exMode 1 |
| 251 | if and eq um 2 or lt c1 48 gt c1 57 |
| 252 | mid = ulong c1 |
| 253 | else |
| 254 | mid = exParseDec 1 um |
| 255 | end |
| 256 | else |
| 257 | if and eq um 1 or lt c0 48 gt c0 57 |
| 258 | mid = ulong c0 |
| 259 | else |
| 260 | mid = exParseDec 0 um |
| 261 | end |
| 262 | end |
| 263 | if or lt mid 97 gt mid 127 |
| 264 | ret 2 |
| 265 | end |
| 266 | if not exEmitOne isHead mid uk |
| 267 | ret 3 |
| 268 | end |
| 269 | ret 0 |
| 270 | end |