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 / nvml.om

492 lines · 9716 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
2note nvml.om: state, transport requests, error policy, nvmlInit_v2 and nvmlShutdown for compat/nvml.
3note Pure unit nvml_step (nvml.om, query.om, step.om). The generated library (native/nvml/api.om, lowered
4note to compat/nvml) owns no policy: it calls omega_nvml_step, performs the one action the step asks for
5note through omega2_nvrm_open_file, omega2_nvrm_close_file or omega2_nvrm_ioctl (native/nvrm/transport.om),
6note writes the result back and calls the step again until the step reports done.
7note RM layouts: open-gpu-kernel-modules 580.173.02 (commit 20e4e6e1), src/common/sdk/nvidia/inc.
8note Constants: evidence/NVML-2026-11-06/wolfram.txt.
9note
10note s (ulong 128), written by C: 0 op, 1..4 arguments, 14 action result, 15 omega2 status.
11note written by the step: 5 scalar output, 6 nvmlReturn_t, 7 bytes of b at OO to copy out,
12note 8 action (0 done, 1 ioctl, 2 open the path at PO of length 13, 3 close), 9 fd,
13note 10 ioctl nr, 11 header bytes at b 0, 12 params bytes at b PO, 27 store the scalar (1).
14note state: 16 init refcount, 17 phase (1 live), 18 control fd+1, 19 root client, 20 next handle,
15note 21 GPU count, 22 resume point, 23 loop index, 24 pending error, 25 cursor, 26 scratch.
16note GPU k (at most 8) at 32+8k: 0 fd+1, 1 minor, 2 gpuId, 3 deviceInstance, 4 device handle,
17note 5 subdevice handle, 6 compute class.
18note b (uchar 83296): header 0..4607, params PO..PO+55887, output OO..OO+22799.
19
20const SN ulong 128
21const BN ulong 83296
22const PO ulong 4608
23const OO ulong 60496
24
25fn g32 b edit uchar BN off ulong to ulong
26v = ulong 0
27for i ulong 4
28v = or v shl ulong get b add off i mul i 8
29end
30ret v
31end
32
33fn g64 b edit uchar BN off ulong to ulong
34v = ulong 0
35for i ulong 8
36v = or v shl ulong get b add off i mul i 8
37end
38ret v
39end
40
41fn p32 b edit uchar BN off ulong v ulong to void
42for i ulong 4
43put b add off i uchar and shr v mul i 8 255
44end
45end
46
47fn p64 b edit uchar BN off ulong v ulong to void
48for i ulong 8
49put b add off i uchar and shr v mul i 8 255
50end
51end
52
53fn bzero b edit uchar BN off ulong n ulong to void
54for i ulong n
55put b add off i 0
56end
57end
58
59fn dv k ulong f ulong to ulong
60ret add 32 add mul k 8 f
61end
62
63fn done s edit ulong SN code ulong to void
64put s 6 code
65put s 8 0
66put s 22 0
67end
68
69fn act s edit ulong SN k ulong fd ulong nr ulong hl ulong pl ulong to void
70put s 8 k
71put s 9 fd
72put s 10 nr
73put s 11 hl
74put s 12 pl
75end
76
77fn cfd s edit ulong SN to ulong
78ret sub get s 18 1
79end
80
81note NV_ESC_RM_CONTROL (nr 42), NVOS54 32-byte header: hClient 0, hObject 4, cmd 8, status 28.
82fn ctl s edit ulong SN b edit uchar BN obj ulong cmd ulong n ulong to void
83bzero b 0 32
84p32 b 0 get s 19
85p32 b 4 obj
86p32 b 8 cmd
87act s 1 cfd s 42 32 n
88end
89
90note NV_ESC_RM_ALLOC (nr 43), NVOS21 32-byte header: hRoot 0, parent 4, hObjectNew 8, hClass 12,
91note status 28. The root client (class 65, NV01_ROOT_CLIENT) takes its handle from RM.
92fn alc s edit ulong SN b edit uchar BN par ulong cls ulong n ulong to void
93bzero b 0 32
94p32 b 0 get s 19
95p32 b 4 par
96if ne cls 65
97p32 b 8 get s 20
98put s 20 add get s 20 1
99end
100p32 b 12 cls
101act s 1 cfd s 43 32 n
102end
103
104note NV_ESC_RM_FREE (nr 41), NVOS00 16-byte header: hRoot 0, parent 4, hObjectOld 8, status 12.
105fn rmfree s edit ulong SN b edit uchar BN root ulong par ulong obj ulong to void
106bzero b 0 16
107p32 b 0 root
108p32 b 4 par
109p32 b 8 obj
110act s 1 cfd s 41 16 0
111end
112
113note The device path /dev/nvidia<minor> or /dev/nvidiactl at PO; result its length.
114fn path b edit uchar BN minor ulong isctl ulong to ulong
115p64 b PO 7599382571363165231
116if eq isctl 1
117p64 b add PO 8 119247139334500
118ret 14
119end
120p32 b add PO 8 6383972
121n = add PO 11
122if ge minor 100
123put b n uchar add 48 div minor 100
124n = add n 1
125end
126if ge minor 10
127put b n uchar add 48 rem div minor 10 10
128n = add n 1
129end
130put b n uchar add 48 rem minor 10
131ret sub add n 1 PO
132end
133
134note Transport results are a long carried as its two's-complement bits in a ulong; -1 is
135note 18446744073709551615 (2^64-1), -2 ...614, -6 ...610, -13 ...603, -19 ...597.
136note An ioctl result: a nonzero omega2 status or an errno other than EPERM/EACCES (NO_PERMISSION 4)
137note is UNKNOWN (999).
138fn ioerr s edit ulong SN to ulong
139if ne get s 15 0
140ret 999
141end
142x = get s 14
143if eq x 0
144ret 0
145end
146if or eq x 18446744073709551615 eq x 18446744073709551603
147ret 4
148end
149ret 999
150end
151
152note An open result: ENOENT, ENXIO or ENODEV is DRIVER_NOT_LOADED (9), EPERM or EACCES NO_PERMISSION.
153note A non-negative result (below 2^63) is the descriptor.
154fn operr s edit ulong SN to ulong
155if ne get s 15 0
156ret 999
157end
158x = get s 14
159if lt x 9223372036854775808
160ret 0
161end
162if or or eq x 18446744073709551614 eq x 18446744073709551610 eq x 18446744073709551597
163ret 9
164end
165if or eq x 18446744073709551615 eq x 18446744073709551603
166ret 4
167end
168ret 999
169end
170
171note RM status (nvstatuscodes.h): 0x1B INSUFFICIENT_PERMISSIONS -> 4, 0x0F GPU_IS_LOST -> 15,
172note 0x56 NOT_SUPPORTED -> 3, anything else UNKNOWN.
173fn rmerr v ulong to ulong
174if eq v 0
175ret 0
176end
177if eq v 27
178ret 4
179end
180if eq v 15
181ret 15
182end
183if eq v 86
184ret 3
185end
186ret 999
187end
188
189fn chk s edit ulong SN b edit uchar BN off ulong to ulong
190e = ioerr s
191if ne e 0
192ret e
193end
194ret rmerr g32 b off
195end
196
197note Teardown, resume points 100 and 101: per GPU free the subdevice, free the device, close its fd;
198note then free the root client and close the control fd. Cursor s 25 walks items 0..25.
199fn tdtry s edit ulong SN b edit uchar BN t ulong to bool
200if lt t 24
201d = div t 3
202r = rem t 3
203if eq r 0
204x = get s dv d 5
205if ne x 0
206put s dv d 5 0
207rmfree s b get s 19 get s dv d 4 x
208ret true
209end
210ret false
211end
212if eq r 1
213x = get s dv d 4
214if ne x 0
215put s dv d 4 0
216rmfree s b get s 19 get s 19 x
217ret true
218end
219ret false
220end
221x = get s dv d 0
222if ne x 0
223put s dv d 0 0
224act s 3 sub x 1 0 0 0
225ret true
226end
227ret false
228end
229if eq t 24
230x = get s 19
231if ne x 0
232rmfree s b x x x
233put s 19 0
234ret true
235end
236ret false
237end
238x = get s 18
239if ne x 0
240act s 3 sub x 1 0 0 0
241put s 18 0
242ret true
243end
244ret false
245end
246
247fn tdstep s edit ulong SN b edit uchar BN to void
248for t ulong 26
249if ge t get s 25
250if tdtry s b t
251put s 25 add t 1
252put s 22 101
253ret
254end
255end
256end
257e = get s 24
258if eq e 0
259e = get s 26
260end
261for i ulong 96
262put s add 16 i 0
263end
264done s e
265end
266
267fn tdres s edit ulong SN b edit uchar BN to void
268e = ulong 0
269if eq get s 8 1
270e = chk s b 12
271else
272e = ioerr s
273end
274if ne e 0
275put s 26 999
276end
277tdstep s b
278end
279
280fn fail s edit ulong SN b edit uchar BN code ulong to void
281put s 24 code
282put s 25 0
283put s 26 0
284tdstep s b
285end
286
287note Next GPU: NV0000_CTRL_CMD_GPU_GET_ID_INFO_V2 (0x205, ctrl0000gpu.h:172-185) gives deviceInstance.
288fn devnext s edit ulong SN b edit uchar BN to void
289k = get s 23
290if ge k get s 21
291put s 17 1
292put s 16 1
293done s 0
294ret
295end
296bzero b PO 32
297p32 b PO get s dv k 2
298ctl s b get s 19 517 32
299put s 22 5
300end
301
302note NV_ESC_CARD_INFO (nr 200): 64 entries of 72 bytes, valid 0, gpu_id 16, minor_number 56.
303fn cards s edit ulong SN b edit uchar BN to void
304e = ioerr s
305if ne e 0
306fail s b e
307ret
308end
309n = ulong 0
310for i ulong 64
311o = mul i 72
312if ne get b o 0
313if ge n 8
314fail s b 999
315ret
316end
317m = g32 b add o 56
318if gt m 255
319fail s b 999
320ret
321end
322put s dv n 1 m
323put s dv n 2 g32 b add o 16
324n = add n 1
325end
326end
327put s 21 n
328put s 23 0
329devnext s b
330end
331
332note NV0080_CTRL_CMD_GPU_GET_CLASSLIST_V2 (0x800292, ctrl0080gpu.h:506): numClasses 0, classList 4.
333note 52928 is BLACKWELL_COMPUTE_B (0xCEC0), the class GET_PIDS filters on.
334fn clist s edit ulong SN b edit uchar BN k ulong to void
335n = g32 b PO
336if gt n 200
337fail s b 999
338ret
339end
340c = ulong 0
341for i ulong n
342if eq g32 b add add PO 4 mul i 4 52928
343c = 52928
344end
345end
346put s dv k 6 c
347put s 23 add k 1
348devnext s b
349end
350
351fn devstep s edit ulong SN b edit uchar BN pc ulong to void
352k = get s 23
353if eq pc 6
354e = operr s
355if ne e 0
356fail s b e
357ret
358end
359put s dv k 0 add get s 14 1
360bzero b 0 4
361p32 b 0 cfd s
362act s 1 get s 14 201 4 0
363put s 22 7
364ret
365end
366e = ulong 0
367if eq pc 7
368e = ioerr s
369else
370e = chk s b 28
371end
372if ne e 0
373fail s b e
374ret
375end
376if eq pc 5
377put s dv k 3 g32 b add PO 8
378n = path b get s dv k 1 0
379act s 2 0 0 0 0
380put s 13 n
381put s 22 6
382ret
383end
384if eq pc 7
385bzero b PO 56
386p32 b PO get s dv k 3
387p32 b add PO 4 get s 19
388alc s b get s 19 128 56
389put s 22 8
390ret
391end
392if eq pc 8
393put s dv k 4 g32 b 8
394bzero b PO 4
395alc s b get s dv k 4 8320 4
396put s 22 9
397ret
398end
399if eq pc 9
400put s dv k 5 g32 b 8
401bzero b PO 804
402ctl s b get s dv k 4 8389266 804
403put s 22 10
404ret
405end
406clist s b k
407end
408
409note nvmlInit_v2: a live library only counts the reference. Otherwise open /dev/nvidiactl, allocate
410note the root client, read the card table, then per GPU: id info, open and register its device
411note node, allocate NV01_DEVICE_0 (128) and NV20_SUBDEVICE_0 (8320), read the class list.
412note Any failure tears everything down and returns its code with the refcount still 0.
413fn init s edit ulong SN b edit uchar BN to void
414pc = get s 22
415if ge pc 100
416tdres s b
417ret
418end
419if eq pc 0
420if gt get s 16 0
421put s 16 add get s 16 1
422done s 0
423ret
424end
425for i ulong 96
426put s add 16 i 0
427end
428put s 20 3472883713
429n = path b 0 1
430act s 2 0 0 0 0
431put s 13 n
432put s 22 1
433ret
434end
435if eq pc 1
436e = operr s
437if ne e 0
438done s e
439ret
440end
441put s 18 add get s 14 1
442bzero b PO 4
443alc s b 0 65 0
444put s 22 2
445ret
446end
447if eq pc 2
448e = chk s b 28
449if ne e 0
450fail s b e
451ret
452end
453x = g32 b 8
454if eq x 0
455fail s b 999
456ret
457end
458put s 19 x
459bzero b 0 4608
460act s 1 cfd s 200 4608 0
461put s 22 3
462ret
463end
464if eq pc 3
465cards s b
466ret
467end
468devstep s b pc
469end
470
471note nvmlShutdown: UNINITIALIZED (1) without a live library; the last reference tears down and
472note reports UNKNOWN if any free or close failed (the library is closed either way).
473fn shut s edit ulong SN b edit uchar BN to void
474pc = get s 22
475if ge pc 100
476tdres s b
477ret
478end
479if eq get s 16 0
480done s 1
481ret
482end
483if gt get s 16 1
484put s 16 sub get s 16 1
485done s 0
486ret
487end
488put s 24 0
489put s 25 0
490put s 26 0
491tdstep s b
492end