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 / share / share-test.om
| 1 | note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 2 | note Host test for native/share/share.om against tests/share/fake-rm.om. The runner appends |
| 3 | note fn main returning tall (full suite) or trowrite (read-only write must trap 103). |
| 4 | note Records are forged here byte by byte ("OMZC" = 79 77 90 67), not via nvexport, so a |
| 5 | note wrong layout in share.om cannot agree with itself. |
| 6 | note Size constants (Wolfram): 2^13 8192, 2^14 16384, 2^36 68719476736, 2^36+2^12 68719480832. |
| 7 | global tchecks ulong 1 |
| 8 | global tbuf uchar 64 |
| 9 | global tnum uchar 24 |
| 10 | text tok "ZERO_COPY_SHARE_HOST_PASS\n" |
| 11 | text tarmed "ZERO_COPY_SHARE_RO_ARMED\n" |
| 12 | text tbad "ZERO_COPY_SHARE_HOST_FAIL check " |
| 13 | text tnl "\n" |
| 14 | fn tprintn fd int v ulong to void |
| 15 | i = ulong 23 |
| 16 | x = v |
| 17 | put tnum i uchar add 48 rem x 10 |
| 18 | x = div x 10 |
| 19 | while ne x 0 bound 24 |
| 20 | i = sub i 1 |
| 21 | put tnum i uchar add 48 rem x 10 |
| 22 | x = div x 10 |
| 23 | end |
| 24 | w = write fd tnum i sub 24 i |
| 25 | end |
| 26 | fn tcheck yes bool to void |
| 27 | put tchecks 0 add get tchecks 0 1 |
| 28 | if not yes |
| 29 | w = write 2 tbad 0 len tbad |
| 30 | tprintn 2 get tchecks 0 |
| 31 | w = write 2 tnl 0 len tnl |
| 32 | tprintn 2 ulong neg get nverr 0 |
| 33 | w = write 2 tnl 0 len tnl |
| 34 | exit int 1 |
| 35 | end |
| 36 | end |
| 37 | fn tsetup to void |
| 38 | put nvfd 0 900 |
| 39 | put nvfd 1 901 |
| 40 | put nvfd 2 902 |
| 41 | put nvfd 3 903 |
| 42 | put nvobj 0 1000001 |
| 43 | put nvobj 1 1000002 |
| 44 | put nvobj 2 1000003 |
| 45 | put nvobj 3 1000004 |
| 46 | put nvobj 4 1000005 |
| 47 | put nvseq 0 1000100 |
| 48 | put nvstate 0 1 |
| 49 | put nvreg 0 1 |
| 50 | put nvreg 1 1 |
| 51 | put nvfault 0 0 |
| 52 | put nvnext 0 68719476736 |
| 53 | for i ulong 16 |
| 54 | put nvuuid i uchar add i 1 |
| 55 | end |
| 56 | end |
| 57 | fn tslots to ulong |
| 58 | n = ulong 0 |
| 59 | for i ulong 96 |
| 60 | if ne get nvmflag i 0 |
| 61 | n = add n 1 |
| 62 | end |
| 63 | end |
| 64 | ret n |
| 65 | end |
| 66 | fn trec cli uint h uint size ulong to void |
| 67 | for i ulong 24 |
| 68 | put nvshrec i 0 |
| 69 | end |
| 70 | put nvshrec 0 79 |
| 71 | put nvshrec 1 77 |
| 72 | put nvshrec 2 90 |
| 73 | put nvshrec 3 67 |
| 74 | put nvshrec 4 1 |
| 75 | for i ulong 4 |
| 76 | put nvshrec add 8 i uchar and shr cli mul i 8 255 |
| 77 | put nvshrec add 12 i uchar and shr h mul i 8 255 |
| 78 | end |
| 79 | for i ulong 8 |
| 80 | put nvshrec add 16 i uchar and shr size mul i 8 255 |
| 81 | end |
| 82 | end |
| 83 | fn tfill v long size ulong seed ulong to void |
| 84 | off = ulong 0 |
| 85 | ok = true |
| 86 | while lt off size bound 4096 |
| 87 | for j ulong 64 |
| 88 | put tbuf j uchar and add add seed j shr off 6 255 |
| 89 | end |
| 90 | if ne mapwrite v off tbuf 0 64 64 |
| 91 | ok = false |
| 92 | end |
| 93 | off = add off 64 |
| 94 | end |
| 95 | tcheck ok |
| 96 | end |
| 97 | fn tverify v long size ulong seed ulong to void |
| 98 | off = ulong 0 |
| 99 | ok = true |
| 100 | while lt off size bound 4096 |
| 101 | if ne mapread v off tbuf 0 64 64 |
| 102 | ok = false |
| 103 | end |
| 104 | for j ulong 64 |
| 105 | if ne ulong get tbuf j and add add seed j shr off 6 255 |
| 106 | ok = false |
| 107 | end |
| 108 | end |
| 109 | off = add off 64 |
| 110 | end |
| 111 | tcheck ok |
| 112 | end |
| 113 | note Every refused import: no slot, no fault, descriptors balanced, no extra live object. |
| 114 | fn tclean slots ulong live ulong to void |
| 115 | tcheck eq tslots slots |
| 116 | tcheck eq get nvfault 0 0 |
| 117 | tcheck eq get fcnt 10 get fcnt 11 |
| 118 | tcheck eq fklivecnt get nvobj 0 live |
| 119 | end |
| 120 | note A malformed or mismatched record is refused before any RM or UVM call. |
| 121 | fn tnocall want ulong code long to void |
| 122 | c = get fcnt 0 |
| 123 | s = tslots |
| 124 | l = fklivecnt get nvobj 0 |
| 125 | tcheck eq nvimport want false neg long 1 |
| 126 | tcheck eq get nverr 0 code |
| 127 | tcheck eq get fcnt 0 c |
| 128 | tclean s l |
| 129 | end |
| 130 | note An RM refusal of the dup: -1 with the RM status in nverr, nothing kept, no further call. |
| 131 | fn trmref want ulong status ulong to void |
| 132 | d = get fcnt 2 |
| 133 | c = get fcnt 0 |
| 134 | s = tslots |
| 135 | l = fklivecnt get nvobj 0 |
| 136 | tcheck eq nvimport want false neg long 1 |
| 137 | tcheck eq get nverr 0 long status |
| 138 | tcheck eq get fcnt 2 d |
| 139 | tcheck eq get fcnt 0 add c 1 |
| 140 | tclean s l |
| 141 | end |
| 142 | note A size the object does not have: dup made, proven wrong by RM_MAP_MEMORY, then freed. |
| 143 | note maps is how many RM_MAP_MEMORY calls RM accepts on the way (the probe, for a larger object). |
| 144 | fn tsize want ulong maps ulong to void |
| 145 | d = get fcnt 2 |
| 146 | f = get fcnt 3 |
| 147 | m = get fcnt 4 |
| 148 | s = tslots |
| 149 | l = fklivecnt get nvobj 0 |
| 150 | tcheck eq nvimport want false neg long 1 |
| 151 | tcheck eq get nverr 0 neg long 34 |
| 152 | tcheck eq get fcnt 2 add d 1 |
| 153 | tcheck eq get fcnt 3 add f 1 |
| 154 | tcheck eq get fcnt 4 add m maps |
| 155 | tclean s l |
| 156 | end |
| 157 | |
| 158 | fn town to long |
| 159 | m = nvalloc 8192 false |
| 160 | tcheck gt m 0 |
| 161 | s = nvfind m |
| 162 | tcheck lt s 96 |
| 163 | h = get nvmobj s |
| 164 | tcheck nvexport m |
| 165 | tcheck eq get fcnt 1 1 |
| 166 | tcheck eq get flast 4 0 |
| 167 | tcheck eq ulong get flast 5 kshdupbit |
| 168 | tcheck eq ulong get flast 6 kshtoken |
| 169 | tcheck eq get flast 7 0 |
| 170 | tcheck eq get nvshrec 0 79 |
| 171 | tcheck eq get nvshrec 1 77 |
| 172 | tcheck eq get nvshrec 2 90 |
| 173 | tcheck eq get nvshrec 3 67 |
| 174 | tcheck eq nvshget 4 1 |
| 175 | tcheck eq nvshget 8 get nvobj 0 |
| 176 | tcheck eq nvshget 12 h |
| 177 | tcheck eq nvshg64 16 8192 |
| 178 | tcheck eq get fkshr fkfind get nvobj 0 h 1 |
| 179 | note Export refusals: unknown mapping, faulted context. No RM call either way. |
| 180 | c = get fcnt 0 |
| 181 | tcheck not nvexport 777 |
| 182 | tcheck eq get nverr 0 neg long 22 |
| 183 | put nvfault 0 1 |
| 184 | tcheck not nvexport m |
| 185 | tcheck eq get nverr 0 neg long 5 |
| 186 | put nvfault 0 0 |
| 187 | tcheck eq get fcnt 0 c |
| 188 | tcheck eq get fcnt 1 1 |
| 189 | note Same-process import of the owner's record aliases the owner's pages. |
| 190 | tfill m 8192 11 |
| 191 | i = nvimport 8192 false |
| 192 | tcheck gt i 0 |
| 193 | tcheck ne i m |
| 194 | tverify i 8192 11 |
| 195 | tfill i 8192 23 |
| 196 | tverify m 8192 23 |
| 197 | tcheck nvdrop i |
| 198 | tverify m 8192 23 |
| 199 | ret m |
| 200 | end |
| 201 | fn tforeign to void |
| 202 | note Owner process B (RM client 2000001) shares object 5001; this process imports it. |
| 203 | fi = fkforeign 2000001 5001 16384 true |
| 204 | b = get fkbk fi |
| 205 | tfill get fbview b 16384 7 |
| 206 | trec 2000001 5001 16384 |
| 207 | d = get fcnt 2 |
| 208 | s = tslots |
| 209 | i = nvimport 16384 false |
| 210 | tcheck gt i 0 |
| 211 | tcheck eq tslots add s 1 |
| 212 | tcheck eq get fcnt 2 add d 1 |
| 213 | tcheck eq ulong and get flast 0 3 0 |
| 214 | tcheck eq get flast 3 3 |
| 215 | tcheck eq ulong and get flast 1 3 0 |
| 216 | tcheck eq ulong get flast 2 kextrw |
| 217 | tcheck eq ulong get flast 8 kdupflagsnone |
| 218 | tverify i 16384 7 |
| 219 | tfill i 16384 41 |
| 220 | tverify get fbview b 16384 41 |
| 221 | note Read-only import of the same object. |
| 222 | ro = nvimport 16384 true |
| 223 | tcheck gt ro 0 |
| 224 | tcheck eq ulong and get flast 0 3 kmapro |
| 225 | tcheck eq get flast 3 1 |
| 226 | tcheck eq ulong and get flast 1 3 kdmaro |
| 227 | tcheck eq ulong get flast 2 kextro |
| 228 | tverify ro 16384 41 |
| 229 | note An import is not re-exportable. |
| 230 | c = get fcnt 0 |
| 231 | tcheck not nvexport i |
| 232 | tcheck eq get nverr 0 neg long 1 |
| 233 | tcheck eq get fcnt 0 c |
| 234 | note Owner frees first: the backing lives on through both dups. |
| 235 | r = get fcnt 12 |
| 236 | fkunobj fi |
| 237 | tcheck eq get fcnt 12 r |
| 238 | tverify i 16384 41 |
| 239 | tverify ro 16384 41 |
| 240 | u = get fcnt 9 |
| 241 | x = get fcnt 6 |
| 242 | f = get fcnt 3 |
| 243 | tcheck nvdrop i |
| 244 | tcheck eq get fcnt 9 add u 1 |
| 245 | tcheck eq get fcnt 6 add x 1 |
| 246 | tcheck eq get fcnt 3 add f 1 |
| 247 | tcheck eq get fcnt 12 r |
| 248 | tcheck nvdrop ro |
| 249 | tcheck eq get fcnt 12 add r 1 |
| 250 | tcheck eq tslots s |
| 251 | end |
| 252 | fn tnegative m long to void |
| 253 | f2 = fkforeign 2000001 5002 8192 true |
| 254 | f3 = fkforeign 2000001 5003 8192 false |
| 255 | f4 = fkforeign 2000001 5004 16384 true |
| 256 | note Wrong handle, wrong client, object not shared. |
| 257 | trec 2000001 5099 8192 |
| 258 | trmref 8192 kerrnotfound |
| 259 | trec 3000001 5002 8192 |
| 260 | trmref 8192 kerrclient |
| 261 | trec 2000001 5003 8192 |
| 262 | trmref 8192 kerrperm |
| 263 | note Size mismatch against the real object, both directions. |
| 264 | trec 2000001 5002 16384 |
| 265 | tsize 16384 0 |
| 266 | trec 2000001 5004 8192 |
| 267 | tsize 8192 1 |
| 268 | note Caller's expected size differs from the record. |
| 269 | trec 2000001 5002 8192 |
| 270 | tnocall 4096 neg long 34 |
| 271 | note Malformed records. |
| 272 | trec 2000001 5002 8192 |
| 273 | put nvshrec 0 80 |
| 274 | tnocall 8192 neg long 22 |
| 275 | trec 2000001 5002 8192 |
| 276 | put nvshrec 4 2 |
| 277 | tnocall 8192 neg long 22 |
| 278 | trec 0 5002 8192 |
| 279 | tnocall 8192 neg long 22 |
| 280 | trec 2000001 0 8192 |
| 281 | tnocall 8192 neg long 22 |
| 282 | trec 2000001 5002 0 |
| 283 | tnocall 0 neg long 22 |
| 284 | trec 2000001 5002 4097 |
| 285 | tnocall 4097 neg long 22 |
| 286 | trec 2000001 5002 68719480832 |
| 287 | tnocall 68719480832 neg long 22 |
| 288 | note Faulted context. |
| 289 | trec 2000001 5002 8192 |
| 290 | put nvfault 0 1 |
| 291 | c = get fcnt 0 |
| 292 | tcheck eq nvimport 8192 false neg long 1 |
| 293 | tcheck eq get nverr 0 neg long 5 |
| 294 | tcheck eq get fcnt 0 c |
| 295 | put nvfault 0 0 |
| 296 | note GPU-side failure after the CPU map: quarantined slot and faulted context, as nvalloc. |
| 297 | s = tslots |
| 298 | put finj 0 kuvmrange |
| 299 | put finjst 0 uint kerrlimit |
| 300 | tcheck eq nvimport 8192 false neg long 1 |
| 301 | tcheck eq get nvfault 0 1 |
| 302 | tcheck eq tslots add s 1 |
| 303 | q = ulong 96 |
| 304 | for i ulong 96 |
| 305 | if and ne get nvmflag i 0 ne i nvfind m |
| 306 | q = i |
| 307 | end |
| 308 | end |
| 309 | tcheck lt q 96 |
| 310 | tcheck eq get nvmflag q 3 |
| 311 | tcheck nvmrel q |
| 312 | tcheck eq tslots s |
| 313 | put nvfault 0 0 |
| 314 | end |
| 315 | fn tall to int |
| 316 | tsetup |
| 317 | m = town |
| 318 | tforeign |
| 319 | tnegative m |
| 320 | tcheck nvdrop m |
| 321 | tcheck eq tslots 0 |
| 322 | tcheck eq fklivecnt get nvobj 0 0 |
| 323 | tcheck eq get fcnt 10 get fcnt 11 |
| 324 | for j ulong 16 |
| 325 | tcheck eq get frlive j 0 |
| 326 | tcheck eq get fdmlive j 0 |
| 327 | end |
| 328 | w = write 1 tok 0 len tok |
| 329 | ret 0 |
| 330 | end |
| 331 | fn trowrite to int |
| 332 | tsetup |
| 333 | fi = fkforeign 2000001 6001 8192 true |
| 334 | trec 2000001 6001 8192 |
| 335 | ro = nvimport 8192 true |
| 336 | tcheck gt ro 0 |
| 337 | w = write 1 tarmed 0 len tarmed |
| 338 | x = mapwrite ro 0 tbuf 0 1 |
| 339 | ret 1 |
| 340 | end |