interplane.Get Omega
Read in your language

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

branch main Branches Tags History

omega-mv / gpu / nvidia / native / smi / rm.om

299 lines · 6306 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
2note rm.om: cudapp-smi resource-manager queries and main. Appended after smi.om, native/nvrm/context.om
3note and native/smi/util.om.
4note The --rm path opens /dev/nvidiactl and /dev/nvidia0 through nvstart and issues only read-only
5note subdevice controls (no memory allocation, no channel, no mapping), then frees every handle.
6note Control layouts: NVIDIA open-gpu-kernel-modules tag 580.173.02 (commit 20e4e6e1),
7note src/common/sdk/nvidia/inc/ctrl/ctrl2080/ctrl2080gpu.h, ctrl2080thermal.h and ctrl2080perf.h;
8note see native/smi/README.md.
9note 545259792 NV2080_CTRL_CMD_GPU_GET_NAME_STRING 0x20800110, 132-byte params
10note 545259917 NV2080_CTRL_CMD_GPU_GET_PIDS 0x2080018d, 3812-byte params
11note 545259918 NV2080_CTRL_CMD_GPU_GET_PID_INFO 0x2080018e, 14408-byte params
12note 545260819 NV2080_CTRL_CMD_THERMAL_SYSTEM_EXECUTE_V2 0x20800513, 1432-byte params
13note 545267816 NV2080_CTRL_CMD_PERF_GET_CURRENT_PSTATE 0x20802068, 4-byte params
14note 545267862 NV2080_CTRL_CMD_PERF_GET_GPUMON_PERFMON_UTIL_SAMPLES_V2 0x20802096, 55888-byte params
15note (issued by nvbig in native/smi/util.om)
16note Exit codes added by this unit (stdout stays empty; the context is closed before the refusal):
17note 30 resource-manager open failed (nvstart)
18note 31 a resource-manager control failed
19note 32 malformed control reply
20note 33 teardown failed (nvstop)
21note 34 --rm needs exactly one GPU in ROOT/proc/driver/nvidia/gpus
22
23text trmop "resource-manager open failed"
24text trmct "resource-manager control failed"
25text trmbad "malformed resource-manager reply"
26text trmtd "resource-manager teardown failed"
27text trmone "--rm needs exactly one GPU"
28text kapp "compute_app."
29text kumem ".used_memory="
30text kumemb ".used_memory_bytes="
31text kapps "compute_apps="
32
33note Closes the context, then refuses; a teardown failure takes precedence.
34fn rmfail code int msg view uchar * to void
35if not nvstop
36refuse 33 trmtd
37end
38refuse code msg
39end
40
41fn rmctl cmd uint n ulong to void
42if not nvctrl get nvobj 2 cmd n
43rmfail 31 trmct
44end
45end
46
47note Performance state: currPstate is one bit NV2080_CTRL_PERF_PSTATES_P0 (1) .. P15 (0x8000), printed
48note as P<n>. UNDEFINED (0) or NV_ERR_NOT_SUPPORTED (0x56) print [N/A]; any other bit pattern is
49note malformed and any other failure is a control failure.
50fn rmpst to void
51npzero
52og 0 kpst
53if not nvctrl get nvobj 2 545267816 4
54if ne nhget 28 86
55rmfail 31 trmct
56end
57ona
58ret
59end
60v = npget 0
61if eq v 0
62ona
63ret
64end
65for k ulong 16
66if eq v shl uint 1 k
67oc 80
68odec k
69onl
70ret
71end
72end
73rmfail 32 trmbad
74end
75
76note Utilization: the newest PERFMON sample, at (tracker + 71) mod 72; ctrl2080perf.h:580-588 puts the
77note newest entry before tracker. gr.util (sample +136) and fb.util (sample +8) are pct*100 and print
78note as the integer percent. NV_ERR_NOT_SUPPORTED, or an empty ring (count 0 or a zero timestamp in the
79note newest sample), prints [N/A]. A count above 72, a tracker at or above 72 or a util above 10000
80note is malformed; any other failure is a control failure.
81fn rmutil to void
82sbzero
83put smbig 0 2
84sbput 4 55872
85if not nvbig 545267862 55888
86if not eq nhget 28 86
87rmfail 31 trmct
88end
89og 0 kutg
90ona
91og 0 kutm
92ona
93ret
94end
95if or gt sbget 8 72 ge sbget 12 72
96rmfail 32 trmbad
97end
98o = add 16 mul rem add ulong sbget 12 71 72 776
99if or eq sbget 8 0 eq sbg64 o 0
100og 0 kutg
101ona
102og 0 kutm
103ona
104ret
105end
106g = sbget add o 136
107m = sbget add o 8
108if or gt g 10000 gt m 10000
109rmfail 32 trmbad
110end
111og 0 kutg
112odec ulong div g 100
113onl
114og 0 kutm
115odec ulong div m 100
116onl
117end
118
119note Product name: flags 0 selects ASCII; the name must be zero-terminated printable ASCII.
120fn rmname to void
121npzero
122rmctl 545259792 132
123if ne npget 0 0
124rmfail 32 trmbad
125end
126n = ulong 0
127while and lt n 64 ne get nvpar add 4 n 0 bound 65
128c = get nvpar add 4 n
129if or lt c 32 gt c 126
130rmfail 32 trmbad
131end
132n = add n 1
133end
134if or eq n 0 eq n 64
135rmfail 32 trmbad
136end
137og 0 kname
138for i ulong n
139oc get nvpar add 4 i
140end
141onl
142end
143
144note One thermal instruction at list slot k: opcode at +8, operands at +12 and +16.
145fn thins k ulong op uint a uint b uint to void
146o = add 24 mul k 44
147npput add o 8 op
148npput add o 12 a
149npput add o 16 b
150end
151
152fn thrun n ulong to void
153npput 0 1
154npput 4 0
155npput 8 44
156npput 12 0
157npput 20 uint n
158rmctl 545260819 1432
159for k ulong n
160o = add 24 mul k 44
161if or ne npget add o 4 1 ne npget o 0
162rmfail 32 trmbad
163end
164end
165end
166
167note GPU temperature: the first sensor whose target has type GPU (1). Without such a sensor the
168note field is [N/A]. More than 32 instructions in the second pass is a malformed reply.
169fn rmtemp to void
170npzero
171thins 0 256 0 0
172thins 1 1280 0 0
173thrun 2
174nt = ulong npget 36
175ns = ulong npget 80
176if gt add nt mul ns 2 32
177rmfail 32 trmbad
178end
179npzero
180for t ulong nt
181thins t 257 uint t 0
182end
183for s ulong ns
184thins add nt mul s 2 1312 uint s 0
185thins add add nt mul s 2 1 5376 uint s 0
186end
187thrun add nt mul ns 2
188og 0 ktemp
189for s ulong ns
190tg = npget add add 24 mul add nt mul s 2 44 16
191if ge ulong tg nt
192rmfail 32 trmbad
193end
194if eq npget add add 24 mul ulong tg 44 16 1
195v = npget add add 24 mul add add nt mul s 2 1 44 16
196if ge v 2147483648
197oc 45
198odec ulong sub 0 v
199else
200odec ulong v
201end
202onl
203ret
204end
205end
206ona
207end
208
209note Compute processes: GET_PIDS by the compute class returns PIDs with GPU contexts, then
210note GET_PID_INFO index 0 (video memory usage) gives memPrivate bytes per PID.
211fn rmpids to void
212npzero
213npput 0 0
214npput 4 get nvcls 0
215rmctl 545259917 3812
216n = ulong npget 8
217if gt n 200
218rmfail 32 trmbad
219end
220p = new uint 200 0
221for i ulong n
222put p i npget add 12 mul i 4
223end
224npzero
225npput 0 uint n
226for i ulong n
227npput add 8 mul i 72 get p i
228npput add 12 mul i 72 0
229end
230if gt n 0
231rmctl 545259918 14408
232end
233for i ulong n
234o = add 8 mul i 72
235if ne npget o get p i
236rmfail 32 trmbad
237end
238og 0 kapp
239odec i
240ot kpid
241odec ulong get p i
242onl
243if ne npget add o 8 0
244og 0 kapp
245odec i
246ot kumemb
247ona
248og 0 kapp
249odec i
250ot kumem
251ona
252continue
253end
254m = npg64 add o 16
255og 0 kapp
256odec i
257ot kumemb
258odec m
259onl
260og 0 kapp
261odec i
262ot kumem
263odec shr m 20
264onl
265end
266og 0 kapps
267odec n
268onl
269end
270
271fn rmrun to void
272if ne get gst 6 1
273refuse 34 trmone
274end
275if not nvstart
276if not nvstop
277refuse 33 trmtd
278end
279refuse 30 trmop
280end
281rmname
282rmtemp
283rmpst
284rmutil
285rmpids
286if not nvstop
287refuse 33 trmtd
288end
289end
290
291fn main to int
292args
293report
294if ne get gst 9 0
295rmrun
296end
297oflush
298ret 0
299end