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/omega-mv/blob/main/gpu/nvidia/native/nvml/query.om # omega-mv Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance. Brought by drakestapleton Sign in to star 1 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-mv / gpu / nvidia / native / nvml / query.om` 486 lines ยท 9221 bytes Raw Blame History 1 note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 2 note query.om: the device queries of compat/nvml, after nvml.om. Every query first checks, in order: 3 note a live library (else UNINITIALIZED 1), the GPU index s 1 below the count and a non-null output 4 note s 2 (else INVALID_ARGUMENT 2), as nvml.h:4432-4443 and its siblings document. 5 6 fn pre s edit ulong SN to ulong 7 if eq get s 17 0 8 ret 1 9 end 10 if ge get s 1 get s 21 11 ret 2 12 end 13 if eq get s 2 0 14 ret 2 15 end 16 ret 0 17 end 18 19 fn hsub s edit ulong SN to ulong 20 ret get s dv get s 1 5 21 end 22 23 fn scal s edit ulong SN v ulong to void 24 put s 5 v 25 put s 27 1 26 end 27 28 note nvmlDeviceGetCount_v2 (nvml.h:4221) and nvmlDeviceGetHandleByIndex_v2 (nvml.h:4289). 29 fn count s edit ulong SN to void 30 if eq get s 17 0 31 done s 1 32 ret 33 end 34 if eq get s 2 0 35 done s 2 36 ret 37 end 38 scal s get s 21 39 done s 0 40 end 41 42 fn handle s edit ulong SN to void 43 e = pre s 44 if ne e 0 45 done s e 46 ret 47 end 48 scal s get s 1 49 done s 0 50 end 51 52 note nvmlDeviceGetName (nvml.h:4432): NV2080_CTRL_CMD_GPU_GET_NAME_STRING (0x20800110, 53 note ctrl2080gpu.h:318), 132-byte params, flags 0 (ASCII) at 0, the name at 4. The name must be 54 note printable ASCII of 1..95 bytes ended by a zero within its 128 bytes. A length s 3 below the name 55 note plus its terminator is INSUFFICIENT_SIZE (7). 56 fn name s edit ulong SN b edit uchar BN to void 57 if eq get s 22 0 58 e = pre s 59 if ne e 0 60 done s e 61 ret 62 end 63 bzero b PO 132 64 ctl s b hsub s `545259792` 132 65 put s 22 1 66 ret 67 end 68 e = chk s b 28 69 if ne e 0 70 done s e 71 ret 72 end 73 if ne g32 b PO 0 74 done s 999 75 ret 76 end 77 n = ulong 0 78 z = false 79 for i ulong 128 80 c = get b add add PO 4 i 81 if not z 82 if eq c 0 83 z = true 84 n = i 85 else 86 if or lt c 32 gt c 126 87 done s 999 88 ret 89 end 90 end 91 end 92 end 93 if or not z or eq n 0 gt n 95 94 done s 999 95 ret 96 end 97 if lt get s 3 add n 1 98 done s 7 99 ret 100 end 101 for i ulong n 102 put b add OO i get b add add PO 4 i 103 end 104 put b add OO n 0 105 put s 7 add n 1 106 done s 0 107 end 108 109 fn hexc d ulong to uchar 110 if lt d 10 111 ret uchar add 48 d 112 end 113 ret uchar add 87 d 114 end 115 116 note nvmlDeviceGetUUID (nvml.h:4816): NV2080_CTRL_CMD_GPU_GET_GID_INFO (0x2080014a, 117 note ctrl2080gpu.h:1775-1798), 268-byte params: index 0, flags 4 = 2 (BINARY, SHA1), length 8 = 16, 118 note data 12. Printed as nvidia-smi does: GPU- then 8-4-4-4-12 lower-case hex, 40 bytes plus a zero. 119 fn uuid s edit ulong SN b edit uchar BN to void 120 if eq get s 22 0 121 e = pre s 122 if ne e 0 123 done s e 124 ret 125 end 126 bzero b PO 268 127 p32 b add PO 4 2 128 ctl s b hsub s `545259850` 268 129 put s 22 1 130 ret 131 end 132 e = chk s b 28 133 if ne e 0 134 done s e 135 ret 136 end 137 if ne g32 b add PO 8 16 138 done s 999 139 ret 140 end 141 if lt get s 3 41 142 done s 7 143 ret 144 end 145 put b OO 71 146 put b add OO 1 80 147 put b add OO 2 85 148 put b add OO 3 45 149 n = add OO 4 150 for i ulong 16 151 if or or eq i 4 eq i 6 or eq i 8 eq i 10 152 put b n 45 153 n = add n 1 154 end 155 v = ulong get b add add PO 12 i 156 put b n hexc shr v 4 157 put b add n 1 hexc and v 15 158 n = add n 2 159 end 160 put b n 0 161 put s 7 41 162 done s 0 163 end 164 165 note Thermal instructions (NV2080_CTRL_CMD_THERMAL_SYSTEM_EXECUTE_V2 0x20800513, ctrl2080thermal.h:135), 166 note 1432-byte params: API version 1 at 0, instruction size 44 at 8, count at 20, 32 instructions 167 note from 24, opcode at +8, operands at +12 and +16, executed flag +4 and result +0. 168 fn thins b edit uchar BN k ulong op ulong a ulong to void 169 o = add add PO 24 mul k 44 170 p32 b add o 8 op 171 p32 b add o 12 a 172 end 173 174 fn thgo s edit ulong SN b edit uchar BN n ulong to void 175 p32 b PO 1 176 p32 b add PO 8 44 177 p32 b add PO 20 n 178 ctl s b hsub s `545260819` 1432 179 end 180 181 fn thok b edit uchar BN n ulong to bool 182 for k ulong n 183 o = add add PO 24 mul k 44 184 if or ne g32 b add o 4 1 ne g32 b o 0 185 ret false 186 end 187 end 188 ret true 189 end 190 191 fn thread s edit ulong SN b edit uchar BN to void 192 nt = get s 25 193 ns = get s 26 194 for k ulong ns 195 q = add nt mul k 2 196 tg = g32 b add add add PO 24 mul q 44 16 197 if ge tg nt 198 done s 999 199 ret 200 end 201 if eq g32 b add add add PO 24 mul tg 44 16 1 202 v = g32 b add add add PO 24 mul add q 1 44 16 203 if ge v `2147483648` 204 done s 999 205 ret 206 end 207 scal s v 208 done s 0 209 ret 210 end 211 end 212 done s 3 213 end 214 215 note nvmlDeviceGetTemperature (nvml.h:5571), sensor s 3 must be NVML_TEMPERATURE_GPU (0, nvml.h:936). 216 note Pass 1 counts targets (opcode 256) and sensors (1280); pass 2 asks each target's type (257) and 217 note each sensor's target (1312) and reading (5376). The first sensor on a GPU-type (1) target 218 note answers; none is NOT_SUPPORTED (3). More than 32 instructions or a negative reading is UNKNOWN. 219 fn temp s edit ulong SN b edit uchar BN to void 220 pc = get s 22 221 if eq pc 0 222 e = pre s 223 if ne e 0 224 done s e 225 ret 226 end 227 if ne get s 3 0 228 done s 2 229 ret 230 end 231 bzero b PO 1432 232 thins b 0 256 0 233 thins b 1 1280 0 234 thgo s b 2 235 put s 22 1 236 ret 237 end 238 e = chk s b 28 239 if ne e 0 240 done s e 241 ret 242 end 243 if eq pc 2 244 if not thok b add get s 25 mul get s 26 2 245 done s 999 246 ret 247 end 248 thread s b 249 ret 250 end 251 if not thok b 2 252 done s 999 253 ret 254 end 255 nt = g32 b add PO 36 256 ns = g32 b add PO 80 257 if gt add nt mul ns 2 32 258 done s 999 259 ret 260 end 261 if eq ns 0 262 done s 3 263 ret 264 end 265 put s 25 nt 266 put s 26 ns 267 bzero b PO 1432 268 for t ulong nt 269 thins b t 257 t 270 end 271 for k ulong ns 272 thins b add nt mul k 2 1312 k 273 thins b add add nt mul k 2 1 5376 k 274 end 275 thgo s b add nt mul ns 2 276 put s 22 2 277 end 278 279 note nvmlDeviceGetMemoryInfo (nvml.h:6330): NV2080_CTRL_CMD_FB_GET_INFO_V2 (0x20801303, 280 note ctrl2080fb.h:459), 1028-byte params: count 0, then {index, data} pairs from 4. Asks IS_ZERO_FB 281 note (0x36), TOTAL_RAM_SIZE (0x08) and HEAP_FREE (0x16), both in KiB (ctrl2080fb.h:310,328,360). A GPU 282 note without framebuffer is NOT_SUPPORTED (nvml.h:6352-6354). Output nvmlMemory_t {total, free, used}. 283 fn mem s edit ulong SN b edit uchar BN to void 284 if eq get s 22 0 285 e = pre s 286 if ne e 0 287 done s e 288 ret 289 end 290 bzero b PO 1028 291 p32 b PO 3 292 p32 b add PO 4 54 293 p32 b add PO 12 8 294 p32 b add PO 20 22 295 ctl s b hsub s `545264387` 1028 296 put s 22 1 297 ret 298 end 299 e = chk s b 28 300 if ne e 0 301 done s e 302 ret 303 end 304 if or or ne g32 b add PO 4 54 ne g32 b add PO 12 8 ne g32 b add PO 20 22 305 done s 999 306 ret 307 end 308 if ne g32 b add PO 8 0 309 done s 3 310 ret 311 end 312 t = g32 b add PO 16 313 f = g32 b add PO 24 314 if gt f t 315 done s 999 316 ret 317 end 318 p64 b OO mul t 1024 319 p64 b add OO 8 mul f 1024 320 p64 b add OO 16 mul sub t f 1024 321 put s 7 24 322 done s 0 323 end 324 325 note nvmlDeviceGetUtilizationRates (nvml.h:6671): the newest PERFMON sample as in native/smi/util.om, 326 note NV2080_CTRL_CMD_PERF_GET_GPUMON_PERFMON_UTIL_SAMPLES_V2 (0x20802096, ctrl2080perf.h:447-592), 327 note 55888-byte params: type 2 at 0, bufSize 55872 at 4, count 8, tracker 12, 72 samples of 776 from 328 note 16; newest at (tracker+71) mod 72, fb.util +8, gr.util +136 in percent*100. An empty ring or a 329 note malformed reply is UNKNOWN (999). Output nvmlUtilization_t {gpu, memory} in percent. 330 fn util s edit ulong SN b edit uchar BN to void 331 if eq get s 22 0 332 e = pre s 333 if ne e 0 334 done s e 335 ret 336 end 337 bzero b PO 55888 338 put b PO 2 339 p32 b add PO 4 55872 340 ctl s b hsub s `545267862` 55888 341 put s 22 1 342 ret 343 end 344 e = chk s b 28 345 if ne e 0 346 done s e 347 ret 348 end 349 c = g32 b add PO 8 350 r = g32 b add PO 12 351 if or gt c 72 ge r 72 352 done s 999 353 ret 354 end 355 o = add add PO 16 mul rem add r 71 72 776 356 if or eq c 0 eq g64 b o 0 357 done s 999 358 ret 359 end 360 g = g32 b add o 136 361 m = g32 b add o 8 362 if or gt g 10000 gt m 10000 363 done s 999 364 ret 365 end 366 p32 b OO div g 100 367 p32 b add OO 4 div m 100 368 put s 7 8 369 done s 0 370 end 371 372 note One NV2080_CTRL_CMD_GPU_GET_PID_INFO (0x2080018e, ctrl2080gpu.h:3590-3666) chunk of at most 200 373 note PIDs from s 23: count at 0, 72-byte entries from 8: pid 0, index 4 = 0 (VIDEO_MEMORY_USAGE), 374 note result 8, memPrivate 16. 375 fn pchunk s edit ulong SN b edit uchar BN to void 376 k = get s 23 377 m = sub get s 25 k 378 if gt m 200 379 m = 200 380 end 381 bzero b PO 14408 382 p32 b PO m 383 for i ulong m 384 p32 b add add PO 8 mul i 72 g32 b add OO mul add k i 24 385 end 386 put s 26 m 387 ctl s b hsub s `545259918` 14408 388 put s 22 2 389 end 390 391 fn pdone s edit ulong SN b edit uchar BN to void 392 e = chk s b 28 393 if ne e 0 394 done s e 395 ret 396 end 397 k = get s 23 398 for i ulong get s 26 399 o = add add PO 8 mul i 72 400 q = add OO mul add k i 24 401 if ne g32 b o g32 b q 402 done s 999 403 ret 404 end 405 if ne g32 b add o 8 0 406 p64 b add q 8 `18446744073709551615` 407 else 408 p64 b add q 8 g64 b add o 16 409 end 410 end 411 k = add k get s 26 412 put s 23 k 413 if lt k get s 25 414 pchunk s b 415 ret 416 end 417 scal s k 418 put s 7 mul k 24 419 done s 0 420 end 421 422 note nvmlDeviceGetComputeRunningProcesses_v3 (nvml.h:6944-6985): s 2 infoCount non-null, s 3 its 423 note value, s 4 infos non-null (may be null only when s 3 is 0). NV2080_CTRL_CMD_GPU_GET_PIDS 424 note (0x2080018d, ctrl2080gpu.h:3521-3540), 3812-byte params: idType 0 (CLASS), id 4 = the compute 425 note class, count 8 (at most 950), pids from 12. More PIDs than s 3 is INSUFFICIENT_SIZE with the 426 note count stored. Output nvmlProcessInfo_t {pid 0, usedGpuMemory 8, gpuInstanceId 16, 427 note computeInstanceId 20} (nvml.h:301-312), ids 0xFFFFFFFF without MIG; a failed PID entry reports 428 note usedGpuMemory NVML_VALUE_NOT_AVAILABLE (nvml.h:155). 429 fn procs s edit ulong SN b edit uchar BN to void 430 pc = get s 22 431 if eq pc 2 432 pdone s b 433 ret 434 end 435 if eq pc 0 436 e = pre s 437 if ne e 0 438 done s e 439 ret 440 end 441 if and eq get s 4 0 ne get s 3 0 442 done s 2 443 ret 444 end 445 c = get s dv get s 1 6 446 if eq c 0 447 done s 3 448 ret 449 end 450 bzero b PO 3812 451 p32 b add PO 4 c 452 ctl s b hsub s `545259917` 3812 453 put s 22 1 454 ret 455 end 456 e = chk s b 28 457 if ne e 0 458 done s e 459 ret 460 end 461 n = g32 b add PO 8 462 if gt n 950 463 done s 999 464 ret 465 end 466 if gt n get s 3 467 scal s n 468 done s 7 469 ret 470 end 471 if eq n 0 472 scal s 0 473 done s 0 474 ret 475 end 476 for i ulong n 477 q = add OO mul i 24 478 p32 b q g32 b add add PO 12 mul i 4 479 p64 b add q 8 0 480 p32 b add q 16 `4294967295` 481 p32 b add q 20 `4294967295` 482 end 483 put s 25 n 484 put s 23 0 485 pchunk s b 486 end