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 / blackwell / batch.om
| 1 | note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 2 | note Compose context.om, vector.om, launch.om, batch.om. No alternate driver or queue. |
| 3 | note Bodies are produced by gbbody, or an equivalent INLINE/DMA body WITHOUT gbtail. |
| 4 | note Every body has a WFI release and full shader invalidation before the next body. |
| 5 | note QMD/bank updates are inline DMA, never CPU overwrites while the GPU reads them. |
| 6 | note Source: class/clc96f.h:75-87 RELEASE_WFI_EN; om/streams/streams.om INVALL. |
| 7 | note All gbmem allocations and code/data operands stay live and immutable until completion. |
| 8 | note No reset, append, free or retry after uncertain completion: nvfault remains latched. |
| 9 | global gbst ulong 8 |
| 10 | note gbst: expected, recorded, bytes, phase(0 idle,1 recording,2 in-flight,3 poison), |
| 11 | note bad index(count means final tail), bad caller id, kicks, waits. |
| 12 | global gbids ulong 512 |
| 13 | global gbpkt long 1 |
| 14 | fn gbberr idx ulong id ulong err long to bool |
| 15 | put gbst 4 idx |
| 16 | put gbst 5 id |
| 17 | put gbst 3 3 |
| 18 | put nverr 0 err |
| 19 | ret false |
| 20 | end |
| 21 | note Allocate once after opening the context. GPU-uncached packet storage. |
| 22 | fn gbbopen to bool |
| 23 | if ne get nvfault 0 0 |
| 24 | ret false |
| 25 | end |
| 26 | if gt get gbpkt 0 0 |
| 27 | ret true |
| 28 | end |
| 29 | m = nvalloc 1048576 false |
| 30 | if le m 0 |
| 31 | ret false |
| 32 | end |
| 33 | put gbpkt 0 m |
| 34 | ret true |
| 35 | end |
| 36 | note Count admission precedes body recording or any send. A bad append poisons the whole batch. |
| 37 | fn gbbegin count ulong to bool |
| 38 | if or ne get nvfault 0 0 eq get gbst 3 2 |
| 39 | ret false |
| 40 | end |
| 41 | if or eq count 0 gt count 512 |
| 42 | ret gbberr 0 0 -75 |
| 43 | end |
| 44 | if le get gbpkt 0 0 |
| 45 | ret gbberr 0 0 -22 |
| 46 | end |
| 47 | put gbst 0 count |
| 48 | put gbst 1 0 |
| 49 | put gbst 2 0 |
| 50 | put gbst 3 1 |
| 51 | put gbst 4 18446744073709551615 |
| 52 | put gbst 5 0 |
| 53 | put gbst 6 0 |
| 54 | put gbst 7 0 |
| 55 | ret true |
| 56 | end |
| 57 | note Copy directly into the persistent submit mapping, not through a second megabyte buffer. |
| 58 | fn gbbcopy to bool |
| 59 | n = get gbused 0 |
| 60 | base = get gbst 2 |
| 61 | r = mapwrite get gbpkt 0 base gbcmd 0 n |
| 62 | if ne r long n |
| 63 | ret gbberr get gbst 1 0 -5 |
| 64 | end |
| 65 | put gbst 2 add base n |
| 66 | ret true |
| 67 | end |
| 68 | note dep = zero for none, or producer index+1. Only already-recorded producers are admissible. |
| 69 | fn gbappend id ulong dep ulong to bool |
| 70 | idx = get gbst 1 |
| 71 | if or ne get gbst 3 1 ne get nvfault 0 0 |
| 72 | ret false |
| 73 | end |
| 74 | if ge idx get gbst 0 |
| 75 | ret gbberr idx id -75 |
| 76 | end |
| 77 | if gt dep idx |
| 78 | ret gbberr idx id -22 |
| 79 | end |
| 80 | n = get gbused 0 |
| 81 | if or or eq n 0 gt n 65536 ne rem n 4 0 |
| 82 | ret gbberr idx id -22 |
| 83 | end |
| 84 | note Reserve seam release/invalidate (32 bytes) and unchanged tail (68 bytes) before copying. |
| 85 | note Add, never subtract: after a seam the used bytes may exceed 1048476 (n<=65536, no overflow). |
| 86 | if gt add n get gbst 2 1048476 |
| 87 | ret gbberr idx id -75 |
| 88 | end |
| 89 | if not gbbcopy |
| 90 | ret false |
| 91 | end |
| 92 | put gbids idx id |
| 93 | if gt get gbst 0 1 |
| 94 | put gbused 0 0 |
| 95 | va = add mapaddr get gbmem 3 add ulong 32 mul idx 4 |
| 96 | gbrel va 6 |
| 97 | note Full shader invalidation after the WFI release has drained this grid. |
| 98 | gbmth 1 540 1 |
| 99 | gbemit 4113 |
| 100 | if not gbbcopy |
| 101 | ret false |
| 102 | end |
| 103 | end |
| 104 | put gbst 1 add idx 1 |
| 105 | ret true |
| 106 | end |
| 107 | note Scan seals without waiting. Blame FIRST uncompleted index and the caller's kernel id. |
| 108 | note Tail timeout with all seals complete is count, not a fabricated kernel failure. |
| 109 | fn gbbcheck to bool |
| 110 | n = get gbst 0 |
| 111 | if gt n 1 |
| 112 | for i ulong n |
| 113 | if ne mapget get gbmem 3 add ulong 32 mul i 4 4 6 |
| 114 | put gbst 4 i |
| 115 | put gbst 5 get gbids i |
| 116 | ret false |
| 117 | end |
| 118 | end |
| 119 | else |
| 120 | if ne mapget get gbmem 2 8192 4 6 |
| 121 | put gbst 4 0 |
| 122 | put gbst 5 get gbids 0 |
| 123 | ret false |
| 124 | end |
| 125 | end |
| 126 | put gbst 4 n |
| 127 | put gbst 5 0 |
| 128 | ret true |
| 129 | end |
| 130 | note Existing nvwait is sleep-polling: never spin or inherit a process spin window. |
| 131 | note One nvsend and one nvwait. The second marker follows the unchanged C3 L2 flush. |
| 132 | fn gbbsubmit budget ulong to bool |
| 133 | if or ne get gbst 3 1 ne get nvfault 0 0 |
| 134 | ret false |
| 135 | end |
| 136 | if ne get gbst 1 get gbst 0 |
| 137 | ret gbberr get gbst 1 0 -22 |
| 138 | end |
| 139 | if or eq budget 0 gt budget 30000000000 |
| 140 | ret gbberr get gbst 1 0 -22 |
| 141 | end |
| 142 | put gbused 0 0 |
| 143 | gbtail |
| 144 | if not gbbcopy |
| 145 | ret false |
| 146 | end |
| 147 | r = mapset get gbmem 2 8192 4 0 |
| 148 | r = mapset get gbmem 3 0 4 0 |
| 149 | r = mapset get gbmem 3 16 4 0 |
| 150 | for i ulong get gbst 0 |
| 151 | r = mapset get gbmem 3 add ulong 32 mul i 4 4 0 |
| 152 | end |
| 153 | n = get gbst 2 |
| 154 | put gbst 3 2 |
| 155 | put nvstage 0 41 |
| 156 | if not nvsend get gbpkt 0 0 uint div n 4 |
| 157 | note Conservative fail-stop even if the driver refused before its doorbell. |
| 158 | put nvfault 0 1 |
| 159 | put gbst 3 3 |
| 160 | ret false |
| 161 | end |
| 162 | put gbst 6 1 |
| 163 | put gbst 7 1 |
| 164 | put nvstage 0 42 |
| 165 | if not nvwait get gbmem 3 16 1179010630 budget |
| 166 | ok = gbbcheck |
| 167 | put nvfault 0 1 |
| 168 | put gbst 3 3 |
| 169 | ret false |
| 170 | end |
| 171 | ok = gbbcheck |
| 172 | if or not ok ne mapget get gbmem 3 0 4 1145324612 |
| 173 | put nvfault 0 1 |
| 174 | put gbst 3 3 |
| 175 | put nverr 0 -5 |
| 176 | ret false |
| 177 | end |
| 178 | put gbst 3 0 |
| 179 | put gbst 4 18446744073709551615 |
| 180 | put nvstage 0 43 |
| 181 | ret true |
| 182 | end |