interplane.Get Omega
Read in your language

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

branch main Branches Tags History

CUDApp / native / nvml / api.om

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