CUDApp
CUDA++: AIEN’s GPU machine-code toolchain, runtime and driver client for NVIDIA GPUs without the CUDA toolkit. Hardware coverage and driver replacement limits are explicit.
Brought by drakestapleton
CUDApp / tests / speculation / teardown-host-test.om
| 1 | note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 2 | note Synthetic host refusal fixture. The private unit replaces device calls, close and mapdrop. |
| 3 | note No GPU file is opened and no kernel, model, or hardware result is claimed. |
| 4 | global tchecks ulong 1 |
| 5 | global tblocked uchar 4 |
| 6 | global tlive uchar 4 |
| 7 | global tdrops ulong 4 |
| 8 | global tmapmode uchar 1 |
| 9 | global tmclose ulong 1 |
| 10 | global tmopen ulong 1 |
| 11 | global tcloses ulong 2 |
| 12 | global tdcalls ulong 1 |
| 13 | global tdfail uchar 1 |
| 14 | global tcfail uchar 1 |
| 15 | text tok "NATIVE_TEARDOWN_HOST_PASS\n" |
| 16 | text tbad "NATIVE_TEARDOWN_HOST_FAIL\n" |
| 17 | fn tcheck yes bool to void |
| 18 | put tchecks 0 add get tchecks 0 1 |
| 19 | if not yes |
| 20 | r = write 2 tbad 0 len tbad |
| 21 | exit int 1 |
| 22 | end |
| 23 | end |
| 24 | fn tunexpected to long |
| 25 | if ne get tmapmode 0 0 |
| 26 | put tmopen 0 add get tmopen 0 1 |
| 27 | ret 42 |
| 28 | end |
| 29 | tcheck false |
| 30 | ret neg long 5 |
| 31 | end |
| 32 | fn tmapnew fd int offset ulong size ulong access int mode int to long |
| 33 | tcheck eq get tmapmode 0 1 |
| 34 | tcheck eq fd 42 |
| 35 | tcheck eq offset 0 |
| 36 | tcheck eq size 4096 |
| 37 | tcheck eq access 3 |
| 38 | tcheck eq mode 1 |
| 39 | put tlive 3 1 |
| 40 | ret 14 |
| 41 | end |
| 42 | fn tdriver to long |
| 43 | note A retry after descriptor closure must never issue another RM or UVM call. |
| 44 | tcheck eq get nvstate 0 1 |
| 45 | put tdcalls 0 add get tdcalls 0 1 |
| 46 | if ne get tdfail 0 0 |
| 47 | put tdfail 0 0 |
| 48 | ret neg long 11 |
| 49 | end |
| 50 | ret 0 |
| 51 | end |
| 52 | fn tdrop m long to long |
| 53 | tcheck and ge m 11 le m 14 |
| 54 | i = ulong sub m 11 |
| 55 | tcheck eq get tlive i 1 |
| 56 | put tdrops i add get tdrops i 1 |
| 57 | if ne get tblocked i 0 |
| 58 | ret neg long 11 |
| 59 | end |
| 60 | put tlive i 0 |
| 61 | ret 0 |
| 62 | end |
| 63 | fn tclose fd int to long |
| 64 | if eq fd 42 |
| 65 | put tmclose 0 add get tmclose 0 1 |
| 66 | tcheck eq get tmclose 0 1 |
| 67 | ret neg long 5 |
| 68 | end |
| 69 | tcheck and ge fd 40 le fd 41 |
| 70 | i = ulong sub fd 40 |
| 71 | put tcloses i add get tcloses i 1 |
| 72 | note A descriptor number could be reused after the first close, even if close reports an error. |
| 73 | tcheck eq get tcloses i 1 |
| 74 | if and eq i 0 ne get tcfail 0 0 |
| 75 | ret neg long 5 |
| 76 | end |
| 77 | ret 0 |
| 78 | end |
| 79 | fn tprepare to void |
| 80 | for i ulong len nvfd |
| 81 | put nvfd i neg int 1 |
| 82 | end |
| 83 | put nvfd 0 40 |
| 84 | put nvfd 1 41 |
| 85 | for i ulong len nvobj |
| 86 | put nvobj i 0 |
| 87 | end |
| 88 | for i ulong len nvreg |
| 89 | put nvreg i 0 |
| 90 | end |
| 91 | for i ulong len nvmflag |
| 92 | put nvmflag i 0 |
| 93 | put nvmobj i 0 |
| 94 | put nvmmap i 0 |
| 95 | put nvmaddr i 0 |
| 96 | put nvmlen i 0 |
| 97 | end |
| 98 | for i ulong 3 |
| 99 | put tblocked i 0 |
| 100 | put tlive i 1 |
| 101 | put tdrops i 0 |
| 102 | end |
| 103 | for i ulong 2 |
| 104 | put tcloses i 0 |
| 105 | end |
| 106 | put tdcalls 0 0 |
| 107 | put tdfail 0 0 |
| 108 | put tcfail 0 0 |
| 109 | put nverr 0 0 |
| 110 | put nvfault 0 0 |
| 111 | put nvstate 0 1 |
| 112 | put nvchreg 0 0 |
| 113 | put nvsched 0 1 |
| 114 | put nvbar 0 11 |
| 115 | put nvchva 0 12 |
| 116 | put nvfifo 0 0 |
| 117 | put nvnotify 0 0 |
| 118 | put nvput 0 0 |
| 119 | put nvret 0 0 |
| 120 | put nvmflag 0 2 |
| 121 | put nvmmap 0 13 |
| 122 | put nvmaddr 0 4096 |
| 123 | put nvmlen 0 4096 |
| 124 | end |
| 125 | fn tclosed to void |
| 126 | tcheck eq get nvstate 0 0 |
| 127 | tcheck eq get nvsched 0 0 |
| 128 | tcheck eq get nvbar 0 0 |
| 129 | tcheck eq get nvchva 0 0 |
| 130 | for i ulong len nvfd |
| 131 | tcheck eq get nvfd i neg int 1 |
| 132 | end |
| 133 | for i ulong 2 |
| 134 | tcheck eq get tcloses i 1 |
| 135 | end |
| 136 | for i ulong 3 |
| 137 | tcheck eq get tlive i 0 |
| 138 | end |
| 139 | for i ulong len nvmflag |
| 140 | tcheck eq get nvmflag i 0 |
| 141 | tcheck eq get nvmobj i 0 |
| 142 | tcheck eq get nvmmap i 0 |
| 143 | tcheck eq get nvmaddr i 0 |
| 144 | tcheck eq get nvmlen i 0 |
| 145 | end |
| 146 | for i ulong len nvobj |
| 147 | tcheck eq get nvobj i 0 |
| 148 | end |
| 149 | end |
| 150 | fn tretained which ulong to void |
| 151 | if eq which 0 |
| 152 | tcheck eq get nvbar 0 11 |
| 153 | end |
| 154 | if eq which 1 |
| 155 | tcheck eq get nvchva 0 12 |
| 156 | end |
| 157 | if eq which 2 |
| 158 | tcheck eq get nvmflag 0 2 |
| 159 | tcheck eq get nvmmap 0 13 |
| 160 | tcheck eq get nvmaddr 0 4096 |
| 161 | tcheck eq get nvmlen 0 4096 |
| 162 | end |
| 163 | tcheck eq get tlive which 1 |
| 164 | tcheck eq get nvstate 0 2 |
| 165 | tcheck eq get nvfault 0 1 |
| 166 | tcheck eq get nvsched 0 0 |
| 167 | for i ulong len nvfd |
| 168 | tcheck eq get nvfd i neg int 1 |
| 169 | end |
| 170 | end |
| 171 | fn tretry which ulong drvfail bool to void |
| 172 | tprepare |
| 173 | put tblocked which 1 |
| 174 | if drvfail |
| 175 | note Refuse channel destruction before its handles retire; retry must not free them through closed fds. |
| 176 | put nvobj 6 101 |
| 177 | put nvobj 8 102 |
| 178 | put nvobj 9 103 |
| 179 | put tdfail 0 1 |
| 180 | end |
| 181 | tcheck not nvstop |
| 182 | tretained which |
| 183 | before = get tdcalls 0 |
| 184 | tcheck not nvstop |
| 185 | tretained which |
| 186 | tcheck eq get tdcalls 0 before |
| 187 | for i ulong 2 |
| 188 | tcheck eq get tcloses i 1 |
| 189 | end |
| 190 | put tblocked which 0 |
| 191 | tcheck nvstop |
| 192 | tclosed |
| 193 | tcheck eq get tdcalls 0 before |
| 194 | tcheck eq get nvfault 0 1 |
| 195 | tcheck not nvstart |
| 196 | tcheck eq get nverr 0 neg long 5 |
| 197 | count = get tdrops which |
| 198 | tcheck nvstop |
| 199 | tcheck eq get tdrops which count |
| 200 | tclosed |
| 201 | end |
| 202 | fn tphaseguard to void |
| 203 | note Force cleanup cannot retire live driver ownership before descriptors close. |
| 204 | tprepare |
| 205 | put nvmflag 0 15 |
| 206 | put nvmobj 0 201 |
| 207 | tcheck not nvmforce |
| 208 | tcheck eq get nverr 0 neg long 16 |
| 209 | tcheck eq get nvstate 0 1 |
| 210 | tcheck eq get nvfault 0 0 |
| 211 | tcheck eq get nvmflag 0 15 |
| 212 | tcheck eq get nvmobj 0 201 |
| 213 | tcheck eq get nvmmap 0 13 |
| 214 | tcheck eq get nvmaddr 0 4096 |
| 215 | tcheck eq get nvmlen 0 4096 |
| 216 | for i ulong 3 |
| 217 | tcheck eq get tdrops i 0 |
| 218 | tcheck eq get tlive i 1 |
| 219 | end |
| 220 | for i ulong 2 |
| 221 | tcheck eq get tcloses i 0 |
| 222 | end |
| 223 | tcheck eq get tdcalls 0 0 |
| 224 | tcheck nvstop |
| 225 | tclosed |
| 226 | end |
| 227 | fn tunpublished to void |
| 228 | note Close fails after mapping succeeds; a refused unmap must remain reachable. |
| 229 | tprepare |
| 230 | put tmapmode 0 1 |
| 231 | put tmopen 0 0 |
| 232 | put tmclose 0 0 |
| 233 | put tblocked 3 1 |
| 234 | put tdrops 3 0 |
| 235 | put tlive 3 0 |
| 236 | tcheck eq nvcpumap 201 4096 false 0 neg long 1 |
| 237 | tcheck eq get tmopen 0 1 |
| 238 | tcheck eq get tmclose 0 1 |
| 239 | tcheck eq get tlive 3 1 |
| 240 | tcheck eq get tdrops 3 1 |
| 241 | tcheck eq get nvfault 0 1 |
| 242 | tcheck not nvstop |
| 243 | tcheck eq get nvstate 0 2 |
| 244 | tcheck eq get tlive 3 1 |
| 245 | note A faulted caller cannot overwrite the quarantined handle or reopen a descriptor. |
| 246 | tcheck eq nvcpumap 202 4096 false 0 neg long 1 |
| 247 | tcheck eq get tmopen 0 1 |
| 248 | before = get tdcalls 0 |
| 249 | tcheck not nvstop |
| 250 | tcheck eq get tdcalls 0 before |
| 251 | tcheck eq get tmclose 0 1 |
| 252 | put tblocked 3 0 |
| 253 | tcheck nvstop |
| 254 | tclosed |
| 255 | tcheck eq get tlive 3 0 |
| 256 | tcheck eq get nvfault 0 1 |
| 257 | count = get tdrops 3 |
| 258 | tcheck nvstop |
| 259 | tcheck eq get tdrops 3 count |
| 260 | tcheck not nvstart |
| 261 | put tmapmode 0 0 |
| 262 | end |
| 263 | fn main to int |
| 264 | note Closed contexts stay idempotent without touching descriptors or mappings. |
| 265 | tcheck nvstop |
| 266 | tprepare |
| 267 | tcheck nvstop |
| 268 | tclosed |
| 269 | tcheck eq get nvfault 0 0 |
| 270 | for i ulong 3 |
| 271 | tcheck eq get tdrops i 1 |
| 272 | end |
| 273 | tcheck nvstop |
| 274 | tclosed |
| 275 | tretry 0 false |
| 276 | tretry 1 false |
| 277 | tretry 2 false |
| 278 | tretry 1 true |
| 279 | tphaseguard |
| 280 | note An error from the descriptor close must latch the fault without retrying that descriptor. |
| 281 | tprepare |
| 282 | put tcfail 0 1 |
| 283 | tcheck not nvstop |
| 284 | tclosed |
| 285 | tcheck eq get nvfault 0 1 |
| 286 | tcheck nvstop |
| 287 | tclosed |
| 288 | tcheck not nvstart |
| 289 | tunpublished |
| 290 | tcheck eq write 1 tok 0 len tok long len tok |
| 291 | ret 0 |
| 292 | end |