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/dsv41/decoder/check-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 / dsv41 / decoder / check-arboris-prefetch.om` 364 lines ยท 8318 bytes Raw Blame History 1 note SPDX-License-Identifier: AGPL-3.0-only 2 note Pure OM-2 CPU host gate for the dsv41-decode prefetch pipeline (no GPU is opened). 3 note Compose in place of decode-cli.om. usage: check-arboris-prefetch SIDECAR SHARD BAD_SIDECAR 4 note SIDECAR and SHARD are the layer-3 sidecar and its checkpoint shard; BAD_SIDECAR is a copy of 5 note SIDECAR whose expert 9 digest has one byte changed. Exit 0 passes; every other exit names one check. 6 note 1. Staging slot choice: free first, else the longest-waiting verified slot, never one in flight 7 note 2. Look-ahead bookkeeping: depth counts, launch counts, guess scoring, guess reading 8 note 3. Off arm: no prefetch workers, no staging memory, no dispatch, no request to any worker 9 note 4. On arm: guesses are staged by workers, an unrelated gate never waits for them, a needed one is 10 note published byte-exact from staging without polluting the slot table, and a payload that fails 11 note its digest is never used 12 const apLayer ulong 3 13 14 fn apOpen arg ulong to int 15 path = new uchar 4096 0 16 n = argread arg path 0 4096 17 if le n 0 18 ret -1 19 end 20 ret int fopen path 0 ulong n 524288 0 21 end 22 23 fn apKey eid ulong to ulong 24 ret add mul apLayer 384 eid 25 end 26 27 fn apSetGate a uint b uint c uint d uint e uint g uint to void 28 put dfCurIds 0 a 29 put dfCurIds 1 b 30 put dfCurIds 2 c 31 put dfCurIds 3 d 32 put dfCurIds 4 e 33 put dfCurIds 5 g 34 end 35 36 fn apUnitSlots to int 37 for s ulong dfPfSlots 38 put dfPfSlotKey s long add 1000 s 39 put dfPfSlotState s 2 40 put dfPfSlotSeq s add 100 s 41 put dfPfOfKey add 1000 s uchar add s 1 42 end 43 put dfPfSlotSeq 17 5 44 put dfPfStat 0 0 45 if ne dfPfPickSlot 17 46 ret 61 47 end 48 if or ne get dfPfOfKey 1017 0 ne get dfPfSlotState 17 0 49 ret 62 50 end 51 if ne get dfPfStat 0 1 52 ret 63 53 end 54 if ne dfPfPickSlot 17 55 ret 65 56 end 57 if ne get dfPfStat 0 1 58 ret 66 59 end 60 for s ulong dfPfSlots 61 put dfPfSlotState s 1 62 end 63 if ne dfPfPickSlot -1 64 ret 67 65 end 66 ret 0 67 end 68 69 fn apUnitDepths to int 70 put dfArbPfMeta 4 0 71 if or ne dfSpecDepths 0 0 ne dfSpecRecords 0 0 72 ret 71 73 end 74 put dfArbPfMeta 4 1 75 if or ne dfSpecDepths 0 dfSpecN ne dfSpecRecords 0 add 2 mul 2 dfSpecN 76 ret 72 77 end 78 last = sub 39 dfSpecDepthAt 0 79 if or ne dfSpecDepths last 1 ne dfSpecDepths add last 1 0 80 ret 73 81 end 82 put dfArbPfMeta 4 0 83 ret 0 84 end 85 86 fn apUnitScore to int 87 d0 = dfSpecDepthAt 0 88 layer = add d0 3 89 for i ulong 6 90 put dfSpecStat i 0 91 end 92 for j ulong 6 93 put dfSpecHist add mul layer 6 j uint add j 1 94 end 95 apSetGate 1 2 9 10 11 12 96 dfSpecScore layer 97 if or ne get dfSpecStat 0 6 ne get dfSpecStat 1 2 98 ret 75 99 end 100 dfSpecScore sub d0 1 101 if or ne get dfSpecStat 0 6 ne get dfSpecStat 1 2 102 ret 76 103 end 104 ret 0 105 end 106 107 fn apUnitRead to int 108 raw = new uchar 24 0 109 io = mapnew -1 0 ioTotalBytes 3 33 110 if le io 0 111 ret 70 112 end 113 put dwMaps 4 io 114 diPut raw 0 4 5 115 diPut raw 4 4 6 116 diPut raw 8 4 7 117 diPut raw 12 4 400 118 diPut raw 16 4 9 119 diPut raw 20 4 10 120 if ne mapwrite io ioSpecIds raw 0 24 24 121 ret 70 122 end 123 put dfArbPfMeta 4 1 124 ok = dfSpecRead 4 125 put dfArbPfMeta 4 0 126 u1 = mapdrop io 127 put dwMaps 4 0 128 if not ok 129 ret 77 130 end 131 if or ne get dfSpecIds 0 5 ne get dfSpecIds 3 0xffffffff 132 ret 78 133 end 134 base = mul add 4 dfSpecDepthAt 0 6 135 if or ne get dfSpecHist add base 2 7 ne get dfSpecHist add base 3 0xffffffff 136 ret 79 137 end 138 ret 0 139 end 140 141 note Off arm (DSV41_ARBORIS_PREFETCH=0). Each exit has a mutant in check-prefetch-mutants.sh that only 142 note it rejects: 43 (H, a setting above 1 accepted), 40 (E, start ignores its argument), 38 (A, prefetch 143 note workers started and the dispatch switch removed), 41 (P, prefetch workers started with prefetch off). 144 fn apCheckOffArm to int 145 if dfStartWorkers 2 146 dfStopWorkers 147 ret 43 148 end 149 if not dfStartWorkers 0 150 ret 31 151 end 152 if ne get dfArbPfMeta 4 0 153 dfStopWorkers 154 ret 40 155 end 156 for j ulong 6 157 put dfSpecIds j uint add j 1 158 end 159 dfArbDispatchPrefetch sub apLayer dfSpecDepthAt 0 160 if or ne get dfArbPfMeta 0 0 ne get dfArbPfMeta 3 0 161 dfStopWorkers 162 ret 38 163 end 164 if or ne get dfPfActive 0 0 gt get dfPfStage 0 0 165 dfStopWorkers 166 ret 41 167 end 168 dfStopWorkers 169 ret 0 170 end 171 172 note The slab bytes of a published expert must hash to the digest in its sidecar descriptor. 173 fn apSlotDigestOk sidecar int eid ulong to bool 174 ctx = new uchar 104 0 175 digest = new uchar 32 0 176 desc = new uchar 64 0 177 buf = new uchar `1048576` 0 178 slot = get dfSlotOf apKey eid 179 if lt slot 0 180 ret false 181 end 182 if not diRead sidecar desc mul eid 64 64 183 ret false 184 end 185 phys = get dfPhysical ulong slot 186 m = get dwSlabMaps div phys 800 187 off = mul rem phys 800 deBytes 188 sha256_init ctx 189 pos = ulong 0 190 while lt pos deBytes 191 n = sub deBytes pos 192 if gt n len buf 193 n = len buf 194 end 195 if ne mapread m add off pos buf 0 n long n 196 ret false 197 end 198 sha256_update ctx part buf 0 n 199 pos = add pos n 200 end 201 sha256_final ctx digest 202 for i ulong 8 203 if ne get digest i get desc add 8 i 204 ret false 205 end 206 end 207 ret true 208 end 209 210 note Guesses 1..6 for apLayer are dispatched once, and a gate that needs none of them neither waits for 211 note them nor collects their replies. 212 fn apOnDispatch to int 213 if or ne get dfPfActive 0 6 le get dfPfStage 0 0 214 ret 44 215 end 216 for j ulong 18 217 put dfSpecIds j 0xffffffff 218 end 219 for j ulong 6 220 put dfSpecIds j uint add j 1 221 end 222 src = sub apLayer dfSpecDepthAt 0 223 dfArbDispatchPrefetch src 224 if or ne get dfArbPfMeta 3 6 ne get dfArbPfMeta 0 6 225 ret 32 226 end 227 if or lt dfPfLookup apKey 1 0 lt dfPfLookup apKey 6 0 228 ret 33 229 end 230 apSetGate 11 12 13 14 15 16 231 if ne dfResolveGate apLayer 1 232 ret 45 233 end 234 if or ne get dfArbPfMeta 1 0 ne get dfArbPfMeta 0 6 235 ret 46 236 end 237 if or ne get dfStats 1 6 ne get dfArbPfMeta 2 0 238 ret 47 239 end 240 ret 0 241 end 242 243 note A gate that needs guess 1 gets it from staging: byte-exact, counted as used, staging slot freed, 244 note and the unused guess 2 stays out of the slot table. 245 fn apOnUse sidecar int to int 246 apSetGate 1 21 22 23 24 25 247 if ne dfResolveGate apLayer 1 248 ret 34 249 end 250 if or ne get dfArbPfMeta 2 1 ne get dfStats 1 11 251 ret 35 252 end 253 if or lt get dfSlotOf apKey 1 0 ge dfPfLookup apKey 1 0 254 ret 36 255 end 256 if or ge get dfSlotOf apKey 2 0 lt dfPfLookup apKey 2 0 257 ret 37 258 end 259 if not apSlotDigestOk sidecar 1 260 ret 48 261 end 262 if not apSlotDigestOk sidecar 21 263 ret 49 264 end 265 ret 0 266 end 267 268 note A staged payload whose digest does not match is dropped, and the gate that needs that expert stops 269 note the decoder instead of using it. 270 fn apOnBadPayload sidecar int bad int to int 271 put dfSidecarFD apLayer bad 272 failed = get dfPfStat 1 273 dfPfHarvest 274 if lt dfPfIdleWorker 0 275 dfPfFinish 0 276 end 277 if ne dfPfDispatch apLayer 9 1 278 ret 50 279 end 280 slot = dfPfLookup apKey 9 281 if lt slot 0 282 ret 51 283 end 284 if dfPfAwait ulong slot apKey 9 false 285 ret 52 286 end 287 if or ne get dfPfStat 1 add failed 1 ge dfPfLookup apKey 9 0 288 ret 53 289 end 290 apSetGate 9 21 22 23 24 25 291 if ne dfResolveGate apLayer -1 292 ret 54 293 end 294 put dfSidecarFD apLayer sidecar 295 ret 0 296 end 297 298 fn apCheckOnArm sidecar int bad int to int 299 if not dfStartWorkers 1 300 ret 31 301 end 302 for i ulong 6 303 put dfStats i 0 304 end 305 rc = apOnDispatch 306 if eq rc 0 307 rc = apOnUse sidecar 308 end 309 if eq rc 0 310 rc = apOnBadPayload sidecar bad 311 end 312 dfStopWorkers 313 if and eq rc 0 or ne get dfPfActive 0 0 gt get dfPfStage 0 0 314 ret 55 315 end 316 ret rc 317 end 318 319 fn apUnits to int 320 rc = apUnitSlots 321 if eq rc 0 322 rc = apUnitDepths 323 end 324 if eq rc 0 325 rc = apUnitScore 326 end 327 if eq rc 0 328 rc = apUnitRead 329 end 330 ret rc 331 end 332 333 fn main to int 334 if ne argcnt 4 335 ret 64 336 end 337 sidecar = apOpen 1 338 shard = apOpen 2 339 bad = apOpen 3 340 if or lt sidecar 0 or lt shard 0 lt bad 0 341 ret 66 342 end 343 put dfSidecarFD apLayer sidecar 344 put dfShardFD apLayer shard 345 dfInitSlabMap 7 346 put dwSlabMaps 0 mapnew -1 0 mul 7 deBytes 3 33 347 put dwSlabMaps 4 mapnew -1 0 deBytes 3 33 348 if or le get dwSlabMaps 0 0 le get dwSlabMaps 4 0 349 ret 70 350 end 351 rc = apUnits 352 if eq rc 0 353 rc = apCheckOffArm 354 end 355 if eq rc 0 356 rc = apCheckOnArm sidecar bad 357 end 358 u1 = mapdrop get dwSlabMaps 0 359 u2 = mapdrop get dwSlabMaps 4 360 u3 = fclose sidecar 361 u4 = fclose shard 362 u5 = fclose bad 363 ret rc 364 end