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/inkling2/arboris/prefetch.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 / inkling2 / arboris / prefetch.om` 233 lines ยท 6306 bytes Raw Blame History 1 note SPDX-License-Identifier: AGPL-3.0-only 2 note Arboris expert-prefetch adapter and online sum-over-paths co-activation 3 note predictor for Inkling-2-Mini (24 layers, 128 experts, top-8, looped passes). 4 note 5 note Static ABI: scores are the settled logical FP32 score plane in [0, 1]; 6 note a node maps to one expert in 0..127 or 0xffffffff (ignored). Duplicate 7 note mappings aggregate by maximum score. Zero scores never issue I/O. Lower 8 note expert ID breaks exact ties. Caller controls I/O budget via the number of 9 note 2-word OP3 records in outbuf (up to 128 records = 256 uints). -1 rejects 10 note invalid input. 11 note 12 note Online predictor: 24 transitions (0..22 for L->L+1, including 17 for 13 note L17->L18 exiting the looped core on pass 2; 23 for looped core pass wrap 14 note L17->L6 on passes 0/1, matching core_start=6, core_end=18, num_passes=3) 15 note x 128 source experts x 16 Space-Saving slots packed as 16 note (count << 16) | target_eid. 17 18 global ikArbEdges uint 49152 19 global ikArbPrev uint 8 20 global ikArbPrevLayer ulong 1 21 22 fn ik_ar_select_experts peak edit uint 128 outbuf edit uint * to long 23 for slot ulong div len outbuf 2 bound 128 24 best = ulong 0 25 for id ulong 128 26 if gt get peak id get peak best 27 best = id 28 end 29 end 30 if eq get peak best 0 31 ret long slot 32 end 33 put outbuf mul slot 2 3 34 put outbuf add 1 mul slot 2 uint best 35 put peak best 0 36 end 37 ret long div len outbuf 2 38 end 39 40 fn ik_ar_vote_expert peak edit uint 128 id uint score uint to bool 41 if gt score 0x3f800000 42 ret false 43 end 44 if ne id 0xffffffff 45 if ge id 128 46 ret false 47 end 48 if gt score get peak ulong id 49 put peak ulong id score 50 end 51 end 52 ret true 53 end 54 55 fn ik_arboris_expert_hints scores view uint * experts view uint * outbuf edit uint * to long 56 if or ne len scores len experts ne and len outbuf 1 0 57 ret long -1 58 end 59 if or gt len scores 0xffffffff gt len outbuf 256 60 ret long -1 61 end 62 peak = new uint 128 0 63 for i ulong len scores bound 0xffffffff 64 id = get experts i 65 score = get scores i 66 if not ik_ar_vote_expert peak id score 67 ret long -1 68 end 69 end 70 ret ik_ar_select_experts peak outbuf 71 end 72 73 note Send advisory OP3 records to the read-ring consumer. The demand router path 74 note retains authority over the actual experts executed for inference. 75 fn ik_arboris_send_hints fd int records view uint * count ulong to bool 76 if or gt count 128 gt count div len records 2 77 ret false 78 end 79 b = new uchar 8 0 80 for i ulong count bound 128 81 pos = mul i 2 82 if or ne get records pos 3 ge get records add pos 1 128 83 ret false 84 end 85 end 86 for i ulong count bound 128 87 expert = get records add 1 mul i 2 88 put b 0 3 89 put b 4 uchar and expert 255 90 put b 5 uchar shr expert 8 91 sent = ulong 0 92 while lt sent 8 bound 8 93 n = write fd b sent sub 8 sent 94 if le n 0 95 ret false 96 end 97 sent = add sent ulong n 98 end 99 end 100 ret true 101 end 102 103 fn ikArbResetToken to void 104 put ikArbPrevLayer 0 24 105 for k ulong 8 106 put ikArbPrev k 0xffffffff 107 end 108 end 109 110 fn ikArbResetAll to void 111 for i ulong 49152 112 put ikArbEdges i 0 113 end 114 ikArbResetToken 115 end 116 117 fn ikArbPack cnt ulong tgt ulong to uint 118 ret ao_pack cnt tgt 119 end 120 121 fn ikArbHalveRow rowBase ulong to void 122 row = new uint 16 0 123 for h ulong 16 124 put row h get ikArbEdges add rowBase h 125 end 126 ao_halve_row_span row 0 16 127 for h ulong 16 128 put ikArbEdges add rowBase h get row h 129 end 130 end 131 132 fn ikArbBumpEdge trans ulong src ulong tgt ulong to void 133 if or ge trans 24 or ge src 128 ge tgt 128 134 ret 135 end 136 row = new uint 16 0 137 rowBase = mul add mul trans 128 src 16 138 for j ulong 16 139 put row j get ikArbEdges add rowBase j 140 end 141 ao_bump_row row 0 16 tgt 142 for j ulong 16 143 put ikArbEdges add rowBase j get row j 144 end 145 end 146 147 note Update online co-activation graph on observing layer's top-8 experts. 148 note Only learns genuine adjacent transitions: prevLayer == layer - 1 for layer 149 note in 1..23 (transitions 0..22, including 17 for L17 -> L18 on pass 2), or 150 note prevLayer == 17 when layer == 6 (transition 23 for looped core pass wrap 151 note L17 -> L6 on passes 0 and 1, matching core_start=6, core_end=18, num_passes=3). 152 note Non-adjacent or repeated-layer calls update prev without corrupting edges. 153 fn ikArbUpdate layer ulong curIds view uint 8 to void 154 if ge layer 24 155 ret 156 end 157 prevL = get ikArbPrevLayer 0 158 trans = ao_resolve_step 24 17 6 prevL layer 159 if lt trans 24 160 for s ulong 8 161 src = ulong get ikArbPrev s 162 if lt src 128 163 for d ulong 8 164 tgt = ulong get curIds d 165 if lt tgt 128 166 ikArbBumpEdge trans src tgt 167 end 168 end 169 end 170 end 171 end 172 for k ulong 8 173 put ikArbPrev k get curIds k 174 end 175 put ikArbPrevLayer 0 layer 176 end 177 178 fn ikArbInitCfg cfg edit ulong 6 to void 179 put cfg 0 24 180 put cfg 1 128 181 put cfg 2 8 182 put cfg 3 16 183 put cfg 4 17 184 put cfg 5 6 185 end 186 187 note Sum-over-paths scoring for transition `trans` (0..22 for L -> L+1, including 188 note 17 for L17 -> L18 on final loop pass 2; 23 for looped core wrap L17 -> L6 on 189 note loop passes 0 and 1). 190 fn ikArbScoreNext trans ulong curIds view uint 8 scores edit ulong 128 to void 191 cfg = new ulong 6 0 192 row = new uint 16 0 193 meta = new ulong 4 0 194 ikArbInitCfg cfg 195 if not ao_scores_zero cfg scores 196 ret 197 end 198 if ge trans 24 199 ret 200 end 201 put meta 0 0 202 put meta 1 16 203 put meta 2 128 204 put meta 3 1 205 for s ulong 8 206 src = ulong get curIds s 207 if lt src 128 208 rowBase = mul add mul trans 128 src 16 209 for j ulong 16 210 put row j get ikArbEdges add rowBase j 211 end 212 ao_score_add row meta scores 213 end 214 end 215 end 216 217 note Pick up to len(outbuf)/2 highest-scoring non-resident experts for nextLayer (0..23). 218 note resident[nextLayer * 128 + eid] >= 0 marks an already-resident expert to skip. 219 note Emits 2-word OP3 records [3, eid] into outbuf and zeros consumed scores. 220 fn ikArbPickTopK nextLayer ulong scores edit ulong 128 resident view long 3072 outbuf edit uint * to long 221 cfg = new ulong 6 0 222 if or ge nextLayer 24 ne and len outbuf 1 0 223 ret long -1 224 end 225 if gt len outbuf 256 226 ret long -1 227 end 228 ikArbInitCfg cfg 229 if ne ao_mask_resident cfg nextLayer resident scores 0 230 ret long -1 231 end 232 ret ao_pick_op3 cfg scores outbuf 233 end