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/CUDApp/blob/main/tests/share/fake-rm.om # 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 Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `CUDApp / tests / share / fake-rm.om` 441 lines · 8727 bytes Raw Blame History 1 note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 2 note Fake NVIDIA RM and UVM for the zero-copy host test. No device file is opened. 3 note The runner renames devctl, devcall, uvmctl, fopen, fclose, mapbind and mapnew in a private 4 note copy of context.om plus share.om to the fk words below. Layouts, request numbers and 5 note statuses come from the generated k functions (tests/share/abi-oracle.c), not from share.om. 6 note Each memory object's pages are a memfd, so a CPU import really aliases the owner's bytes. 7 note Map bounds follow 580.173.02 mapping_cpu.c: offset at or past the end is INVALID_BASE, 8 note zero length or a span past the end is INVALID_LIMIT. 9 text fkname "fake-rm-memory" 10 global fkcli uint 64 11 global fkhnd uint 64 12 global fkbk ulong 64 13 global fklive uchar 64 14 global fkshr uchar 64 15 global fbfd int 16 16 global fbsize ulong 16 17 global fbref uint 16 18 global fbview long 16 19 global fbn ulong 1 20 global fdopen uchar 32 21 global fdbk ulong 32 22 global fdro uchar 32 23 global fdn ulong 1 24 global frbase ulong 16 25 global frlive uchar 16 26 global fdmh uint 16 27 global fdmlive uchar 16 28 note Counters: 0 RM and UVM calls, 1 shares, 2 dups, 3 frees, 4 maps accepted, 5 DMA maps, 29 note 6 DMA unmaps, 7 UVM ranges, 8 UVM external maps, 9 UVM frees, 10 opens, 11 closes, 30 note 12 backings released, 13 binds. 31 global fcnt ulong 16 32 note Last seen: 0 map flags, 1 DMA flags, 2 UVM mapping type, 3 bind access, 4 share target, 33 note 5 share mask, 6 share type, 7 share action, 8 dup flags. 34 global flast uint 16 35 global finj ulong 1 36 global finjst uint 1 37 global fkchk ulong 1 38 text fkbad "ZERO_COPY_SHARE_HOST_FAIL fake check " 39 text fknl "\n" 40 note A fake-side contract breach: share.om sent something the RM ABI does not allow. 41 fn fkok yes bool to void 42 put fkchk 0 add get fkchk 0 1 43 if not yes 44 w = write 2 fkbad 0 len fkbad 45 tprintn 2 get fkchk 0 46 w = write 2 fknl 0 len fknl 47 exit int 1 48 end 49 end 50 fn fkbump i ulong to void 51 put fcnt i add get fcnt i 1 52 end 53 fn fkfind cli uint h uint to ulong 54 for i ulong 64 55 if and ne get fklive i 0 and eq get fkcli i cli eq get fkhnd i h 56 ret i 57 end 58 end 59 ret 64 60 end 61 fn fkhascli cli uint to bool 62 for i ulong 64 63 if and ne get fklive i 0 eq get fkcli i cli 64 ret true 65 end 66 end 67 ret false 68 end 69 fn fklivecnt cli uint to ulong 70 n = ulong 0 71 for i ulong 64 72 if and ne get fklive i 0 eq get fkcli i cli 73 n = add n 1 74 end 75 end 76 ret n 77 end 78 fn fkback size ulong to ulong 79 b = get fbn 0 80 fkok lt b 16 81 m = int memfd fkname 0 len fkname 0 82 fkok ge m 0 83 fkok eq ftrunc m long size 0 84 v = mapnew m 0 size 3 1 85 fkok gt v 0 86 put fbfd b m 87 put fbsize b size 88 put fbref b 0 89 put fbview b v 90 put fbn 0 add b 1 91 ret b 92 end 93 fn fkobj cli uint h uint b ulong to ulong 94 fkok eq fkfind cli h 64 95 for i ulong 64 96 if eq get fklive i 0 97 put fkcli i cli 98 put fkhnd i h 99 put fkbk i b 100 put fkshr i 0 101 put fklive i 1 102 put fbref b add get fbref b 1 103 ret i 104 end 105 end 106 fkok false 107 ret 64 108 end 109 fn fkunobj i ulong to void 110 b = get fkbk i 111 put fklive i 0 112 put fkshr i 0 113 fkok gt get fbref b 0 114 put fbref b sub get fbref b 1 115 if eq get fbref b 0 116 fkok eq mapdrop get fbview b 0 117 fkok eq fclose get fbfd b 0 118 fkbump 12 119 end 120 end 121 note An object owned by another process's RM client. 122 fn fkforeign cli uint h uint size ulong shared bool to ulong 123 i = fkobj cli h fkback size 124 if shared 125 put fkshr i 1 126 end 127 ret i 128 end 129 130 fn fkopen code ulong to long 131 fkok or eq code 1 eq code 3 132 i = get fdn 0 133 fkok lt i 32 134 put fdn 0 add i 1 135 put fdopen i 1 136 put fdbk i 0 137 put fdro i 0 138 fkbump 10 139 ret long add 1000 i 140 end 141 fn fkfdi fd int to ulong 142 fkok and ge fd 1000 lt fd 1032 143 i = ulong sub fd 1000 144 fkok lt i get fdn 0 145 ret i 146 end 147 fn fkclose fd int to long 148 i = fkfdi fd 149 fkok eq get fdopen i 1 150 put fdopen i 0 151 fkbump 11 152 ret 0 153 end 154 fn fknew fd int off ulong n ulong acc int mode int to long 155 fkok false 156 ret neg long 5 157 end 158 fn fkbind m long fd int off ulong acc int to long 159 i = fkfdi fd 160 fkok eq get fdopen i 1 161 fkok eq off 0 162 fkok ne get fdbk i 0 163 put flast 3 uint acc 164 b = sub get fdbk i 1 165 if and ne get fdro i 0 ne acc 1 166 ret neg long 13 167 end 168 fkbump 13 169 if eq acc 1 170 ret mapbind m get fbfd b 0 1 171 end 172 ret mapbind m get fbfd b 0 3 173 end 174 175 fn fkctl fd int req uint off ulong n ulong to long 176 fkok eq off 0 177 fkok eq fd get nvfd 0 178 fkbump 0 179 r = ulong req 180 if eq r kreqfree 181 fkok eq n kszfree 182 fkfreeop 183 ret 0 184 end 185 if eq r kreqshare 186 fkok eq n kszshare 187 fkshareop 188 ret 0 189 end 190 if eq r kreqdup 191 fkok eq n kszdup 192 fkdupop 193 ret 0 194 end 195 if eq r kreqmap 196 fkok eq n kszmap 197 fkmapop 198 ret 0 199 end 200 if eq r kreqdma 201 fkok eq n kszdma 202 fkdmaop 203 ret 0 204 end 205 if eq r krequndma 206 fkok eq n kszundma 207 fkundmaop 208 ret 0 209 end 210 fkok false 211 ret neg long 22 212 end 213 fn fkcall fd int req uint ho ulong hn ulong po ulong pn ulong to long 214 fkok eq fd get nvfd 0 215 fkok eq ulong req kreqalloc 216 fkok and eq ho 0 eq hn 32 217 fkok eq po 0 218 fkbump 0 219 fkok eq nhget kalcclient get nvobj 0 220 fkok eq nhget kalcparent get nvobj 1 221 fkok eq nhget kalcclass 62 222 h = nhget kalcnew 223 fkok ne h 0 224 size = npg64 kmemsize 225 fkok and gt size 0 eq and size 4095 0 226 i = fkobj get nvobj 0 h fkback size 227 nhput kalcstatus 0 228 ret 0 229 end 230 fn fkuvm fd int cmd uint off ulong n ulong to long 231 fkok eq fd get nvfd 2 232 fkok eq off 0 233 fkbump 0 234 c = ulong cmd 235 if and ne get finj 0 0 eq c get finj 0 236 put finj 0 0 237 if eq c kuvmrange 238 npput krangestatus get finjst 0 239 end 240 if eq c kuvmmapext 241 npput kextstatus get finjst 0 242 end 243 ret 0 244 end 245 if eq c kuvmrange 246 fkok eq n kszrange 247 fkrangeop 248 ret 0 249 end 250 if eq c kuvmmapext 251 fkok eq n kszmapext 252 fkextop 253 ret 0 254 end 255 if eq c kuvmfree 256 fkok eq n kszuvmfree 257 fkufreeop 258 ret 0 259 end 260 fkok false 261 ret neg long 22 262 end 263 264 fn fkfreeop to void 265 fkok eq nhget kfreeclient get nvobj 0 266 fkok eq nhget kfreeparent get nvobj 1 267 i = fkfind get nvobj 0 nhget kfreeobj 268 if eq i 64 269 nhput kfreestatus uint kerrnotfound 270 ret 271 end 272 for j ulong 16 273 if and ne get fdmlive j 0 eq get fdmh j get fkhnd i 274 put fdmlive j 0 275 end 276 end 277 fkunobj i 278 fkbump 3 279 nhput kfreestatus 0 280 end 281 fn fkshareop to void 282 i = fkfind npget kshclient npget kshobj 283 put flast 4 npget kshtarget 284 put flast 5 npget kshmask 285 put flast 6 and npget kshtype 65535 286 put flast 7 uint get nvpar kshaction 287 if eq i 64 288 npput kshstatus uint kerrnotfound 289 ret 290 end 291 if and eq ulong npget kshmask kshdupbit eq ulong get flast 6 kshtoken 292 put fkshr i 1 293 end 294 fkbump 1 295 npput kshstatus 0 296 end 297 fn fkdupop to void 298 cli = npget kdupclient 299 fkok eq cli get nvobj 0 300 fkok eq npget kdupparent get nvobj 1 301 h = npget kdupobj 302 fkok ne h 0 303 put flast 8 npget kdupflags 304 scli = npget kdupsrcclient 305 if not fkhascli scli 306 npput kdupstatus uint kerrclient 307 ret 308 end 309 s = fkfind scli npget kdupsrcobj 310 if eq s 64 311 npput kdupstatus uint kerrnotfound 312 ret 313 end 314 if and ne scli cli eq get fkshr s 0 315 npput kdupstatus uint kerrperm 316 ret 317 end 318 i = fkobj cli h get fkbk s 319 fkbump 2 320 npput kdupstatus 0 321 end 322 fn fkmapop to void 323 fkok eq npget kmapclient get nvobj 0 324 fkok eq npget kmapdevice get nvobj 1 325 i = fkfind get nvobj 0 npget kmapmem 326 if eq i 64 327 npput kmapstatus uint kerrnotfound 328 ret 329 end 330 size = get fbsize get fkbk i 331 off = npg64 kmapoffset 332 n = npg64 kmaplength 333 fl = npget kmapflags 334 put flast 0 fl 335 if ge off size 336 npput kmapstatus uint kerrbase 337 ret 338 end 339 if or eq n 0 gt add off n size 340 npput kmapstatus uint kerrlimit 341 ret 342 end 343 d = fkfdi int npget kmapfd 344 fkok eq get fdopen d 1 345 put fdbk d add get fkbk i 1 346 put fdro d 0 347 if eq ulong and fl 3 kmapro 348 put fdro d 1 349 end 350 fkbump 4 351 npput kmapstatus 0 352 end 353 fn fkdmaop to void 354 fkok eq npget kdmaclient get nvobj 0 355 fkok eq npget kdmadevice get nvobj 1 356 fkok eq npget kdmactx get nvobj 3 357 h = npget kdmamem 358 put flast 1 npget kdmaflags 359 o = fkfind get nvobj 0 h 360 if eq o 64 361 npput kdmastatus uint kerrnotfound 362 ret 363 end 364 note GPU VA is fixed at a reserved UVM range and covers the whole object. 365 fkok fkhasrange npg64 kdmaoffset 366 fkok eq npg64 kdmalength get fbsize get fkbk o 367 for j ulong 16 368 if eq get fdmlive j 0 369 put fdmh j h 370 put fdmlive j 1 371 fkbump 5 372 npput kdmastatus 0 373 ret 374 end 375 end 376 fkok false 377 end 378 fn fkundmaop to void 379 h = npget kundmamem 380 for j ulong 16 381 if and ne get fdmlive j 0 eq get fdmh j h 382 put fdmlive j 0 383 fkbump 6 384 npput kundmastatus 0 385 ret 386 end 387 end 388 npput kundmastatus uint kerrnotfound 389 end 390 fn fkrangeop to void 391 b = npg64 krangebase 392 fkok gt npg64 krangelength 0 393 for j ulong 16 394 if eq get frlive j 0 395 put frbase j b 396 put frlive j 1 397 fkbump 7 398 npput krangestatus 0 399 ret 400 end 401 end 402 fkok false 403 end 404 fn fkhasrange b ulong to bool 405 for j ulong 16 406 if and ne get frlive j 0 eq get frbase j b 407 ret true 408 end 409 end 410 ret false 411 end 412 fn fkextop to void 413 fkok fkhasrange npg64 kextbase 414 fkok eq npg64 kextcount 1 415 fkok eq npget kextfd uint get nvfd 0 416 fkok eq npget kextclient get nvobj 0 417 put flast 2 npget kexttype 418 for i ulong 16 419 fkok eq get nvpar add kextuuid i get nvuuid i 420 end 421 o = fkfind get nvobj 0 npget kextmem 422 if eq o 64 423 npput kextstatus uint kerrnotfound 424 ret 425 end 426 fkok eq npg64 kextlength get fbsize get fkbk o 427 fkbump 8 428 npput kextstatus 0 429 end 430 fn fkufreeop to void 431 b = npg64 kfreebase 432 for j ulong 16 433 if and ne get frlive j 0 eq get frbase j b 434 put frlive j 0 435 fkbump 9 436 npput kfreestat 0 437 ret 438 end 439 end 440 fkok false 441 end