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
omega-mv / gpu / nvidia / native / arboris / step.om
| 1 | note SPDX-License-Identifier: AGPL-3.0-only |
| 2 | note Native SM121 sparse hop over six owned arena maps. Enter on the serialized |
| 3 | note dispatcher after the producer drops its writable aliases. The supervisor |
| 4 | note owns the capability-table mapping, authenticated subject and fencing. |
| 5 | note Return zero only after both the QMD release and the post-flush WFI marker. |
| 6 | note Query specialization (prefix size, hop count). Zero hops means the v1 kernel. |
| 7 | global ar_wave_spec ulong 2 |
| 8 | global ar_code_nodes ulong 1 |
| 9 | global ar_code_planes ulong 1 |
| 10 | global ar_code_bytes ulong 1 |
| 11 | global ar_fenced_seq ulong 1 |
| 12 | note Captured by the serialized submitter only after successful retirement. |
| 13 | note Subject, handle id, generation, model, epoch, input bank and wave controls. |
| 14 | global ar_fenced_claim ulong 7 |
| 15 | |
| 16 | fn ar_record_fence subject ulong h view ulong 2 m view ulong 16 controls ulong to void |
| 17 | put ar_fenced_claim 0 subject |
| 18 | put ar_fenced_claim 1 get h 0 |
| 19 | put ar_fenced_claim 2 get h 1 |
| 20 | put ar_fenced_claim 3 get m 0 |
| 21 | put ar_fenced_claim 4 get m 7 |
| 22 | put ar_fenced_claim 5 get m 6 |
| 23 | put ar_fenced_claim 6 controls |
| 24 | put ar_fenced_seq 0 get nvret 0 |
| 25 | end |
| 26 | |
| 27 | fn ar_sparse_data m view ulong 16 to bool |
| 28 | n = get m 1 |
| 29 | arcs = get m 3 |
| 30 | t = get ar_maps 1 |
| 31 | w = get ar_maps 2 |
| 32 | if or ne mapget t 0 4 0x41525431 ne mapget t 4 4 n |
| 33 | ret false |
| 34 | end |
| 35 | if or ne mapget t 8 4 arcs ne mapget t 12 4 0 |
| 36 | ret false |
| 37 | end |
| 38 | prev = ulong 0 |
| 39 | for i ulong n bound 0x1fffffff |
| 40 | next = mapget t add 16 mul i 4 4 |
| 41 | if or lt next prev gt next arcs |
| 42 | ret false |
| 43 | end |
| 44 | prev = next |
| 45 | end |
| 46 | if ne prev arcs |
| 47 | ret false |
| 48 | end |
| 49 | start = mul add n 4 4 |
| 50 | for k ulong arcs bound 0xffffffff |
| 51 | if ge mapget t add start mul k 4 4 n |
| 52 | ret false |
| 53 | end |
| 54 | if gt mapget w mul k 4 4 0x3f800000 |
| 55 | ret false |
| 56 | end |
| 57 | end |
| 58 | x = get ar_maps add 3 get m 6 |
| 59 | for i ulong div get m 11 4 bound 0x4000000000 |
| 60 | if gt mapget x mul i 4 4 0x3f800000 |
| 61 | ret false |
| 62 | end |
| 63 | end |
| 64 | ret true |
| 65 | end |
| 66 | |
| 67 | fn ar_retire_code to bool |
| 68 | if and ne get nvstate 0 0 ne get nvfault 0 0 |
| 69 | ret false |
| 70 | end |
| 71 | if ne get nvret 0 get nvput 0 |
| 72 | ret false |
| 73 | end |
| 74 | for j ulong 5 |
| 75 | i = sub ulong 4 j |
| 76 | tok = get gbmem i |
| 77 | if gt tok 0 |
| 78 | if eq get nvstate 0 1 |
| 79 | if not nvdrop tok |
| 80 | ret false |
| 81 | end |
| 82 | else |
| 83 | if ne get nvstate 0 0 |
| 84 | ret false |
| 85 | end |
| 86 | end |
| 87 | put gbmem i 0 |
| 88 | end |
| 89 | end |
| 90 | put ar_fenced_seq 0 0 |
| 91 | put ar_code_model 0 0 |
| 92 | put ar_code_bytes 0 0 |
| 93 | put ar_wave_spec 0 0 |
| 94 | put ar_wave_spec 1 0 |
| 95 | put ar_code_nodes 0 0 |
| 96 | put ar_code_planes 0 0 |
| 97 | ret true |
| 98 | end |
| 99 | |
| 100 | fn ar_step_close to bool |
| 101 | if not ar_retire_code |
| 102 | ret false |
| 103 | end |
| 104 | ar_drop_compute |
| 105 | ret true |
| 106 | end |
| 107 | |
| 108 | fn ar_install_code m view ulong 16 code view uchar 16384 size ulong to bool |
| 109 | if or eq get nvsched 0 0 ne get ar_code_nodes 0 0 |
| 110 | ret false |
| 111 | end |
| 112 | for i ulong 5 |
| 113 | if ne get gbmem i 0 |
| 114 | ret false |
| 115 | end |
| 116 | end |
| 117 | if eq size 0 |
| 118 | ret false |
| 119 | end |
| 120 | for i ulong 5 |
| 121 | bytes = ulong 4096 |
| 122 | if eq i 4 |
| 123 | bytes = aligned_size size 4096 16384 |
| 124 | end |
| 125 | if eq i 2 |
| 126 | note QMD0, QMD1, semaphore and full 64 KiB scratch are disjoint. |
| 127 | bytes = ulong 81920 |
| 128 | end |
| 129 | tok = nvalloc bytes false |
| 130 | if le tok 0 |
| 131 | ret false |
| 132 | end |
| 133 | put gbmem i tok |
| 134 | end |
| 135 | if ne mapwrite get gbmem 4 0 code 0 size long size |
| 136 | ret false |
| 137 | end |
| 138 | put ar_code_model 0 get m 0 |
| 139 | put ar_code_bytes 0 size |
| 140 | put ar_code_nodes 0 get m 1 |
| 141 | put ar_code_planes 0 get m 4 |
| 142 | ret true |
| 143 | end |
| 144 | |
| 145 | fn ar_step_open m view ulong 16 to bool |
| 146 | if ne get m 0 arboris_sparse_magic |
| 147 | ret false |
| 148 | end |
| 149 | if not ar_snapshot_matches m |
| 150 | ret false |
| 151 | end |
| 152 | code = new uchar 16384 0 |
| 153 | n = get m 1 |
| 154 | size = ulong 0 |
| 155 | if eq get m 4 1 |
| 156 | size = arboris_emit_relax n code |
| 157 | else |
| 158 | if eq get m 4 2 |
| 159 | size = arboris_emit_spread n code |
| 160 | end |
| 161 | end |
| 162 | ret ar_install_code m code size |
| 163 | end |
| 164 | |
| 165 | note Multi-hop calls compute a single explicitly bounded query result. Its |
| 166 | note specialized binary digest binds the hop count in the signed claim. |
| 167 | fn ar_open_query m view ulong 16 leaves ulong hops ulong to bool |
| 168 | if or ne get m 0 arboris_sparse_magic ne get m 4 1 |
| 169 | ret false |
| 170 | end |
| 171 | if or not ar_snapshot_matches m or eq hops 0 gt leaves get m 1 |
| 172 | ret false |
| 173 | end |
| 174 | if ne get m 3 0 |
| 175 | if gt hops div 0xffffffffffffffff mul get m 3 get m 2 |
| 176 | ret false |
| 177 | end |
| 178 | end |
| 179 | code = new uchar 16384 0 |
| 180 | size = ulong 0 |
| 181 | if eq leaves get m 1 |
| 182 | size = arboris_emit_persistent leaves hops code |
| 183 | else |
| 184 | note The maximum row cursor after its final 32-wide stride fits a uint. |
| 185 | if or ne hops 1 gt get m 3 0xffffffdf |
| 186 | ret false |
| 187 | end |
| 188 | size = arboris_emit_hubs get m 1 leaves code |
| 189 | end |
| 190 | if not ar_install_code m code size |
| 191 | ret false |
| 192 | end |
| 193 | put ar_wave_spec 0 leaves |
| 194 | put ar_wave_spec 1 hops |
| 195 | ret true |
| 196 | end |
| 197 | |
| 198 | fn ar_query_geometry shape view ulong 7 slots view ulong 20 b edit uint 236 q1 edit uint 96 to bool |
| 199 | m = new ulong 16 0 |
| 200 | for i ulong 5 |
| 201 | put m i get slots mul i 2 |
| 202 | end |
| 203 | n = get shape 1 |
| 204 | leaves = get ar_wave_spec 0 |
| 205 | put m 8 128 |
| 206 | put m 9 1 |
| 207 | put m 11 get shape 3 |
| 208 | put m 12 40 |
| 209 | if eq n leaves |
| 210 | put m 10 1 |
| 211 | put m 13 mul n 8 |
| 212 | else |
| 213 | put m 10 add div add leaves 127 128 div add sub n leaves 3 4 |
| 214 | end |
| 215 | if ne bw_qmd1 m q1 0 |
| 216 | ret false |
| 217 | end |
| 218 | put b 220 u32lo get m 10 |
| 219 | ret eq bw_qmd_verify q1 0 |
| 220 | end |
| 221 | |
| 222 | fn ar_step_slots s edit ulong 20 to void |
| 223 | put s 0 mapaddr get gbmem 4 |
| 224 | put s 1 get nvmlen nvfind get gbmem 4 |
| 225 | put s 2 mapaddr get gbmem 1 |
| 226 | put s 3 4096 |
| 227 | q = mapaddr get gbmem 2 |
| 228 | put s 4 add q 16384 |
| 229 | put s 5 65536 |
| 230 | put s 6 add q 8192 |
| 231 | put s 7 16 |
| 232 | put s 8 q |
| 233 | put s 9 384 |
| 234 | put s 10 add q 4096 |
| 235 | put s 11 384 |
| 236 | for i ulong 4 |
| 237 | tok = get ar_maps add i 1 |
| 238 | j = add 12 mul i 2 |
| 239 | put s j mapaddr tok |
| 240 | put s add j 1 get nvmlen nvfind tok |
| 241 | end |
| 242 | end |
| 243 | |
| 244 | fn ar_native_packet slots view ulong 20 b view uint * q0 view uint 96 q1 view uint 96 to bool |
| 245 | if or le len b 224 gt len b 256 |
| 246 | ret false |
| 247 | end |
| 248 | for i ulong 96 |
| 249 | put gbq0 i get q0 i |
| 250 | put gbq1 i get q1 i |
| 251 | end |
| 252 | put gbused 0 0 |
| 253 | gbsetup |
| 254 | gbdma get slots 2 224 |
| 255 | for i ulong 224 |
| 256 | gbemit get b i |
| 257 | end |
| 258 | gbdma add get slots 2 896 uint sub len b 224 |
| 259 | for i ulong sub len b 224 bound 32 |
| 260 | gbemit get b add i 224 |
| 261 | end |
| 262 | gbinline get slots 8 false |
| 263 | gbdma get slots 6 1 |
| 264 | gbemit 1 |
| 265 | gbinline get slots 10 true |
| 266 | gbtail |
| 267 | ret true |
| 268 | end |
| 269 | |
| 270 | fn ar_step_pack shape view ulong 7 slots view ulong 20 planes ulong to bool |
| 271 | d = new uint 224 0 |
| 272 | b = new uint 236 0 |
| 273 | q0 = new uint 96 0 |
| 274 | q1 = new uint 96 0 |
| 275 | gbdriver get slots 2 |
| 276 | for i ulong 224 |
| 277 | put d i get gbcb i |
| 278 | end |
| 279 | rc = ulong 1 |
| 280 | if eq planes 1 |
| 281 | rc = arboris_relax_qmd shape slots d b q0 q1 |
| 282 | else |
| 283 | rc = arboris_wave_qmd shape slots d b q0 q1 |
| 284 | end |
| 285 | if ne rc 0 |
| 286 | ret false |
| 287 | end |
| 288 | if ne get ar_wave_spec 1 0 |
| 289 | if not ar_query_geometry shape slots b q1 |
| 290 | ret false |
| 291 | end |
| 292 | end |
| 293 | ret ar_native_packet slots b q0 q1 |
| 294 | end |
| 295 | |
| 296 | fn ar_sparse_header m view ulong 16 to bool |
| 297 | if or ne get m 0 arboris_sparse_magic ne get ar_code_model 0 arboris_sparse_magic |
| 298 | ret false |
| 299 | end |
| 300 | if or ne get m 1 get ar_code_nodes 0 ne get m 4 get ar_code_planes 0 |
| 301 | ret false |
| 302 | end |
| 303 | for i ulong 6 |
| 304 | if le get ar_maps i 0 |
| 305 | ret false |
| 306 | end |
| 307 | if eq nvfind get ar_maps i 96 |
| 308 | ret false |
| 309 | end |
| 310 | end |
| 311 | if not ar_snapshot_matches m |
| 312 | ret false |
| 313 | end |
| 314 | ret true |
| 315 | end |
| 316 | |
| 317 | note Slab 4 words 6 and 7 are the channel sequence and device completion. |
| 318 | note The work QMD has already passed the post-flush WFI point. Publish the |
| 319 | note 16-byte sequence/status record with inline DMA, then flush and release |
| 320 | note the private completion marker. The host must observe both before sealing. |
| 321 | fn ar_completion_word seq ulong to uint |
| 322 | ret uint add 1 rem seq 0xffffffff |
| 323 | end |
| 324 | |
| 325 | fn ar_channel_idle to bool |
| 326 | ret and eq get nvfault 0 0 eq get nvret 0 get nvput 0 |
| 327 | end |
| 328 | fn ar_release_receipt va ulong seq ulong marker ulong to void |
| 329 | gbdma add va 48 4 |
| 330 | gbemit gblo seq |
| 331 | gbemit gbhi seq |
| 332 | gbemit 6 |
| 333 | gbemit 0 |
| 334 | gbflush |
| 335 | gbrel add marker 32 ar_completion_word seq |
| 336 | end |
| 337 | |
| 338 | fn ar_device_receipt tok long seq ulong to bool |
| 339 | if or le tok 0 eq seq 0 |
| 340 | ret false |
| 341 | end |
| 342 | if ne mapget tok 56 8 6 |
| 343 | ret false |
| 344 | end |
| 345 | ret and eq mapget tok 48 8 seq eq mapget tok 0 8 0 |
| 346 | end |
| 347 | |
| 348 | note The private WFI semaphore and imported receipt occupy different mappings. |
| 349 | note Retire logical work only once all writes for this exact sequence are visible. |
| 350 | fn ar_work_visible tok long mark long q long seq ulong to bool |
| 351 | if not ar_device_receipt tok seq |
| 352 | ret false |
| 353 | end |
| 354 | if ne mapget mark 16 4 1179010630 |
| 355 | ret false |
| 356 | end |
| 357 | ret and eq mapget mark 0 4 1145324612 eq mapget q 8192 4 6 |
| 358 | end |
| 359 | |
| 360 | fn ar_wait_visible tok long mark long q long seq ulong to bool |
| 361 | start = monons |
| 362 | while true |
| 363 | if ar_work_visible tok mark q seq |
| 364 | ret true |
| 365 | end |
| 366 | if ne mapget tok 0 8 0 |
| 367 | ret false |
| 368 | end |
| 369 | now = monons |
| 370 | if or lt now start ge sub now start 5000000000 |
| 371 | ret false |
| 372 | end |
| 373 | if ne sleepns 100000 0 |
| 374 | ret false |
| 375 | end |
| 376 | end |
| 377 | ret false |
| 378 | end |
| 379 | |
| 380 | fn ar_step_send to bool |
| 381 | if or not ar_channel_idle ne get ar_fenced_seq 0 0 |
| 382 | ret false |
| 383 | end |
| 384 | q = get gbmem 2 |
| 385 | mark = get gbmem 3 |
| 386 | if ne mapset q 8192 4 0 0 |
| 387 | ret false |
| 388 | end |
| 389 | if ne mapset mark 0 4 0 0 |
| 390 | ret false |
| 391 | end |
| 392 | if ne mapset mark 32 4 0 0 |
| 393 | ret false |
| 394 | end |
| 395 | if ne mapset mark 16 4 0 0 |
| 396 | ret false |
| 397 | end |
| 398 | tok = get ar_maps 5 |
| 399 | if or le tok 0 eq get nvput 0 0xffffffffffffffff |
| 400 | ret false |
| 401 | end |
| 402 | if ne mapget tok 0 8 0 |
| 403 | ret false |
| 404 | end |
| 405 | if ne mapset tok 56 8 0 0 |
| 406 | ret false |
| 407 | end |
| 408 | seq = add get nvput 0 1 |
| 409 | ar_release_receipt mapaddr tok seq mapaddr mark |
| 410 | bytes = get gbused 0 |
| 411 | if ne mapwrite get gbmem 0 0 gbcmd 0 bytes long bytes |
| 412 | ret false |
| 413 | end |
| 414 | if not nvsend get gbmem 0 0 uint div bytes 4 |
| 415 | ret false |
| 416 | end |
| 417 | if not nvwait mark 32 ar_completion_word seq 5000000000 |
| 418 | ret false |
| 419 | end |
| 420 | if not ar_wait_visible tok mark q seq |
| 421 | put nvfault 0 1 |
| 422 | ret false |
| 423 | end |
| 424 | ret true |
| 425 | end |
| 426 | |
| 427 | fn ar_sparse_locked table long subject ulong h view ulong 2 m view ulong 16 decay ulong threshold ulong to ulong |
| 428 | if not caproot_validate table subject h m |
| 429 | ret 1 |
| 430 | end |
| 431 | if ne get ar_fenced_seq 0 0 |
| 432 | ret 7 |
| 433 | end |
| 434 | if not ar_sparse_header m |
| 435 | ret 2 |
| 436 | end |
| 437 | if not ar_sparse_data m |
| 438 | ret 3 |
| 439 | end |
| 440 | shape = new ulong 7 0 |
| 441 | put shape 0 get ar_code_nodes 0 |
| 442 | put shape 1 get m 1 |
| 443 | put shape 2 get m 3 |
| 444 | put shape 3 get m 2 |
| 445 | put shape 4 get m 6 |
| 446 | put shape 5 decay |
| 447 | put shape 6 threshold |
| 448 | slots = new ulong 20 0 |
| 449 | ar_step_slots slots |
| 450 | if not ar_step_pack shape slots get m 4 |
| 451 | ret 4 |
| 452 | end |
| 453 | if not caproot_validate table subject h m |
| 454 | ret 1 |
| 455 | end |
| 456 | if not ar_step_send |
| 457 | ret 5 |
| 458 | end |
| 459 | ar_record_fence subject h m or decay shl threshold 32 |
| 460 | ret 0 |
| 461 | end |
| 462 | |
| 463 | note Acquire before CSR validation. If the queue may still own resources, |
| 464 | note only retirement and settlement or teardown can release this lease. |
| 465 | fn ar_sparse_dispatch table long subject ulong h view ulong 2 m view ulong 16 decay ulong threshold ulong to ulong |
| 466 | if ne get ar_fenced_seq 0 0 |
| 467 | ret 7 |
| 468 | end |
| 469 | if or not ar_channel_idle not ar_claim_compute 2 |
| 470 | ret 8 |
| 471 | end |
| 472 | rc = ar_sparse_locked table subject h m decay threshold |
| 473 | if and ne rc 0 ar_channel_idle |
| 474 | ar_drop_compute |
| 475 | end |
| 476 | ret rc |
| 477 | end |
| 478 | |
| 479 | fn ar_sparse_hop table long subject ulong h view ulong 2 m view ulong 16 decay ulong threshold ulong to ulong |
| 480 | if ne get ar_wave_spec 1 0 |
| 481 | ret 2 |
| 482 | end |
| 483 | ret ar_sparse_dispatch table subject h m decay threshold |
| 484 | end |
| 485 | |
| 486 | note spec words are requested leaves, hops and the FP32 decay bits. |
| 487 | fn ar_sparse_query table long subject ulong h view ulong 2 m view ulong 16 spec view ulong 3 to ulong |
| 488 | if eq get spec 1 0 |
| 489 | ret 2 |
| 490 | end |
| 491 | if ne get spec 1 get ar_wave_spec 1 |
| 492 | ret 2 |
| 493 | end |
| 494 | if ne get spec 0 get ar_wave_spec 0 |
| 495 | ret 2 |
| 496 | end |
| 497 | ret ar_sparse_dispatch table subject h m get spec 2 0 |
| 498 | end |