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