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 / om / gpu / dsv41 / decoder / workspace.om

411 lines · 9728 bytes Raw Blame History
1note SPDX-License-Identifier: AGPL-3.0-only
2note Scratch, I/O, and multi-chunk slab GPU mappings (up to 4 x 800 = 3200 slots,
3note 20480-token context), decode LUT, and typed QMD launch wrappers.
4global dwMaps long 5
5global dwSizes ulong 5
6global dwSlabMaps long 7
7global dwSlabSizes ulong 7
8global dfWrReq int 6
9global dfWrRep int 6
10global dfWrPid long 6
11global dfWrActive ulong 1
12note dwMaps: 0=zone1, 1=kv, 2=slabChunk0, 3=scratch, 4=io
13
14const wsLut ulong 0
15const wsRopeBase ulong 4096
16const wsRopeComp ulong 5246976
17const wsOnes ulong 10489856
18const wsResA ulong 10510336
19const wsResB ulong 10592256
20const wsPreMix ulong 10674176
21const wsAttnPre ulong 10674432
22const wsAttnPost ulong 10674688
23const wsAttnComb ulong 10674944
24const wsFfnPre ulong 10675200
25const wsFfnPost ulong 10675456
26const wsFfnComb ulong 10675712
27const wsRaw24 ulong 10675968
28const wsStat ulong 10676224
29const wsX ulong 10676480
30const wsXNorm ulong 10696960
31const wsSubOut ulong 10717440
32const wsPacked ulong 10737920
33const wsScales ulong 10803456
34const wsRecon ulong 10803712
35const wsQr ulong 10934784
36const wsQ ulong 10939904
37const wsKv ulong 11070976
38const wsScores ulong 11073024
39const wsAttnOut ulong 11236864
40const wsWoAOut ulong 11367936
41const wsGateLogits ulong 11400704
42const wsExpGate ulong 11402240
43const wsExpUp ulong 11411456
44const wsExpAct ulong 11420672
45const wsSharedOut ulong 11429888
46const wsRoutedOut ulong 11450368
47const wsEngramGain1 ulong 11573248
48const wsEngramGain14 ulong 11655168
49const wsEngramRows ulong 11737088
50const wsEngramKV ulong 11761664
51const wsEngramValid ulong 11864064
52const wsEngramGate ulong 11864320
53const wsPosBuf ulong 11864576
54const wsIdxBuf ulong 11864832
55const wsIdxQ ulong 11868928
56const wsIdxW ulong 11885312
57const wsIdxScores ulong 11885568
58const wsIdxLens ulong 11967488
59const wsCandKeep ulong 11967744
60const wsCandBlocks ulong 11977984
61const wsCandIds ulong 11988224
62const wsTopMask ulong 12070144
63const wsCompKv ulong 12152064
64const wsCompGate ulong 12156160
65const wsCompOut ulong 12160256
66const wsCompK ulong 12162304
67const wsKvConcat ulong 12163072
68const wsUnpack ulong 54368256
69const wsTotalBytes ulong 65000000
70
71const ioToken ulong 0
72const ioExpIds ulong 256
73const ioExpWeights ulong 512
74const ioEngramRaw ulong 768
75const ioEngramScales ulong 6912
76const ioEngramIds ulong 7168
77const ioIdxCopy ulong 7424
78const ioDump ulong 16384
79const ioLogits ulong 98304
80const ioTotalBytes ulong 655360
81
82fn dwE4m3 c uint to uint
83 e = and shr c 3 15
84 m = and c 7
85 raw = or shl add e 120 23 shl m 20
86 if eq e 0
87 raw = bitcast uint mul f32 m 0.001953125f32
88 end
89 if and eq e 15 eq m 7
90 raw = uint 0x7fc00000
91 end
92 ret or raw shl and c 128 24
93end
94
95fn dwE2m1 c uint to uint
96 e = and shr c 1 3
97 m = and c 1
98 raw = or shl add e 126 23 shl m 22
99 if eq e 0
100 raw = bitcast uint mul f32 m 0.5f32
101 end
102 ret or raw shl and c 8 28
103end
104
105fn dwInitScratch to bool
106 lut = new uchar 1088 0
107 for i ulong 272
108 v = dwE4m3 uint i
109 if ge i 256
110 v = dwE2m1 uint sub i 256
111 end
112 for j ulong 4
113 put lut add mul i 4 j uchar and shr v uint mul j 8 255
114 end
115 end
116 scr = get dwMaps 3
117 if ne mapwrite scr wsLut lut 0 1088 1088
118 ret false
119 end
120 ones = new uchar 20480 0
121 for i ulong 5120
122 put ones add mul i 4 2 128
123 put ones add mul i 4 3 63
124 end
125 if ne mapwrite scr wsOnes ones 0 20480 20480
126 ret false
127 end
128 if ne mapset scr wsEngramValid 4 1 0
129 ret false
130 end
131 if not drFillTable scr wsRopeBase 10000.0f64 false
132 ret false
133 end
134 if not drFillTable scr wsRopeComp 160000.0f64 true
135 ret false
136 end
137 ret true
138end
139
140fn dwMulBf16Pair qb view uchar 40960 kb view uchar 40960 prod edit uchar 81920 to void
141 for i ulong 20480
142 p = mul i 2
143 qu = or shl uint get qb p 16 shl uint get qb add p 1 24
144 ku = or shl uint get kb p 16 shl uint get kb add p 1 24
145 pv = bitcast uint mul bitcast f32 qu bitcast f32 ku
146 q = mul i 4
147 put prod q uchar and pv 255
148 put prod add q 1 uchar and shr pv 8 255
149 put prod add q 2 uchar and shr pv 16 255
150 put prod add q 3 uchar and shr pv 24 255
151 end
152end
153
154fn dwPrecomputeEngramGain layer ulong dest ulong to bool
155 qoff = get lmLayer add mul layer lmStride 39
156 koff = get lmLayer add mul layer lmStride 40
157 if or eq qoff lmMissing eq koff lmMissing
158 ret false
159 end
160 qb = new uchar 40960 0
161 kb = new uchar 40960 0
162 prod = new uchar 81920 0
163 if ne mapread get dwMaps 0 qoff qb 0 40960 40960
164 ret false
165 end
166 if ne mapread get dwMaps 0 koff kb 0 40960 40960
167 ret false
168 end
169 dwMulBf16Pair qb kb prod
170 ret eq mapwrite get dwMaps 3 dest prod 0 81920 81920
171end
172
173fn dwBind idx ulong off ulong span ulong to bool
174 ret dnBind get dwMaps idx get dwSizes idx off span
175end
176
177fn dwBindSlab chunk ulong off ulong span ulong to bool
178 ret dnBind get dwSlabMaps chunk get dwSlabSizes chunk off span
179end
180
181fn dwBf16Unpack srcIdx ulong srcOff ulong dstIdx ulong dstOff ulong count ulong to bool
182 if not dwBind srcIdx srcOff mul count 2
183 ret false
184 end
185 if not dwBind dstIdx dstOff mul count 4
186 ret false
187 end
188 headArg uint count
189 ret dnRecord 19 uint div add count 127 128 1 1 128
190end
191
192fn dwBf16Pack srcIdx ulong srcOff ulong dstIdx ulong dstOff ulong count ulong to bool
193 if not dwBind srcIdx srcOff mul count 4
194 ret false
195 end
196 if not dwBind dstIdx dstOff mul count 2
197 ret false
198 end
199 headArg uint count
200 ret dnRecord 18 uint div add count 127 128 1 1 128
201end
202
203fn dwQuantFp8 inOff ulong count ulong to bool
204 if not dwBind 3 inOff mul count 4
205 ret false
206 end
207 if not dwBind 3 wsLut 1088
208 ret false
209 end
210 if not dwBind 3 wsPacked count
211 ret false
212 end
213 if not dwBind 3 wsScales div count 32
214 ret false
215 end
216 if not dwBind 3 wsRecon mul count 4
217 ret false
218 end
219 ret dnRecord 8 uint div count 32 1 1 16
220end
221
222fn dwQuantFp4 inOff ulong count ulong to bool
223 if not dwBind 3 inOff mul count 4
224 ret false
225 end
226 if not dwBind 3 wsLut 1088
227 ret false
228 end
229 if not dwBind 3 wsPacked div count 2
230 ret false
231 end
232 if not dwBind 3 wsScales div count 32
233 ret false
234 end
235 if not dwBind 3 wsRecon mul count 4
236 ret false
237 end
238 ret dnRecord 9 uint div count 32 1 1 16
239end
240
241fn dwQuantKv inOff ulong count ulong to bool
242 if not dwBind 3 inOff mul count 4
243 ret false
244 end
245 if not dwBind 3 wsLut 1088
246 ret false
247 end
248 if not dwBind 3 wsPacked div count 2
249 ret false
250 end
251 if not dwBind 3 wsScales div count 16
252 ret false
253 end
254 if not dwBind 3 wsRecon mul count 4
255 ret false
256 end
257 ret dnRecord 10 uint div count 16 1 1 8
258end
259
260fn dwFp8Gemm wIdx ulong wOff ulong sOff ulong dstOff ulong k ulong n ulong to bool
261 if and eq rem n 8 0 eq rem k 32 0
262 if not dwBind 3 wsPacked k
263 ret false
264 end
265 if not dwBind wIdx wOff mul n k
266 ret false
267 end
268 if not dwBind 3 wsScales div k 32
269 ret false
270 end
271 if not dwBind wIdx sOff mul div add n 31 32 div k 32
272 ret false
273 end
274 if not dwBind 3 dstOff mul n 4
275 ret false
276 end
277 headArg uint k
278 ret dnRecord 29 uint div n 8 1 1 32
279 end
280 if not dwBind 3 wsPacked k
281 ret false
282 end
283 if not dwBind wIdx wOff mul n k
284 ret false
285 end
286 if not dwBind 3 wsScales div k 32
287 ret false
288 end
289 if not dwBind wIdx sOff mul div add n 31 32 div k 32
290 ret false
291 end
292 if not dwBind 3 wsLut 1088
293 ret false
294 end
295 if not dwBind 3 dstOff mul n 4
296 ret false
297 end
298 headArg uint k
299 headArg uint n
300 ret dnRecord 4 uint div add n 127 128 1 1 128
301end
302
303fn dwFp4GemmChunk chunk ulong wOff ulong sOff ulong dstOff ulong k ulong n ulong to bool
304 if and eq rem n 8 0 eq rem k 32 0
305 if not dwBind 3 wsPacked k
306 ret false
307 end
308 if not dwBindSlab chunk wOff mul n div k 2
309 ret false
310 end
311 if not dwBind 3 wsScales div k 32
312 ret false
313 end
314 if not dwBindSlab chunk sOff mul n div k 32
315 ret false
316 end
317 if not dwBind 3 dstOff mul n 4
318 ret false
319 end
320 headArg uint k
321 ret dnRecord 28 uint div n 8 1 1 32
322 end
323 if not dwBind 3 wsPacked k
324 ret false
325 end
326 if not dwBindSlab chunk wOff mul n div k 2
327 ret false
328 end
329 if not dwBind 3 wsScales div k 32
330 ret false
331 end
332 if not dwBindSlab chunk sOff mul n div k 32
333 ret false
334 end
335 if not dwBind 3 wsLut 1088
336 ret false
337 end
338 if not dwBind 3 dstOff mul n 4
339 ret false
340 end
341 headArg uint k
342 headArg uint n
343 ret dnRecord 5 uint div add n 127 128 1 1 128
344end
345
346fn dwDense aOff ulong wIdx ulong wOff ulong dstOff ulong k ulong n ulong to bool
347 if not dwBind 3 aOff mul k 4
348 ret false
349 end
350 if not dwBind wIdx wOff mul mul n k 4
351 ret false
352 end
353 if not dwBind 3 dstOff mul n 4
354 ret false
355 end
356 headArg uint k
357 headArg uint n
358 if eq rem k 32 0
359 ret dnRecord 31 uint n 1 1 32
360 end
361 ret dnRecord 11 uint div add n 127 128 1 1 128
362end
363
364fn dwRmsNorm inOff ulong gainZ1Off ulong dstOff ulong d ulong to bool
365 if not dwBf16Unpack 0 gainZ1Off 3 wsUnpack d
366 ret false
367 end
368 if not dwBind 3 inOff mul d 4
369 ret false
370 end
371 if not dwBind 3 wsStat 4
372 ret false
373 end
374 headArg uint d
375 if eq rem d 32 0
376 if not dnRecord 30 1 1 1 32
377 ret false
378 end
379 else
380 if not dnRecord 12 1 1 1 1
381 ret false
382 end
383 end
384 if not dwBind 3 inOff mul d 4
385 ret false
386 end
387 if not dwBind 3 wsUnpack mul d 4
388 ret false
389 end
390 if not dwBind 3 wsStat 4
391 ret false
392 end
393 if not dwBind 3 dstOff mul d 4
394 ret false
395 end
396 headArg uint d
397 if not dnRecord 13 uint div add d 127 128 1 1 128
398 ret false
399 end
400 if not dwBf16Pack 3 dstOff 3 wsPacked d
401 ret false
402 end
403 ret dwBf16Unpack 3 wsPacked 3 dstOff d
404end
405
406fn dwRoundBf16 bufOff ulong d ulong to bool
407 if not dwBf16Pack 3 bufOff 3 wsPacked d
408 ret false
409 end
410 ret dwBf16Unpack 3 wsPacked 3 bufOff d
411end