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