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/native/nvml/api.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 / native / nvml / api.om` 467 lines · 15407 bytes Raw Blame History 1 note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 2 note api.om: the CUDA++ libnvidia-ml subset as an omega-bridge cabi-1 library unit (omega-bridge#83). 3 note tools/bridge-seeded lib-c, lib-h and lib-map lower it to compat/nvml/libnvidia-ml.c, compat/nvml/nvml.h 4 note and compat/nvml/libnvidia-ml.map; tests/nvml/gate.om regenerates all three and compares them byte for byte. 5 note Types, values and prototypes follow CUDA 13.0 nvml.h (the 55 facts in tests/nvml/abi.om). The request 6 note protocol, RM construction and error text stay in nvml.om, query.om and errstr.om, imported below; this 7 note unit owns the protocol loop, the action dispatch to the #281 transport, the copy bounds and the string 8 note cache that compat/nvml/cudapp_nvml.c held in handwritten C. 9 note cabi library libnvidia-ml.so.1 header nvml.h 10 note cabi lock NvLock process mutex 11 note cabi status nvmlReturn_t nvmlReturn_enum int32 trap 999 12 note cabi value nvmlReturn_t NVML_SUCCESS 0 13 note cabi value nvmlReturn_t NVML_ERROR_UNINITIALIZED 1 14 note cabi value nvmlReturn_t NVML_ERROR_INVALID_ARGUMENT 2 15 note cabi value nvmlReturn_t NVML_ERROR_NOT_SUPPORTED 3 16 note cabi value nvmlReturn_t NVML_ERROR_NO_PERMISSION 4 17 note cabi value nvmlReturn_t NVML_ERROR_ALREADY_INITIALIZED 5 18 note cabi value nvmlReturn_t NVML_ERROR_NOT_FOUND 6 19 note cabi value nvmlReturn_t NVML_ERROR_INSUFFICIENT_SIZE 7 20 note cabi value nvmlReturn_t NVML_ERROR_INSUFFICIENT_POWER 8 21 note cabi value nvmlReturn_t NVML_ERROR_DRIVER_NOT_LOADED 9 22 note cabi value nvmlReturn_t NVML_ERROR_TIMEOUT 10 23 note cabi value nvmlReturn_t NVML_ERROR_IRQ_ISSUE 11 24 note cabi value nvmlReturn_t NVML_ERROR_LIBRARY_NOT_FOUND 12 25 note cabi value nvmlReturn_t NVML_ERROR_FUNCTION_NOT_FOUND 13 26 note cabi value nvmlReturn_t NVML_ERROR_CORRUPTED_INFOROM 14 27 note cabi value nvmlReturn_t NVML_ERROR_GPU_IS_LOST 15 28 note cabi value nvmlReturn_t NVML_ERROR_RESET_REQUIRED 16 29 note cabi value nvmlReturn_t NVML_ERROR_OPERATING_SYSTEM 17 30 note cabi value nvmlReturn_t NVML_ERROR_LIB_RM_VERSION_MISMATCH 18 31 note cabi value nvmlReturn_t NVML_ERROR_IN_USE 19 32 note cabi value nvmlReturn_t NVML_ERROR_MEMORY 20 33 note cabi value nvmlReturn_t NVML_ERROR_NO_DATA 21 34 note cabi value nvmlReturn_t NVML_ERROR_VGPU_ECC_NOT_SUPPORTED 22 35 note cabi value nvmlReturn_t NVML_ERROR_INSUFFICIENT_RESOURCES 23 36 note cabi value nvmlReturn_t NVML_ERROR_FREQ_NOT_SUPPORTED 24 37 note cabi value nvmlReturn_t NVML_ERROR_ARGUMENT_VERSION_MISMATCH 25 38 note cabi value nvmlReturn_t NVML_ERROR_DEPRECATED 26 39 note cabi value nvmlReturn_t NVML_ERROR_NOT_READY 27 40 note cabi value nvmlReturn_t NVML_ERROR_GPU_NOT_FOUND 28 41 note cabi value nvmlReturn_t NVML_ERROR_INVALID_STATE 29 42 note cabi value nvmlReturn_t NVML_ERROR_RESET_TYPE_NOT_SUPPORTED 30 43 note cabi value nvmlReturn_t NVML_ERROR_UNKNOWN 999 44 note cabi enum nvmlTemperatureSensors_t nvmlTemperatureSensors_enum uint32 45 note cabi value nvmlTemperatureSensors_t NVML_TEMPERATURE_GPU 0 46 note cabi value nvmlTemperatureSensors_t NVML_TEMPERATURE_COUNT 1 47 note cabi define NVML_VALUE_NOT_AVAILABLE (-1) 48 note cabi define NVML_DEVICE_UUID_BUFFER_SIZE 80 49 note cabi define NVML_DEVICE_UUID_V2_BUFFER_SIZE 96 50 note cabi define NVML_DEVICE_NAME_BUFFER_SIZE 64 51 note cabi define NVML_DEVICE_NAME_V2_BUFFER_SIZE 96 52 note cabi aliasguard NVML_NO_UNVERSIONED_FUNC_DEFS 53 note cabi alias nvmlInit nvmlInit_v2 54 note cabi alias nvmlDeviceGetCount nvmlDeviceGetCount_v2 55 note cabi alias nvmlDeviceGetHandleByIndex nvmlDeviceGetHandleByIndex_v2 56 note cabi alias nvmlDeviceGetComputeRunningProcesses nvmlDeviceGetComputeRunningProcesses_v3 57 note cabi handle nvmlDevice_t nvmlDevice_st pool NvDevs count 8 lock NvLock 58 note cabi record nvmlUtilization_t nvmlUtilization_st size 8 align 4 59 note cabi field nvmlUtilization_t gpu uint32 0 60 note cabi field nvmlUtilization_t memory uint32 4 61 note cabi record nvmlMemory_t nvmlMemory_st size 24 align 8 62 note cabi field nvmlMemory_t total uint64 0 63 note cabi field nvmlMemory_t free uint64 8 64 note cabi field nvmlMemory_t used uint64 16 65 note cabi record nvmlProcessInfo_v2_t nvmlProcessInfo_v2_st size 24 align 8 alias nvmlProcessInfo_t 66 note cabi field nvmlProcessInfo_v2_t pid uint32 0 67 note cabi field nvmlProcessInfo_v2_t usedGpuMemory uint64 8 68 note cabi field nvmlProcessInfo_v2_t gpuInstanceId uint32 16 69 note cabi field nvmlProcessInfo_v2_t computeInstanceId uint32 20 70 note State: NvS the 128-word step state, NvB the step buffer (request at 0, payload at 4608, output at 60496), 71 note NvR the import result word, NvT the 32 cached error strings of 64 bytes, NvO the errstr scratch (0..63) 72 note and the per-slot cache flags (64..95). 73 note cabi state NvS ulong 128 process lock NvLock 74 note cabi state NvB uchar 83296 process lock NvLock 75 note cabi state NvR ulong 1 process lock NvLock 76 note cabi state NvT uchar 2048 process lock NvLock 77 note cabi state NvO uchar 96 process lock NvLock 78 note cabi cstr NvT slots 32 width 64 fallback "Unknown Error" lock NvLock 79 note cabi export nvmlInit_v2 nv_init status nvmlReturn_t lock NvLock 80 note cabi bind nvmlInit_v2 s NvS 81 note cabi bind nvmlInit_v2 b NvB 82 note cabi bind nvmlInit_v2 r NvR 83 note cabi export nvmlShutdown nv_shut status nvmlReturn_t lock NvLock 84 note cabi bind nvmlShutdown s NvS 85 note cabi bind nvmlShutdown b NvB 86 note cabi bind nvmlShutdown r NvR 87 note cabi export nvmlErrorString nv_err cstr NvT lock NvLock 88 note cabi bind nvmlErrorString t NvT 89 note cabi bind nvmlErrorString o NvO 90 note cabi bind nvmlErrorString r NvR 91 note cabi arg nvmlErrorString result nvmlReturn_t 92 note cabi export nvmlDeviceGetCount_v2 nv_count status nvmlReturn_t lock NvLock 93 note cabi bind nvmlDeviceGetCount_v2 s NvS 94 note cabi bind nvmlDeviceGetCount_v2 b NvB 95 note cabi bind nvmlDeviceGetCount_v2 r NvR 96 note cabi arg nvmlDeviceGetCount_v2 deviceCount nullable out uint32 commit 0 97 note cabi export nvmlDeviceGetHandleByIndex_v2 nv_handle status nvmlReturn_t lock NvLock 98 note cabi bind nvmlDeviceGetHandleByIndex_v2 s NvS 99 note cabi bind nvmlDeviceGetHandleByIndex_v2 b NvB 100 note cabi bind nvmlDeviceGetHandleByIndex_v2 r NvR 101 note cabi arg nvmlDeviceGetHandleByIndex_v2 index uint32 102 note cabi arg nvmlDeviceGetHandleByIndex_v2 device nullable out nvmlDevice_t commit 0 103 note cabi export nvmlDeviceGetName nv_name status nvmlReturn_t lock NvLock 104 note cabi bind nvmlDeviceGetName s NvS 105 note cabi bind nvmlDeviceGetName b NvB 106 note cabi bind nvmlDeviceGetName r NvR 107 note cabi arg nvmlDeviceGetName device nvmlDevice_t 108 note cabi arg nvmlDeviceGetName name nullable out char length length commit 0 data NvB 60496 109 note cabi arg nvmlDeviceGetName length uint32 110 note cabi export nvmlDeviceGetUUID nv_uuid status nvmlReturn_t lock NvLock 111 note cabi bind nvmlDeviceGetUUID s NvS 112 note cabi bind nvmlDeviceGetUUID b NvB 113 note cabi bind nvmlDeviceGetUUID r NvR 114 note cabi arg nvmlDeviceGetUUID device nvmlDevice_t 115 note cabi arg nvmlDeviceGetUUID uuid nullable out char length length commit 0 data NvB 60496 116 note cabi arg nvmlDeviceGetUUID length uint32 117 note cabi export nvmlDeviceGetTemperature nv_temp status nvmlReturn_t lock NvLock 118 note cabi bind nvmlDeviceGetTemperature s NvS 119 note cabi bind nvmlDeviceGetTemperature b NvB 120 note cabi bind nvmlDeviceGetTemperature r NvR 121 note cabi arg nvmlDeviceGetTemperature device nvmlDevice_t 122 note cabi arg nvmlDeviceGetTemperature sensorType nvmlTemperatureSensors_t 123 note cabi arg nvmlDeviceGetTemperature temp nullable out uint32 commit 0 124 note cabi export nvmlDeviceGetMemoryInfo nv_mem status nvmlReturn_t lock NvLock 125 note cabi bind nvmlDeviceGetMemoryInfo s NvS 126 note cabi bind nvmlDeviceGetMemoryInfo b NvB 127 note cabi bind nvmlDeviceGetMemoryInfo r NvR 128 note cabi arg nvmlDeviceGetMemoryInfo device nvmlDevice_t 129 note cabi arg nvmlDeviceGetMemoryInfo memory nullable out nvmlMemory_t commit 0 data NvB 60496 130 note cabi export nvmlDeviceGetUtilizationRates nv_util status nvmlReturn_t lock NvLock 131 note cabi bind nvmlDeviceGetUtilizationRates s NvS 132 note cabi bind nvmlDeviceGetUtilizationRates b NvB 133 note cabi bind nvmlDeviceGetUtilizationRates r NvR 134 note cabi arg nvmlDeviceGetUtilizationRates device nvmlDevice_t 135 note cabi arg nvmlDeviceGetUtilizationRates utilization nullable out nvmlUtilization_t commit 0 data NvB 60496 136 note cabi export nvmlDeviceGetComputeRunningProcesses_v3 nv_procs status nvmlReturn_t lock NvLock 137 note cabi bind nvmlDeviceGetComputeRunningProcesses_v3 s NvS 138 note cabi bind nvmlDeviceGetComputeRunningProcesses_v3 b NvB 139 note cabi bind nvmlDeviceGetComputeRunningProcesses_v3 r NvR 140 note cabi arg nvmlDeviceGetComputeRunningProcesses_v3 device nvmlDevice_t 141 note cabi arg nvmlDeviceGetComputeRunningProcesses_v3 infoCount nullable inout uint32 commit 1 142 note cabi arg nvmlDeviceGetComputeRunningProcesses_v3 infos nullable out nvmlProcessInfo_v2_t count infoCount commit 2 data NvB 60496 143 note cabi import nv_step omega_nvml_step result r span s 0 sn span b 0 bn 144 note cabi import nv_errs omega_nvml_errstr result r value code span o 0 on 145 note cabi import nv_ioctl omega2_nvrm_ioctl result r value fd value nr span b 0 hl span b 4608 pl 146 note cabi import nv_open omega2_nvrm_open_file result r span b 4608 pn 147 note cabi import nv_close omega2_nvrm_close_file result r value fd 148 149 note Import stubs: the bridge replaces each body with a checked call to the named C symbol. 150 fn nv_step r edit ulong 1 s edit ulong 128 sn ulong b edit uchar 83296 bn ulong to ulong 151 ret 0 152 end 153 154 fn nv_errs r edit ulong 1 code ulong o edit uchar 96 on ulong to ulong 155 ret 0 156 end 157 158 fn nv_ioctl r edit ulong 1 fd ulong nr ulong b edit uchar 83296 hl ulong pl ulong to ulong 159 ret 0 160 end 161 162 fn nv_open r edit ulong 1 b edit uchar 83296 pn ulong to ulong 163 ret 0 164 end 165 166 fn nv_close r edit ulong 1 fd ulong to ulong 167 ret 0 168 end 169 170 note nv_set: the operation and its four arguments in s[0..4]. 171 fn nv_set s edit ulong 128 op ulong a1 ulong a2 ulong a3 ulong a4 ulong to void 172 put s 0 op 173 put s 1 a1 174 put s 2 a2 175 put s 3 a3 176 put s 4 a4 177 end 178 179 note nv_act: perform the action the step requested (1 ioctl, 2 open, 3 close) and record the result in 180 note s[14] and the transport status in s[15]; 0 is a malformed request. 181 fn nv_act s edit ulong 128 b edit uchar 83296 r edit ulong 1 to ulong 182 k = get s 8 183 put r 0 0 184 st = ulong 0 185 if or eq k 0 gt k 3 186 ret 0 187 end 188 if eq k 1 189 hl = get s 11 190 pl = get s 12 191 if or gt hl 4608 gt pl 55888 192 ret 0 193 end 194 st = nv_ioctl r get s 9 get s 10 b hl pl 195 end 196 if eq k 2 197 pn = get s 13 198 if or eq pn 0 gt pn 55888 199 ret 0 200 end 201 st = nv_open r b pn 202 end 203 if eq k 3 204 st = nv_close r get s 9 205 end 206 put s 14 get r 0 207 put s 15 st 208 ret 1 209 end 210 211 note nv_run: step until the unit reports done (1) or the protocol fails (0), at most 4096 steps. 212 fn nv_run s edit ulong 128 b edit uchar 83296 r edit ulong 1 to ulong 213 ok = ulong 0 214 put s 22 0 215 for n ulong 4096 216 put r 0 1 217 c = nv_step r s 128 b 83296 218 if or ne c 0 ne get r 0 0 219 break 220 end 221 if eq get s 8 0 222 ok = 1 223 break 224 end 225 if eq nv_act s b r 0 226 break 227 end 228 end 229 put s 22 0 230 ret ok 231 end 232 233 note nv_fin: the copy bounds: at most cap output bytes, output only with a destination, a scalar only 234 note with a destination and below 2^32. 1 accepts the step's result. 235 fn nv_fin s edit ulong 128 cap ulong out ulong scl ulong to ulong 236 n = get s 7 237 if gt n cap 238 ret 0 239 end 240 if and ne n 0 eq out 0 241 ret 0 242 end 243 if ne get s 27 0 244 if or eq scl 0 gt get s 5 `4294967295` 245 ret 0 246 end 247 end 248 ret 1 249 end 250 251 note nv_code: the step's status when it is an nvmlReturn_t value, else NVML_ERROR_UNKNOWN. 252 fn nv_code s edit ulong 128 to ulong 253 v = get s 6 254 if or le v 30 eq v 999 255 ret v 256 end 257 ret 999 258 end 259 260 note nv_bare: Init and Shutdown. 261 fn nv_bare fr edit ulong 2 s edit ulong 128 b edit uchar 83296 r edit ulong 1 op ulong to ulong 262 nv_set s op 0 0 0 0 263 if eq nv_run s b r 0 264 ret 0 265 end 266 if eq nv_fin s 0 0 0 0 267 ret 0 268 end 269 put fr 0 nv_code s 270 ret 0 271 end 272 273 fn nv_init fr edit ulong 2 s edit ulong 128 b edit uchar 83296 r edit ulong 1 to ulong 274 ret nv_bare fr s b r 1 275 end 276 277 fn nv_shut fr edit ulong 2 s edit ulong 128 b edit uchar 83296 r edit ulong 1 to ulong 278 ret nv_bare fr s b r 2 279 end 280 281 note Count: f2 deviceCount present, f3 the count. 282 fn nv_count fr edit ulong 4 s edit ulong 128 b edit uchar 83296 r edit ulong 1 to ulong 283 p = get fr 2 284 nv_set s 3 0 p 0 0 285 if eq nv_run s b r 0 286 ret 0 287 end 288 if eq nv_fin s 0 0 p 0 289 ret 0 290 end 291 if ne get s 27 0 292 put fr 3 get s 5 293 put fr 1 1 294 end 295 put fr 0 nv_code s 296 ret 0 297 end 298 299 note HandleByIndex: f2 index, f3 device present, f4 the handle index (below the pool of 8). 300 fn nv_handle fr edit ulong 5 s edit ulong 128 b edit uchar 83296 r edit ulong 1 to ulong 301 nv_set s 4 get fr 2 get fr 3 0 0 302 if eq nv_run s b r 0 303 ret 0 304 end 305 if eq nv_fin s 0 0 1 0 306 ret 0 307 end 308 c = nv_code s 309 if eq c 0 310 v = ulong 0 311 if ne get s 27 0 312 v = get s 5 313 end 314 if ge v 8 315 ret 0 316 end 317 if ne get fr 3 0 318 put fr 4 v 319 put fr 1 1 320 end 321 end 322 put fr 0 c 323 ret 0 324 end 325 326 note Name and UUID: f2 device, f3 buffer present, f4 bytes written (with the NUL), f5 length. 327 fn nv_str fr edit ulong 6 s edit ulong 128 b edit uchar 83296 r edit ulong 1 op ulong to ulong 328 nv_set s op get fr 2 get fr 3 get fr 5 0 329 if eq nv_run s b r 0 330 ret 0 331 end 332 if eq nv_fin s get fr 5 get fr 3 0 0 333 ret 0 334 end 335 n = get s 7 336 if ne n 0 337 put fr 4 n 338 put fr 1 1 339 end 340 put fr 0 nv_code s 341 ret 0 342 end 343 344 fn nv_name fr edit ulong 6 s edit ulong 128 b edit uchar 83296 r edit ulong 1 to ulong 345 ret nv_str fr s b r 5 346 end 347 348 fn nv_uuid fr edit ulong 6 s edit ulong 128 b edit uchar 83296 r edit ulong 1 to ulong 349 ret nv_str fr s b r 6 350 end 351 352 note Temperature: f2 device, f3 sensor, f4 temp present, f5 the temperature. 353 fn nv_temp fr edit ulong 6 s edit ulong 128 b edit uchar 83296 r edit ulong 1 to ulong 354 p = get fr 4 355 nv_set s 7 get fr 2 p get fr 3 0 356 if eq nv_run s b r 0 357 ret 0 358 end 359 if eq nv_fin s 0 0 p 0 360 ret 0 361 end 362 if ne get s 27 0 363 put fr 5 get s 5 364 put fr 1 1 365 end 366 put fr 0 nv_code s 367 ret 0 368 end 369 370 note Memory (24 bytes) and utilization (8 bytes): f2 device, f3 record present. 371 fn nv_rec fr edit ulong 4 s edit ulong 128 b edit uchar 83296 r edit ulong 1 op ulong sz ulong to ulong 372 nv_set s op get fr 2 get fr 3 0 0 373 if eq nv_run s b r 0 374 ret 0 375 end 376 if eq nv_fin s sz get fr 3 0 0 377 ret 0 378 end 379 n = get s 7 380 if ne n 0 381 if ne n sz 382 ret 0 383 end 384 put fr 1 1 385 end 386 put fr 0 nv_code s 387 ret 0 388 end 389 390 fn nv_mem fr edit ulong 4 s edit ulong 128 b edit uchar 83296 r edit ulong 1 to ulong 391 ret nv_rec fr s b r 8 24 392 end 393 394 fn nv_util fr edit ulong 4 s edit ulong 128 b edit uchar 83296 r edit ulong 1 to ulong 395 ret nv_rec fr s b r 9 8 396 end 397 398 note Processes: f2 device, f3 infoCount present, f4 *infoCount, f5 infos present, f6 records written; 399 note the capacity is 24 bytes per requested entry. 400 fn nv_procs fr edit ulong 7 s edit ulong 128 b edit uchar 83296 r edit ulong 1 to ulong 401 p = get fr 3 402 w = ulong 0 403 if ne p 0 404 w = get fr 4 405 end 406 nv_set s 10 get fr 2 p w get fr 5 407 if eq nv_run s b r 0 408 ret 0 409 end 410 if eq nv_fin s mul w 24 get fr 5 p 0 411 ret 0 412 end 413 m = ulong 0 414 n = get s 7 415 if ne n 0 416 if ne rem n 24 0 417 ret 0 418 end 419 put fr 6 div n 24 420 m = 4 421 end 422 if ne get s 27 0 423 put fr 4 get s 5 424 m = add m 2 425 end 426 put fr 1 m 427 put fr 0 nv_code s 428 ret 0 429 end 430 431 note ErrorString: f0 the cache slot (32 selects the fallback), f1 the length, f2 the code. Each slot is 432 note filled once, so a returned pointer stays valid and unchanged for the life of the process. 433 fn nv_err fr edit ulong 3 t edit uchar 2048 o edit uchar 96 r edit ulong 1 to ulong 434 put fr 0 32 435 put fr 1 0 436 put r 0 0 437 c = nv_errs r get fr 2 o 64 438 if ne c 0 439 ret 0 440 end 441 v = get r 0 442 n = and v 255 443 k = and shr v 8 255 444 if or ge n 64 ge k 32 445 ret 0 446 end 447 z = mul k 64 448 if eq ulong get o add 64 k 0 449 for j ulong 64 450 put t add z j get o j 451 end 452 put t add z n uchar 0 453 put o add 64 k uchar 1 454 end 455 m = ulong 64 456 for i ulong 64 457 if and eq m 64 eq ulong get t add z i 0 458 m = i 459 end 460 end 461 if ge m 64 462 ret 0 463 end 464 put fr 0 k 465 put fr 1 m 466 ret 0 467 end