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 / engine / arboris_q4.om

239 lines · 4847 bytes Raw Blame History
1note SPDX-License-Identifier: AGPL-3.0-only
2note om/gpu/engine/arboris_q4.om: Live Arboris Online Adaptive Sum-Over-Paths Expert Prefetcher
3note for Qwen 3.8 Flash Next (48 layers, 512 experts/layer, top-10 routed experts per token).
4note 47 cross-layer transitions (L -> L+1) x 512 source experts x 16 Space-Saving slots
5note packed as (count << 16) | target_eid = 385,024 uints (~1.47 MiB static table).
6note Overlapped asynchronously with lm_head on the Full-APU path (zero critical-path latency).
7
8const Q4A_LAYERS ulong 48
9const Q4A_TRANS ulong 47
10const Q4A_NEXP ulong 512
11const Q4A_TOPK ulong 10
12const Q4A_EDGES ulong 385024
13const Q4A_TOP1 ulong 24064
14
15global q4ArbEdges uint 385024
16global q4ArbTop1 uint 24064
17global q4ArbScores ulong 512
18global q4ArbTouch ulong 256
19global q4ArbTrace uint 480
20global q4ArbTraceBytes uchar 2048
21global q4ArbPred uint 10
22global q4ArbHits ulong 1
23global q4ArbTotal ulong 1
24
25fn q4ArbResetAll to void
26for i ulong Q4A_EDGES
27put q4ArbEdges i 0
28end
29for i ulong Q4A_TOP1
30put q4ArbTop1 i 0xffffffff
31end
32put q4ArbHits 0 0
33put q4ArbTotal 0 0
34end
35
36fn q4ArbPack cnt ulong tgt ulong to uint
37ret or shl uint cnt 16 uint tgt
38end
39
40fn q4ArbHalve base ulong to void
41for h ulong 16
42hw = get q4ArbEdges add base h
43if ne hw 0
44hc = shr ulong shr hw 16 1
45if eq hc 0
46hc = ulong 1
47end
48put q4ArbEdges add base h q4ArbPack hc ulong and hw 65535
49end
50end
51end
52
53fn q4ArbUpdateEdge trans ulong src ulong tgt ulong to void
54base = mul add mul trans Q4A_NEXP src 16
55minIdx = ulong 0
56minCnt = ulong 65536
57for s ulong 16
58w = get q4ArbEdges add base s
59if eq w 0
60put q4ArbEdges add base s q4ArbPack 1 tgt
61ret
62end
63e = ulong and w 65535
64c = ulong shr w 16
65if eq e tgt
66c = add c 1
67if gt c 65000
68q4ArbHalve base
69c = shr c 1
70end
71put q4ArbEdges add base s q4ArbPack c tgt
72ret
73end
74if lt c minCnt
75minCnt = c
76minIdx = s
77end
78end
79if gt minCnt 1
80put q4ArbEdges add base minIdx q4ArbPack sub minCnt 1 ulong and get q4ArbEdges add base minIdx 65535
81else
82put q4ArbEdges add base minIdx q4ArbPack 1 tgt
83end
84end
85
86fn q4ArbRefreshTop1 trans ulong src ulong to void
87row = add mul trans Q4A_NEXP src
88base = mul row 16
89bestCnt = ulong 0
90bestTgt = uint 0xffffffff
91for s ulong 16
92w = get q4ArbEdges add base s
93if ne w 0
94c = ulong shr w 16
95if gt c bestCnt
96bestCnt = c
97bestTgt = and w 65535
98end
99end
100end
101put q4ArbTop1 row bestTgt
102end
103
104fn q4ArbAccumLayer trans ulong to ulong
105nTouch = ulong 0
106tBase = mul trans Q4A_TOPK
107for i ulong Q4A_TOPK
108src = ulong get q4ArbTrace add tBase i
109if lt src Q4A_NEXP
110base = mul add mul trans Q4A_NEXP src 16
111for s ulong 16
112w = get q4ArbEdges add base s
113if ne w 0
114tgt = ulong and w 65535
115cnt = ulong shr w 16
116if lt tgt Q4A_NEXP
117prev = get q4ArbScores tgt
118if and eq prev 0 lt nTouch 256
119put q4ArbTouch nTouch tgt
120nTouch = add nTouch 1
121end
122put q4ArbScores tgt add prev cnt
123end
124end
125end
126end
127end
128ret nTouch
129end
130
131fn q4ArbPickBest nTouch ulong to ulong
132best = ulong Q4A_NEXP
133bestSc = ulong 0
134for ti ulong nTouch bound 256
135e = get q4ArbTouch ti
136sc = get q4ArbScores e
137if gt sc bestSc
138bestSc = sc
139best = e
140end
141end
142ret best
143end
144
145fn q4ArbPredictLayer trans ulong to ulong
146nTouch = q4ArbAccumLayer trans
147if eq nTouch 0
148ret 0
149end
150picked = ulong 0
151for slot ulong Q4A_TOPK
152best = q4ArbPickBest nTouch
153if eq best Q4A_NEXP
154break
155end
156put q4ArbPred slot uint best
157put q4ArbScores best 0
158picked = add picked 1
159end
160for ti ulong nTouch bound 256
161put q4ArbScores get q4ArbTouch ti 0
162end
163ret picked
164end
165
166fn q4ArbScoreLayer nextL ulong np ulong to ulong
167hits = ulong 0
168nBase = mul nextL Q4A_TOPK
169for i ulong np bound 10
170p = get q4ArbPred i
171for j ulong Q4A_TOPK
172if eq p get q4ArbTrace add nBase j
173hits = add hits 1
174break
175end
176end
177end
178ret hits
179end
180
181fn q4ArbObservePair trans ulong to void
182sBase = mul trans Q4A_TOPK
183tBase = mul add trans 1 Q4A_TOPK
184for i ulong Q4A_TOPK
185src = ulong get q4ArbTrace add sBase i
186if lt src Q4A_NEXP
187for j ulong Q4A_TOPK
188tgt = ulong get q4ArbTrace add tBase j
189if lt tgt Q4A_NEXP
190q4ArbUpdateEdge trans src tgt
191end
192end
193q4ArbRefreshTop1 trans src
194end
195end
196end
197
198fn q4ArbUnpackTrace nL ulong to void
199nIds = mul nL Q4A_TOPK
200for i ulong nIds bound 480
201p = mul i 4
202b0 = uint get q4ArbTraceBytes p
203b1 = shl uint get q4ArbTraceBytes add p 1 8
204b2 = shl uint get q4ArbTraceBytes add p 2 16
205b3 = shl uint get q4ArbTraceBytes add p 3 24
206put q4ArbTrace i or or b0 b1 or b2 b3
207end
208end
209
210fn q4ArbProcessTrace shmMap long shmOff ulong to void
211nL = get engSpec MS_LAYERS
212if gt nL Q4A_LAYERS
213nL = ulong Q4A_LAYERS
214end
215nb = mul mul nL Q4A_TOPK 4
216r = mapread shmMap shmOff q4ArbTraceBytes 0 nb
217q4ArbUnpackTrace nL
218if le nL 1
219ret
220end
221nTr = sub nL 1
222for tr ulong nTr bound 47
223np = q4ArbPredictLayer tr
224if gt np 0
225h = q4ArbScoreLayer add tr 1 np
226put q4ArbHits 0 add get q4ArbHits 0 h
227put q4ArbTotal 0 add get q4ArbTotal 0 np
228end
229q4ArbObservePair tr
230end
231end
232
233fn q4ArbHitPctX10 to ulong
234tot = get q4ArbTotal 0
235if eq tot 0
236ret 0
237end
238ret div mul get q4ArbHits 0 1000 tot
239end