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 / inkling2 / decoder / prefill_b8.om

929 lines · 18451 bytes Raw Blame History
1note SPDX-License-Identifier: AGPL-3.0-only
2note Pure Seeded-Omega B=8 Batched Prefill Engine for Inkling-2-Mini on GB10 (ZERO CUDA, ZERO C).
3note Uses bf16_gemm_batch_fast (kernel 26, 8x fewer BF16 weight loads) and
4note nvfp4_gemm_dedup_fast / mxfp8_gemm_dedup_fast (kernels 27/28, deduplicated MoE experts across 8 tokens).
5note Composes after: emit_fast.om + emit_batch.om + arboris + safetensors + tokenizer + decode.om + batcher.om.
6
7const B8_H ulong 0x600000
8const B8_HNORM ulong 0x620000
9const B8_HK ulong 0x640000
10const B8_HV ulong 0x660000
11const B8_HRES ulong 0x680000
12const B8_Q ulong 0x6a0000
13const B8_K ulong 0x6c0000
14const B8_V ulong 0x6d0000
15const B8_GATE ulong 0x6e0000
16const B8_RLAT ulong 0x700000
17const B8_SINK ulong 0x708000
18const B8_KSCP ulong 0x710000
19const B8_VSCP ulong 0x711000
20const B8_AOUT ulong 0x720000
21const B8_OPROJ ulong 0x740000
22const B8_OSCONV ulong 0x760000
23const B8_BLOCKS ulong 0x780000
24const B8_PREBLK ulong 0x840000
25const B8_PREH ulong 0x890000
26const B8_PREVBLK ulong 0x8b0000
27const B8_MSGS ulong 0x900000
28const B8_AROUT ulong 0x950000
29const B8_MLPIN ulong 0x990000
30const B8_MLPNORM ulong 0x9b0000
31const B8_RLOGITS ulong 0x9d0000
32const B8_RIDS ulong 0x9d2000
33const B8_RWTS ulong 0x9d3000
34const B8_META13 ulong 0x9e0000
35const B8_META2 ulong 0x9e2000
36const B8_XQ ulong 0x9f0000
37const B8_XREC ulong 0xa20000
38const B8_C13 ulong 0xb00000
39const B8_SWI ulong 0xc00000
40const B8_C2 ulong 0xc80000
41const B8_MLPOUT ulong 0xd40000
42const B8_MGCAT ulong 0xd60000
43const B8_MGLAT ulong 0xd90000
44const B8_MGFG ulong 0xda0000
45const B8_MGGN ulong 0xdc0000
46const B8_QSCR ulong 0xde0000
47
48global ikB8Toks uint 8
49global ikB8MetaBuf uchar 3072
50global ikB8ArbIds uint 3072
51
52fn ikB8PutU32Meta off ulong v uint to void
53put ikB8MetaBuf off uchar and v 255
54put ikB8MetaBuf add off 1 uchar and shr v 8 255
55put ikB8MetaBuf add off 2 uchar and shr v 16 255
56put ikB8MetaBuf add off 3 uchar and shr v 24 255
57end
58
59fn ikB8EmbedWrite b ulong invRms f32 to void
60ar = get ikStArena 0
61normBase = sub get ikGW 1 get ikStArenaVa 0
62wk = get ikDWork 0
63r0 = mapread ar normBase ikDOutBuf 0 9216
64for i ulong 2304
65o = mul i 4
66g = ikDBufF32 o
67v = mul mul get ikDProjTmp i invRms g
68ikDBufPutF32 o v
69end
70r1 = mapwrite wk add B8_H mul b 9216 ikDOutBuf 0 9216
71end
72
73fn ikB8EmbedOne b ulong tok ulong to void
74ar = get ikStArena 0
75embBase = add sub get ikGW 0 get ikStArenaVa 0 mul tok 4608
76r = mapread ar embBase ikDOutBuf 0 4608
77sq = f32 0.0f32
78for i ulong 2304
79v = ikDReadBf16Buf i
80put ikDProjTmp i v
81sq = add sq mul v v
82end
83invRms = div f32 1.0f32 fsqrt add div sq f32 2304.0f32 f32 0.000001f32
84ikB8EmbedWrite b invRms
85end
86
87fn ikB8Copy8 dstOff ulong srcOff ulong to bool
88ikDArgReset
89ikDPtr ikDW srcOff
90ikDPtr 0
91ikDPtr ikDW dstOff
92ikDArgU 18432
93ret ikDBatchAdd 23 144 1 1 128
94end
95
96fn ikB8Add8 dstOff ulong aOff ulong bOff ulong to bool
97ikDArgReset
98ikDPtr ikDW aOff
99ikDPtr ikDW bOff
100ikDPtr ikDW dstOff
101ikDArgU 18432
102ret ikDBatchAdd 23 144 1 1 128
103end
104
105fn ikB8Bf16 wVa ulong xOff ulong yOff ulong k uint n uint to bool
106ikDArgReset
107ikDPtr wVa
108ikDPtr ikDW xOff
109ikDPtr ikDW yOff
110ikDArgU k
111ikDArgU n
112ikDArgU 8
113gx = div add n 7 8
114ret ikDBatchAdd 26 gx 1 1 256
115end
116
117fn ikB8CrossPassMsgs loopIdx ulong to bool
118nPrev = get ikDPrevBlockCnt 0
119vaQ = add get ikGW 5 mul mul loopIdx 2 9216
120vaKV = add get ikGW 6 mul mul loopIdx 2 9216
121for b ulong 8
122pBlk = add B8_PREVBLK mul b 0x9000
123mBase = add B8_MSGS mul b 0x9000
124ikDArgReset
125ikDPtr ikDW pBlk
126ikDPtr 0
127ikDPtr ikDW 0x190000
128ikDArgU 2304
129if not ikDBatchAdd 5 uint nPrev 1 1 256
130ret false
131end
132ikDPtr ikDW 0x190000
133ikDPtr vaQ
134ikDPtr ikDW mBase
135ikDArgU uint nPrev
136ikDArgU 1
137ikDArgU 2304
138if not ikDBatchAdd 4 1 1 1 256
139ret false
140end
141ikDPtr ikDW 0x190000
142ikDPtr add vaQ 9216
143ikDPtr ikDW add mBase 27648
144ikDArgU uint nPrev
145ikDArgU 1
146ikDArgU 2304
147if not ikDBatchAdd 4 1 1 1 256
148ret false
149end
150ikDPtr ikDW 0x190000
151ikDPtr vaKV
152ikDPtr ikDW add mBase 9216
153ikDArgU uint nPrev
154ikDArgU 2
155ikDArgU 2304
156if not ikDBatchAdd 4 2 1 1 256
157ret false
158end
159end
160ret true
161end
162
163fn ikB8MsgGateApplyOne l ulong slotBase ulong hOff ulong mOff ulong b ulong outBase ulong to bool
164lOff = add B8_MGLAT mul b 256
165fgOff = add B8_MGFG mul b 9216
166gnOff = add B8_MGGN mul b 9216
167oOff = add outBase mul b 9216
168ikDArgReset
169ikDPtr ikLva l add slotBase 1
170ikDPtr ikDW lOff
171ikDPtr ikDW fgOff
172ikDArgU 2304
173if not ikDBatchAdd 21 72 1 1 256
174ret false
175end
176ikDPtr ikLva l add slotBase 2
177ikDPtr ikDW lOff
178ikDPtr ikDW gnOff
179ikDArgU 2304
180if not ikDBatchAdd 21 72 1 1 256
181ret false
182end
183ikDPtr ikDW hOff
184ikDPtr ikDW mOff
185ikDPtr ikDW fgOff
186ikDPtr ikDW gnOff
187ikDPtr ikDW oOff
188ikDArgU 2304
189ret ikDBatchAdd 19 18 1 1 128
190end
191
192fn ikB8MsgGate l ulong ctrlIdx ulong hBase ulong hStride ulong msgRel ulong outBase ulong to bool
193slotBase = add 28 mul ctrlIdx 3
194for b ulong 8
195hOff = add hBase mul b hStride
196mOff = add add B8_MSGS mul b 0x9000 msgRel
197cOff = add B8_MGCAT mul b 18432
198ikDArgReset
199ikDPtr ikDW hOff
200ikDPtr 0
201ikDPtr ikDW cOff
202ikDArgU 2304
203if not ikDBatchAdd 5 1 1 1 256
204ret false
205end
206ikDPtr ikDW mOff
207ikDPtr 0
208ikDPtr ikDW add cOff 9216
209ikDArgU 2304
210if not ikDBatchAdd 5 1 1 1 256
211ret false
212end
213end
214if not ikB8Bf16 ikLva l slotBase B8_MGCAT B8_MGLAT 4608 64
215ret false
216end
217for b ulong 8
218hOff = add hBase mul b hStride
219mOff = add add B8_MSGS mul b 0x9000 msgRel
220if not ikB8MsgGateApplyOne l slotBase hOff mOff b outBase
221ret false
222end
223end
224ret true
225end
226
227fn ikB8AttnResOne b ulong bc ulong qVa ulong qCnt uint to bool
228blk = add B8_BLOCKS mul b 0x18000
229h = add B8_H mul b 9216
230ao = add B8_AROUT mul b 0x7000
231ret ikDBatchAttnRes blk bc h qVa qCnt ao
232end
233
234fn ikB8PrepAttnIn l ulong isFull bool hasMsgs bool to bool
235if not ikB8Copy8 B8_HRES B8_H
236ret false
237end
238bc = get ikDBlockCnt 0
239if gt l 0
240qCnt = uint 1
241if isFull
242qCnt = uint 3
243end
244qVa = get ikAttnQOff sub l 1
245for b ulong 8
246if not ikB8AttnResOne b bc qVa qCnt
247ret false
248end
249end
250else
251for b ulong 8
252if not ikDBatchCopy2304 add B8_AROUT mul b 0x7000 add B8_H mul b 9216
253ret false
254end
255end
256end
257if not hasMsgs
258for b ulong 8
259arBase = add B8_AROUT mul b 0x7000
260if not ikDBatchCopy2304 add B8_H mul b 9216 arBase
261ret false
262end
263if isFull
264if not ikDBatchCopy2304 add B8_HK mul b 9216 add arBase 9216
265ret false
266end
267if not ikDBatchCopy2304 add B8_HV mul b 9216 add arBase 18432
268ret false
269end
270else
271if not ikDBatchCopy2304 add B8_HK mul b 9216 arBase
272ret false
273end
274if not ikDBatchCopy2304 add B8_HV mul b 9216 arBase
275ret false
276end
277end
278end
279else
280if not ikB8MsgGate l 0 B8_AROUT 0x7000 0 B8_H
281ret false
282end
283if isFull
284if not ikB8MsgGate l 1 add B8_AROUT 9216 0x7000 9216 B8_HK
285ret false
286end
287if not ikB8MsgGate l 2 add B8_AROUT 18432 0x7000 18432 B8_HV
288ret false
289end
290else
291if not ikB8MsgGate l 1 B8_AROUT 0x7000 9216 B8_HK
292ret false
293end
294if not ikB8MsgGate l 2 B8_AROUT 0x7000 18432 B8_HV
295ret false
296end
297end
298end
299ret true
300end
301
302fn ikB8AttnKvSconv step ulong l ulong isFull bool to bool
303scBase = ikDScBaseStep step
304if isFull
305if not ikB8Bf16 ikLva l 12 B8_HK B8_KSCP 2304 32
306ret false
307end
308if not ikB8Bf16 ikLva l 13 B8_HV B8_VSCP 2304 32
309ret false
310end
311for b ulong 8
312kOff = add B8_K mul b 4096
313vOff = add B8_V mul b 4096
314ikDArgReset
315ikDPtr ikDW kOff
316ikDPtr ikDW scBase
317ikDPtr ikLva l 10
318ikDPtr ikDW add B8_KSCP mul b 128
319ikDPtr ikDW kOff
320ikDArgU 1024
321ikDArgU 7
322if not ikDBatchAdd 18 8 1 1 128
323ret false
324end
325ikDPtr ikDW vOff
326ikDPtr ikDW add scBase 12288
327ikDPtr ikLva l 11
328ikDPtr ikDW add B8_VSCP mul b 128
329ikDPtr ikDW vOff
330ikDArgU 1024
331ikDArgU 7
332if not ikDBatchAdd 18 8 1 1 128
333ret false
334end
335end
336else
337for b ulong 8
338kOff = add B8_K mul b 4096
339vOff = add B8_V mul b 4096
340ikDArgReset
341ikDPtr ikDW kOff
342ikDPtr ikDW scBase
343ikDPtr ikLva l 10
344ikDPtr ikDW kOff
345ikDArgU 1024
346if not ikDBatchAdd 11 8 1 1 128
347ret false
348end
349ikDPtr ikDW vOff
350ikDPtr ikDW add scBase 12288
351ikDPtr ikLva l 11
352ikDPtr ikDW vOff
353ikDArgU 1024
354if not ikDBatchAdd 11 8 1 1 128
355ret false
356end
357end
358end
359ret true
360end
361
362fn ikB8AttnCausalOne step ulong l ulong isFull bool b ulong posQ ulong to bool
363dMaxRel = add posQ 1
364if gt dMaxRel 1024
365dMaxRel = ulong 1024
366end
367relTiles = div add dMaxRel 127 128
368ikDArgReset
369ikDPtr ikDW add B8_RLAT mul b 1536
370ikDPtr ikLva l 7
371ikDPtr ikDW 0x020000
372ikDArgU uint dMaxRel
373if not ikDBatchAdd 22 uint relTiles 24 1 128
374ret false
375end
376kva = ikDKvVaStep step
377ikDPtr ikDW add B8_K mul b 4096
378ikDPtr ikDW add B8_V mul b 4096
379ikDPtr kva
380ikDPtr add kva IK_KV_HALF_BYTES
381ikDArgU uint IK_TMAX
382ikDArgU uint posQ
383if not ikDBatchAdd 24 8 1 1 64
384ret false
385end
386splitS = uint 1
387if ge posQ 64
388splitS = uint 4
389end
390if ge posQ 512
391splitS = uint 8
392end
393ikDPtr ikDW add B8_Q mul b 12288
394ikDPtr kva
395ikDPtr add kva IK_KV_HALF_BYTES
396ikDPtr ikDW 0x020000
397ikDPtr ikDW 0x1e2000
398ikDPtr ikDW 0x1e4000
399ikDArgU 24
400ikDArgU 8
401ikDArgU uint IK_TMAX
402ikDArgU 1024
403ikDArgU uint posQ
404if isFull
405ikDArgU 0
406else
407ikDArgU 1024
408end
409ikDArgU splitS
410if not ikDBatchAdd 13 24 splitS 1 256
411ret false
412end
413ikDPtr ikDW 0x1e2000
414ikDPtr ikDW 0x1e4000
415ikDPtr ikDW add B8_SINK mul b 96
416ikDPtr ikDW add B8_GATE mul b 12288
417ikDPtr ikDW add B8_AOUT mul b 12288
418ikDArgU 24
419ikDArgU splitS
420ret ikDBatchAdd 14 24 1 1 32
421end
422
423fn ikB8RunLayerAttn step ulong l ulong startPosQ ulong hasMsgs bool to bool
424isFull = or or eq l 5 eq l 11 or eq l 17 eq l 23
425if not ikB8PrepAttnIn l isFull hasMsgs
426ret false
427end
428ikDArgReset
429ikDPtr ikDW B8_H
430ikDPtr ikLva l 16
431ikDPtr ikDW B8_HNORM
432ikDArgU 2304
433if not ikDBatchAdd 5 8 1 1 256
434ret false
435end
436ikDPtr ikDW B8_HK
437if isFull
438ikDPtr ikLva l 17
439else
440ikDPtr ikLva l 16
441end
442ikDPtr ikDW B8_HK
443ikDArgU 2304
444if not ikDBatchAdd 5 8 1 1 256
445ret false
446end
447ikDPtr ikDW B8_HV
448if isFull
449ikDPtr ikLva l 18
450else
451ikDPtr ikLva l 16
452end
453ikDPtr ikDW B8_HV
454ikDArgU 2304
455if not ikDBatchAdd 5 8 1 1 256
456ret false
457end
458if not ikB8Bf16 ikLva l 0 B8_HNORM B8_Q 2304 3072
459ret false
460end
461if not ikB8Bf16 ikLva l 1 B8_HK B8_K 2304 1024
462ret false
463end
464if not ikB8Bf16 ikLva l 2 B8_HV B8_V 2304 1024
465ret false
466end
467if not ikB8Bf16 ikLva l 3 B8_HNORM B8_RLAT 2304 384
468ret false
469end
470if not ikB8Bf16 ikLva l 5 B8_HNORM B8_GATE 2304 3072
471ret false
472end
473if not ikB8Bf16 ikLva l 6 B8_HNORM B8_SINK 2304 24
474ret false
475end
476if not ikB8AttnKvSconv step l isFull
477ret false
478end
479ikDArgReset
480ikDPtr ikDW B8_Q
481ikDPtr ikLva l 8
482ikDPtr ikDW 0x1e0000
483ikDPtr ikDW B8_Q
484ikDArgU 24
485ikDArgU 128
486ikDArgU ikDF32Bits 22.627417f32
487if isFull
488ikDArgU 3
489else
490ikDArgU 1
491end
492if not ikDBatchAdd 7 24 8 1 32
493ret false
494end
495ikDPtr ikDW B8_K
496ikDPtr 0
497ikDPtr 0
498ikDPtr ikDW B8_K
499ikDArgU 8
500ikDArgU 128
501ikDArgU ikDF32Bits 22.627417f32
502ikDArgU 0
503if not ikDBatchAdd 7 8 8 1 32
504ret false
505end
506ikDPtr ikDW B8_V
507ikDPtr 0
508ikDPtr ikDW B8_V
509ikDArgU 128
510if not ikDBatchAdd 5 64 1 1 256
511ret false
512end
513ikDPtr ikDW B8_RLAT
514ikDPtr ikLva l 9
515ikDPtr ikDW 0x1e0000
516ikDPtr ikDW B8_RLAT
517ikDArgU 24
518ikDArgU 16
519ikDArgU ikDF32Bits 8.0f32
520if isFull
521ikDArgU 3
522else
523ikDArgU 1
524end
525if not ikDBatchAdd 7 24 8 1 32
526ret false
527end
528for b ulong 8
529if not ikB8AttnCausalOne step l isFull b add startPosQ b
530ret false
531end
532end
533if not ikB8Bf16 ikLva l 4 B8_AOUT B8_OPROJ 3072 2304
534ret false
535end
536scBase = ikDScBaseStep step
537for b ulong 8
538ikDArgReset
539ikDPtr ikDW add B8_OPROJ mul b 9216
540ikDPtr ikDW add scBase 24576
541ikDPtr ikLva l 14
542ikDPtr ikDW add B8_OSCONV mul b 9216
543ikDArgU 2304
544if not ikDBatchAdd 11 18 1 1 128
545ret false
546end
547end
548ret true
549end
550
551fn ikB8UploadMeta l ulong to ulong
552wk = get ikDWork 0
553r = mapread wk B8_RIDS ikDOutBuf 0 256
554ids = new uint 64 0
555for i ulong 64
556o = mul i 4
557b0 = uint get ikDOutBuf o
558b1 = shl uint get ikDOutBuf add o 1 8
559b2 = shl uint get ikDOutBuf add o 2 16
560b3 = shl uint get ikDOutBuf add o 3 24
561put ids i or or b0 b1 or b2 b3
562end
563u = msDedupExperts ids 8
564for i ulong 64
565ikB8PutU32Meta mul i 4 get msUniqEids i
566ikB8PutU32Meta add 256 mul i 4 get msUniqCnt i
567end
568for i ulong 512
569ikB8PutU32Meta add 512 mul i 4 get msSlotMap i
570end
571if lt l 20
572ikDReadArenaChunk ikLva l 24 512
573for i ulong 512
574put ikB8MetaBuf add 2560 i get ikDOutBuf i
575end
576rw1 = mapwrite wk B8_META13 ikB8MetaBuf 0 3072
577ikDReadArenaChunk ikLva l 27 512
578for i ulong 512
579put ikB8MetaBuf add 2560 i get ikDOutBuf i
580end
581rw2 = mapwrite wk B8_META2 ikB8MetaBuf 0 3072
582else
583rw3 = mapwrite wk B8_META13 ikB8MetaBuf 0 2560
584end
585ret u
586end
587
588fn ikB8RecordArb step ulong to void
589wk = get ikDWork 0
590r = mapread wk B8_RIDS ikDOutBuf 0 256
591for b ulong 8
592dstBase = add mul mul b 48 8 mul step 8
593for k ulong 8
594o = mul add mul b 8 k 4
595b0 = uint get ikDOutBuf o
596b1 = shl uint get ikDOutBuf add o 1 8
597b2 = shl uint get ikDOutBuf add o 2 16
598b3 = shl uint get ikDOutBuf add o 3 24
599put ikB8ArbIds add dstBase k or or b0 b1 or b2 b3
600end
601end
602end
603
604fn ikB8MlpAttnResOne b ulong bc2 ulong mqVa ulong to bool
605blk = add B8_BLOCKS mul b 0x18000
606hr = add B8_HRES mul b 9216
607mi = add B8_MLPIN mul b 9216
608ret ikDBatchAttnRes blk bc2 hr mqVa 1 mi
609end
610
611fn ikB8RunLayerMlpPre step ulong l ulong hasMsgs bool to bool
612isBoundary = eq rem l 6 0
613if isBoundary
614bc = get ikDBlockCnt 0
615for b ulong 8
616dstB = add add B8_BLOCKS mul b 0x18000 mul bc 9216
617srcB = add B8_HRES mul b 9216
618if not ikDBatchCopy2304 dstB srcB
619ret false
620end
621end
622put ikDBlockCnt 0 add bc 1
623if not ikB8Copy8 B8_HRES B8_OSCONV
624ret false
625end
626else
627if not ikB8Add8 B8_HRES B8_HRES B8_OSCONV
628ret false
629end
630end
631mqVa = get ikMlpQOff l
632bc2 = get ikDBlockCnt 0
633for b ulong 8
634if not ikB8MlpAttnResOne b bc2 mqVa
635ret false
636end
637end
638if hasMsgs
639if not ikB8MsgGate l 3 B8_MLPIN 9216 27648 B8_MLPIN
640ret false
641end
642end
643ikDArgReset
644ikDPtr ikDW B8_MLPIN
645ikDPtr ikLva l 19
646ikDPtr ikDW B8_MLPNORM
647ikDArgU 2304
648if not ikDBatchAdd 5 8 1 1 256
649ret false
650end
651if not ikB8Bf16 ikLva l 20 B8_MLPNORM B8_RLOGITS 2304 128
652ret false
653end
654for b ulong 8
655ikDArgReset
656ikDPtr ikDW add B8_RLOGITS mul b 512
657ikDPtr ikLva l 21
658ikDPtr ikDW add B8_RIDS mul b 32
659ikDPtr ikDW add B8_RWTS mul b 32
660if not ikDBatchAdd 12 1 1 1 32
661ret false
662end
663end
664lutva = mapaddr get ikDKLut 0
665ikDArgReset
666if lt l 20
667ikDPtr ikDW B8_MLPNORM
668ikDPtr lutva
669ikDPtr ikDW 0x059000
670ikDPtr ikDW B8_QSCR
671ikDPtr ikDW add B8_QSCR 0x18000
672ikDPtr ikDW B8_XQ
673ikDArgU 1152
674if not ikDBatchAdd 8 9 1 1 128
675ret false
676end
677else
678ikDPtr ikDW B8_MLPNORM
679ikDPtr lutva
680ikDPtr ikDW B8_QSCR
681ikDPtr ikDW add B8_QSCR 0x18000
682ikDPtr ikDW B8_XQ
683ikDArgU 576
684if not ikDBatchAdd 9 5 1 1 128
685ret false
686end
687end
688ikDPtr ikDW B8_XQ
689ikDPtr ikDW B8_XREC
690ikDArgU 2304
691if not ikDBatchAdd 25 18 8 1 128
692ret false
693end
694ret ikDBatchRun
695end
696
697fn ikB8RunLayerMlpPost step ulong l ulong u ulong to bool
698if not ikDBatchStart
699ret false
700end
701lutva = mapaddr get ikDKLut 0
702ikDArgReset
703if lt l 20
704ikDPtr ikDW B8_XREC
705ikDPtr ikLva l 22
706ikDPtr ikLva l 23
707ikDPtr ikDW B8_META13
708ikDPtr lutva
709ikDPtr ikDW B8_C13
710ikDArgU 2304
711ikDArgU 2304
712if not ikDBatchAdd 27 288 uint u 1 256
713ret false
714end
715ikDPtr ikDW B8_C13
716ikDPtr ikDW B8_RWTS
717ikDPtr lutva
718ikDPtr ikDW 0x059000
719ikDPtr ikDW B8_QSCR
720ikDPtr ikDW add B8_QSCR 0x18000
721ikDPtr ikDW B8_SWI
722ikDArgU 1152
723if not ikDBatchAdd 17 1 64 1 128
724ret false
725end
726ikDPtr ikDW B8_SWI
727ikDPtr ikLva l 25
728ikDPtr ikLva l 26
729ikDPtr ikDW B8_META2
730ikDPtr lutva
731ikDPtr ikDW B8_C2
732ikDArgU 1152
733ikDArgU 2304
734if not ikDBatchAdd 27 288 uint u 1 256
735ret false
736end
737else
738ikDPtr ikDW B8_XREC
739ikDPtr ikLva l 22
740ikDPtr ikLva l 23
741ikDPtr ikDW B8_META13
742ikDPtr lutva
743ikDPtr ikDW B8_C13
744ikDArgU 2304
745ikDArgU 2304
746if not ikDBatchAdd 28 288 uint u 1 256
747ret false
748end
749ikDPtr ikDW B8_C13
750ikDPtr ikDW B8_RWTS
751ikDPtr ikDW B8_SWI
752ikDPtr 0
753ikDArgU 1152
754if not ikDBatchAdd 10 9 64 1 128
755ret false
756end
757ikDPtr ikDW B8_SWI
758ikDPtr lutva
759ikDPtr ikDW B8_QSCR
760ikDPtr ikDW add B8_QSCR 0x18000
761ikDPtr ikDW B8_XREC
762ikDArgU 2304
763if not ikDBatchAdd 9 18 1 1 128
764ret false
765end
766ikDPtr ikDW B8_XREC
767ikDPtr ikLva l 25
768ikDPtr ikLva l 26
769ikDPtr ikDW B8_META13
770ikDPtr lutva
771ikDPtr ikDW B8_C2
772ikDArgU 1152
773ikDArgU 2304
774if not ikDBatchAdd 28 288 uint u 1 256
775ret false
776end
777end
778scBase = ikDScBaseStep step
779for b ulong 8
780ikDArgReset
781ikDPtr ikDW add B8_C2 mul b 73728
782ikDPtr ikDW add scBase 52224
783ikDPtr ikLva l 15
784ikDPtr ikDW add B8_MLPOUT mul b 9216
785ikDArgU 2304
786if not ikDBatchAdd 15 18 1 1 128
787ret false
788end
789end
790ret ikB8Add8 B8_H B8_HRES B8_MLPOUT
791end
792
793fn ikB8RunLayer step ulong l ulong startPosQ ulong hasMsgs bool to bool
794if not ikB8RunLayerAttn step l startPosQ hasMsgs
795ret false
796end
797if not ikB8RunLayerMlpPre step l hasMsgs
798ret false
799end
800ikB8RecordArb step
801u = ikB8UploadMeta l
802ret ikB8RunLayerMlpPost step l u
803end
804
805fn ikB8ArbFlushOne b ulong to void
806ikArbResetToken
807put ikDArbHasPred 0 0
808tokBase = mul mul b 48 8
809for s ulong 48
810for k ulong 8
811id = get ikB8ArbIds add tokBase add mul s 8 k
812o = add mul s 32 mul k 4
813put ikDOutBuf o uchar and id 255
814put ikDOutBuf add o 1 uchar and shr id 8 255
815put ikDOutBuf add o 2 uchar and shr id 16 255
816put ikDOutBuf add o 3 uchar and shr id 24 255
817end
818end
819for l ulong 6
820ikDArbStepBuf l l
821end
822for j ulong 12
823ikDArbStepBuf add 6 j add 6 j
824end
825for pass ulong 2
826for j ulong 12
827ikDArbStepBuf add add 18 mul pass 12 j add 6 j
828end
829end
830for j ulong 6
831ikDArbStepBuf add 42 j add 18 j
832end
833end
834
835fn ikB8SavePreLoop to bool
836if not ikB8Copy8 B8_PREH B8_H
837ret false
838end
839bc = get ikDBlockCnt 0
840for b ulong 8
841if not ikDBatchCopyBlocks add B8_PREBLK mul b 0x9000 add B8_BLOCKS mul b 0x18000 bc
842ret false
843end
844end
845put ikDPreBlockCnt 0 bc
846ret true
847end
848
849fn ikB8StartLoopPass to bool
850preN = get ikDPreBlockCnt 0
851curN = get ikDBlockCnt 0
852nPrev = sub curN add preN 1
853for b ulong 8
854srcB = add add B8_BLOCKS mul b 0x18000 mul add preN 1 9216
855dstP = add B8_PREVBLK mul b 0x9000
856if not ikDBatchCopyBlocks dstP srcB nPrev
857ret false
858end
859if not ikDBatchCopy2304 add dstP mul nPrev 9216 add B8_H mul b 9216
860ret false
861end
862end
863put ikDPrevBlockCnt 0 add nPrev 1
864if not ikB8Copy8 B8_H B8_PREH
865ret false
866end
867for b ulong 8
868if not ikDBatchCopyBlocks add B8_BLOCKS mul b 0x18000 add B8_PREBLK mul b 0x9000 preN
869ret false
870end
871end
872put ikDBlockCnt 0 preN
873ret true
874end
875
876note Prefill 8 prompt tokens (loaded in global ikB8Toks[0..7]) starting at startPosQ in slot.
877fn ikDPrefillBatch8 slot ulong startPosQ ulong to bool
878put ikDSlot 0 slot
879for b ulong 8
880ikB8EmbedOne b ulong get ikB8Toks b
881end
882put ikDBlockCnt 0 0
883if not ikDBatchStart
884ret false
885end
886for l ulong 6
887if not ikB8RunLayer l l startPosQ false
888ret false
889end
890end
891if not ikB8SavePreLoop
892ret false
893end
894for j ulong 12
895l = add 6 j
896if not ikB8RunLayer l l startPosQ false
897ret false
898end
899end
900for pass ulong 2
901if not ikB8StartLoopPass
902ret false
903end
904for j ulong 12
905step = add add 18 mul pass 12 j
906l = add 6 j
907if not ikB8CrossPassMsgs j
908ret false
909end
910if not ikB8RunLayer step l startPosQ true
911ret false
912end
913end
914end
915for j ulong 6
916step = add 42 j
917l = add 18 j
918if not ikB8RunLayer step l startPosQ false
919ret false
920end
921end
922if not ikDBatchRun
923ret false
924end
925for b ulong 8
926ikB8ArbFlushOne b
927end
928ret true
929end