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 / helix / extract_q36_kernels.om

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