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 / smi / rmfake.om
| 1 | note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 2 | note rmfake.om: host-only stand-in for the NVIDIA resource manager, for the cudapp-smi --rm tier. |
| 3 | note tests/smi/run.sh rewrites every OS effect in private copies of native/nvrm/context.om and |
| 4 | note native/smi/util.om into the words below and appends this unit between them and native/smi/rm.om. |
| 5 | note No device file is opened. |
| 6 | note Replies imitate a GB10 with one GPU; they are synthetic, not a hardware record. |
| 7 | note SMIFAULT=<c> in the environment selects one fault: |
| 8 | note o open of the control node fails s subdevice reports a different SM version |
| 9 | note c name control fails (0x56) n name has no terminating zero |
| 10 | note t a thermal instruction is not executed |
| 11 | note p GET_PIDS count above its table f the device free fails |
| 12 | note u pstate control not supported m pstate reply has two bits set |
| 13 | note q pstate control refused with NV_ERR_INSUFFICIENT_PERMISSIONS (0x1b) |
| 14 | note w utilization control not supported e utilization ring empty (count 0) |
| 15 | note z newest utilization sample has a zero timestamp |
| 16 | note y utilization control refused with NV_ERR_INSUFFICIENT_PERMISSIONS (0x1b) |
| 17 | note r utilization tracker 72 (outside the ring) x newest gr.util 10001 |
| 18 | note Without a fault the pstate is P8 (0x100), the value nvidia-smi showed on the live GB10, and the |
| 19 | note utilization ring is full with tracker 5: the newest sample (index 4) holds gr 4200 and fb 1300 |
| 20 | note (42 % and 13 %); every other sample k holds gr 100*k and fb 50*k, so a wrong index is visible. |
| 21 | note Every control command outside the allowlist fails with 0x56 and logs "FAKE UNKNOWN". |
| 22 | note Each effect writes one stderr line "FAKE <what>" for the runner to count. |
| 23 | |
| 24 | text sfkey "SMIFAULT=" |
| 25 | text sfalc "FAKE alloc\n" |
| 26 | text sfctl "FAKE control\n" |
| 27 | text sffree "FAKE free\n" |
| 28 | text sfcls "FAKE close\n" |
| 29 | text sfopn "FAKE open\n" |
| 30 | text sfunk "FAKE UNKNOWN\n" |
| 31 | text sfbad "FAKE UNEXPECTED\n" |
| 32 | text sfgpu "NVIDIA GB10" |
| 33 | global sfenv uchar 256 |
| 34 | global sfst ulong 4 |
| 35 | |
| 36 | fn sflog t view uchar * to void |
| 37 | n = write 2 t 0 len t |
| 38 | end |
| 39 | |
| 40 | note Fault letter from SMIFAULT, read once (gst-like cache: sfst 0 = letter + 1, 0 unread). |
| 41 | fn sfmode to uchar |
| 42 | if ne get sfst 0 0 |
| 43 | ret uchar sub get sfst 0 1 |
| 44 | end |
| 45 | m = uchar 0 |
| 46 | ec = envcnt |
| 47 | for i ulong ulong ec |
| 48 | n = envread i sfenv 0 len sfenv |
| 49 | if le n long len sfkey |
| 50 | continue |
| 51 | end |
| 52 | same = true |
| 53 | for k ulong len sfkey |
| 54 | if ne get sfenv k get sfkey k |
| 55 | same = false |
| 56 | end |
| 57 | end |
| 58 | if same |
| 59 | m = get sfenv len sfkey |
| 60 | end |
| 61 | end |
| 62 | put sfst 0 add ulong m 1 |
| 63 | ret m |
| 64 | end |
| 65 | |
| 66 | fn sfcard to void |
| 67 | put nvcard 0 1 |
| 68 | put nvcard 16 0 |
| 69 | put nvcard 17 15 |
| 70 | end |
| 71 | |
| 72 | fn sfname bad bool to void |
| 73 | for i ulong len sfgpu |
| 74 | put nvpar add 4 i get sfgpu i |
| 75 | end |
| 76 | if bad |
| 77 | for i ulong 64 |
| 78 | put nvpar add 4 i 65 |
| 79 | end |
| 80 | end |
| 81 | end |
| 82 | |
| 83 | fn sftherm to void |
| 84 | n = ulong npget 20 |
| 85 | for k ulong n |
| 86 | o = add 24 mul k 44 |
| 87 | op = npget add o 8 |
| 88 | npput o 0 |
| 89 | npput add o 4 1 |
| 90 | if eq op 256 |
| 91 | npput add o 12 1 |
| 92 | end |
| 93 | if eq op 1280 |
| 94 | npput add o 12 1 |
| 95 | end |
| 96 | if eq op 257 |
| 97 | npput add o 16 1 |
| 98 | end |
| 99 | if eq op 1312 |
| 100 | npput add o 16 0 |
| 101 | end |
| 102 | if eq op 5376 |
| 103 | npput add o 16 37 |
| 104 | end |
| 105 | end |
| 106 | if eq sfmode 116 |
| 107 | npput 28 0 |
| 108 | end |
| 109 | end |
| 110 | |
| 111 | fn sfpinfo to void |
| 112 | n = ulong npget 0 |
| 113 | for i ulong n |
| 114 | o = add 8 mul i 72 |
| 115 | npput add o 8 0 |
| 116 | npp64 add o 16 add mul ulong 335 1048576 12345 |
| 117 | end |
| 118 | end |
| 119 | |
| 120 | note Utilization samples (NV2080_CTRL_CMD_PERF_GET_GPUMON_PERFMON_UTIL_SAMPLES_V2) into smbig. |
| 121 | note A request other than type 2 with bufSize 55872 is unexpected. |
| 122 | fn sfutil to uint |
| 123 | if or ne get smbig 0 2 ne sbget 4 55872 |
| 124 | sflog sfbad |
| 125 | ret 31 |
| 126 | end |
| 127 | if eq sfmode 119 |
| 128 | ret 86 |
| 129 | end |
| 130 | if eq sfmode 121 |
| 131 | ret 27 |
| 132 | end |
| 133 | if eq sfmode 101 |
| 134 | ret 0 |
| 135 | end |
| 136 | sbput 8 72 |
| 137 | if eq sfmode 114 |
| 138 | sbput 12 72 |
| 139 | else |
| 140 | sbput 12 5 |
| 141 | end |
| 142 | for k ulong 72 |
| 143 | o = add 16 mul k 776 |
| 144 | put smbig o 1 |
| 145 | sbput add o 136 uint mul k 100 |
| 146 | sbput add o 8 uint mul k 50 |
| 147 | end |
| 148 | o = ulong 3120 |
| 149 | sbput add o 136 4200 |
| 150 | sbput add o 8 1300 |
| 151 | if eq sfmode 120 |
| 152 | sbput add o 136 10001 |
| 153 | end |
| 154 | if eq sfmode 122 |
| 155 | put smbig o 0 |
| 156 | end |
| 157 | ret 0 |
| 158 | end |
| 159 | |
| 160 | fn sfctrl to uint |
| 161 | cmd = nhget 8 |
| 162 | sflog sfctl |
| 163 | if eq cmd 517 |
| 164 | npput 8 7 |
| 165 | ret 0 |
| 166 | end |
| 167 | if eq cmd 8389266 |
| 168 | npput 0 3 |
| 169 | npput 4 52928 |
| 170 | npput 8 51567 |
| 171 | npput 12 50017 |
| 172 | ret 0 |
| 173 | end |
| 174 | if eq cmd 545264168 |
| 175 | if eq sfmode 115 |
| 176 | npput 8 2561 |
| 177 | else |
| 178 | npput 8 2564 |
| 179 | end |
| 180 | ret 0 |
| 181 | end |
| 182 | if eq cmd 545259792 |
| 183 | if eq sfmode 99 |
| 184 | ret 86 |
| 185 | end |
| 186 | sfname eq sfmode 110 |
| 187 | ret 0 |
| 188 | end |
| 189 | if eq cmd 545260819 |
| 190 | sftherm |
| 191 | ret 0 |
| 192 | end |
| 193 | if eq cmd 545259917 |
| 194 | if eq sfmode 112 |
| 195 | npput 8 951 |
| 196 | else |
| 197 | npput 8 1 |
| 198 | npput 12 4242 |
| 199 | end |
| 200 | ret 0 |
| 201 | end |
| 202 | if eq cmd 545267816 |
| 203 | if eq sfmode 113 |
| 204 | ret 27 |
| 205 | end |
| 206 | if eq sfmode 117 |
| 207 | ret 86 |
| 208 | end |
| 209 | if eq sfmode 109 |
| 210 | npput 0 384 |
| 211 | else |
| 212 | npput 0 256 |
| 213 | end |
| 214 | ret 0 |
| 215 | end |
| 216 | if eq cmd 545259918 |
| 217 | sfpinfo |
| 218 | ret 0 |
| 219 | end |
| 220 | if eq cmd 545267862 |
| 221 | ret sfutil |
| 222 | end |
| 223 | sflog sfunk |
| 224 | ret 86 |
| 225 | end |
| 226 | |
| 227 | note Every RM ioctl request number context.om uses on the smi path; anything else is unexpected. |
| 228 | fn smdrv q uint to long |
| 229 | if eq q 3223340587 |
| 230 | sflog sfalc |
| 231 | if eq nhget 12 65 |
| 232 | nhput 8 3251634177 |
| 233 | end |
| 234 | nhput 28 0 |
| 235 | ret 0 |
| 236 | end |
| 237 | if eq q 3223340586 |
| 238 | nhput 28 sfctrl |
| 239 | ret 0 |
| 240 | end |
| 241 | if eq q 3222292009 |
| 242 | sflog sffree |
| 243 | if and eq sfmode 102 eq nhget 8 nvbad |
| 244 | nhput 12 86 |
| 245 | else |
| 246 | nhput 12 0 |
| 247 | end |
| 248 | ret 0 |
| 249 | end |
| 250 | if eq q 3523233480 |
| 251 | sfcard |
| 252 | ret 0 |
| 253 | end |
| 254 | if eq q 3221505737 |
| 255 | ret 0 |
| 256 | end |
| 257 | sflog sfbad |
| 258 | ret neg long 1 |
| 259 | end |
| 260 | |
| 261 | note The device handle context.om allocates first after the root (its handle counter start). |
| 262 | fn nvbad to uint |
| 263 | ret 3472883713 |
| 264 | end |
| 265 | |
| 266 | fn smfopen to long |
| 267 | sflog sfopn |
| 268 | if eq sfmode 111 |
| 269 | ret neg long 2 |
| 270 | end |
| 271 | put sfst 1 add get sfst 1 1 |
| 272 | ret long add 39 get sfst 1 |
| 273 | end |
| 274 | |
| 275 | fn smclose fd int to long |
| 276 | sflog sfcls |
| 277 | if or lt fd 40 gt fd 41 |
| 278 | sflog sfbad |
| 279 | ret neg long 9 |
| 280 | end |
| 281 | ret 0 |
| 282 | end |
| 283 | |
| 284 | fn smbad to long |
| 285 | sflog sfbad |
| 286 | ret neg long 1 |
| 287 | end |
| 288 | |
| 289 | fn smget m long off ulong w ulong to ulong |
| 290 | sflog sfbad |
| 291 | ret 0 |
| 292 | end |
| 293 | |
| 294 | fn smaddr m long to ulong |
| 295 | sflog sfbad |
| 296 | ret 0 |
| 297 | end |