A high-throughput and memory-efficient inference and serving engine for LLMs
Mirrored from https://github.com/tduncan-lum/Nvidia-Optimization-Stack---VLLM.git
Synced Nov 15, 23:30 UTC
[core] port pynvml into vllm codebase (#12963)
Signed-off-by: youkaichao <youkaichao@gmail.com>
youkaichao committed
Feb 9, 2025 at 15:00 UTC
cf797aa856995a474eec310884f2a71a3826c0f3
6 files changed
+6169
-35
.pre-commit-config.yaml
+18
-2
@@ -8,25 +8,28 @@ repos:
8
- id: yapf
9
args: [--in-place, --verbose]
10
additional_dependencies: [toml] # TODO: Remove when yapf is upgraded
11
+ exclude: 'vllm/third_party/.*'
12
- repo: https://github.com/astral-sh/ruff-pre-commit
13
rev: v0.9.3
14
hooks:
15
- id: ruff
16
args: [--output-format, github]
17
+ exclude: 'vllm/third_party/.*'
18
- repo: https://github.com/codespell-project/codespell
19
rev: v2.4.0
20
hooks:
21
- id: codespell
20
- exclude: 'benchmarks/sonnet.txt|(build|tests/(lora/data|models/fixtures|prompts))/.*'
22
+ exclude: 'benchmarks/sonnet.txt|(build|tests/(lora/data|models/fixtures|prompts))/.*|vllm/third_party/.*'
23
- repo: https://github.com/PyCQA/isort
24
rev: 5.13.2
25
hooks:
26
- id: isort
27
+ exclude: 'vllm/third_party/.*'
28
- repo: https://github.com/pre-commit/mirrors-clang-format
29
rev: v19.1.7
30
hooks:
31
- id: clang-format
29
- exclude: 'csrc/(moe/topk_softmax_kernels.cu|quantization/gguf/(ggml-common.h|dequantize.cuh|vecdotq.cuh|mmq.cuh|mmvq.cuh))'
32
+ exclude: 'csrc/(moe/topk_softmax_kernels.cu|quantization/gguf/(ggml-common.h|dequantize.cuh|vecdotq.cuh|mmq.cuh|mmvq.cuh))|vllm/third_party/.*'
33
types_or: [c++, cuda]
34
args: [--style=file, --verbose]
35
- repo: https://github.com/jackdewinter/pymarkdown
@@ -34,10 +37,12 @@ repos:
37
hooks:
38
- id: pymarkdown
39
args: [fix]
40
+ exclude: 'vllm/third_party/.*'
41
- repo: https://github.com/rhysd/actionlint
42
rev: v1.7.7
43
hooks:
44
- id: actionlint
45
+ exclude: 'vllm/third_party/.*'
46
- repo: local
47
hooks:
48
- id: mypy-local
@@ -47,6 +52,7 @@ repos:
52
types: [python]
53
additional_dependencies: &mypy_deps [mypy==1.11.1, types-setuptools, types-PyYAML, types-requests]
54
stages: [pre-commit] # Don't run in CI
55
+ exclude: 'vllm/third_party/.*'
56
- id: mypy-3.9 # TODO: Use https://github.com/pre-commit/mirrors-mypy when mypy setup is less awkward
57
name: Run mypy for Python 3.9
58
entry: tools/mypy.sh 1 "3.9"
@@ -54,6 +60,7 @@ repos:
60
types: [python]
61
additional_dependencies: *mypy_deps
62
stages: [manual] # Only run in CI
63
+ exclude: 'vllm/third_party/.*'
64
- id: mypy-3.10 # TODO: Use https://github.com/pre-commit/mirrors-mypy when mypy setup is less awkward
65
name: Run mypy for Python 3.10
66
entry: tools/mypy.sh 1 "3.10"
@@ -61,6 +68,7 @@ repos:
68
types: [python]
69
additional_dependencies: *mypy_deps
70
stages: [manual] # Only run in CI
71
+ exclude: 'vllm/third_party/.*'
72
- id: mypy-3.11 # TODO: Use https://github.com/pre-commit/mirrors-mypy when mypy setup is less awkward
73
name: Run mypy for Python 3.11
74
entry: tools/mypy.sh 1 "3.11"
@@ -68,6 +76,7 @@ repos:
76
types: [python]
77
additional_dependencies: *mypy_deps
78
stages: [manual] # Only run in CI
79
+ exclude: 'vllm/third_party/.*'
80
- id: mypy-3.12 # TODO: Use https://github.com/pre-commit/mirrors-mypy when mypy setup is less awkward
81
name: Run mypy for Python 3.12
82
entry: tools/mypy.sh 1 "3.12"
@@ -75,16 +84,19 @@ repos:
84
types: [python]
85
additional_dependencies: *mypy_deps
86
stages: [manual] # Only run in CI
87
+ exclude: 'vllm/third_party/.*'
88
- id: shellcheck
89
name: Lint shell scripts
90
entry: tools/shellcheck.sh
91
language: script
92
types: [shell]
93
+ exclude: 'vllm/third_party/.*'
94
- id: png-lint
95
name: Lint PNG exports from excalidraw
96
entry: tools/png-lint.sh
97
language: script
98
types: [png]
99
+ exclude: 'vllm/third_party/.*'
100
- id: signoff-commit
101
name: Sign-off Commit
102
entry: bash
@@ -97,17 +109,20 @@ repos:
109
language: system
110
verbose: true
111
stages: [commit-msg]
112
+ exclude: 'vllm/third_party/.*'
113
- id: check-spdx-header
114
name: Check SPDX headers
115
entry: python tools/check_spdx_header.py
116
language: python
117
types: [python]
118
+ exclude: 'vllm/third_party/.*'
119
- id: suggestion
120
name: Suggestion
121
entry: bash -c 'echo "To bypass pre-commit hooks, add --no-verify to git commit."'
122
language: system
123
verbose: true
124
pass_filenames: false
125
+ exclude: 'vllm/third_party/.*'
126
- id: check-filenames
127
name: Check for spaces in all filenames
128
entry: bash
@@ -117,3 +132,4 @@ repos:
132
language: system
133
always_run: true
134
pass_filenames: false
135
+ exclude: 'vllm/third_party/.*'
requirements-cuda.txt
-1
@@ -3,7 +3,6 @@
3
4
# Dependencies for NVIDIA GPUs
5
ray[default] >= 2.9
6
-nvidia-ml-py >= 12.560.30 # for pynvml package
6
torch == 2.5.1
7
torchaudio==2.5.1
8
# These must be updated alongside torch
tests/utils.py
+3
-2
@@ -46,8 +46,9 @@ if current_platform.is_rocm():
46
finally:
47
amdsmi_shut_down()
48
elif current_platform.is_cuda():
49
- from pynvml import (nvmlDeviceGetHandleByIndex, nvmlDeviceGetMemoryInfo,
50
- nvmlInit, nvmlShutdown)
49
+ from vllm.third_party.pynvml import (nvmlDeviceGetHandleByIndex,
50
+ nvmlDeviceGetMemoryInfo, nvmlInit,
51
+ nvmlShutdown)
52
53
@contextmanager
54
def _nvml():
vllm/third_party/__init__.py
vllm/third_party/pynvml.py
new
+6139
@@ -0,0 +1,6139 @@
1
+# SPDX-License-Identifier: Apache-2.0
2
+# copied from https://pypi.org/project/nvidia-ml-py
3
+# version 12.570.86
4
+
5
+#####
6
+# Copyright (c) 2011-2023, NVIDIA Corporation. All rights reserved.
7
+#
8
+# Redistribution and use in source and binary forms, with or without
9
+# modification, are permitted provided that the following conditions are met:
10
+#
11
+# * Redistributions of source code must retain the above copyright notice,
12
+# this list of conditions and the following disclaimer.
13
+# * Redistributions in binary form must reproduce the above copyright
14
+# notice, this list of conditions and the following disclaimer in the
15
+# documentation and/or other materials provided with the distribution.
16
+# * Neither the name of the NVIDIA Corporation nor the names of its
17
+# contributors may be used to endorse or promote products derived from
18
+# this software without specific prior written permission.
19
+#
20
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21
+# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23
+# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
24
+# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
30
+# THE POSSIBILITY OF SUCH DAMAGE.
31
+#####
32
+
33
+##
34
+# Python bindings for the NVML library
35
+##
36
+from ctypes import *
37
+from ctypes.util import find_library
38
+from functools import wraps
39
+import sys
40
+import os
41
+import threading
42
+import string
43
+
44
+## C Type mappings ##
45
+## Enums
46
+_nvmlEnableState_t = c_uint
47
+NVML_FEATURE_DISABLED = 0
48
+NVML_FEATURE_ENABLED = 1
49
+
50
+_nvmlBrandType_t = c_uint
51
+NVML_BRAND_UNKNOWN = 0
52
+NVML_BRAND_QUADRO = 1
53
+NVML_BRAND_TESLA = 2
54
+NVML_BRAND_NVS = 3
55
+NVML_BRAND_GRID = 4 # Deprecated from API reporting. Keeping definition for backward compatibility.
56
+NVML_BRAND_GEFORCE = 5
57
+NVML_BRAND_TITAN = 6
58
+NVML_BRAND_NVIDIA_VAPPS = 7 # NVIDIA Virtual Applications
59
+NVML_BRAND_NVIDIA_VPC = 8 # NVIDIA Virtual PC
60
+NVML_BRAND_NVIDIA_VCS = 9 # NVIDIA Virtual Compute Server
61
+NVML_BRAND_NVIDIA_VWS = 10 # NVIDIA RTX Virtual Workstation
62
+NVML_BRAND_NVIDIA_CLOUD_GAMING = 11 # NVIDIA Cloud Gaming
63
+NVML_BRAND_NVIDIA_VGAMING = NVML_BRAND_NVIDIA_CLOUD_GAMING # Deprecated from API reporting. Keeping definition for backward compatibility.
64
+NVML_BRAND_QUADRO_RTX = 12
65
+NVML_BRAND_NVIDIA_RTX = 13
66
+NVML_BRAND_NVIDIA = 14
67
+NVML_BRAND_GEFORCE_RTX = 15 # Unused
68
+NVML_BRAND_TITAN_RTX = 16 # Unused
69
+NVML_BRAND_COUNT = 17
70
+
71
+_nvmlTemperatureThresholds_t = c_uint
72
+NVML_TEMPERATURE_THRESHOLD_SHUTDOWN = 0
73
+NVML_TEMPERATURE_THRESHOLD_SLOWDOWN = 1
74
+NVML_TEMPERATURE_THRESHOLD_MEM_MAX = 2
75
+NVML_TEMPERATURE_THRESHOLD_GPU_MAX = 3
76
+NVML_TEMPERATURE_THRESHOLD_ACOUSTIC_MIN = 4
77
+NVML_TEMPERATURE_THRESHOLD_ACOUSTIC_CURR = 5
78
+NVML_TEMPERATURE_THRESHOLD_ACOUSTIC_MAX = 6
79
+NVML_TEMPERATURE_THRESHOLD_GPS_CURR = 7
80
+NVML_TEMPERATURE_THRESHOLD_COUNT = 8
81
+
82
+_nvmlTemperatureSensors_t = c_uint
83
+NVML_TEMPERATURE_GPU = 0
84
+NVML_TEMPERATURE_COUNT = 1
85
+
86
+
87
+_nvmlComputeMode_t = c_uint
88
+NVML_COMPUTEMODE_DEFAULT = 0
89
+NVML_COMPUTEMODE_EXCLUSIVE_THREAD = 1 ## Support Removed
90
+NVML_COMPUTEMODE_PROHIBITED = 2
91
+NVML_COMPUTEMODE_EXCLUSIVE_PROCESS = 3
92
+NVML_COMPUTEMODE_COUNT = 4
93
+
94
+_nvmlMemoryLocation_t = c_uint
95
+NVML_MEMORY_LOCATION_L1_CACHE = 0
96
+NVML_MEMORY_LOCATION_L2_CACHE = 1
97
+NVML_MEMORY_LOCATION_DEVICE_MEMORY = 2
98
+NVML_MEMORY_LOCATION_DRAM = 2
99
+NVML_MEMORY_LOCATION_REGISTER_FILE = 3
100
+NVML_MEMORY_LOCATION_TEXTURE_MEMORY = 4
101
+NVML_MEMORY_LOCATION_TEXTURE_SHM = 5
102
+NVML_MEMORY_LOCATION_CBU = 6
103
+NVML_MEMORY_LOCATION_SRAM = 7
104
+NVML_MEMORY_LOCATION_COUNT = 8
105
+
106
+NVML_NVLINK_MAX_LINKS = 18
107
+
108
+# For backwards compatibility, maintain the incorrectly-named "LANES" define
109
+NVML_NVLINK_MAX_LANES = NVML_NVLINK_MAX_LINKS
110
+
111
+_nvmlNvLinkErrorCounter_t = c_uint
112
+NVML_NVLINK_ERROR_DL_REPLAY = 0
113
+NVML_NVLINK_ERROR_DL_RECOVERY = 1
114
+NVML_NVLINK_ERROR_DL_CRC_FLIT = 2
115
+NVML_NVLINK_ERROR_DL_CRC_DATA = 3
116
+NVML_NVLINK_ERROR_DL_ECC_DATA = 4
117
+NVML_NVLINK_ERROR_COUNT = 5
118
+
119
+_nvmlNvLinkEccLaneErrorCounter_t = c_uint
120
+NVML_NVLINK_ERROR_DL_ECC_LANE0 = 0
121
+NVML_NVLINK_ERROR_DL_ECC_LANE1 = 1
122
+NVML_NVLINK_ERROR_DL_ECC_LANE2 = 2
123
+NVML_NVLINK_ERROR_DL_ECC_LANE3 = 3
124
+NVML_NVLINK_ERROR_DL_ECC_COUNT = 5
125
+
126
+_nvmlNvLinkCapability_t = c_uint
127
+NVML_NVLINK_CAP_P2P_SUPPORTED = 0
128
+NVML_NVLINK_CAP_SYSMEM_ACCESS = 1
129
+NVML_NVLINK_CAP_P2P_ATOMICS = 2
130
+NVML_NVLINK_CAP_SYSMEM_ATOMICS= 3
131
+NVML_NVLINK_CAP_SLI_BRIDGE = 4
132
+NVML_NVLINK_CAP_VALID = 5
133
+NVML_NVLINK_CAP_COUNT = 6
134
+
135
+_nvmlNvLinkUtilizationCountPktTypes_t = c_uint
136
+NVML_NVLINK_COUNTER_PKTFILTER_NOP = 0x1
137
+NVML_NVLINK_COUNTER_PKTFILTER_READ = 0x2
138
+NVML_NVLINK_COUNTER_PKTFILTER_WRITE = 0x4
139
+NVML_NVLINK_COUNTER_PKTFILTER_RATOM = 0x8
140
+NVML_NVLINK_COUNTER_PKTFILTER_NRATOM = 0x10
141
+NVML_NVLINK_COUNTER_PKTFILTER_FLUSH = 0x20
142
+NVML_NVLINK_COUNTER_PKTFILTER_RESPDATA = 0x40
143
+NVML_NVLINK_COUNTER_PKTFILTER_RESPNODATA = 0x80
144
+NVML_NVLINK_COUNTER_PKTFILTER_ALL = 0xFF
145
+
146
+_nvmlNvLinkUtilizationCountUnits_t = c_uint
147
+NVML_NVLINK_COUNTER_UNIT_CYCLES = 0
148
+NVML_NVLINK_COUNTER_UNIT_PACKETS = 1
149
+NVML_NVLINK_COUNTER_UNIT_BYTES = 2
150
+NVML_NVLINK_COUNTER_UNIT_RESERVED = 3
151
+NVML_NVLINK_COUNTER_UNIT_COUNT = 4
152
+
153
+_nvmlNvLinkDeviceType_t = c_uint
154
+NVML_NVLINK_DEVICE_TYPE_GPU = 0x00
155
+NVML_NVLINK_DEVICE_TYPE_IBMNPU = 0x01
156
+NVML_NVLINK_DEVICE_TYPE_SWITCH = 0x02
157
+NVML_NVLINK_DEVICE_TYPE_UNKNOWN = 0xFF
158
+
159
+# These are deprecated, instead use _nvmlMemoryErrorType_t
160
+_nvmlEccBitType_t = c_uint
161
+NVML_SINGLE_BIT_ECC = 0
162
+NVML_DOUBLE_BIT_ECC = 1
163
+NVML_ECC_ERROR_TYPE_COUNT = 2
164
+
165
+_nvmlEccCounterType_t = c_uint
166
+NVML_VOLATILE_ECC = 0
167
+NVML_AGGREGATE_ECC = 1
168
+NVML_ECC_COUNTER_TYPE_COUNT = 2
169
+
170
+_nvmlMemoryErrorType_t = c_uint
171
+NVML_MEMORY_ERROR_TYPE_CORRECTED = 0
172
+NVML_MEMORY_ERROR_TYPE_UNCORRECTED = 1
173
+NVML_MEMORY_ERROR_TYPE_COUNT = 2
174
+
175
+_nvmlClockType_t = c_uint
176
+NVML_CLOCK_GRAPHICS = 0
177
+NVML_CLOCK_SM = 1
178
+NVML_CLOCK_MEM = 2
179
+NVML_CLOCK_VIDEO = 3
180
+NVML_CLOCK_COUNT = 4
181
+
182
+_nvmlClockId_t = c_uint
183
+NVML_CLOCK_ID_CURRENT = 0
184
+NVML_CLOCK_ID_APP_CLOCK_TARGET = 1
185
+NVML_CLOCK_ID_APP_CLOCK_DEFAULT = 2
186
+NVML_CLOCK_ID_CUSTOMER_BOOST_MAX = 3
187
+NVML_CLOCK_ID_COUNT = 4
188
+
189
+_nvmlDriverModel_t = c_uint
190
+NVML_DRIVER_WDDM = 0
191
+NVML_DRIVER_WDM = 1
192
+NVML_DRIVER_MCDM = 2
193
+
194
+NVML_MAX_GPU_PERF_PSTATES = 16
195
+
196
+_nvmlPstates_t = c_uint
197
+NVML_PSTATE_0 = 0
198
+NVML_PSTATE_1 = 1
199
+NVML_PSTATE_2 = 2
200
+NVML_PSTATE_3 = 3
201
+NVML_PSTATE_4 = 4
202
+NVML_PSTATE_5 = 5
203
+NVML_PSTATE_6 = 6
204
+NVML_PSTATE_7 = 7
205
+NVML_PSTATE_8 = 8
206
+NVML_PSTATE_9 = 9
207
+NVML_PSTATE_10 = 10
208
+NVML_PSTATE_11 = 11
209
+NVML_PSTATE_12 = 12
210
+NVML_PSTATE_13 = 13
211
+NVML_PSTATE_14 = 14
212
+NVML_PSTATE_15 = 15
213
+NVML_PSTATE_UNKNOWN = 32
214
+
215
+_nvmlInforomObject_t = c_uint
216
+NVML_INFOROM_OEM = 0
217
+NVML_INFOROM_ECC = 1
218
+NVML_INFOROM_POWER = 2
219
+NVML_INFOROM_DEN = 3
220
+NVML_INFOROM_COUNT = 4
221
+
222
+_nvmlReturn_t = c_uint
223
+NVML_SUCCESS = 0
224
+NVML_ERROR_UNINITIALIZED = 1
225
+NVML_ERROR_INVALID_ARGUMENT = 2
226
+NVML_ERROR_NOT_SUPPORTED = 3
227
+NVML_ERROR_NO_PERMISSION = 4
228
+NVML_ERROR_ALREADY_INITIALIZED = 5
229
+NVML_ERROR_NOT_FOUND = 6
230
+NVML_ERROR_INSUFFICIENT_SIZE = 7
231
+NVML_ERROR_INSUFFICIENT_POWER = 8
232
+NVML_ERROR_DRIVER_NOT_LOADED = 9
233
+NVML_ERROR_TIMEOUT = 10
234
+NVML_ERROR_IRQ_ISSUE = 11
235
+NVML_ERROR_LIBRARY_NOT_FOUND = 12
236
+NVML_ERROR_FUNCTION_NOT_FOUND = 13
237
+NVML_ERROR_CORRUPTED_INFOROM = 14
238
+NVML_ERROR_GPU_IS_LOST = 15
239
+NVML_ERROR_RESET_REQUIRED = 16
240
+NVML_ERROR_OPERATING_SYSTEM = 17
241
+NVML_ERROR_LIB_RM_VERSION_MISMATCH = 18
242
+NVML_ERROR_IN_USE = 19
243
+NVML_ERROR_MEMORY = 20
244
+NVML_ERROR_NO_DATA = 21
245
+NVML_ERROR_VGPU_ECC_NOT_SUPPORTED = 22
246
+NVML_ERROR_INSUFFICIENT_RESOURCES = 23
247
+NVML_ERROR_FREQ_NOT_SUPPORTED = 24
248
+NVML_ERROR_ARGUMENT_VERSION_MISMATCH = 25
249
+NVML_ERROR_DEPRECATED = 26
250
+NVML_ERROR_NOT_READY = 27
251
+NVML_ERROR_GPU_NOT_FOUND = 28
252
+NVML_ERROR_INVALID_STATE = 29
253
+NVML_ERROR_UNKNOWN = 999
254
+
255
+_nvmlFanState_t = c_uint
256
+NVML_FAN_NORMAL = 0
257
+NVML_FAN_FAILED = 1
258
+
259
+_nvmlFanControlPolicy_t = c_uint
260
+NVML_FAN_POLICY_TEMPERATURE_CONTINOUS_SW = 0
261
+NVML_FAN_POLICY_MANUAL = 1
262
+
263
+_nvmlLedColor_t = c_uint
264
+NVML_LED_COLOR_GREEN = 0
265
+NVML_LED_COLOR_AMBER = 1
266
+
267
+_nvmlGpuOperationMode_t = c_uint
268
+NVML_GOM_ALL_ON = 0
269
+NVML_GOM_COMPUTE = 1
270
+NVML_GOM_LOW_DP = 2
271
+
272
+_nvmlPageRetirementCause_t = c_uint
273
+NVML_PAGE_RETIREMENT_CAUSE_MULTIPLE_SINGLE_BIT_ECC_ERRORS = 0
274
+NVML_PAGE_RETIREMENT_CAUSE_DOUBLE_BIT_ECC_ERROR = 1
275
+NVML_PAGE_RETIREMENT_CAUSE_COUNT = 2
276
+
277
+_nvmlRestrictedAPI_t = c_uint
278
+NVML_RESTRICTED_API_SET_APPLICATION_CLOCKS = 0
279
+NVML_RESTRICTED_API_SET_AUTO_BOOSTED_CLOCKS = 1
280
+NVML_RESTRICTED_API_COUNT = 2
281
+
282
+_nvmlBridgeChipType_t = c_uint
283
+NVML_BRIDGE_CHIP_PLX = 0
284
+NVML_BRIDGE_CHIP_BRO4 = 1
285
+NVML_MAX_PHYSICAL_BRIDGE = 128
286
+
287
+_nvmlValueType_t = c_uint
288
+NVML_VALUE_TYPE_DOUBLE = 0
289
+NVML_VALUE_TYPE_UNSIGNED_INT = 1
290
+NVML_VALUE_TYPE_UNSIGNED_LONG = 2
291
+NVML_VALUE_TYPE_UNSIGNED_LONG_LONG = 3
292
+NVML_VALUE_TYPE_SIGNED_LONG_LONG = 4
293
+NVML_VALUE_TYPE_SIGNED_INT = 5
294
+NVML_VALUE_TYPE_UNSIGNED_SHORT = 6
295
+NVML_VALUE_TYPE_COUNT = 7
296
+
297
+_nvmlNvlinkVersion_t = c_uint
298
+NVML_NVLINK_VERSION_INVALID = 0
299
+NVML_NVLINK_VERSION_1_0 = 1
300
+NVML_NVLINK_VERSION_2_0 = 2
301
+NVML_NVLINK_VERSION_2_2 = 3
302
+NVML_NVLINK_VERSION_3_0 = 4
303
+NVML_NVLINK_VERSION_3_1 = 5
304
+NVML_NVLINK_VERSION_4_0 = 6
305
+NVML_NVLINK_VERSION_5_0 = 7
306
+
307
+_nvmlPerfPolicyType_t = c_uint
308
+NVML_PERF_POLICY_POWER = 0
309
+NVML_PERF_POLICY_THERMAL = 1
310
+NVML_PERF_POLICY_SYNC_BOOST = 2
311
+NVML_PERF_POLICY_BOARD_LIMIT = 3
312
+NVML_PERF_POLICY_LOW_UTILIZATION = 4
313
+NVML_PERF_POLICY_RELIABILITY = 5
314
+NVML_PERF_POLICY_TOTAL_APP_CLOCKS = 10
315
+NVML_PERF_POLICY_TOTAL_BASE_CLOCKS = 11
316
+NVML_PERF_POLICY_COUNT = 12
317
+
318
+_nvmlEncoderQueryType_t = c_uint
319
+NVML_ENCODER_QUERY_H264 = 0
320
+NVML_ENCODER_QUERY_HEVC = 1
321
+NVML_ENCODER_QUERY_AV1 = 2
322
+NVML_ENCODER_QUERY_UNKNOWN = 255
323
+
324
+_nvmlFBCSessionType_t = c_uint
325
+NVML_FBC_SESSION_TYPE_UNKNOWN = 0
326
+NVML_FBC_SESSION_TYPE_TOSYS = 1
327
+NVML_FBC_SESSION_TYPE_CUDA = 2
328
+NVML_FBC_SESSION_TYPE_VID = 3
329
+NVML_FBC_SESSION_TYPE_HWENC = 4
330
+
331
+_nvmlDetachGpuState_t = c_uint
332
+NVML_DETACH_GPU_KEEP = 0
333
+NVML_DETACH_GPU_REMOVE = 1
334
+
335
+_nvmlPcieLinkState_t = c_uint
336
+NVML_PCIE_LINK_KEEP = 0
337
+NVML_PCIE_LINK_SHUT_DOWN = 1
338
+
339
+_nvmlSamplingType_t = c_uint
340
+NVML_TOTAL_POWER_SAMPLES = 0
341
+NVML_GPU_UTILIZATION_SAMPLES = 1
342
+NVML_MEMORY_UTILIZATION_SAMPLES = 2
343
+NVML_ENC_UTILIZATION_SAMPLES = 3
344
+NVML_DEC_UTILIZATION_SAMPLES = 4
345
+NVML_PROCESSOR_CLK_SAMPLES = 5
346
+NVML_MEMORY_CLK_SAMPLES = 6
347
+NVML_MODULE_POWER_SAMPLES = 7
348
+NVML_JPG_UTILIZATION_SAMPLES = 8
349
+NVML_OFA_UTILIZATION_SAMPLES = 9
350
+NVML_SAMPLINGTYPE_COUNT = 10
351
+
352
+_nvmlPcieUtilCounter_t = c_uint
353
+NVML_PCIE_UTIL_TX_BYTES = 0
354
+NVML_PCIE_UTIL_RX_BYTES = 1
355
+NVML_PCIE_UTIL_COUNT = 2
356
+
357
+_nvmlGpuTopologyLevel_t = c_uint
358
+NVML_TOPOLOGY_INTERNAL = 0
359
+NVML_TOPOLOGY_SINGLE = 10
360
+NVML_TOPOLOGY_MULTIPLE = 20
361
+NVML_TOPOLOGY_HOSTBRIDGE = 30
362
+NVML_TOPOLOGY_NODE = 40
363
+NVML_TOPOLOGY_CPU = NVML_TOPOLOGY_NODE
364
+NVML_TOPOLOGY_SYSTEM = 50
365
+
366
+_nvmlGpuP2PCapsIndex_t = c_uint
367
+NVML_P2P_CAPS_INDEX_READ = 0,
368
+NVML_P2P_CAPS_INDEX_WRITE = 1
369
+NVML_P2P_CAPS_INDEX_NVLINK =2
370
+NVML_P2P_CAPS_INDEX_ATOMICS = 3
371
+#
372
+# NVML_P2P_CAPS_INDEX_PROP is deprecated.
373
+# Use NVML_P2P_CAPS_INDEX_PCI instead.
374
+#
375
+NVML_P2P_CAPS_INDEX_PROP = 4
376
+NVML_P2P_CAPS_INDEX_PCI = 4
377
+NVML_P2P_CAPS_INDEX_UNKNOWN = 5
378
+
379
+_nvmlGpuP2PStatus_t = c_uint
380
+NVML_P2P_STATUS_OK = 0
381
+NVML_P2P_STATUS_CHIPSET_NOT_SUPPORED = 1
382
+NVML_P2P_STATUS_CHIPSET_NOT_SUPPORTED = NVML_P2P_STATUS_CHIPSET_NOT_SUPPORED
383
+NVML_P2P_STATUS_GPU_NOT_SUPPORTED = 2
384
+NVML_P2P_STATUS_IOH_TOPOLOGY_NOT_SUPPORTED =3
385
+NVML_P2P_STATUS_DISABLED_BY_REGKEY =4
386
+NVML_P2P_STATUS_NOT_SUPPORTED =5
387
+NVML_P2P_STATUS_UNKNOWN =6
388
+
389
+_nvmlDeviceArchitecture_t = c_uint
390
+NVML_DEVICE_ARCH_KEPLER = 2
391
+NVML_DEVICE_ARCH_MAXWELL = 3
392
+NVML_DEVICE_ARCH_PASCAL = 4
393
+NVML_DEVICE_ARCH_VOLTA = 5
394
+NVML_DEVICE_ARCH_TURING = 6
395
+NVML_DEVICE_ARCH_AMPERE = 7
396
+NVML_DEVICE_ARCH_ADA = 8
397
+NVML_DEVICE_ARCH_HOPPER = 9
398
+NVML_DEVICE_ARCH_BLACKWELL = 10
399
+NVML_DEVICE_ARCH_T23X = 11
400
+NVML_DEVICE_ARCH_UNKNOWN = 0xffffffff
401
+
402
+# PCI bus Types
403
+_nvmlBusType_t = c_uint
404
+NVML_BUS_TYPE_UNKNOWN = 0
405
+NVML_BUS_TYPE_PCI = 1
406
+NVML_BUS_TYPE_PCIE = 2
407
+NVML_BUS_TYPE_FPCI = 3
408
+NVML_BUS_TYPE_AGP = 4
409
+
410
+_nvmlPowerSource_t = c_uint
411
+NVML_POWER_SOURCE_AC = 0x00000000
412
+NVML_POWER_SOURCE_BATTERY = 0x00000001
413
+NVML_POWER_SOURCE_UNDERSIZED = 0x00000002
414
+
415
+_nvmlAdaptiveClockInfoStatus_t = c_uint
416
+NVML_ADAPTIVE_CLOCKING_INFO_STATUS_DISABLED = 0x00000000
417
+NVML_ADAPTIVE_CLOCKING_INFO_STATUS_ENABLED = 0x00000001
418
+
419
+_nvmlClockLimitId_t = c_uint
420
+NVML_CLOCK_LIMIT_ID_RANGE_START = 0xffffff00
421
+NVML_CLOCK_LIMIT_ID_TDP = 0xffffff01
422
+NVML_CLOCK_LIMIT_ID_UNLIMITED = 0xffffff02
423
+
424
+_nvmlPcieLinkMaxSpeed_t = c_uint
425
+NVML_PCIE_LINK_MAX_SPEED_INVALID = 0x00000000
426
+NVML_PCIE_LINK_MAX_SPEED_2500MBPS = 0x00000001
427
+NVML_PCIE_LINK_MAX_SPEED_5000MBPS = 0x00000002
428
+NVML_PCIE_LINK_MAX_SPEED_8000MBPS = 0x00000003
429
+NVML_PCIE_LINK_MAX_SPEED_16000MBPS = 0x00000004
430
+NVML_PCIE_LINK_MAX_SPEED_32000MBPS = 0x00000005
431
+NVML_PCIE_LINK_MAX_SPEED_64000MBPS = 0x00000006
432
+
433
+_nvmlPcieAtomicsCapability_t = c_uint
434
+NVML_PCIE_ATOMICS_CAP_FETCHADD32 = 0x01
435
+NVML_PCIE_ATOMICS_CAP_FETCHADD64 = 0x02
436
+NVML_PCIE_ATOMICS_CAP_SWAP32 = 0x04
437
+NVML_PCIE_ATOMICS_CAP_SWAP64 = 0x08
438
+NVML_PCIE_ATOMICS_CAP_CAS32 = 0x10
439
+NVML_PCIE_ATOMICS_CAP_CAS64 = 0x20
440
+NVML_PCIE_ATOMICS_CAP_CAS128 = 0x40
441
+NVML_PCIE_ATOMICS_OPS_MAX = 7
442
+
443
+_nvmlAffinityScope_t = c_uint
444
+NVML_AFFINITY_SCOPE_NODE = 0
445
+NVML_AFFINITY_SCOPE_SOCKET = 1
446
+
447
+_nvmlDeviceGpuRecoveryAction_t = c_uint
448
+NVML_GPU_RECOVERY_ACTION_NONE = 0
449
+NVML_GPU_RECOVERY_ACTION_GPU_RESET = 1
450
+NVML_GPU_RECOVERY_ACTION_NODE_REBOOT = 2
451
+NVML_GPU_RECOVERY_ACTION_DRAIN_P2P = 3
452
+NVML_GPU_RECOVERY_ACTION_DRAIN_AND_RESET = 4
453
+
454
+# C preprocessor defined values
455
+nvmlFlagDefault = 0
456
+nvmlFlagForce = 1
457
+NVML_INIT_FLAG_NO_GPUS = 1
458
+NVML_INIT_FLAG_NO_ATTACH = 2
459
+
460
+NVML_MAX_GPC_COUNT = 32
461
+
462
+# buffer size
463
+NVML_DEVICE_INFOROM_VERSION_BUFFER_SIZE = 16
464
+NVML_DEVICE_UUID_BUFFER_SIZE = 80
465
+NVML_DEVICE_UUID_V2_BUFFER_SIZE = 96
466
+NVML_SYSTEM_DRIVER_VERSION_BUFFER_SIZE = 80
467
+NVML_SYSTEM_NVML_VERSION_BUFFER_SIZE = 80
468
+NVML_DEVICE_NAME_BUFFER_SIZE = 64
469
+NVML_DEVICE_NAME_V2_BUFFER_SIZE = 96
470
+NVML_DEVICE_SERIAL_BUFFER_SIZE = 30
471
+NVML_DEVICE_PART_NUMBER_BUFFER_SIZE = 80
472
+NVML_DEVICE_GPU_PART_NUMBER_BUFFER_SIZE = 80
473
+NVML_DEVICE_VBIOS_VERSION_BUFFER_SIZE = 32
474
+NVML_DEVICE_PCI_BUS_ID_BUFFER_SIZE = 32
475
+NVML_DEVICE_PCI_BUS_ID_BUFFER_V2_SIZE = 16
476
+NVML_GRID_LICENSE_BUFFER_SIZE = 128
477
+NVML_VGPU_NAME_BUFFER_SIZE = 64
478
+NVML_GRID_LICENSE_FEATURE_MAX_COUNT = 3
479
+NVML_VGPU_METADATA_OPAQUE_DATA_SIZE = sizeof(c_uint) + 256
480
+NVML_VGPU_PGPU_METADATA_OPAQUE_DATA_SIZE = 256
481
+NVML_DEVICE_GPU_FRU_PART_NUMBER_BUFFER_SIZE = 0x14 # NV2080_GPU_MAX_PRODUCT_PART_NUMBER_LENGTH
482
+NVML_PERF_MODES_BUFFER_SIZE = 2048
483
+
484
+# Format strings
485
+NVML_DEVICE_PCI_BUS_ID_LEGACY_FMT = "%04X:%02X:%02X.0"
486
+NVML_DEVICE_PCI_BUS_ID_FMT = "%08X:%02X:%02X.0"
487
+
488
+NVML_VALUE_NOT_AVAILABLE_ulonglong = c_ulonglong(-1)
489
+NVML_VALUE_NOT_AVAILABLE_uint = c_uint(-1)
490
+
491
+'''
492
+ Field Identifiers.
493
+
494
+ All Identifiers pertain to a device. Each ID is only used once and is guaranteed never to change.
495
+'''
496
+NVML_FI_DEV_ECC_CURRENT = 1 # Current ECC mode. 1=Active. 0=Inactive
497
+NVML_FI_DEV_ECC_PENDING = 2 # Pending ECC mode. 1=Active. 0=Inactive
498
+
499
+#ECC Count Totals
500
+NVML_FI_DEV_ECC_SBE_VOL_TOTAL = 3 # Total single bit volatile ECC errors
501
+NVML_FI_DEV_ECC_DBE_VOL_TOTAL = 4 # Total double bit volatile ECC errors
502
+NVML_FI_DEV_ECC_SBE_AGG_TOTAL = 5 # Total single bit aggregate (persistent) ECC errors
503
+NVML_FI_DEV_ECC_DBE_AGG_TOTAL = 6 # Total double bit aggregate (persistent) ECC errors
504
+#Individual ECC locations
505
+NVML_FI_DEV_ECC_SBE_VOL_L1 = 7 # L1 cache single bit volatile ECC errors
506
+NVML_FI_DEV_ECC_DBE_VOL_L1 = 8 # L1 cache double bit volatile ECC errors
507
+NVML_FI_DEV_ECC_SBE_VOL_L2 = 9 # L2 cache single bit volatile ECC errors
508
+NVML_FI_DEV_ECC_DBE_VOL_L2 = 10 # L2 cache double bit volatile ECC errors
509
+NVML_FI_DEV_ECC_SBE_VOL_DEV = 11 # Device memory single bit volatile ECC errors
510
+NVML_FI_DEV_ECC_DBE_VOL_DEV = 12 # Device memory double bit volatile ECC errors
511
+NVML_FI_DEV_ECC_SBE_VOL_REG = 13 # Register file single bit volatile ECC errors
512
+NVML_FI_DEV_ECC_DBE_VOL_REG = 14 # Register file double bit volatile ECC errors
513
+NVML_FI_DEV_ECC_SBE_VOL_TEX = 15 # Texture memory single bit volatile ECC errors
514
+NVML_FI_DEV_ECC_DBE_VOL_TEX = 16 # Texture memory double bit volatile ECC errors
515
+NVML_FI_DEV_ECC_DBE_VOL_CBU = 17 # CBU double bit volatile ECC errors
516
+NVML_FI_DEV_ECC_SBE_AGG_L1 = 18 # L1 cache single bit aggregate (persistent) ECC errors
517
+NVML_FI_DEV_ECC_DBE_AGG_L1 = 19 # L1 cache double bit aggregate (persistent) ECC errors
518
+NVML_FI_DEV_ECC_SBE_AGG_L2 = 20 # L2 cache single bit aggregate (persistent) ECC errors
519
+NVML_FI_DEV_ECC_DBE_AGG_L2 = 21 # L2 cache double bit aggregate (persistent) ECC errors
520
+NVML_FI_DEV_ECC_SBE_AGG_DEV = 22 # Device memory single bit aggregate (persistent) ECC errors
521
+NVML_FI_DEV_ECC_DBE_AGG_DEV = 23 # Device memory double bit aggregate (persistent) ECC errors
522
+NVML_FI_DEV_ECC_SBE_AGG_REG = 24 # Register File single bit aggregate (persistent) ECC errors
523
+NVML_FI_DEV_ECC_DBE_AGG_REG = 25 # Register File double bit aggregate (persistent) ECC errors
524
+NVML_FI_DEV_ECC_SBE_AGG_TEX = 26 # Texture memory single bit aggregate (persistent) ECC errors
525
+NVML_FI_DEV_ECC_DBE_AGG_TEX = 27 # Texture memory double bit aggregate (persistent) ECC errors
526
+NVML_FI_DEV_ECC_DBE_AGG_CBU = 28 # CBU double bit aggregate ECC errors
527
+
528
+# Page Retirement
529
+NVML_FI_DEV_RETIRED_SBE = 29 # Number of retired pages because of single bit errors
530
+NVML_FI_DEV_RETIRED_DBE = 30 # Number of retired pages because of double bit errors
531
+NVML_FI_DEV_RETIRED_PENDING = 31 # If any pages are pending retirement. 1=yes. 0=no.
532
+
533
+# NvLink Flit Error Counters
534
+NVML_FI_DEV_NVLINK_CRC_FLIT_ERROR_COUNT_L0 = 32 # NVLink flow control CRC Error Counter for Lane 0
535
+NVML_FI_DEV_NVLINK_CRC_FLIT_ERROR_COUNT_L1 = 33 # NVLink flow control CRC Error Counter for Lane 1
536
+NVML_FI_DEV_NVLINK_CRC_FLIT_ERROR_COUNT_L2 = 34 # NVLink flow control CRC Error Counter for Lane 2
537
+NVML_FI_DEV_NVLINK_CRC_FLIT_ERROR_COUNT_L3 = 35 # NVLink flow control CRC Error Counter for Lane 3
538
+NVML_FI_DEV_NVLINK_CRC_FLIT_ERROR_COUNT_L4 = 36 # NVLink flow control CRC Error Counter for Lane 4
539
+NVML_FI_DEV_NVLINK_CRC_FLIT_ERROR_COUNT_L5 = 37 # NVLink flow control CRC Error Counter for Lane 5
540
+NVML_FI_DEV_NVLINK_CRC_FLIT_ERROR_COUNT_TOTAL = 38 # NVLink flow control CRC Error Counter total for all Lanes
541
+
542
+# NvLink CRC Data Error Counters
543
+NVML_FI_DEV_NVLINK_CRC_DATA_ERROR_COUNT_L0 = 39 # NVLink data CRC Error Counter for Lane 0
544
+NVML_FI_DEV_NVLINK_CRC_DATA_ERROR_COUNT_L1 = 40 # NVLink data CRC Error Counter for Lane 1
545
+NVML_FI_DEV_NVLINK_CRC_DATA_ERROR_COUNT_L2 = 41 # NVLink data CRC Error Counter for Lane 2
546
+NVML_FI_DEV_NVLINK_CRC_DATA_ERROR_COUNT_L3 = 42 # NVLink data CRC Error Counter for Lane 3
547
+NVML_FI_DEV_NVLINK_CRC_DATA_ERROR_COUNT_L4 = 43 # NVLink data CRC Error Counter for Lane 4
548
+NVML_FI_DEV_NVLINK_CRC_DATA_ERROR_COUNT_L5 = 44 # NVLink data CRC Error Counter for Lane 5
549
+NVML_FI_DEV_NVLINK_CRC_DATA_ERROR_COUNT_TOTAL = 45 # NvLink data CRC Error Counter total for all Lanes
550
+
551
+# NvLink Replay Error Counters
552
+NVML_FI_DEV_NVLINK_REPLAY_ERROR_COUNT_L0 = 46 # NVLink Replay Error Counter for Lane 0
553
+NVML_FI_DEV_NVLINK_REPLAY_ERROR_COUNT_L1 = 47 # NVLink Replay Error Counter for Lane 1
554
+NVML_FI_DEV_NVLINK_REPLAY_ERROR_COUNT_L2 = 48 # NVLink Replay Error Counter for Lane 2
555
+NVML_FI_DEV_NVLINK_REPLAY_ERROR_COUNT_L3 = 49 # NVLink Replay Error Counter for Lane 3
556
+NVML_FI_DEV_NVLINK_REPLAY_ERROR_COUNT_L4 = 50 # NVLink Replay Error Counter for Lane 4
557
+NVML_FI_DEV_NVLINK_REPLAY_ERROR_COUNT_L5 = 51 # NVLink Replay Error Counter for Lane 5
558
+NVML_FI_DEV_NVLINK_REPLAY_ERROR_COUNT_TOTAL = 52 # NVLink Replay Error Counter total for all Lanes
559
+
560
+# NvLink Recovery Error Counters
561
+NVML_FI_DEV_NVLINK_RECOVERY_ERROR_COUNT_L0 = 53 # NVLink Recovery Error Counter for Lane 0
562
+NVML_FI_DEV_NVLINK_RECOVERY_ERROR_COUNT_L1 = 54 # NVLink Recovery Error Counter for Lane 1
563
+NVML_FI_DEV_NVLINK_RECOVERY_ERROR_COUNT_L2 = 55 # NVLink Recovery Error Counter for Lane 2
564
+NVML_FI_DEV_NVLINK_RECOVERY_ERROR_COUNT_L3 = 56 # NVLink Recovery Error Counter for Lane 3
565
+NVML_FI_DEV_NVLINK_RECOVERY_ERROR_COUNT_L4 = 57 # NVLink Recovery Error Counter for Lane 4
566
+NVML_FI_DEV_NVLINK_RECOVERY_ERROR_COUNT_L5 = 58 # NVLink Recovery Error Counter for Lane 5
567
+NVML_FI_DEV_NVLINK_RECOVERY_ERROR_COUNT_TOTAL = 59 # NVLink Recovery Error Counter total for all Lanes
568
+
569
+# NvLink Bandwidth Counters
570
+NVML_FI_DEV_NVLINK_BANDWIDTH_C0_L0 = 60 # NVLink Bandwidth Counter for Counter Set 0, Lane 0
571
+NVML_FI_DEV_NVLINK_BANDWIDTH_C0_L1 = 61 # NVLink Bandwidth Counter for Counter Set 0, Lane 1
572
+NVML_FI_DEV_NVLINK_BANDWIDTH_C0_L2 = 62 # NVLink Bandwidth Counter for Counter Set 0, Lane 2
573
+NVML_FI_DEV_NVLINK_BANDWIDTH_C0_L3 = 63 # NVLink Bandwidth Counter for Counter Set 0, Lane 3
574
+NVML_FI_DEV_NVLINK_BANDWIDTH_C0_L4 = 64 # NVLink Bandwidth Counter for Counter Set 0, Lane 4
575
+NVML_FI_DEV_NVLINK_BANDWIDTH_C0_L5 = 65 # NVLink Bandwidth Counter for Counter Set 0, Lane 5
576
+NVML_FI_DEV_NVLINK_BANDWIDTH_C0_TOTAL = 66 # NVLink Bandwidth Counter Total for Counter Set 0, All Lanes
577
+
578
+# NvLink Bandwidth Counters
579
+NVML_FI_DEV_NVLINK_BANDWIDTH_C1_L0 = 67 # NVLink Bandwidth Counter for Counter Set 1, Lane 0
580
+NVML_FI_DEV_NVLINK_BANDWIDTH_C1_L1 = 68 # NVLink Bandwidth Counter for Counter Set 1, Lane 1
581
+NVML_FI_DEV_NVLINK_BANDWIDTH_C1_L2 = 69 # NVLink Bandwidth Counter for Counter Set 1, Lane 2
582
+NVML_FI_DEV_NVLINK_BANDWIDTH_C1_L3 = 70 # NVLink Bandwidth Counter for Counter Set 1, Lane 3
583
+NVML_FI_DEV_NVLINK_BANDWIDTH_C1_L4 = 71 # NVLink Bandwidth Counter for Counter Set 1, Lane 4
584
+NVML_FI_DEV_NVLINK_BANDWIDTH_C1_L5 = 72 # NVLink Bandwidth Counter for Counter Set 1, Lane 5
585
+NVML_FI_DEV_NVLINK_BANDWIDTH_C1_TOTAL = 73 # NVLink Bandwidth Counter Total for Counter Set 1, All Lanes
586
+
587
+# Perf Policy Counters
588
+NVML_FI_DEV_PERF_POLICY_POWER = 74 # Perf Policy Counter for Power Policy
589
+NVML_FI_DEV_PERF_POLICY_THERMAL = 75 # Perf Policy Counter for Thermal Policy
590
+NVML_FI_DEV_PERF_POLICY_SYNC_BOOST = 76 # Perf Policy Counter for Sync boost Policy
591
+NVML_FI_DEV_PERF_POLICY_BOARD_LIMIT = 77 # Perf Policy Counter for Board Limit
592
+NVML_FI_DEV_PERF_POLICY_LOW_UTILIZATION = 78 # Perf Policy Counter for Low GPU Utilization Policy
593
+NVML_FI_DEV_PERF_POLICY_RELIABILITY = 79 # Perf Policy Counter for Reliability Policy
594
+NVML_FI_DEV_PERF_POLICY_TOTAL_APP_CLOCKS = 80 # Perf Policy Counter for Total App Clock Policy
595
+NVML_FI_DEV_PERF_POLICY_TOTAL_BASE_CLOCKS = 81 # Perf Policy Counter for Total Base Clocks Policy
596
+
597
+# Memory temperatures
598
+NVML_FI_DEV_MEMORY_TEMP = 82 # Memory temperature for the device
599
+
600
+# Energy Counter
601
+NVML_FI_DEV_TOTAL_ENERGY_CONSUMPTION = 83 # Total energy consumption for the GPU in mJ since the driver was last reloaded
602
+
603
+# NVLink Speed
604
+NVML_FI_DEV_NVLINK_SPEED_MBPS_L0 = 84
605
+NVML_FI_DEV_NVLINK_SPEED_MBPS_L1 = 85
606
+NVML_FI_DEV_NVLINK_SPEED_MBPS_L2 = 86
607
+NVML_FI_DEV_NVLINK_SPEED_MBPS_L3 = 87
608
+NVML_FI_DEV_NVLINK_SPEED_MBPS_L4 = 88
609
+NVML_FI_DEV_NVLINK_SPEED_MBPS_L5 = 89
610
+NVML_FI_DEV_NVLINK_SPEED_MBPS_COMMON = 90
611
+
612
+# NVLink Link Count
613
+NVML_FI_DEV_NVLINK_LINK_COUNT = 91
614
+
615
+# Page Retirement pending fields
616
+NVML_FI_DEV_RETIRED_PENDING_SBE = 92
617
+NVML_FI_DEV_RETIRED_PENDING_DBE = 93
618
+
619
+# PCIe replay and replay rollover counters
620
+NVML_FI_DEV_PCIE_REPLAY_COUNTER = 94
621
+NVML_FI_DEV_PCIE_REPLAY_ROLLOVER_COUNTER = 95
622
+
623
+# NvLink Flit Error Counters
624
+NVML_FI_DEV_NVLINK_CRC_FLIT_ERROR_COUNT_L6 = 96 # NVLink flow control CRC Error Counter for Lane 6
625
+NVML_FI_DEV_NVLINK_CRC_FLIT_ERROR_COUNT_L7 = 97 # NVLink flow control CRC Error Counter for Lane 7
626
+NVML_FI_DEV_NVLINK_CRC_FLIT_ERROR_COUNT_L8 = 98 # NVLink flow control CRC Error Counter for Lane 8
627
+NVML_FI_DEV_NVLINK_CRC_FLIT_ERROR_COUNT_L9 = 99 # NVLink flow control CRC Error Counter for Lane 9
628
+NVML_FI_DEV_NVLINK_CRC_FLIT_ERROR_COUNT_L10 = 100 # NVLink flow control CRC Error Counter for Lane 10
629
+NVML_FI_DEV_NVLINK_CRC_FLIT_ERROR_COUNT_L11 = 101 # NVLink flow control CRC Error Counter for Lane 11
630
+
631
+# NvLink CRC Data Error Counters
632
+NVML_FI_DEV_NVLINK_CRC_DATA_ERROR_COUNT_L6 = 102 # NVLink data CRC Error Counter for Lane 6
633
+NVML_FI_DEV_NVLINK_CRC_DATA_ERROR_COUNT_L7 = 103 # NVLink data CRC Error Counter for Lane 7
634
+NVML_FI_DEV_NVLINK_CRC_DATA_ERROR_COUNT_L8 = 104 # NVLink data CRC Error Counter for Lane 8
635
+NVML_FI_DEV_NVLINK_CRC_DATA_ERROR_COUNT_L9 = 105 # NVLink data CRC Error Counter for Lane 9
636
+NVML_FI_DEV_NVLINK_CRC_DATA_ERROR_COUNT_L10 = 106 # NVLink data CRC Error Counter for Lane 10
637
+NVML_FI_DEV_NVLINK_CRC_DATA_ERROR_COUNT_L11 = 107 # NVLink data CRC Error Counter for Lane 11
638
+
639
+# NvLink Replay Error Counters
640
+NVML_FI_DEV_NVLINK_REPLAY_ERROR_COUNT_L6 = 108 # NVLink Replay Error Counter for Lane 6
641
+NVML_FI_DEV_NVLINK_REPLAY_ERROR_COUNT_L7 = 109 # NVLink Replay Error Counter for Lane 7
642
+NVML_FI_DEV_NVLINK_REPLAY_ERROR_COUNT_L8 = 110 # NVLink Replay Error Counter for Lane 8
643
+NVML_FI_DEV_NVLINK_REPLAY_ERROR_COUNT_L9 = 111 # NVLink Replay Error Counter for Lane 9
644
+NVML_FI_DEV_NVLINK_REPLAY_ERROR_COUNT_L10 = 112 # NVLink Replay Error Counter for Lane 10
645
+NVML_FI_DEV_NVLINK_REPLAY_ERROR_COUNT_L11 = 113 # NVLink Replay Error Counter for Lane 11
646
+
647
+# NvLink Recovery Error Counters
648
+NVML_FI_DEV_NVLINK_RECOVERY_ERROR_COUNT_L6 = 114 # NVLink Recovery Error Counter for Lane 6
649
+NVML_FI_DEV_NVLINK_RECOVERY_ERROR_COUNT_L7 = 115 # NVLink Recovery Error Counter for Lane 7
650
+NVML_FI_DEV_NVLINK_RECOVERY_ERROR_COUNT_L8 = 116 # NVLink Recovery Error Counter for Lane 8
651
+NVML_FI_DEV_NVLINK_RECOVERY_ERROR_COUNT_L9 = 117 # NVLink Recovery Error Counter for Lane 9
652
+NVML_FI_DEV_NVLINK_RECOVERY_ERROR_COUNT_L10 = 118 # NVLink Recovery Error Counter for Lane 10
653
+NVML_FI_DEV_NVLINK_RECOVERY_ERROR_COUNT_L11 = 119 # NVLink Recovery Error Counter for Lane 11
654
+
655
+# NvLink Bandwidth Counters
656
+NVML_FI_DEV_NVLINK_BANDWIDTH_C0_L6 = 120 # NVLink Bandwidth Counter for Counter Set 0, Lane 6
657
+NVML_FI_DEV_NVLINK_BANDWIDTH_C0_L7 = 121 # NVLink Bandwidth Counter for Counter Set 0, Lane 7
658
+NVML_FI_DEV_NVLINK_BANDWIDTH_C0_L8 = 122 # NVLink Bandwidth Counter for Counter Set 0, Lane 8
659
+NVML_FI_DEV_NVLINK_BANDWIDTH_C0_L9 = 123 # NVLink Bandwidth Counter for Counter Set 0, Lane 9
660
+NVML_FI_DEV_NVLINK_BANDWIDTH_C0_L10 = 124 # NVLink Bandwidth Counter for Counter Set 0, Lane 10
661
+NVML_FI_DEV_NVLINK_BANDWIDTH_C0_L11 = 125 # NVLink Bandwidth Counter for Counter Set 0, Lane 11
662
+
663
+# NvLink Bandwidth Counters
664
+NVML_FI_DEV_NVLINK_BANDWIDTH_C1_L6 = 126 # NVLink Bandwidth Counter for Counter Set 1, Lane 6
665
+NVML_FI_DEV_NVLINK_BANDWIDTH_C1_L7 = 127 # NVLink Bandwidth Counter for Counter Set 1, Lane 7
666
+NVML_FI_DEV_NVLINK_BANDWIDTH_C1_L8 = 128 # NVLink Bandwidth Counter for Counter Set 1, Lane 8
667
+NVML_FI_DEV_NVLINK_BANDWIDTH_C1_L9 = 129 # NVLink Bandwidth Counter for Counter Set 1, Lane 9
668
+NVML_FI_DEV_NVLINK_BANDWIDTH_C1_L10 = 130 # NVLink Bandwidth Counter for Counter Set 1, Lane 10
669
+NVML_FI_DEV_NVLINK_BANDWIDTH_C1_L11 = 131 # NVLink Bandwidth Counter for Counter Set 1, Lane 11
670
+
671
+# NVLink Speed
672
+NVML_FI_DEV_NVLINK_SPEED_MBPS_L6 = 132
673
+NVML_FI_DEV_NVLINK_SPEED_MBPS_L7 = 133
674
+NVML_FI_DEV_NVLINK_SPEED_MBPS_L8 = 134
675
+NVML_FI_DEV_NVLINK_SPEED_MBPS_L9 = 135
676
+NVML_FI_DEV_NVLINK_SPEED_MBPS_L10 = 136
677
+NVML_FI_DEV_NVLINK_SPEED_MBPS_L11 = 137
678
+
679
+# NVLink Throughput Counters
680
+NVML_FI_DEV_NVLINK_THROUGHPUT_DATA_TX = 138 # NVLink TX Data throughput in KiB
681
+NVML_FI_DEV_NVLINK_THROUGHPUT_DATA_RX = 139 # NVLink RX Data throughput in KiB
682
+NVML_FI_DEV_NVLINK_THROUGHPUT_RAW_TX = 140 # NVLink TX Data + protocol overhead in KiB
683
+NVML_FI_DEV_NVLINK_THROUGHPUT_RAW_RX = 141 # NVLink RX Data + protocol overhead in KiB
684
+
685
+# Row Remapper
686
+NVML_FI_DEV_REMAPPED_COR = 142
687
+NVML_FI_DEV_REMAPPED_UNC = 143
688
+NVML_FI_DEV_REMAPPED_PENDING = 144
689
+NVML_FI_DEV_REMAPPED_FAILURE = 145
690
+
691
+#Remote device NVLink ID
692
+NVML_FI_DEV_NVLINK_REMOTE_NVLINK_ID = 146
693
+
694
+# Number of NVLinks connected to NVSwitch
695
+NVML_FI_DEV_NVSWITCH_CONNECTED_LINK_COUNT = 147
696
+
697
+# NvLink ECC Data Error Counters
698
+NVML_FI_DEV_NVLINK_ECC_DATA_ERROR_COUNT_L0 = 148 #< NVLink data ECC Error Counter for Link 0
699
+NVML_FI_DEV_NVLINK_ECC_DATA_ERROR_COUNT_L1 = 149 #< NVLink data ECC Error Counter for Link 1
700
+NVML_FI_DEV_NVLINK_ECC_DATA_ERROR_COUNT_L2 = 150 #< NVLink data ECC Error Counter for Link 2
701
+NVML_FI_DEV_NVLINK_ECC_DATA_ERROR_COUNT_L3 = 151 #< NVLink data ECC Error Counter for Link 3
702
+NVML_FI_DEV_NVLINK_ECC_DATA_ERROR_COUNT_L4 = 152 #< NVLink data ECC Error Counter for Link 4
703
+NVML_FI_DEV_NVLINK_ECC_DATA_ERROR_COUNT_L5 = 153 #< NVLink data ECC Error Counter for Link 5
704
+NVML_FI_DEV_NVLINK_ECC_DATA_ERROR_COUNT_L6 = 154 #< NVLink data ECC Error Counter for Link 6
705
+NVML_FI_DEV_NVLINK_ECC_DATA_ERROR_COUNT_L7 = 155 #< NVLink data ECC Error Counter for Link 7
706
+NVML_FI_DEV_NVLINK_ECC_DATA_ERROR_COUNT_L8 = 156 #< NVLink data ECC Error Counter for Link 8
707
+NVML_FI_DEV_NVLINK_ECC_DATA_ERROR_COUNT_L9 = 157 #< NVLink data ECC Error Counter for Link 9
708
+NVML_FI_DEV_NVLINK_ECC_DATA_ERROR_COUNT_L10 = 158 #< NVLink data ECC Error Counter for Link 10
709
+NVML_FI_DEV_NVLINK_ECC_DATA_ERROR_COUNT_L11 = 159 #< NVLink data ECC Error Counter for Link 11
710
+NVML_FI_DEV_NVLINK_ECC_DATA_ERROR_COUNT_TOTAL = 160 #< NvLink data ECC Error Counter total for all Links
711
+
712
+NVML_FI_DEV_NVLINK_ERROR_DL_REPLAY = 161
713
+NVML_FI_DEV_NVLINK_ERROR_DL_RECOVERY = 162
714
+NVML_FI_DEV_NVLINK_ERROR_DL_CRC = 163
715
+NVML_FI_DEV_NVLINK_GET_SPEED = 164
716
+NVML_FI_DEV_NVLINK_GET_STATE = 165
717
+NVML_FI_DEV_NVLINK_GET_VERSION = 166
718
+
719
+NVML_FI_DEV_NVLINK_GET_POWER_STATE = 167
720
+NVML_FI_DEV_NVLINK_GET_POWER_THRESHOLD = 168
721
+
722
+NVML_FI_DEV_PCIE_L0_TO_RECOVERY_COUNTER = 169
723
+
724
+NVML_FI_DEV_C2C_LINK_COUNT = 170
725
+NVML_FI_DEV_C2C_LINK_GET_STATUS = 171
726
+NVML_FI_DEV_C2C_LINK_GET_MAX_BW = 172
727
+
728
+NVML_FI_DEV_PCIE_COUNT_CORRECTABLE_ERRORS = 173
729
+NVML_FI_DEV_PCIE_COUNT_NAKS_RECEIVED = 174
730
+NVML_FI_DEV_PCIE_COUNT_RECEIVER_ERROR = 175
731
+NVML_FI_DEV_PCIE_COUNT_BAD_TLP = 176
732
+NVML_FI_DEV_PCIE_COUNT_NAKS_SENT = 177
733
+NVML_FI_DEV_PCIE_COUNT_BAD_DLLP = 178
734
+NVML_FI_DEV_PCIE_COUNT_NON_FATAL_ERROR = 179
735
+NVML_FI_DEV_PCIE_COUNT_FATAL_ERROR = 180
736
+NVML_FI_DEV_PCIE_COUNT_UNSUPPORTED_REQ = 181
737
+NVML_FI_DEV_PCIE_COUNT_LCRC_ERROR = 182
738
+NVML_FI_DEV_PCIE_COUNT_LANE_ERROR = 183
739
+
740
+NVML_FI_DEV_IS_RESETLESS_MIG_SUPPORTED = 184
741
+
742
+NVML_FI_DEV_POWER_AVERAGE = 185
743
+NVML_FI_DEV_POWER_INSTANT = 186
744
+NVML_FI_DEV_POWER_MIN_LIMIT = 187
745
+NVML_FI_DEV_POWER_MAX_LIMIT = 188
746
+NVML_FI_DEV_POWER_DEFAULT_LIMIT = 189
747
+NVML_FI_DEV_POWER_CURRENT_LIMIT = 190
748
+NVML_FI_DEV_ENERGY = 191
749
+NVML_FI_DEV_POWER_REQUESTED_LIMIT = 192
750
+
751
+NVML_FI_DEV_TEMPERATURE_SHUTDOWN_TLIMIT = 193
752
+NVML_FI_DEV_TEMPERATURE_SLOWDOWN_TLIMIT = 194
753
+NVML_FI_DEV_TEMPERATURE_MEM_MAX_TLIMIT = 195
754
+NVML_FI_DEV_TEMPERATURE_GPU_MAX_TLIMIT = 196
755
+
756
+NVML_FI_DEV_PCIE_COUNT_TX_BYTES = 197
757
+NVML_FI_DEV_PCIE_COUNT_RX_BYTES = 198
758
+
759
+NVML_FI_DEV_IS_MIG_MODE_INDEPENDENT_MIG_QUERY_CAPABLE = 199
760
+
761
+NVML_FI_DEV_NVLINK_GET_POWER_THRESHOLD_MAX = 200
762
+
763
+NVML_FI_DEV_NVLINK_COUNT_XMIT_PACKETS = 201
764
+NVML_FI_DEV_NVLINK_COUNT_XMIT_BYTES = 202
765
+NVML_FI_DEV_NVLINK_COUNT_RCV_PACKETS = 203
766
+NVML_FI_DEV_NVLINK_COUNT_RCV_BYTES = 204
767
+NVML_FI_DEV_NVLINK_COUNT_VL15_DROPPED = 205 # Deprecated, do not use
768
+NVML_FI_DEV_NVLINK_COUNT_MALFORMED_PACKET_ERRORS = 206
769
+NVML_FI_DEV_NVLINK_COUNT_BUFFER_OVERRUN_ERRORS = 207
770
+NVML_FI_DEV_NVLINK_COUNT_RCV_ERRORS = 208
771
+NVML_FI_DEV_NVLINK_COUNT_RCV_REMOTE_ERRORS = 209
772
+NVML_FI_DEV_NVLINK_COUNT_RCV_GENERAL_ERRORS = 210
773
+NVML_FI_DEV_NVLINK_COUNT_LOCAL_LINK_INTEGRITY_ERRORS = 211
774
+NVML_FI_DEV_NVLINK_COUNT_XMIT_DISCARDS = 212
775
+
776
+NVML_FI_DEV_NVLINK_COUNT_LINK_RECOVERY_SUCCESSFUL_EVENTS = 213
777
+NVML_FI_DEV_NVLINK_COUNT_LINK_RECOVERY_FAILED_EVENTS = 214
778
+NVML_FI_DEV_NVLINK_COUNT_LINK_RECOVERY_EVENTS = 215
779
+
780
+NVML_FI_DEV_NVLINK_COUNT_RAW_BER_LANE0 = 216 # Deprecated, do not use
781
+NVML_FI_DEV_NVLINK_COUNT_RAW_BER_LANE1 = 217 # Deprecated, do not use
782
+NVML_FI_DEV_NVLINK_COUNT_RAW_BER = 218 # Deprecated, do not use
783
+NVML_FI_DEV_NVLINK_COUNT_EFFECTIVE_ERRORS = 219
784
+NVML_FI_DEV_NVLINK_COUNT_EFFECTIVE_BER = 220
785
+NVML_FI_DEV_NVLINK_COUNT_SYMBOL_ERRORS = 221
786
+NVML_FI_DEV_NVLINK_COUNT_SYMBOL_BER = 222
787
+
788
+NVML_FI_DEV_NVLINK_GET_POWER_THRESHOLD_MIN = 223
789
+NVML_FI_DEV_NVLINK_GET_POWER_THRESHOLD_UNITS = 224 # Values are in the form NVML_NVLINK_LOW_POWER_THRESHOLD_UNIT_*
790
+NVML_FI_DEV_NVLINK_GET_POWER_THRESHOLD_SUPPORTED = 225
791
+
792
+NVML_FI_DEV_RESET_STATUS = 226 # Deprecated use NVML_FI_DEV_GET_GPU_RECOVERY_ACTION instead
793
+NVML_FI_DEV_DRAIN_AND_RESET_STATUS = 227 # Deprecated use NVML_FI_DEV_GET_GPU_RECOVERY_ACTION instead
794
+NVML_FI_DEV_PCIE_OUTBOUND_ATOMICS_MASK = 228
795
+NVML_FI_DEV_PCIE_INBOUND_ATOMICS_MASK = 229
796
+NVML_FI_DEV_GET_GPU_RECOVERY_ACTION = 230
797
+
798
+NVML_FI_DEV_NVLINK_COUNT_FEC_HISTORY_0 = 235
799
+NVML_FI_DEV_NVLINK_COUNT_FEC_HISTORY_1 = 236
800
+NVML_FI_DEV_NVLINK_COUNT_FEC_HISTORY_2 = 237
801
+NVML_FI_DEV_NVLINK_COUNT_FEC_HISTORY_3 = 238
802
+NVML_FI_DEV_NVLINK_COUNT_FEC_HISTORY_4 = 239
803
+NVML_FI_DEV_NVLINK_COUNT_FEC_HISTORY_5 = 240
804
+NVML_FI_DEV_NVLINK_COUNT_FEC_HISTORY_6 = 241
805
+NVML_FI_DEV_NVLINK_COUNT_FEC_HISTORY_7 = 242
806
+NVML_FI_DEV_NVLINK_COUNT_FEC_HISTORY_8 = 243
807
+NVML_FI_DEV_NVLINK_COUNT_FEC_HISTORY_9 = 244
808
+NVML_FI_DEV_NVLINK_COUNT_FEC_HISTORY_10 = 245
809
+NVML_FI_DEV_NVLINK_COUNT_FEC_HISTORY_11 = 246
810
+NVML_FI_DEV_NVLINK_COUNT_FEC_HISTORY_12 = 247
811
+NVML_FI_DEV_NVLINK_COUNT_FEC_HISTORY_13 = 248
812
+NVML_FI_DEV_NVLINK_COUNT_FEC_HISTORY_14 = 249
813
+NVML_FI_DEV_NVLINK_COUNT_FEC_HISTORY_15 = 250
814
+NVML_FI_PWR_SMOOTHING_ENABLED = 251 # Enablement (0/DISABLED or 1/ENABLED)
815
+NVML_FI_PWR_SMOOTHING_PRIV_LVL = 252 # Current privilege level
816
+NVML_FI_PWR_SMOOTHING_IMM_RAMP_DOWN_ENABLED = 253 # Immediate ramp down enablement (0/DISABLED or 1/ENABLED)
817
+NVML_FI_PWR_SMOOTHING_APPLIED_TMP_CEIL = 254 # Applied TMP ceiling value
818
+NVML_FI_PWR_SMOOTHING_APPLIED_TMP_FLOOR = 255 # Applied TMP floor value
819
+NVML_FI_PWR_SMOOTHING_MAX_PERCENT_TMP_FLOOR_SETTING = 256 # Max % TMP Floor value
820
+NVML_FI_PWR_SMOOTHING_MIN_PERCENT_TMP_FLOOR_SETTING = 257 # Min % TMP Floor value
821
+NVML_FI_PWR_SMOOTHING_HW_CIRCUITRY_PERCENT_LIFETIME_REMAINING = 258 # HW Circuitry % lifetime remaining
822
+NVML_FI_PWR_SMOOTHING_MAX_NUM_PRESET_PROFILES = 259 # Max number of preset profiles
823
+NVML_FI_PWR_SMOOTHING_PROFILE_PERCENT_TMP_FLOOR = 260 # % TMP floor for a given profile
824
+NVML_FI_PWR_SMOOTHING_PROFILE_RAMP_UP_RATE = 261 # Ramp up rate in mW/s for a given profile
825
+NVML_FI_PWR_SMOOTHING_PROFILE_RAMP_DOWN_RATE = 262 # Ramp down rate in mW/s for a given profile
826
+NVML_FI_PWR_SMOOTHING_PROFILE_RAMP_DOWN_HYST_VAL = 263 # Ramp down hysteresis value in ms for a given profile
827
+NVML_FI_PWR_SMOOTHING_ACTIVE_PRESET_PROFILE = 264 # Active preset profile number
828
+NVML_FI_PWR_SMOOTHING_ADMIN_OVERRIDE_PERCENT_TMP_FLOOR = 265 # % TMP floor for a given profile
829
+NVML_FI_PWR_SMOOTHING_ADMIN_OVERRIDE_RAMP_UP_RATE = 266 # Ramp up rate in mW/s for a given profile
830
+NVML_FI_PWR_SMOOTHING_ADMIN_OVERRIDE_RAMP_DOWN_RATE = 267 # Ramp down rate in mW/s for a given profile
831
+NVML_FI_PWR_SMOOTHING_ADMIN_OVERRIDE_RAMP_DOWN_HYST_VAL = 268 # Ramp down hysteresis value in ms for a given profile
832
+
833
+NVML_FI_MAX = 269 # One greater than the largest field ID defined above
834
+
835
+# NVML_FI_DEV_NVLINK_GET_STATE state enums
836
+NVML_NVLINK_STATE_INACTIVE = 0x0
837
+NVML_NVLINK_STATE_ACTIVE = 0x1
838
+NVML_NVLINK_STATE_SLEEP = 0x2
839
+
840
+NVML_NVLINK_LOW_POWER_THRESHOLD_UNIT_100US = 0 # NVML_FI_DEV_NVLINK_GET_POWER_THRESHOLD_UNITS
841
+NVML_NVLINK_LOW_POWER_THRESHOLD_UNIT_50US = 1 # NVML_FI_DEV_NVLINK_GET_POWER_THRESHOLD_UNITS
842
+
843
+## Enums needed for the method nvmlDeviceGetVirtualizationMode and nvmlDeviceSetVirtualizationMode
844
+NVML_GPU_VIRTUALIZATION_MODE_NONE = 0 # Represents Bare Metal GPU
845
+NVML_GPU_VIRTUALIZATION_MODE_PASSTHROUGH = 1 # Device is associated with GPU-Passthorugh
846
+NVML_GPU_VIRTUALIZATION_MODE_VGPU = 2 # Device is associated with vGPU inside virtual machine.
847
+NVML_GPU_VIRTUALIZATION_MODE_HOST_VGPU = 3 # Device is associated with VGX hypervisor in vGPU mode
848
+NVML_GPU_VIRTUALIZATION_MODE_HOST_VSGA = 4 # Device is associated with VGX hypervisor in vSGA mode
849
+
850
+## Lib loading ##
851
+nvmlLib = None
852
+libLoadLock = threading.Lock()
853
+_nvmlLib_refcount = 0 # Incremented on each nvmlInit and decremented on nvmlShutdown
854
+
855
+## vGPU Management
856
+_nvmlVgpuTypeId_t = c_uint
857
+_nvmlVgpuInstance_t = c_uint
858
+
859
+_nvmlVgpuVmIdType_t = c_uint
860
+NVML_VGPU_VM_ID_DOMAIN_ID = 0
861
+NVML_VGPU_VM_ID_UUID = 1
862
+
863
+_nvmlGridLicenseFeatureCode_t = c_uint
864
+NVML_GRID_LICENSE_FEATURE_CODE_UNKNOWN = 0
865
+NVML_GRID_LICENSE_FEATURE_CODE_VGPU = 1
866
+NVML_GRID_LICENSE_FEATURE_CODE_NVIDIA_RTX = 2
867
+NVML_GRID_LICENSE_FEATURE_CODE_VWORKSTATION = 2 # deprecated, use NVML_GRID_LICENSE_FEATURE_CODE_NVIDIA_RTX.
868
+NVML_GRID_LICENSE_FEATURE_CODE_GAMING = 3
869
+NVML_GRID_LICENSE_FEATURE_CODE_COMPUTE = 4
870
+
871
+_nvmlGridLicenseExpiryStatus_t = c_uint8
872
+NVML_GRID_LICENSE_EXPIRY_NOT_AVAILABLE = 0, # Expiry information not available
873
+NVML_GRID_LICENSE_EXPIRY_INVALID = 1, # Invalid expiry or error fetching expiry
874
+NVML_GRID_LICENSE_EXPIRY_VALID = 2, # Valid expiry
875
+NVML_GRID_LICENSE_EXPIRY_NOT_APPLICABLE = 3, # Expiry not applicable
876
+NVML_GRID_LICENSE_EXPIRY_PERMANENT = 4, # Permanent expiry
877
+
878
+_nvmlVgpuCapability_t = c_uint
879
+NVML_VGPU_CAP_NVLINK_P2P = 0 # vGPU P2P over NVLink is supported
880
+NVML_VGPU_CAP_GPUDIRECT = 1 # GPUDirect capability is supported
881
+NVML_VGPU_CAP_MULTI_VGPU_EXCLUSIVE = 2 # vGPU profile cannot be mixed with other vGPU profiles in same VM
882
+NVML_VGPU_CAP_EXCLUSIVE_TYPE = 3 # vGPU profile cannot run on a GPU alongside other profiles of different type
883
+NVML_VGPU_CAP_EXCLUSIVE_SIZE = 4 # vGPU profile cannot run on a GPU alongside other profiles of different size
884
+NVML_VGPU_CAP_COUNT = 5
885
+
886
+_nvmlVgpuDriverCapability_t = c_uint
887
+NVML_VGPU_DRIVER_CAP_HETEROGENEOUS_MULTI_VGPU = 0 # Supports mixing of different vGPU profiles within one guest VM
888
+NVML_VGPU_DRIVER_CAP_WARM_UPDATE = 1 # Supports FSR and warm update of vGPU host driver without terminating the running guest VM
889
+NVML_VGPU_DRIVER_CAP_COUNT = 2
890
+
891
+_nvmlDeviceVgpuCapability_t = c_uint
892
+NVML_DEVICE_VGPU_CAP_FRACTIONAL_MULTI_VGPU = 0 # Query whether the fractional vGPU profiles on this GPU can be used in multi-vGPU configurations
893
+NVML_DEVICE_VGPU_CAP_HETEROGENEOUS_TIMESLICE_PROFILES = 1 # Query whether the GPU supports concurrent execution of timesliced vGPU profiles of differing types
894
+NVML_DEVICE_VGPU_CAP_HETEROGENEOUS_TIMESLICE_SIZES = 2 # Query whether the GPU supports concurrent execution of timesliced vGPU profiles of differing framebuffer sizes
895
+NVML_DEVICE_VGPU_CAP_READ_DEVICE_BUFFER_BW = 3 # Query the GPU's read_device_buffer expected bandwidth capacity in megabytes per second
896
+NVML_DEVICE_VGPU_CAP_WRITE_DEVICE_BUFFER_BW = 4 # Query the GPU's write_device_buffer expected bandwidth capacity in megabytes per second
897
+NVML_DEVICE_VGPU_CAP_DEVICE_STREAMING = 5 # Query whether the vGPU profiles on the GPU supports migration data streaming
898
+NVML_DEVICE_VGPU_CAP_MINI_QUARTER_GPU = 6 # Set/Get support of mini-quarter vGPU profiles
899
+NVML_DEVICE_VGPU_CAP_COMPUTE_MEDIA_ENGINE_GPU = 7 # Set/Get support for compute media engine vGPU profiles
900
+NVML_DEVICE_VGPU_CAP_WARM_UPDATE = 8 # Query whether the GPU supports FSR and warm update
901
+NVML_DEVICE_VGPU_CAP_HOMOGENEOUS_PLACEMENTS = 9 # Query whether the GPU supports reporting of placements of timesliced vGPU profiles with identical framebuffer sizes
902
+NVML_DEVICE_VGPU_CAP_COUNT = 10
903
+
904
+_nvmlVgpuGuestInfoState_t = c_uint
905
+NVML_VGPU_INSTANCE_GUEST_INFO_STATE_UNINITIALIZED = 0
906
+NVML_VGPU_INSTANCE_GUEST_INFO_STATE_INITIALIZED = 1
907
+
908
+_nvmlVgpuVmCompatibility_t = c_uint
909
+NVML_VGPU_VM_COMPATIBILITY_NONE = 0x0
910
+NVML_VGPU_VM_COMPATIBILITY_COLD = 0x1
911
+NVML_VGPU_VM_COMPATIBILITY_HIBERNATE = 0x2
912
+NVML_VGPU_VM_COMPATIBILITY_SLEEP = 0x4
913
+NVML_VGPU_VM_COMPATIBILITY_LIVE = 0x8
914
+
915
+_nvmlVgpuPgpuCompatibilityLimitCode_t = c_uint
916
+NVML_VGPU_COMPATIBILITY_LIMIT_NONE = 0x0
917
+NVML_VGPU_COMPATIBILITY_LIMIT_HOST_DRIVER = 0x1
918
+NVML_VGPU_COMPATIBILITY_LIMIT_GUEST_DRIVER = 0x2
919
+NVML_VGPU_COMPATIBILITY_LIMIT_GPU = 0x4
920
+NVML_VGPU_COMPATIBILITY_LIMIT_OTHER = 0x80000000
921
+
922
+_nvmlHostVgpuMode_t = c_uint
923
+NVML_HOST_VGPU_MODE_NON_SRIOV = 0
924
+NVML_HOST_VGPU_MODE_SRIOV = 1
925
+
926
+_nvmlConfComputeGpusReadyState_t = c_uint
927
+NVML_CC_ACCEPTING_CLIENT_REQUESTS_FALSE = 0
928
+NVML_CC_ACCEPTING_CLIENT_REQUESTS_TRUE = 1
929
+
930
+_nvmlConfComputeGpuCaps_t = c_uint
931
+NVML_CC_SYSTEM_GPUS_CC_NOT_CAPABLE = 0
932
+NVML_CC_SYSTEM_GPUS_CC_CAPABLE = 1
933
+
934
+_nvmlConfComputeCpuCaps_t = c_uint
935
+NVML_CC_SYSTEM_CPU_CAPS_NONE = 0
936
+NVML_CC_SYSTEM_CPU_CAPS_AMD_SEV = 1
937
+NVML_CC_SYSTEM_CPU_CAPS_INTEL_TDX = 2
938
+NVML_CC_SYSTEM_CPU_CAPS_AMD_SEV_SNP = 3
939
+NVML_CC_SYSTEM_CPU_CAPS_AMD_SNP_VTOM = 4
940
+
941
+_nvmlConfComputeDevToolsMode_t = c_uint
942
+NVML_CC_SYSTEM_DEVTOOLS_MODE_OFF = 0
943
+NVML_CC_SYSTEM_DEVTOOLS_MODE_ON = 1
944
+
945
+NVML_CC_SYSTEM_MULTIGPU_NONE = 0
946
+NVML_CC_SYSTEM_MULTIGPU_PROTECTED_PCIE = 1
947
+
948
+NVML_CC_SYSTEM_ENVIRONMENT_UNAVAILABLE = 0
949
+NVML_CC_SYSTEM_ENVIRONMENT_SIM = 1
950
+NVML_CC_SYSTEM_ENVIRONMENT_PROD = 2
951
+
952
+_nvmlConfComputeCcFeature_t = c_uint
953
+NVML_CC_SYSTEM_FEATURE_DISABLED = 0
954
+NVML_CC_SYSTEM_FEATURE_ENABLED = 1
955
+
956
+_nvmlConfComputeCcKeyRotationThreshAttackerAdv_t = c_uint
957
+NVML_CC_KEY_ROTATION_THRESH_ATTACKER_ADVANTAGE_MIN = 50
958
+NVML_CC_KEY_ROTATION_THRESH_ATTACKER_ADVANTAGE_MAX = 65
959
+
960
+# GSP firmware
961
+NVML_GSP_FIRMWARE_VERSION_BUF_SIZE = 0x40
962
+
963
+class NVMLLibraryMismatchError(Exception):
964
+ pass
965
+
966
+## Error Checking ##
967
+class NVMLError(Exception):
968
+ _valClassMapping = dict()
969
+ # List of currently known error codes
970
+ _errcode_to_string = {
971
+ NVML_ERROR_UNINITIALIZED: "Uninitialized",
972
+ NVML_ERROR_INVALID_ARGUMENT: "Invalid Argument",
973
+ NVML_ERROR_NOT_SUPPORTED: "Not Supported",
974
+ NVML_ERROR_NO_PERMISSION: "Insufficient Permissions",
975
+ NVML_ERROR_ALREADY_INITIALIZED: "Already Initialized",
976
+ NVML_ERROR_NOT_FOUND: "Not Found",
977
+ NVML_ERROR_INSUFFICIENT_SIZE: "Insufficient Size",
978
+ NVML_ERROR_INSUFFICIENT_POWER: "Insufficient External Power",
979
+ NVML_ERROR_DRIVER_NOT_LOADED: "Driver Not Loaded",
980
+ NVML_ERROR_TIMEOUT: "Timeout",
981
+ NVML_ERROR_IRQ_ISSUE: "Interrupt Request Issue",
982
+ NVML_ERROR_LIBRARY_NOT_FOUND: "NVML Shared Library Not Found",
983
+ NVML_ERROR_FUNCTION_NOT_FOUND: "Function Not Found",
984
+ NVML_ERROR_CORRUPTED_INFOROM: "Corrupted infoROM",
985
+ NVML_ERROR_GPU_IS_LOST: "GPU is lost",
986
+ NVML_ERROR_RESET_REQUIRED: "GPU requires restart",
987
+ NVML_ERROR_OPERATING_SYSTEM: "The operating system has blocked the request.",
988
+ NVML_ERROR_LIB_RM_VERSION_MISMATCH: "RM has detected an NVML/RM version mismatch.",
989
+ NVML_ERROR_MEMORY: "Insufficient Memory",
990
+ NVML_ERROR_UNKNOWN: "Unknown Error",
991
+ }
992
+ def __new__(typ, value):
993
+ '''
994
+ Maps value to a proper subclass of NVMLError.
995
+ See _extractNVMLErrorsAsClasses function for more details
996
+ '''
997
+ if typ == NVMLError:
998
+ typ = NVMLError._valClassMapping.get(value, typ)
999
+ obj = Exception.__new__(typ)
1000
+ obj.value = value
1001
+ return obj
1002
+ def __str__(self):
1003
+ try:
1004
+ if self.value not in NVMLError._errcode_to_string:
1005
+ NVMLError._errcode_to_string[self.value] = str(nvmlErrorString(self.value))
1006
+ return NVMLError._errcode_to_string[self.value]
1007
+ except NVMLError:
1008
+ return "NVML Error with code %d" % self.value
1009
+ def __eq__(self, other):
1010
+ return self.value == other.value
1011
+
1012
+def nvmlExceptionClass(nvmlErrorCode):
1013
+ if nvmlErrorCode not in NVMLError._valClassMapping:
1014
+ raise ValueError('nvmlErrorCode %s is not valid' % nvmlErrorCode)
1015
+ return NVMLError._valClassMapping[nvmlErrorCode]
1016
+
1017
+def _extractNVMLErrorsAsClasses():
1018
+ '''
1019
+ Generates a hierarchy of classes on top of NVMLError class.
1020
+
1021
+ Each NVML Error gets a new NVMLError subclass. This way try,except blocks can filter appropriate
1022
+ exceptions more easily.
1023
+
1024
+ NVMLError is a parent class. Each NVML_ERROR_* gets it's own subclass.
1025
+ e.g. NVML_ERROR_ALREADY_INITIALIZED will be turned into NVMLError_AlreadyInitialized
1026
+ '''
1027
+ this_module = sys.modules[__name__]
1028
+ nvmlErrorsNames = [x for x in dir(this_module) if x.startswith("NVML_ERROR_")]
1029
+ for err_name in nvmlErrorsNames:
1030
+ # e.g. Turn NVML_ERROR_ALREADY_INITIALIZED into NVMLError_AlreadyInitialized
1031
+ class_name = "NVMLError_" + string.capwords(err_name.replace("NVML_ERROR_", ""), "_").replace("_", "")
1032
+ err_val = getattr(this_module, err_name)
1033
+ def gen_new(val):
1034
+ def new(typ):
1035
+ obj = NVMLError.__new__(typ, val)
1036
+ return obj
1037
+ return new
1038
+ new_error_class = type(class_name, (NVMLError,), {'__new__': gen_new(err_val)})
1039
+ new_error_class.__module__ = __name__
1040
+ setattr(this_module, class_name, new_error_class)
1041
+ NVMLError._valClassMapping[err_val] = new_error_class
1042
+_extractNVMLErrorsAsClasses()
1043
+
1044
+def _nvmlCheckReturn(ret):
1045
+ if (ret != NVML_SUCCESS):
1046
+ raise NVMLError(ret)
1047
+ return ret
1048
+
1049
+## Function access ##
1050
+_nvmlGetFunctionPointer_cache = dict() # function pointers are cached to prevent unnecessary libLoadLock locking
1051
+def _nvmlGetFunctionPointer(name):
1052
+ global nvmlLib
1053
+
1054
+ if name in _nvmlGetFunctionPointer_cache:
1055
+ return _nvmlGetFunctionPointer_cache[name]
1056
+
1057
+ libLoadLock.acquire()
1058
+ try:
1059
+ # ensure library was loaded
1060
+ if (nvmlLib == None):
1061
+ raise NVMLError(NVML_ERROR_UNINITIALIZED)
1062
+ try:
1063
+ _nvmlGetFunctionPointer_cache[name] = getattr(nvmlLib, name)
1064
+ return _nvmlGetFunctionPointer_cache[name]
1065
+ except AttributeError:
1066
+ raise NVMLError(NVML_ERROR_FUNCTION_NOT_FOUND)
1067
+ finally:
1068
+ # lock is always freed
1069
+ libLoadLock.release()
1070
+
1071
+## Alternative object
1072
+# Allows the object to be printed
1073
+# Allows mismatched types to be assigned
1074
+# - like None when the Structure variant requires c_uint
1075
+class nvmlFriendlyObject(object):
1076
+ def __init__(self, dictionary):
1077
+ for x in dictionary:
1078
+ setattr(self, x, dictionary[x])
1079
+ def __str__(self):
1080
+ return self.__dict__.__str__()
1081
+
1082
+def nvmlStructToFriendlyObject(struct):
1083
+ d = {}
1084
+ for x in struct._fields_:
1085
+ key = x[0]
1086
+ value = getattr(struct, key)
1087
+ # only need to convert from bytes if bytes, no need to check python version.
1088
+ d[key] = value.decode() if isinstance(value, bytes) else value
1089
+ obj = nvmlFriendlyObject(d)
1090
+ return obj
1091
+
1092
+# pack the object so it can be passed to the NVML library
1093
+def nvmlFriendlyObjectToStruct(obj, model):
1094
+ for x in model._fields_:
1095
+ key = x[0]
1096
+ value = obj.__dict__[key]
1097
+ # any c_char_p in python3 needs to be bytes, default encoding works fine.
1098
+ if sys.version_info >= (3,):
1099
+ setattr(model, key, value.encode())
1100
+ else:
1101
+ setattr(model, key, value)
1102
+ return model
1103
+
1104
+## Unit structures
1105
+class struct_c_nvmlUnit_t(Structure):
1106
+ pass # opaque handle
1107
+c_nvmlUnit_t = POINTER(struct_c_nvmlUnit_t)
1108
+
1109
+class _PrintableStructure(Structure):
1110
+ """
1111
+ Abstract class that produces nicer __str__ output than ctypes.Structure.
1112
+ e.g. instead of:
1113
+ >>> print str(obj)
1114
+ <class_name object at 0x7fdf82fef9e0>
1115
+ this class will print
1116
+ class_name(field_name: formatted_value, field_name: formatted_value)
1117
+
1118
+ _fmt_ dictionary of <str _field_ name> -> <str format>
1119
+ e.g. class that has _field_ 'hex_value', c_uint could be formatted with
1120
+ _fmt_ = {"hex_value" : "%08X"}
1121
+ to produce nicer output.
1122
+ Default fomratting string for all fields can be set with key "<default>" like:
1123
+ _fmt_ = {"<default>" : "%d MHz"} # e.g all values are numbers in MHz.
1124
+ If not set it's assumed to be just "%s"
1125
+
1126
+ Exact format of returned str from this class is subject to change in the future.
1127
+ """
1128
+ _fmt_ = {}
1129
+ def __str__(self):
1130
+ result = []
1131
+ for x in self._fields_:
1132
+ key = x[0]
1133
+ value = getattr(self, key)
1134
+ fmt = "%s"
1135
+ if key in self._fmt_:
1136
+ fmt = self._fmt_[key]
1137
+ elif "<default>" in self._fmt_:
1138
+ fmt = self._fmt_["<default>"]
1139
+ result.append(("%s: " + fmt) % (key, value))
1140
+ return self.__class__.__name__ + "(" + ", ".join(result) + ")"
1141
+
1142
+ def __getattribute__(self, name):
1143
+ res = super(_PrintableStructure, self).__getattribute__(name)
1144
+ # need to convert bytes to unicode for python3 don't need to for python2
1145
+ # Python 2 strings are of both str and bytes
1146
+ # Python 3 strings are not of type bytes
1147
+ # ctypes should convert everything to the correct values otherwise
1148
+ if isinstance(res, bytes):
1149
+ if isinstance(res, str):
1150
+ return res
1151
+ return res.decode()
1152
+ return res
1153
+
1154
+ def __setattr__(self, name, value):
1155
+ if isinstance(value, str):
1156
+ # encoding a python2 string returns the same value, since python2 strings are bytes already
1157
+ # bytes passed in python3 will be ignored.
1158
+ value = value.encode()
1159
+ super(_PrintableStructure, self).__setattr__(name, value)
1160
+
1161
+class c_nvmlUnitInfo_t(_PrintableStructure):
1162
+ _fields_ = [
1163
+ ('name', c_char * 96),
1164
+ ('id', c_char * 96),
1165
+ ('serial', c_char * 96),
1166
+ ('firmwareVersion', c_char * 96),
1167
+ ]
1168
+
1169
+class c_nvmlC2cModeInfo_v1_t(_PrintableStructure):
1170
+ _fields_ = [
1171
+ ('isC2cEnabled', c_uint)
1172
+ ]
1173
+
1174
+nvmlC2cModeInfo_v1 = 0x1000008;
1175
+
1176
+class c_nvmlLedState_t(_PrintableStructure):
1177
+ _fields_ = [
1178
+ ('cause', c_char * 256),
1179
+ ('color', _nvmlLedColor_t),
1180
+ ]
1181
+
1182
+class c_nvmlPSUInfo_t(_PrintableStructure):
1183
+ _fields_ = [
1184
+ ('state', c_char * 256),
1185
+ ('current', c_uint),
1186
+ ('voltage', c_uint),
1187
+ ('power', c_uint),
1188
+ ]
1189
+
1190
+class c_nvmlUnitFanInfo_t(_PrintableStructure):
1191
+ _fields_ = [
1192
+ ('speed', c_uint),
1193
+ ('state', _nvmlFanState_t),
1194
+ ]
1195
+
1196
+class c_nvmlUnitFanSpeeds_t(_PrintableStructure):
1197
+ _fields_ = [
1198
+ ('fans', c_nvmlUnitFanInfo_t * 24),
1199
+ ('count', c_uint)
1200
+ ]
1201
+
1202
+## Device structures
1203
+class struct_c_nvmlDevice_t(Structure):
1204
+ pass # opaque handle
1205
+c_nvmlDevice_t = POINTER(struct_c_nvmlDevice_t)
1206
+
1207
+class nvmlPciInfoExt_v1_t(_PrintableStructure):
1208
+ _fields_ = [
1209
+ ('version', c_uint),
1210
+ ('domain', c_uint),
1211
+ ('bus', c_uint),
1212
+ ('device', c_uint),
1213
+ ('pciDeviceId', c_uint),
1214
+ ('pciSubSystemId', c_uint),
1215
+ ('baseClass', c_uint),
1216
+ ('subClass', c_uint),
1217
+ ('busId', c_char * NVML_DEVICE_PCI_BUS_ID_BUFFER_SIZE),
1218
+ ]
1219
+ _fmt_ = {
1220
+ 'version' : "0x%04X",
1221
+ 'domain' : "0x%04X",
1222
+ 'bus' : "0x%02X",
1223
+ 'device' : "0x%02X",
1224
+ 'pciDeviceId' : "0x%08X",
1225
+ 'pciSubSystemId' : "0x%08X",
1226
+ 'baseClass' : "0x%01X",
1227
+ 'subClass' : "0x%01X",
1228
+ }
1229
+
1230
+nvmlPciInfoExt_v1 = 0x1000040
1231
+
1232
+# Legacy pciInfo used for _v1 and _v2
1233
+class nvmlPciInfo_v2_t(_PrintableStructure):
1234
+ _fields_ = [
1235
+ ('busId', c_char * NVML_DEVICE_PCI_BUS_ID_BUFFER_V2_SIZE),
1236
+ ('domain', c_uint),
1237
+ ('bus', c_uint),
1238
+ ('device', c_uint),
1239
+ ('pciDeviceId', c_uint),
1240
+
1241
+ # Added in 2.285
1242
+ ('pciSubSystemId', c_uint),
1243
+ ('reserved0', c_uint),
1244
+ ('reserved1', c_uint),
1245
+ ('reserved2', c_uint),
1246
+ ('reserved3', c_uint),
1247
+ ]
1248
+ _fmt_ = {
1249
+ 'domain' : "0x%04X",
1250
+ 'bus' : "0x%02X",
1251
+ 'device' : "0x%02X",
1252
+ 'pciDeviceId' : "0x%08X",
1253
+ 'pciSubSystemId' : "0x%08X",
1254
+ }
1255
+
1256
+class nvmlPciInfo_t(_PrintableStructure):
1257
+ _fields_ = [
1258
+ # Moved to the new busId location below
1259
+ ('busIdLegacy', c_char * NVML_DEVICE_PCI_BUS_ID_BUFFER_V2_SIZE),
1260
+ ('domain', c_uint),
1261
+ ('bus', c_uint),
1262
+ ('device', c_uint),
1263
+ ('pciDeviceId', c_uint),
1264
+
1265
+ # Added in 2.285
1266
+ ('pciSubSystemId', c_uint),
1267
+ # New busId replaced the long deprecated and reserved fields with a
1268
+ # field of the same size in 9.0
1269
+ ('busId', c_char * NVML_DEVICE_PCI_BUS_ID_BUFFER_SIZE),
1270
+ ]
1271
+ _fmt_ = {
1272
+ 'domain' : "0x%08X",
1273
+ 'bus' : "0x%02X",
1274
+ 'device' : "0x%02X",
1275
+ 'pciDeviceId' : "0x%08X",
1276
+ 'pciSubSystemId' : "0x%08X",
1277
+ }
1278
+
1279
+class c_nvmlSystemDriverBranchInfo_v1_t(_PrintableStructure):
1280
+ _fields_ = [
1281
+ ('version', c_uint),
1282
+ ("branch", c_char * NVML_SYSTEM_DRIVER_VERSION_BUFFER_SIZE),
1283
+ ]
1284
+
1285
+SystemDriverBranchInfo_v1 = 0x1000054
1286
+
1287
+class c_nvmlExcludedDeviceInfo_t(_PrintableStructure):
1288
+ _fields_ = [
1289
+ ('pci', nvmlPciInfo_t),
1290
+ ('uuid', c_char * NVML_DEVICE_UUID_BUFFER_SIZE)
1291
+ ]
1292
+
1293
+class nvmlNvLinkUtilizationControl_t(_PrintableStructure):
1294
+ _fields_ = [
1295
+ ('units', _nvmlNvLinkUtilizationCountUnits_t),
1296
+ ('pktfilter', _nvmlNvLinkUtilizationCountPktTypes_t),
1297
+ ]
1298
+
1299
+class c_nvmlMemory_t(_PrintableStructure):
1300
+ _fields_ = [
1301
+ ('total', c_ulonglong),
1302
+ ('free', c_ulonglong),
1303
+ ('used', c_ulonglong),
1304
+ ]
1305
+ _fmt_ = {'<default>': "%d B"}
1306
+
1307
+class c_nvmlMemory_v2_t(_PrintableStructure):
1308
+ _fields_ = [
1309
+ ('version', c_uint),
1310
+ ('total', c_ulonglong),
1311
+ ('reserved', c_ulonglong),
1312
+ ('free', c_ulonglong),
1313
+ ('used', c_ulonglong),
1314
+ ]
1315
+ _fmt_ = {'<default>': "%d B"}
1316
+
1317
+nvmlMemory_v2 = 0x02000028
1318
+
1319
+class c_nvmlBAR1Memory_t(_PrintableStructure):
1320
+ _fields_ = [
1321
+ ('bar1Total', c_ulonglong),
1322
+ ('bar1Free', c_ulonglong),
1323
+ ('bar1Used', c_ulonglong),
1324
+ ]
1325
+ _fmt_ = {'<default>': "%d B"}
1326
+
1327
+class nvmlClkMonFaultInfo_t(Structure):
1328
+ _fields_ = [("clkApiDomain", c_uint),
1329
+ ("clkDomainFaultMask", c_uint)
1330
+ ]
1331
+
1332
+MAX_CLK_DOMAINS = 32
1333
+
1334
+class nvmlClkMonStatus_t(Structure):
1335
+ _fields_ = [("bGlobalStatus", c_uint),
1336
+ ("clkMonListSize", c_uint),
1337
+ ("clkMonList", nvmlClkMonFaultInfo_t * MAX_CLK_DOMAINS)
1338
+ ]
1339
+
1340
+# On Windows with the WDDM driver, usedGpuMemory is reported as None
1341
+# Code that processes this structure should check for None, I.E.
1342
+#
1343
+# if (info.usedGpuMemory == None):
1344
+# # TODO handle the error
1345
+# pass
1346
+# else:
1347
+# print("Using %d MiB of memory" % (info.usedGpuMemory / 1024 / 1024))
1348
+# endif
1349
+#
1350
+# See NVML documentation for more information
1351
+class c_nvmlProcessInfo_v2_t(_PrintableStructure):
1352
+ _fields_ = [
1353
+ ('pid', c_uint),
1354
+ ('usedGpuMemory', c_ulonglong),
1355
+ ('gpuInstanceId', c_uint),
1356
+ ('computeInstanceId', c_uint),
1357
+ ]
1358
+ _fmt_ = {'usedGpuMemory': "%d B"}
1359
+
1360
+c_nvmlProcessInfo_v3_t = c_nvmlProcessInfo_v2_t
1361
+
1362
+c_nvmlProcessInfo_t = c_nvmlProcessInfo_v3_t
1363
+
1364
+_nvmlProcessMode_t = c_uint
1365
+NVML_PROCESS_MODE_COMPUTE = 0
1366
+NVML_PROCESS_MODE_GRAPHICS = 1
1367
+NVML_PROCESS_MODE_MPS = 2
1368
+
1369
+class c_nvmlProcessDetail_v1_t(Structure):
1370
+ _fields_ = [
1371
+ ('pid', c_uint),
1372
+ ('usedGpuMemory', c_ulonglong),
1373
+ ('gpuInstanceId', c_uint),
1374
+ ('computeInstanceId', c_uint),
1375
+ ('usedGpuCcProtectedMemory', c_ulonglong),
1376
+ ]
1377
+
1378
+class c_nvmlProcessDetailList_v1_t(_PrintableStructure):
1379
+ _fields_ = [
1380
+ ('version', c_uint),
1381
+ ('mode', _nvmlProcessMode_t),
1382
+ ('numProcArrayEntries', c_uint),
1383
+ ('procArray', POINTER(c_nvmlProcessDetail_v1_t)),
1384
+ ]
1385
+ _fmt_ = {'numProcArrayEntries': "%d B"}
1386
+
1387
+c_nvmlProcessDetailList_t = c_nvmlProcessDetailList_v1_t
1388
+
1389
+nvmlProcessDetailList_v1 = 0x1000018
1390
+
1391
+class c_nvmlBridgeChipInfo_t(_PrintableStructure):
1392
+ _fields_ = [
1393
+ ('type', _nvmlBridgeChipType_t),
1394
+ ('fwVersion', c_uint),
1395
+ ]
1396
+
1397
+class c_nvmlBridgeChipHierarchy_t(_PrintableStructure):
1398
+ _fields_ = [
1399
+ ('bridgeCount', c_uint),
1400
+ ('bridgeChipInfo', c_nvmlBridgeChipInfo_t * 128),
1401
+ ]
1402
+
1403
+class c_nvmlEccErrorCounts_t(_PrintableStructure):
1404
+ _fields_ = [
1405
+ ('l1Cache', c_ulonglong),
1406
+ ('l2Cache', c_ulonglong),
1407
+ ('deviceMemory', c_ulonglong),
1408
+ ('registerFile', c_ulonglong),
1409
+ ]
1410
+
1411
+class c_nvmlUtilization_t(_PrintableStructure):
1412
+ _fields_ = [
1413
+ ('gpu', c_uint),
1414
+ ('memory', c_uint),
1415
+ ]
1416
+ _fmt_ = {'<default>': "%d %%"}
1417
+
1418
+# Added in 2.285
1419
+class c_nvmlHwbcEntry_t(_PrintableStructure):
1420
+ _fields_ = [
1421
+ ('hwbcId', c_uint),
1422
+ ('firmwareVersion', c_char * 32),
1423
+ ]
1424
+
1425
+class c_nvmlValue_t(Union):
1426
+ _fields_ = [
1427
+ ('dVal', c_double),
1428
+ ('uiVal', c_uint),
1429
+ ('ulVal', c_ulong),
1430
+ ('ullVal', c_ulonglong),
1431
+ ('sllVal', c_longlong),
1432
+ ('siVal', c_int),
1433
+ ('usVal', c_ushort),
1434
+ ]
1435
+
1436
+class c_nvmlSample_t(_PrintableStructure):
1437
+ _fields_ = [
1438
+ ('timeStamp', c_ulonglong),
1439
+ ('sampleValue', c_nvmlValue_t),
1440
+ ]
1441
+
1442
+class c_nvmlViolationTime_t(_PrintableStructure):
1443
+ _fields_ = [
1444
+ ('referenceTime', c_ulonglong),
1445
+ ('violationTime', c_ulonglong),
1446
+ ]
1447
+
1448
+class c_nvmlFieldValue_t(_PrintableStructure):
1449
+ _fields_ = [
1450
+ ('fieldId', c_uint32),
1451
+ ('scopeId', c_uint32),
1452
+ ('timestamp', c_int64),
1453
+ ('latencyUsec', c_int64),
1454
+ ('valueType', _nvmlValueType_t),
1455
+ ('nvmlReturn', _nvmlReturn_t),
1456
+ ('value', c_nvmlValue_t)
1457
+ ]
1458
+
1459
+NVML_NVLINK_TOTAL_SUPPORTED_BW_MODES = 23
1460
+
1461
+nvmlNvlinkSupportedBwModes_v1 = 0x100001c
1462
+class c_nvmlNvlinkSupportedBwModes_v1_t(_PrintableStructure):
1463
+ _fields_ = [
1464
+ ('version', c_uint),
1465
+ ('bwModes', c_uint8 * NVML_NVLINK_TOTAL_SUPPORTED_BW_MODES),
1466
+ ('totalBwModes', c_uint8)
1467
+ ]
1468
+
1469
+ def __init__(self):
1470
+ super(c_nvmlNvlinkSupportedBwModes_v1_t, self).__init__(version=nvmlNvlinkSupportedBwModes_v1)
1471
+
1472
+nvmlNvlinkGetBwMode_v1 = 0x100000c
1473
+class c_nvmlNvlinkGetBwMode_v1_t(_PrintableStructure):
1474
+ _fields_ = [
1475
+ ('version', c_uint),
1476
+ ('bIsBest', c_uint),
1477
+ ('bwMode', c_uint8)
1478
+ ]
1479
+
1480
+ def __init__(self):
1481
+ super(c_nvmlNvlinkGetBwMode_v1_t, self).__init__(version=nvmlNvlinkGetBwMode_v1)
1482
+
1483
+nvmlNvlinkSetBwMode_v1 = 0x100000c
1484
+class c_nvmlNvlinkSetBwMode_v1_t(_PrintableStructure):
1485
+ _fields_ = [
1486
+ ('version', c_uint),
1487
+ ('bSetBest', c_uint),
1488
+ ('bwMode', c_uint8)
1489
+ ]
1490
+
1491
+ def __init__(self):
1492
+ super(c_nvmlNvlinkSetBwMode_v1_t, self).__init__(version=nvmlNvlinkSetBwMode_v1)
1493
+
1494
+class c_nvmlVgpuHeterogeneousMode_v1_t(_PrintableStructure):
1495
+ _fields_ = [
1496
+ ('version', c_uint),
1497
+ ('mode', c_uint),
1498
+ ]
1499
+
1500
+VgpuHeterogeneousMode_v1 = 0x1000008
1501
+
1502
+class c_nvmlVgpuPlacementId_v1_t(_PrintableStructure):
1503
+ _fields_ = [
1504
+ ('version', c_uint),
1505
+ ('placementId', c_uint),
1506
+ ]
1507
+
1508
+VgpuPlacementId_v1 = 0x1000008
1509
+
1510
+class c_nvmlVgpuPlacementList_v1_t(_PrintableStructure):
1511
+ _fields_ = [
1512
+ ('version', c_uint),
1513
+ ('count', c_uint),
1514
+ ('placementSize', c_uint),
1515
+ ('placementIds', POINTER(c_uint)),
1516
+ ]
1517
+
1518
+VgpuPlacementList_v1 = 0x1000018
1519
+
1520
+NVML_VGPU_PGPU_HETEROGENEOUS_MODE = 0
1521
+NVML_VGPU_PGPU_HOMOGENEOUS_MODE = 1
1522
+
1523
+class c_nvmlVgpuPlacementList_v2_t(_PrintableStructure):
1524
+ _fields_ = [
1525
+ ('version', c_uint),
1526
+ ('placementSize', c_uint),
1527
+ ('count', c_uint),
1528
+ ('placementIds', POINTER(c_uint)),
1529
+ ('mode', c_uint),
1530
+ ]
1531
+
1532
+VgpuPlacementList_v2 = 0x2000020
1533
+
1534
+class c_nvmlVgpuTypeBar1Info_v1_t(_PrintableStructure):
1535
+ _fields_ = [
1536
+ ('version', c_uint),
1537
+ ('bar1Size', c_ulonglong),
1538
+ ]
1539
+
1540
+VgpuTypeBar1Info_v1 = 0x1000010
1541
+
1542
+class c_nvmlVgpuInstanceUtilizationSample_t(_PrintableStructure):
1543
+ _fields_ = [
1544
+ ('vgpuInstance', _nvmlVgpuInstance_t),
1545
+ ('timeStamp', c_ulonglong),
1546
+ ('smUtil', c_nvmlValue_t),
1547
+ ('memUtil', c_nvmlValue_t),
1548
+ ('encUtil', c_nvmlValue_t),
1549
+ ('decUtil', c_nvmlValue_t),
1550
+ ]
1551
+
1552
+class c_nvmlVgpuInstanceUtilizationInfo_v1_t(_PrintableStructure):
1553
+ _fields_ = [
1554
+ ('timeStamp', c_ulonglong),
1555
+ ('vgpuInstance', _nvmlVgpuInstance_t),
1556
+ ('smUtil', c_nvmlValue_t),
1557
+ ('memUtil', c_nvmlValue_t),
1558
+ ('encUtil', c_nvmlValue_t),
1559
+ ('decUtil', c_nvmlValue_t),
1560
+ ('jpgUtil', c_nvmlValue_t),
1561
+ ('ofaUtil', c_nvmlValue_t),
1562
+ ]
1563
+
1564
+class c_nvmlVgpuInstancesUtilizationInfo_v1_t(_PrintableStructure):
1565
+ _fields_ = [
1566
+ ('version', c_uint),
1567
+ ('sampleValType', _nvmlValueType_t),
1568
+ ('vgpuInstanceCount', c_uint),
1569
+ ('lastSeenTimeStamp', c_ulonglong),
1570
+ ('vgpuUtilArray', POINTER(c_nvmlVgpuInstanceUtilizationInfo_v1_t)),
1571
+ ]
1572
+
1573
+VgpuInstancesUtilizationInfo_v1 = 0x01000020
1574
+
1575
+class c_nvmlVgpuProcessUtilizationSample_t(_PrintableStructure):
1576
+ _fields_ = [
1577
+ ('vgpuInstance', _nvmlVgpuInstance_t),
1578
+ ('pid', c_uint),
1579
+ ('processName', c_char * NVML_VGPU_NAME_BUFFER_SIZE),
1580
+ ('timeStamp', c_ulonglong),
1581
+ ('smUtil', c_uint),
1582
+ ('memUtil', c_uint),
1583
+ ('encUtil', c_uint),
1584
+ ('decUtil', c_uint),
1585
+ ]
1586
+
1587
+class c_nvmlVgpuProcessUtilizationInfo_v1_t(_PrintableStructure):
1588
+ _fields_ = [
1589
+ ('processName', c_char * NVML_VGPU_NAME_BUFFER_SIZE),
1590
+ ('timeStamp', c_ulonglong),
1591
+ ('vgpuInstance', _nvmlVgpuInstance_t),
1592
+ ('pid', c_uint),
1593
+ ('smUtil', c_uint),
1594
+ ('memUtil', c_uint),
1595
+ ('encUtil', c_uint),
1596
+ ('decUtil', c_uint),
1597
+ ('jpgUtil', c_uint),
1598
+ ('ofaUtil', c_uint),
1599
+ ]
1600
+
1601
+class c_nvmlVgpuProcessesUtilizationInfo_v1_t(_PrintableStructure):
1602
+ _fields_ = [
1603
+ ('version', c_uint),
1604
+ ('vgpuProcessCount', c_uint),
1605
+ ('lastSeenTimeStamp', c_ulonglong),
1606
+ ('vgpuProcUtilArray', POINTER(c_nvmlVgpuProcessUtilizationInfo_v1_t)),
1607
+ ]
1608
+
1609
+VgpuProcessesUtilizationInfo_v1 = 0x01000018
1610
+
1611
+class nvmlVgpuRuntimeState_v1_t(_PrintableStructure):
1612
+ _fields_ = [
1613
+ ('version', c_uint),
1614
+ ('size', c_ulonglong),
1615
+ ]
1616
+
1617
+VgpuRuntimeState_v1 = 0x1000010
1618
+
1619
+class c_nvmlVgpuLicenseExpiry_t(_PrintableStructure):
1620
+ _fields_ = [
1621
+ ('year', c_uint32),
1622
+ ('month', c_uint16),
1623
+ ('day', c_uint16),
1624
+ ('hour', c_uint16),
1625
+ ('min', c_uint16),
1626
+ ('sec', c_uint16),
1627
+ ('status', c_uint8),
1628
+ ]
1629
+
1630
+NVML_GRID_LICENSE_STATE_UNKNOWN = 0
1631
+NVML_GRID_LICENSE_STATE_UNINITIALIZED = 1
1632
+NVML_GRID_LICENSE_STATE_UNLICENSED_UNRESTRICTED = 2
1633
+NVML_GRID_LICENSE_STATE_UNLICENSED_RESTRICTED = 3
1634
+NVML_GRID_LICENSE_STATE_UNLICENSED = 4
1635
+NVML_GRID_LICENSE_STATE_LICENSED = 5
1636
+
1637
+class c_nvmlVgpuLicenseInfo_t(_PrintableStructure):
1638
+ _fields_ = [
1639
+ ('isLicensed', c_uint8),
1640
+ ('licenseExpiry', c_nvmlVgpuLicenseExpiry_t),
1641
+ ('currentState', c_uint),
1642
+ ]
1643
+
1644
+class c_nvmlEncoderSession_t(_PrintableStructure):
1645
+ _fields_ = [
1646
+ ('sessionId', c_uint),
1647
+ ('pid', c_uint),
1648
+ ('vgpuInstance', _nvmlVgpuInstance_t),
1649
+ ('codecType', c_uint),
1650
+ ('hResolution', c_uint),
1651
+ ('vResolution', c_uint),
1652
+ ('averageFps', c_uint),
1653
+ ('encodeLatency', c_uint),
1654
+ ]
1655
+
1656
+class c_nvmlProcessUtilizationSample_t(_PrintableStructure):
1657
+ _fields_ = [
1658
+ ('pid', c_uint),
1659
+ ('timeStamp', c_ulonglong),
1660
+ ('smUtil', c_uint),
1661
+ ('memUtil', c_uint),
1662
+ ('encUtil', c_uint),
1663
+ ('decUtil', c_uint),
1664
+ ]
1665
+
1666
+class c_nvmlProcessUtilizationInfo_v1_t(_PrintableStructure):
1667
+ _fields_ = [
1668
+ ('timeStamp', c_ulonglong),
1669
+ ('pid', c_uint),
1670
+ ('smUtil', c_uint),
1671
+ ('memUtil', c_uint),
1672
+ ('encUtil', c_uint),
1673
+ ('decUtil', c_uint),
1674
+ ('jpgUtil', c_uint),
1675
+ ('ofaUtil', c_uint),
1676
+ ]
1677
+
1678
+class c_nvmlProcessesUtilizationInfo_v1_t(_PrintableStructure):
1679
+ _fields_ = [
1680
+ ('version', c_uint),
1681
+ ('processSamplesCount', c_uint),
1682
+ ('lastSeenTimeStamp', c_ulonglong),
1683
+ ('procUtilArray', POINTER(c_nvmlProcessUtilizationInfo_v1_t)),
1684
+ ]
1685
+
1686
+ProcessesUtilizationInfo_v1 = 0x01000018
1687
+
1688
+class c_nvmlGridLicenseExpiry_t(_PrintableStructure):
1689
+ _fields_ = [
1690
+ ('year', c_uint32),
1691
+ ('month', c_uint16),
1692
+ ('day', c_uint16),
1693
+ ('hour', c_uint16),
1694
+ ('min', c_uint16),
1695
+ ('sec', c_uint16),
1696
+ ('status', c_uint8),
1697
+ ]
1698
+
1699
+class c_nvmlGridLicensableFeature_v4_t(_PrintableStructure):
1700
+ _fields_ = [
1701
+ ('featureCode', _nvmlGridLicenseFeatureCode_t),
1702
+ ('featureState', c_uint),
1703
+ ('licenseInfo', c_char * NVML_GRID_LICENSE_BUFFER_SIZE),
1704
+ ('productName', c_char * NVML_GRID_LICENSE_BUFFER_SIZE),
1705
+ ('featureEnabled', c_uint),
1706
+ ('licenseExpiry', c_nvmlGridLicenseExpiry_t),
1707
+ ]
1708
+
1709
+class c_nvmlGridLicensableFeatures_v4_t(_PrintableStructure):
1710
+ _fields_ = [
1711
+ ('isGridLicenseSupported', c_int),
1712
+ ('licensableFeaturesCount', c_uint),
1713
+ ('gridLicensableFeatures', c_nvmlGridLicensableFeature_v4_t * NVML_GRID_LICENSE_FEATURE_MAX_COUNT),
1714
+ ]
1715
+
1716
+class c_nvmlGridLicensableFeature_v3_t(_PrintableStructure):
1717
+ _fields_ = [
1718
+ ('featureCode', _nvmlGridLicenseFeatureCode_t),
1719
+ ('featureState', c_uint),
1720
+ ('licenseInfo', c_char * NVML_GRID_LICENSE_BUFFER_SIZE),
1721
+ ('productName', c_char * NVML_GRID_LICENSE_BUFFER_SIZE),
1722
+ ('featureEnabled', c_uint),
1723
+ ]
1724
+
1725
+class c_nvmlGridLicensableFeatures_v3_t(_PrintableStructure):
1726
+ _fields_ = [
1727
+ ('isGridLicenseSupported', c_int),
1728
+ ('licensableFeaturesCount', c_uint),
1729
+ ('gridLicensableFeatures', c_nvmlGridLicensableFeature_v3_t * NVML_GRID_LICENSE_FEATURE_MAX_COUNT),
1730
+ ]
1731
+
1732
+class c_nvmlGridLicensableFeature_v2_t(_PrintableStructure):
1733
+ _fields_ = [
1734
+ ('featureCode', _nvmlGridLicenseFeatureCode_t),
1735
+ ('featureState', c_uint),
1736
+ ('licenseInfo', c_char * NVML_GRID_LICENSE_BUFFER_SIZE),
1737
+ ('productName', c_char * NVML_GRID_LICENSE_BUFFER_SIZE),
1738
+ ]
1739
+
1740
+class c_nvmlGridLicensableFeatures_v2_t(_PrintableStructure):
1741
+ _fields_ = [
1742
+ ('isGridLicenseSupported', c_int),
1743
+ ('licensableFeaturesCount', c_uint),
1744
+ ('gridLicensableFeatures', c_nvmlGridLicensableFeature_v2_t * NVML_GRID_LICENSE_FEATURE_MAX_COUNT),
1745
+ ]
1746
+
1747
+class c_nvmlGridLicensableFeature_t(_PrintableStructure):
1748
+ _fields_ = [
1749
+ ('featureCode', _nvmlGridLicenseFeatureCode_t),
1750
+ ('featureState', c_uint),
1751
+ ('licenseInfo', c_char * NVML_GRID_LICENSE_BUFFER_SIZE),
1752
+ ]
1753
+
1754
+class c_nvmlGridLicensableFeatures_t(_PrintableStructure):
1755
+ _fields_ = [
1756
+ ('isGridLicenseSupported', c_int),
1757
+ ('licensableFeaturesCount', c_uint),
1758
+ ('gridLicensableFeatures', c_nvmlGridLicensableFeature_t * NVML_GRID_LICENSE_FEATURE_MAX_COUNT),
1759
+ ]
1760
+
1761
+class c_nvmlMarginTemperature_v1_t(_PrintableStructure):
1762
+ _fields_ = [
1763
+ ('version', c_uint),
1764
+ ('marginTemperature', c_int),
1765
+ ]
1766
+
1767
+nvmlMarginTemperature_v1 = 0x1000008
1768
+
1769
+## Event structures
1770
+class struct_c_nvmlEventSet_t(Structure):
1771
+ pass # opaque handle
1772
+c_nvmlEventSet_t = POINTER(struct_c_nvmlEventSet_t)
1773
+
1774
+nvmlEventTypeSingleBitEccError = 0x0000000000000001
1775
+nvmlEventTypeDoubleBitEccError = 0x0000000000000002
1776
+nvmlEventTypePState = 0x0000000000000004
1777
+nvmlEventTypeXidCriticalError = 0x0000000000000008
1778
+nvmlEventTypeClock = 0x0000000000000010
1779
+nvmlEventTypePowerSourceChange = 0x0000000000000080
1780
+nvmlEventMigConfigChange = 0x0000000000000100
1781
+nvmlEventTypeSingleBitEccErrorStorm = 0x0000000000000200
1782
+nvmlEventTypeDramRetirementEvent = 0x0000000000000400
1783
+nvmlEventTypeDramRetirementFailure = 0x0000000000000800
1784
+nvmlEventTypeNonFatalPoisonError = 0x0000000000001000
1785
+nvmlEventTypeFatalPoisonError = 0x0000000000002000
1786
+nvmlEventTypeGpuUnavailableError = 0x0000000000004000
1787
+nvmlEventTypeGpuRecoveryAction = 0x0000000000008000
1788
+nvmlEventTypeNone = 0x0000000000000000
1789
+nvmlEventTypeAll = (
1790
+ nvmlEventTypeNone
1791
+ | nvmlEventTypeSingleBitEccError
1792
+ | nvmlEventTypeDoubleBitEccError
1793
+ | nvmlEventTypePState
1794
+ | nvmlEventTypeClock
1795
+ | nvmlEventTypePowerSourceChange
1796
+ | nvmlEventTypeXidCriticalError
1797
+ | nvmlEventMigConfigChange
1798
+ | nvmlEventTypeSingleBitEccErrorStorm
1799
+ | nvmlEventTypeDramRetirementEvent
1800
+ | nvmlEventTypeDramRetirementFailure
1801
+ | nvmlEventTypeNonFatalPoisonError
1802
+ | nvmlEventTypeFatalPoisonError
1803
+ | nvmlEventTypeGpuUnavailableError
1804
+ | nvmlEventTypeGpuRecoveryAction
1805
+ )
1806
+
1807
+## Clock Event Reasons defines
1808
+nvmlClocksEventReasonGpuIdle = 0x0000000000000001
1809
+nvmlClocksEventReasonApplicationsClocksSetting = 0x0000000000000002
1810
+nvmlClocksEventReasonUserDefinedClocks = nvmlClocksEventReasonApplicationsClocksSetting # deprecated, use nvmlClocksEventReasonApplicationsClocksSetting
1811
+nvmlClocksEventReasonSwPowerCap = 0x0000000000000004
1812
+nvmlClocksEventReasonHwSlowdown = 0x0000000000000008
1813
+nvmlClocksEventReasonSyncBoost = 0x0000000000000010
1814
+nvmlClocksEventReasonSwThermalSlowdown = 0x0000000000000020
1815
+nvmlClocksEventReasonHwThermalSlowdown = 0x0000000000000040
1816
+nvmlClocksEventReasonHwPowerBrakeSlowdown = 0x0000000000000080
1817
+nvmlClocksEventReasonDisplayClockSetting = 0x0000000000000100
1818
+nvmlClocksEventReasonNone = 0x0000000000000000
1819
+nvmlClocksEventReasonAll = (
1820
+ nvmlClocksEventReasonNone |
1821
+ nvmlClocksEventReasonGpuIdle |
1822
+ nvmlClocksEventReasonApplicationsClocksSetting |
1823
+ nvmlClocksEventReasonSwPowerCap |
1824
+ nvmlClocksEventReasonHwSlowdown |
1825
+ nvmlClocksEventReasonSyncBoost |
1826
+ nvmlClocksEventReasonSwThermalSlowdown |
1827
+ nvmlClocksEventReasonHwThermalSlowdown |
1828
+ nvmlClocksEventReasonHwPowerBrakeSlowdown |
1829
+ nvmlClocksEventReasonDisplayClockSetting
1830
+ )
1831
+
1832
+## Following have been deprecated
1833
+nvmlClocksThrottleReasonGpuIdle = 0x0000000000000001
1834
+nvmlClocksThrottleReasonApplicationsClocksSetting = 0x0000000000000002
1835
+nvmlClocksThrottleReasonUserDefinedClocks = nvmlClocksThrottleReasonApplicationsClocksSetting # deprecated, use nvmlClocksThrottleReasonApplicationsClocksSetting
1836
+nvmlClocksThrottleReasonSwPowerCap = 0x0000000000000004
1837
+nvmlClocksThrottleReasonHwSlowdown = 0x0000000000000008
1838
+nvmlClocksThrottleReasonSyncBoost = 0x0000000000000010
1839
+nvmlClocksThrottleReasonSwThermalSlowdown = 0x0000000000000020
1840
+nvmlClocksThrottleReasonHwThermalSlowdown = 0x0000000000000040
1841
+nvmlClocksThrottleReasonHwPowerBrakeSlowdown = 0x0000000000000080
1842
+nvmlClocksThrottleReasonDisplayClockSetting = 0x0000000000000100
1843
+nvmlClocksThrottleReasonNone = 0x0000000000000000
1844
+nvmlClocksThrottleReasonAll = (
1845
+ nvmlClocksThrottleReasonNone |
1846
+ nvmlClocksThrottleReasonGpuIdle |
1847
+ nvmlClocksThrottleReasonApplicationsClocksSetting |
1848
+ nvmlClocksThrottleReasonSwPowerCap |
1849
+ nvmlClocksThrottleReasonHwSlowdown |
1850
+ nvmlClocksThrottleReasonSyncBoost |
1851
+ nvmlClocksThrottleReasonSwThermalSlowdown |
1852
+ nvmlClocksThrottleReasonHwThermalSlowdown |
1853
+ nvmlClocksThrottleReasonHwPowerBrakeSlowdown |
1854
+ nvmlClocksThrottleReasonDisplayClockSetting
1855
+ )
1856
+
1857
+class c_nvmlEventData_t(_PrintableStructure):
1858
+ _fields_ = [
1859
+ ('device', c_nvmlDevice_t),
1860
+ ('eventType', c_ulonglong),
1861
+ ('eventData', c_ulonglong),
1862
+ ('gpuInstanceId', c_uint),
1863
+ ('computeInstanceId', c_uint)
1864
+ ]
1865
+ _fmt_ = {'eventType': "0x%08X"}
1866
+
1867
+class c_nvmlAccountingStats_t(_PrintableStructure):
1868
+ _fields_ = [
1869
+ ('gpuUtilization', c_uint),
1870
+ ('memoryUtilization', c_uint),
1871
+ ('maxMemoryUsage', c_ulonglong),
1872
+ ('time', c_ulonglong),
1873
+ ('startTime', c_ulonglong),
1874
+ ('isRunning', c_uint),
1875
+ ('reserved', c_uint * 5)
1876
+ ]
1877
+
1878
+class c_nvmlVgpuVersion_t(Structure):
1879
+ _fields_ = [("minVersion", c_uint),
1880
+ ("maxVersion", c_uint)
1881
+ ]
1882
+
1883
+class c_nvmlVgpuMetadata_t(_PrintableStructure):
1884
+ _fields_ = [("version", c_uint),
1885
+ ("revision", c_uint),
1886
+ ("guestInfoState", _nvmlVgpuGuestInfoState_t),
1887
+ ("guestDriverVersion", c_char * NVML_SYSTEM_DRIVER_VERSION_BUFFER_SIZE),
1888
+ ("hostDriverVersion", c_char * NVML_SYSTEM_DRIVER_VERSION_BUFFER_SIZE),
1889
+ ("reserved", c_uint * 6),
1890
+ ("vgpuVirtualizationCaps", c_uint),
1891
+ ("guestVgpuVersion", c_uint),
1892
+ ("opaqueDataSize", c_uint),
1893
+ ("opaqueData", c_char * NVML_VGPU_METADATA_OPAQUE_DATA_SIZE)
1894
+ ]
1895
+
1896
+class c_nvmlVgpuPgpuMetadata_t(_PrintableStructure):
1897
+ _fields_ = [("version", c_uint),
1898
+ ("revision", c_uint),
1899
+ ("hostDriverVersion", c_char * NVML_SYSTEM_DRIVER_VERSION_BUFFER_SIZE),
1900
+ ("pgpuVirtualizationCaps", c_uint),
1901
+ ("reserved", c_uint * 5),
1902
+ ("hostSupportedVgpuRange", c_nvmlVgpuVersion_t),
1903
+ ("opaqueDataSize", c_uint),
1904
+ ("opaqueData", c_char * NVML_VGPU_PGPU_METADATA_OPAQUE_DATA_SIZE)
1905
+ ]
1906
+
1907
+class c_nvmlVgpuPgpuCompatibility_t(Structure):
1908
+ _fields_ = [("vgpuVmCompatibility", _nvmlVgpuVmCompatibility_t),
1909
+ ("compatibilityLimitCode", _nvmlVgpuPgpuCompatibilityLimitCode_t)
1910
+ ]
1911
+
1912
+## vGPU scheduler policy defines
1913
+NVML_VGPU_SCHEDULER_POLICY_UNKNOWN = 0
1914
+NVML_VGPU_SCHEDULER_POLICY_BEST_EFFORT = 1
1915
+NVML_VGPU_SCHEDULER_POLICY_EQUAL_SHARE = 2
1916
+NVML_VGPU_SCHEDULER_POLICY_FIXED_SHARE = 3
1917
+
1918
+## Supported vGPU scheduler policy count
1919
+NVML_SUPPORTED_VGPU_SCHEDULER_POLICY_COUNT = 3
1920
+
1921
+NVML_SCHEDULER_SW_MAX_LOG_ENTRIES = 200
1922
+
1923
+NVML_VGPU_SCHEDULER_ARR_DEFAULT = 0
1924
+NVML_VGPU_SCHEDULER_ARR_DISABLE = 1
1925
+NVML_VGPU_SCHEDULER_ARR_ENABLE = 2
1926
+
1927
+class c_nvmlVgpuSchedDataWithARR_t(_PrintableStructure):
1928
+ _fields_ = [
1929
+ ('avgFactor', c_uint),
1930
+ ('timeslice', c_uint),
1931
+ ]
1932
+
1933
+class c_nvmlVgpuSchedData_t(_PrintableStructure):
1934
+ _fields_ = [
1935
+ ('timeslice', c_uint),
1936
+ ]
1937
+
1938
+class c_nvmlVgpuSchedulerParams_t(Union):
1939
+ _fields_ = [
1940
+ ('vgpuSchedDataWithARR', c_nvmlVgpuSchedDataWithARR_t),
1941
+ ('vgpuSchedData', c_nvmlVgpuSchedData_t),
1942
+ ]
1943
+
1944
+class c_nvmlVgpuSchedulerLogEntry_t(_PrintableStructure):
1945
+ _fields_ = [
1946
+ ('timestamp', c_ulonglong),
1947
+ ('timeRunTotal', c_ulonglong),
1948
+ ('timeRun', c_ulonglong),
1949
+ ('swRunlistId', c_uint),
1950
+ ('targetTimeSlice', c_ulonglong),
1951
+ ('cumulativePreemptionTime', c_ulonglong),
1952
+ ]
1953
+
1954
+class c_nvmlVgpuSchedulerLog_t(_PrintableStructure):
1955
+ _fields_ = [
1956
+ ('engineId', c_uint),
1957
+ ('schedulerPolicy', c_uint),
1958
+ ('arrMode', c_uint),
1959
+ ('schedulerParams', c_nvmlVgpuSchedulerParams_t),
1960
+ ('entriesCount', c_uint),
1961
+ ('logEntries', c_nvmlVgpuSchedulerLogEntry_t * NVML_SCHEDULER_SW_MAX_LOG_ENTRIES),
1962
+ ]
1963
+
1964
+class c_nvmlVgpuSchedulerGetState_t(_PrintableStructure):
1965
+ _fields_ = [
1966
+ ('schedulerPolicy', c_uint),
1967
+ ('arrMode', c_uint),
1968
+ ('schedulerParams', c_nvmlVgpuSchedulerParams_t),
1969
+ ]
1970
+
1971
+class c_nvmlVgpuSchedSetDataWithARR_t(_PrintableStructure):
1972
+ _fields_ = [
1973
+ ('avgFactor', c_uint),
1974
+ ('frequency', c_uint),
1975
+ ]
1976
+
1977
+class c_nvmlVgpuSchedSetData_t(_PrintableStructure):
1978
+ _fields_ = [
1979
+ ('timeslice', c_uint),
1980
+ ]
1981
+
1982
+class c_nvmlVgpuSchedulerSetParams_t(Union):
1983
+ _fields_ = [
1984
+ ('vgpuSchedDataWithARR', c_nvmlVgpuSchedSetDataWithARR_t),
1985
+ ('vgpuSchedData', c_nvmlVgpuSchedSetData_t),
1986
+ ]
1987
+
1988
+class c_nvmlVgpuSchedulerSetState_t(_PrintableStructure):
1989
+ _fields_ = [
1990
+ ('schedulerPolicy', c_uint),
1991
+ ('enableARRMode', c_uint),
1992
+ ('schedulerParams', c_nvmlVgpuSchedulerSetParams_t),
1993
+ ]
1994
+
1995
+class c_nvmlVgpuSchedulerCapabilities_t(_PrintableStructure):
1996
+ _fields_ = [
1997
+ ('supportedSchedulers', c_uint * NVML_SUPPORTED_VGPU_SCHEDULER_POLICY_COUNT),
1998
+ ('maxTimeslice', c_uint),
1999
+ ('minTimeslice', c_uint),
2000
+ ('isArrModeSupported', c_uint),
2001
+ ('maxFrequencyForARR', c_uint),
2002
+ ('minFrequencyForARR', c_uint),
2003
+ ('maxAvgFactorForARR', c_uint),
2004
+ ('minAvgFactorForARR', c_uint),
2005
+ ]
2006
+
2007
+class c_nvmlFBCStats_t(Structure):
2008
+ _fields_ = [("sessionsCount", c_uint),
2009
+ ("averageFPS", c_uint),
2010
+ ("averageLatency", c_uint)
2011
+ ]
2012
+
2013
+class c_nvmlFBCSession_t(_PrintableStructure):
2014
+ _fields_ = [
2015
+ ('sessionId', c_uint),
2016
+ ('pid', c_uint),
2017
+ ('vgpuInstance', _nvmlVgpuInstance_t),
2018
+ ('displayOrdinal', c_uint),
2019
+ ('sessionType', c_uint),
2020
+ ('sessionFlags', c_uint),
2021
+ ('hMaxResolution', c_uint),
2022
+ ('vMaxResolution', c_uint),
2023
+ ('hResolution', c_uint),
2024
+ ('vResolution', c_uint),
2025
+ ('averageFPS', c_uint),
2026
+ ('averageLatency', c_uint),
2027
+ ]
2028
+
2029
+NVML_DEVICE_MIG_DISABLE = 0x0
2030
+NVML_DEVICE_MIG_ENABLE = 0x1
2031
+
2032
+NVML_GPU_INSTANCE_PROFILE_1_SLICE = 0x0
2033
+NVML_GPU_INSTANCE_PROFILE_2_SLICE = 0x1
2034
+NVML_GPU_INSTANCE_PROFILE_3_SLICE = 0x2
2035
+NVML_GPU_INSTANCE_PROFILE_4_SLICE = 0x3
2036
+NVML_GPU_INSTANCE_PROFILE_7_SLICE = 0x4
2037
+NVML_GPU_INSTANCE_PROFILE_8_SLICE = 0x5
2038
+NVML_GPU_INSTANCE_PROFILE_6_SLICE = 0x6
2039
+NVML_GPU_INSTANCE_PROFILE_1_SLICE_REV1 = 0x7
2040
+NVML_GPU_INSTANCE_PROFILE_2_SLICE_REV1 = 0x8
2041
+NVML_GPU_INSTANCE_PROFILE_1_SLICE_REV2 = 0x9
2042
+NVML_GPU_INSTANCE_PROFILE_1_SLICE_GFX = 0xA
2043
+NVML_GPU_INSTANCE_PROFILE_2_SLICE_GFX = 0xB
2044
+NVML_GPU_INSTANCE_PROFILE_4_SLICE_GFX = 0xC
2045
+NVML_GPU_INSTANCE_PROFILE_COUNT = 0xD
2046
+
2047
+class c_nvmlGpuInstancePlacement_t(Structure):
2048
+ _fields_ = [("start", c_uint),
2049
+ ("size", c_uint)
2050
+ ]
2051
+
2052
+class c_nvmlGpuInstanceProfileInfo_t(Structure):
2053
+ _fields_ = [("id", c_uint),
2054
+ ("isP2pSupported", c_uint),
2055
+ ("sliceCount", c_uint),
2056
+ ("instanceCount", c_uint),
2057
+ ("multiprocessorCount", c_uint),
2058
+ ("copyEngineCount", c_uint),
2059
+ ("decoderCount", c_uint),
2060
+ ("encoderCount", c_uint),
2061
+ ("jpegCount", c_uint),
2062
+ ("ofaCount", c_uint),
2063
+ ("memorySizeMB", c_ulonglong),
2064
+ ]
2065
+
2066
+nvmlGpuInstanceProfileInfo_v2 = 0x02000098
2067
+
2068
+class c_nvmlGpuInstanceProfileInfo_v2_t(_PrintableStructure):
2069
+ _fields_ = [("version", c_uint),
2070
+ ("id", c_uint),
2071
+ ("isP2pSupported", c_uint),
2072
+ ("sliceCount", c_uint),
2073
+ ("instanceCount", c_uint),
2074
+ ("multiprocessorCount", c_uint),
2075
+ ("copyEngineCount", c_uint),
2076
+ ("decoderCount", c_uint),
2077
+ ("encoderCount", c_uint),
2078
+ ("jpegCount", c_uint),
2079
+ ("ofaCount", c_uint),
2080
+ ("memorySizeMB", c_ulonglong),
2081
+ ("name", c_char * NVML_DEVICE_NAME_V2_BUFFER_SIZE)
2082
+ ]
2083
+
2084
+ def __init__(self):
2085
+ super(c_nvmlGpuInstanceProfileInfo_v2_t, self).__init__(version=nvmlGpuInstanceProfileInfo_v2)
2086
+
2087
+class c_nvmlGpuInstanceInfo_t(Structure):
2088
+ _fields_ = [("device", c_nvmlDevice_t),
2089
+ ("id", c_uint),
2090
+ ("profileId", c_uint),
2091
+ ("placement", c_nvmlGpuInstancePlacement_t)
2092
+ ]
2093
+
2094
+class struct_c_nvmlGpuInstance_t(Structure):
2095
+ pass # opaque handle
2096
+c_nvmlGpuInstance_t = POINTER(struct_c_nvmlGpuInstance_t)
2097
+
2098
+NVML_COMPUTE_INSTANCE_PROFILE_1_SLICE = 0x0
2099
+NVML_COMPUTE_INSTANCE_PROFILE_2_SLICE = 0x1
2100
+NVML_COMPUTE_INSTANCE_PROFILE_3_SLICE = 0x2
2101
+NVML_COMPUTE_INSTANCE_PROFILE_4_SLICE = 0x3
2102
+NVML_COMPUTE_INSTANCE_PROFILE_7_SLICE = 0x4
2103
+NVML_COMPUTE_INSTANCE_PROFILE_8_SLICE = 0x5
2104
+NVML_COMPUTE_INSTANCE_PROFILE_6_SLICE = 0x6
2105
+NVML_COMPUTE_INSTANCE_PROFILE_1_SLICE_REV1 = 0x7
2106
+NVML_COMPUTE_INSTANCE_PROFILE_COUNT = 0x8
2107
+
2108
+NVML_COMPUTE_INSTANCE_ENGINE_PROFILE_SHARED = 0x0
2109
+NVML_COMPUTE_INSTANCE_ENGINE_PROFILE_COUNT = 0x1
2110
+
2111
+class c_nvmlComputeInstancePlacement_t(Structure):
2112
+ _fields_ = [("start", c_uint),
2113
+ ("size", c_uint)
2114
+ ]
2115
+
2116
+class c_nvmlComputeInstanceProfileInfo_t(Structure):
2117
+ _fields_ = [("id", c_uint),
2118
+ ("sliceCount", c_uint),
2119
+ ("instanceCount", c_uint),
2120
+ ("multiprocessorCount", c_uint),
2121
+ ("sharedCopyEngineCount", c_uint),
2122
+ ("sharedDecoderCount", c_uint),
2123
+ ("sharedEncoderCount", c_uint),
2124
+ ("sharedJpegCount", c_uint),
2125
+ ("sharedOfaCount", c_uint)
2126
+ ]
2127
+
2128
+nvmlComputeInstanceProfileInfo_v2 = 0x02000088
2129
+
2130
+class c_nvmlComputeInstanceProfileInfo_v2_t(_PrintableStructure):
2131
+ _fields_ = [("version", c_uint),
2132
+ ("id", c_uint),
2133
+ ("sliceCount", c_uint),
2134
+ ("instanceCount", c_uint),
2135
+ ("multiprocessorCount", c_uint),
2136
+ ("sharedCopyEngineCount", c_uint),
2137
+ ("sharedDecoderCount", c_uint),
2138
+ ("sharedEncoderCount", c_uint),
2139
+ ("sharedJpegCount", c_uint),
2140
+ ("sharedOfaCount", c_uint),
2141
+ ("name", c_char * NVML_DEVICE_NAME_V2_BUFFER_SIZE)
2142
+ ]
2143
+
2144
+ def __init__(self):
2145
+ super(c_nvmlComputeInstanceProfileInfo_v2_t, self).__init__(version=nvmlComputeInstanceProfileInfo_v2)
2146
+
2147
+class c_nvmlComputeInstanceInfo_t(Structure):
2148
+ _fields_ = [("device", c_nvmlDevice_t),
2149
+ ("gpuInstance", c_nvmlGpuInstance_t),
2150
+ ("id", c_uint),
2151
+ ("profileId", c_uint),
2152
+ ("placement", c_nvmlComputeInstancePlacement_t)
2153
+ ]
2154
+
2155
+NVML_MAX_GPU_UTILIZATIONS = 8
2156
+NVML_GPU_UTILIZATION_DOMAIN_GPU = 0
2157
+NVML_GPU_UTILIZATION_DOMAIN_FB = 1
2158
+NVML_GPU_UTILIZATION_DOMAIN_VID = 2
2159
+NVML_GPU_UTILIZATION_DOMAIN_BUS = 3
2160
+class c_nvmlGpuDynamicPstatesUtilization_t(Structure):
2161
+ _fields_ = [("bIsPresent", c_uint, 1),
2162
+ ("percentage", c_uint),
2163
+ ("incThreshold", c_uint),
2164
+ ("decThreshold", c_uint)]
2165
+class c_nvmlGpuDynamicPstatesInfo_t(Structure):
2166
+ _fields_ = [("flags", c_uint),
2167
+ ("utilization", c_nvmlGpuDynamicPstatesUtilization_t * NVML_MAX_GPU_UTILIZATIONS)]
2168
+
2169
+NVML_MAX_THERMAL_SENSORS_PER_GPU = 3
2170
+
2171
+NVML_THERMAL_TARGET_NONE = 0
2172
+NVML_THERMAL_TARGET_GPU = 1
2173
+NVML_THERMAL_TARGET_MEMORY = 2
2174
+NVML_THERMAL_TARGET_POWER_SUPPLY = 4
2175
+NVML_THERMAL_TARGET_BOARD = 8
2176
+NVML_THERMAL_TARGET_VCD_BOARD = 9
2177
+NVML_THERMAL_TARGET_VCD_INLET = 10
2178
+NVML_THERMAL_TARGET_VCD_OUTLET = 11
2179
+NVML_THERMAL_TARGET_ALL = 15
2180
+NVML_THERMAL_TARGET_UNKNOWN = -1
2181
+
2182
+NVML_THERMAL_CONTROLLER_NONE = 0
2183
+NVML_THERMAL_CONTROLLER_GPU_INTERNAL = 1
2184
+NVML_THERMAL_CONTROLLER_ADM1032 = 2
2185
+NVML_THERMAL_CONTROLLER_ADT7461 = 3
2186
+NVML_THERMAL_CONTROLLER_MAX6649 = 4
2187
+NVML_THERMAL_CONTROLLER_MAX1617 = 5
2188
+NVML_THERMAL_CONTROLLER_LM99 = 6
2189
+NVML_THERMAL_CONTROLLER_LM89 = 7
2190
+NVML_THERMAL_CONTROLLER_LM64 = 8
2191
+NVML_THERMAL_CONTROLLER_G781 = 9
2192
+NVML_THERMAL_CONTROLLER_ADT7473 = 10
2193
+NVML_THERMAL_CONTROLLER_SBMAX6649 = 11
2194
+NVML_THERMAL_CONTROLLER_VBIOSEVT = 12
2195
+NVML_THERMAL_CONTROLLER_OS = 13
2196
+NVML_THERMAL_CONTROLLER_NVSYSCON_CANOAS = 14
2197
+NVML_THERMAL_CONTROLLER_NVSYSCON_E551 = 15
2198
+NVML_THERMAL_CONTROLLER_MAX6649R = 16
2199
+NVML_THERMAL_CONTROLLER_ADT7473S = 17
2200
+NVML_THERMAL_CONTROLLER_UNKNOWN = -1
2201
+
2202
+class c_nvmlGpuThermalSensor_t(Structure):
2203
+ _fields_ = [("controller", c_int),
2204
+ ("defaultMinTemp", c_int),
2205
+ ("defaultMaxTemp", c_int),
2206
+ ("currentTemp", c_int),
2207
+ ("target", c_int)]
2208
+class c_nvmlGpuThermalSettings_t(Structure):
2209
+ _fields_ = [("count", c_uint),
2210
+ ("sensor", c_nvmlGpuThermalSensor_t * NVML_MAX_THERMAL_SENSORS_PER_GPU)]
2211
+
2212
+_nvmlCoolerControl_t = c_uint
2213
+NVML_THERMAL_COOLER_SIGNAL_NONE = 0
2214
+NVML_THERMAL_COOLER_SIGNAL_TOGGLE = 1
2215
+NVML_THERMAL_COOLER_SIGNAL_VARIABLE = 2
2216
+NVML_THERMAL_COOLER_SIGNAL_COUNT = 3
2217
+
2218
+_nvmlCoolerTarget_t = c_uint
2219
+NVML_THERMAL_COOLER_TARGET_NONE = (1 << 0)
2220
+NVML_THERMAL_COOLER_TARGET_GPU = (1 << 1)
2221
+NVML_THERMAL_COOLER_TARGET_MEMORY = (1 << 2)
2222
+NVML_THERMAL_COOLER_TARGET_POWER_SUPPLY = (1 << 3)
2223
+NVML_THERMAL_COOLER_TARGET_GPU_RELATED = (NVML_THERMAL_COOLER_TARGET_GPU | NVML_THERMAL_COOLER_TARGET_MEMORY | NVML_THERMAL_COOLER_TARGET_POWER_SUPPLY)
2224
+
2225
+class c_nvmlCoolerInfo_t(_PrintableStructure):
2226
+ _fields_ = [("version", c_uint),
2227
+ ("index", c_uint),
2228
+ ("coolerControlType", _nvmlCoolerControl_t),
2229
+ ("coolerTarget", _nvmlCoolerTarget_t)
2230
+ ]
2231
+
2232
+nvmlCoolerInfo_v1 = 0x1000010
2233
+
2234
+def nvmlDeviceGetCoolerInfo(handle):
2235
+ c_coolerInfo = c_nvmlCoolerInfo_t()
2236
+ c_coolerInfo.version = nvmlCoolerInfo_v1
2237
+ c_coolerInfo.index = 0
2238
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetCoolerInfo")
2239
+ ret = fn(handle, byref(c_coolerInfo))
2240
+ _nvmlCheckReturn(ret)
2241
+ return [c_coolerInfo.coolerControlType, c_coolerInfo.coolerTarget]
2242
+
2243
+class struct_c_nvmlComputeInstance_t(Structure):
2244
+ pass # opaque handle
2245
+c_nvmlComputeInstance_t = POINTER(struct_c_nvmlComputeInstance_t)
2246
+
2247
+class c_nvmlDeviceAttributes(Structure):
2248
+ _fields_ = [("multiprocessorCount", c_uint),
2249
+ ("sharedCopyEngineCount", c_uint),
2250
+ ("sharedDecoderCount", c_uint),
2251
+ ("sharedEncoderCount", c_uint),
2252
+ ("sharedJpegCount", c_uint),
2253
+ ("sharedOfaCount", c_uint),
2254
+ ("gpuInstanceSliceCount", c_uint),
2255
+ ("computeInstanceSliceCount", c_uint),
2256
+ ("memorySizeMB", c_ulonglong),
2257
+ ]
2258
+
2259
+class c_nvmlRowRemapperHistogramValues(Structure):
2260
+ _fields_ = [("max", c_uint),
2261
+ ("high", c_uint),
2262
+ ("partial", c_uint),
2263
+ ("low", c_uint),
2264
+ ("none", c_uint)
2265
+ ]
2266
+
2267
+NVML_GPU_CERT_CHAIN_SIZE = 0x1000
2268
+NVML_GPU_ATTESTATION_CERT_CHAIN_SIZE = 0x1400
2269
+NVML_CC_GPU_CEC_NONCE_SIZE = 0x20
2270
+NVML_CC_GPU_ATTESTATION_REPORT_SIZE = 0x2000
2271
+NVML_CC_GPU_CEC_ATTESTATION_REPORT_SIZE = 0x1000
2272
+NVML_CC_CEC_ATTESTATION_REPORT_NOT_PRESENT = 0
2273
+NVML_CC_CEC_ATTESTATION_REPORT_PRESENT = 1
2274
+
2275
+class c_nvmlConfComputeSystemState_t(Structure):
2276
+ _fields_ = [('environment', c_uint),
2277
+ ('ccFeature', c_uint),
2278
+ ('devToolsMode', c_uint),
2279
+ ]
2280
+
2281
+nvmlSystemConfComputeSettings_v1 = 0x1000014
2282
+
2283
+class c_nvmlSystemConfComputeSettings_v1_t(Structure):
2284
+ _fields_ = [('version', c_uint),
2285
+ ('environment', c_uint),
2286
+ ('ccFeature', c_uint),
2287
+ ('devToolsMode', c_uint),
2288
+ ('multiGpuMode', c_uint),
2289
+ ]
2290
+ def __init__(self):
2291
+ super(c_nvmlSystemConfComputeSettings_v1_t, self).__init__(version=nvmlSystemConfComputeSettings_v1)
2292
+
2293
+class c_nvmlConfComputeSystemCaps_t(Structure):
2294
+ _fields_ = [('cpuCaps', c_uint),
2295
+ ('gpusCaps', c_uint),
2296
+ ]
2297
+
2298
+class c_nvmlConfComputeMemSizeInfo_t(Structure):
2299
+ _fields_ = [('protectedMemSizeKib', c_ulonglong),
2300
+ ('unprotectedMemSizeKib', c_ulonglong),
2301
+ ]
2302
+
2303
+class c_nvmlConfComputeGpuCertificate_t(Structure):
2304
+ _fields_ = [('certChainSize', c_uint),
2305
+ ('attestationCertChainSize', c_uint),
2306
+ ('certChain', c_uint8 * NVML_GPU_CERT_CHAIN_SIZE),
2307
+ ('attestationCertChain', c_uint8 * NVML_GPU_ATTESTATION_CERT_CHAIN_SIZE),
2308
+ ]
2309
+
2310
+class c_nvmlConfComputeGpuAttestationReport_t(Structure):
2311
+ _fields_ = [('isCecAttestationReportPresent', c_uint),
2312
+ ('attestationReportSize', c_uint),
2313
+ ('cecAttestationReportSize', c_uint),
2314
+ ('nonce', c_uint8 * NVML_CC_GPU_CEC_NONCE_SIZE),
2315
+ ('attestationReport', c_uint8 * NVML_CC_GPU_ATTESTATION_REPORT_SIZE),
2316
+ ('cecAttestationReport', c_uint8 * NVML_CC_GPU_CEC_ATTESTATION_REPORT_SIZE),
2317
+ ]
2318
+
2319
+class c_nvmlConfComputeSetKeyRotationThresholdInfo_t(Structure):
2320
+ _fields_ = [('version', c_uint),
2321
+ ('maxAttackerAdvantage', c_ulong),
2322
+ ]
2323
+ConfComputeSetKeyRotationThresholdInfo_v1 = 0x1000010
2324
+
2325
+class c_nvmlConfComputeGetKeyRotationThresholdInfo_t(Structure):
2326
+ _fields_ = [('version', c_uint),
2327
+ ('attackerAdvantage', c_ulong),
2328
+ ]
2329
+ConfComputeGetKeyRotationThresholdInfo_v1 = 0x1000010
2330
+
2331
+
2332
+## string/bytes conversion for ease of use
2333
+def convertStrBytes(func):
2334
+ '''
2335
+ In python 3, strings are unicode instead of bytes, and need to be converted for ctypes
2336
+ Args from caller: (1, 'string', <__main__.c_nvmlDevice_t at 0xFFFFFFFF>)
2337
+ Args passed to function: (1, b'string', <__main__.c_nvmlDevice_t at 0xFFFFFFFF)>
2338
+ ----
2339
+ Returned from function: b'returned string'
2340
+ Returned to caller: 'returned string'
2341
+ '''
2342
+ @wraps(func)
2343
+ def wrapper(*args, **kwargs):
2344
+ # encoding a str returns bytes in python 2 and 3
2345
+ args = [arg.encode() if isinstance(arg, str) else arg for arg in args]
2346
+ res = func(*args, **kwargs)
2347
+ # In python 2, str and bytes are the same
2348
+ # In python 3, str is unicode and should be decoded.
2349
+ # Ctypes handles most conversions, this only effects c_char and char arrays.
2350
+ if isinstance(res, bytes):
2351
+ if isinstance(res, str):
2352
+ return res
2353
+ return res.decode()
2354
+ return res
2355
+
2356
+ if sys.version_info >= (3,):
2357
+ return wrapper
2358
+ return func
2359
+
2360
+def throwOnVersionMismatch(func):
2361
+ @wraps(func)
2362
+ def wrapper(*args, **kwargs):
2363
+ try:
2364
+ return func(*args, **kwargs)
2365
+ except NVMLError_FunctionNotFound:
2366
+ raise NVMLLibraryMismatchError("Unversioned function called and the "
2367
+ "pyNVML version does not match the NVML lib version. "
2368
+ "Either use matching pyNVML and NVML lib versions or "
2369
+ "use a versioned function such as " + func.__name__ + "_v2")
2370
+ return wrapper
2371
+
2372
+## C function wrappers ##
2373
+def nvmlInitWithFlags(flags):
2374
+ _LoadNvmlLibrary()
2375
+
2376
+ #
2377
+ # Initialize the library
2378
+ #
2379
+ fn = _nvmlGetFunctionPointer("nvmlInitWithFlags")
2380
+ ret = fn(flags)
2381
+ _nvmlCheckReturn(ret)
2382
+
2383
+ # Atomically update refcount
2384
+ global _nvmlLib_refcount
2385
+ libLoadLock.acquire()
2386
+ _nvmlLib_refcount += 1
2387
+ libLoadLock.release()
2388
+ return None
2389
+
2390
+def nvmlInit():
2391
+ nvmlInitWithFlags(0)
2392
+ return None
2393
+
2394
+def _LoadNvmlLibrary():
2395
+ '''
2396
+ Load the library if it isn't loaded already
2397
+ '''
2398
+ global nvmlLib
2399
+
2400
+ if (nvmlLib == None):
2401
+ # lock to ensure only one caller loads the library
2402
+ libLoadLock.acquire()
2403
+
2404
+ try:
2405
+ # ensure the library still isn't loaded
2406
+ if (nvmlLib == None):
2407
+ try:
2408
+ if (sys.platform[:3] == "win"):
2409
+ # cdecl calling convention
2410
+ try:
2411
+ # Check for nvml.dll in System32 first for DCH drivers
2412
+ nvmlLib = CDLL(os.path.join(os.getenv("WINDIR", "C:/Windows"), "System32/nvml.dll"))
2413
+ except OSError as ose:
2414
+ # If nvml.dll is not found in System32, it should be in ProgramFiles
2415
+ # load nvml.dll from %ProgramFiles%/NVIDIA Corporation/NVSMI/nvml.dll
2416
+ nvmlLib = CDLL(os.path.join(os.getenv("ProgramFiles", "C:/Program Files"), "NVIDIA Corporation/NVSMI/nvml.dll"))
2417
+ else:
2418
+ # assume linux
2419
+ nvmlLib = CDLL("libnvidia-ml.so.1")
2420
+ except OSError as ose:
2421
+ _nvmlCheckReturn(NVML_ERROR_LIBRARY_NOT_FOUND)
2422
+ if (nvmlLib == None):
2423
+ _nvmlCheckReturn(NVML_ERROR_LIBRARY_NOT_FOUND)
2424
+ finally:
2425
+ # lock is always freed
2426
+ libLoadLock.release()
2427
+
2428
+def nvmlShutdown():
2429
+ #
2430
+ # Leave the library loaded, but shutdown the interface
2431
+ #
2432
+ fn = _nvmlGetFunctionPointer("nvmlShutdown")
2433
+ ret = fn()
2434
+ _nvmlCheckReturn(ret)
2435
+
2436
+ # Atomically update refcount
2437
+ global _nvmlLib_refcount
2438
+ libLoadLock.acquire()
2439
+ if (0 < _nvmlLib_refcount):
2440
+ _nvmlLib_refcount -= 1
2441
+ libLoadLock.release()
2442
+ return None
2443
+
2444
+# Added in 2.285
2445
+@convertStrBytes
2446
+def nvmlErrorString(result):
2447
+ fn = _nvmlGetFunctionPointer("nvmlErrorString")
2448
+ fn.restype = c_char_p # otherwise return is an int
2449
+ ret = fn(result)
2450
+ return ret
2451
+
2452
+# Added in 2.285
2453
+@convertStrBytes
2454
+def nvmlSystemGetNVMLVersion():
2455
+ c_version = create_string_buffer(NVML_SYSTEM_NVML_VERSION_BUFFER_SIZE)
2456
+ fn = _nvmlGetFunctionPointer("nvmlSystemGetNVMLVersion")
2457
+ ret = fn(c_version, c_uint(NVML_SYSTEM_NVML_VERSION_BUFFER_SIZE))
2458
+ _nvmlCheckReturn(ret)
2459
+ return c_version.value
2460
+
2461
+def nvmlSystemGetCudaDriverVersion():
2462
+ c_cuda_version = c_int()
2463
+ fn = _nvmlGetFunctionPointer("nvmlSystemGetCudaDriverVersion")
2464
+ ret = fn(byref(c_cuda_version))
2465
+ _nvmlCheckReturn(ret)
2466
+ return c_cuda_version.value
2467
+
2468
+def nvmlSystemGetCudaDriverVersion_v2():
2469
+ c_cuda_version = c_int()
2470
+ fn = _nvmlGetFunctionPointer("nvmlSystemGetCudaDriverVersion_v2")
2471
+ ret = fn(byref(c_cuda_version))
2472
+ _nvmlCheckReturn(ret)
2473
+ return c_cuda_version.value
2474
+
2475
+# Added in 2.285
2476
+@convertStrBytes
2477
+def nvmlSystemGetProcessName(pid):
2478
+ c_name = create_string_buffer(1024)
2479
+ fn = _nvmlGetFunctionPointer("nvmlSystemGetProcessName")
2480
+ ret = fn(c_uint(pid), c_name, c_uint(1024))
2481
+ _nvmlCheckReturn(ret)
2482
+ return c_name.value
2483
+
2484
+@convertStrBytes
2485
+def nvmlSystemGetDriverVersion():
2486
+ c_version = create_string_buffer(NVML_SYSTEM_DRIVER_VERSION_BUFFER_SIZE)
2487
+ fn = _nvmlGetFunctionPointer("nvmlSystemGetDriverVersion")
2488
+ ret = fn(c_version, c_uint(NVML_SYSTEM_DRIVER_VERSION_BUFFER_SIZE))
2489
+ _nvmlCheckReturn(ret)
2490
+ return c_version.value
2491
+
2492
+# Added in 2.285
2493
+def nvmlSystemGetHicVersion():
2494
+ c_count = c_uint(0)
2495
+ hics = None
2496
+ fn = _nvmlGetFunctionPointer("nvmlSystemGetHicVersion")
2497
+
2498
+ # get the count
2499
+ ret = fn(byref(c_count), None)
2500
+
2501
+ # this should only fail with insufficient size
2502
+ if ((ret != NVML_SUCCESS) and
2503
+ (ret != NVML_ERROR_INSUFFICIENT_SIZE)):
2504
+ raise NVMLError(ret)
2505
+
2506
+ # If there are no hics
2507
+ if (c_count.value == 0):
2508
+ return []
2509
+
2510
+ hic_array = c_nvmlHwbcEntry_t * c_count.value
2511
+ hics = hic_array()
2512
+ ret = fn(byref(c_count), hics)
2513
+ _nvmlCheckReturn(ret)
2514
+ return hics
2515
+
2516
+def nvmlSystemGetDriverBranch():
2517
+ c_branchInfo = c_nvmlSystemDriverBranchInfo_v1_t(0)
2518
+ c_branchInfo.version = SystemDriverBranchInfo_v1
2519
+ fn = _nvmlGetFunctionPointer("nvmlSystemGetDriverBranch")
2520
+ ret = fn(byref(c_branchInfo), c_uint(NVML_SYSTEM_DRIVER_VERSION_BUFFER_SIZE))
2521
+ _nvmlCheckReturn(ret)
2522
+ return c_branchInfo
2523
+
2524
+## Unit get functions
2525
+def nvmlUnitGetCount():
2526
+ c_count = c_uint()
2527
+ fn = _nvmlGetFunctionPointer("nvmlUnitGetCount")
2528
+ ret = fn(byref(c_count))
2529
+ _nvmlCheckReturn(ret)
2530
+ return c_count.value
2531
+
2532
+def nvmlUnitGetHandleByIndex(index):
2533
+ c_index = c_uint(index)
2534
+ unit = c_nvmlUnit_t()
2535
+ fn = _nvmlGetFunctionPointer("nvmlUnitGetHandleByIndex")
2536
+ ret = fn(c_index, byref(unit))
2537
+ _nvmlCheckReturn(ret)
2538
+ return unit
2539
+
2540
+def nvmlUnitGetUnitInfo(unit):
2541
+ c_info = c_nvmlUnitInfo_t()
2542
+ fn = _nvmlGetFunctionPointer("nvmlUnitGetUnitInfo")
2543
+ ret = fn(unit, byref(c_info))
2544
+ _nvmlCheckReturn(ret)
2545
+ return c_info
2546
+
2547
+def nvmlUnitGetLedState(unit):
2548
+ c_state = c_nvmlLedState_t()
2549
+ fn = _nvmlGetFunctionPointer("nvmlUnitGetLedState")
2550
+ ret = fn(unit, byref(c_state))
2551
+ _nvmlCheckReturn(ret)
2552
+ return c_state
2553
+
2554
+def nvmlUnitGetPsuInfo(unit):
2555
+ c_info = c_nvmlPSUInfo_t()
2556
+ fn = _nvmlGetFunctionPointer("nvmlUnitGetPsuInfo")
2557
+ ret = fn(unit, byref(c_info))
2558
+ _nvmlCheckReturn(ret)
2559
+ return c_info
2560
+
2561
+def nvmlUnitGetTemperature(unit, type):
2562
+ c_temp = c_uint()
2563
+ fn = _nvmlGetFunctionPointer("nvmlUnitGetTemperature")
2564
+ ret = fn(unit, c_uint(type), byref(c_temp))
2565
+ _nvmlCheckReturn(ret)
2566
+ return c_temp.value
2567
+
2568
+def nvmlUnitGetFanSpeedInfo(unit):
2569
+ c_speeds = c_nvmlUnitFanSpeeds_t()
2570
+ fn = _nvmlGetFunctionPointer("nvmlUnitGetFanSpeedInfo")
2571
+ ret = fn(unit, byref(c_speeds))
2572
+ _nvmlCheckReturn(ret)
2573
+ return c_speeds
2574
+
2575
+# added to API
2576
+def nvmlUnitGetDeviceCount(unit):
2577
+ c_count = c_uint(0)
2578
+ # query the unit to determine device count
2579
+ fn = _nvmlGetFunctionPointer("nvmlUnitGetDevices")
2580
+ ret = fn(unit, byref(c_count), None)
2581
+ if (ret == NVML_ERROR_INSUFFICIENT_SIZE):
2582
+ ret = NVML_SUCCESS
2583
+ _nvmlCheckReturn(ret)
2584
+ return c_count.value
2585
+
2586
+def nvmlUnitGetDevices(unit):
2587
+ c_count = c_uint(nvmlUnitGetDeviceCount(unit))
2588
+ device_array = c_nvmlDevice_t * c_count.value
2589
+ c_devices = device_array()
2590
+ fn = _nvmlGetFunctionPointer("nvmlUnitGetDevices")
2591
+ ret = fn(unit, byref(c_count), c_devices)
2592
+ _nvmlCheckReturn(ret)
2593
+ return c_devices
2594
+
2595
+## Device get functions
2596
+def nvmlDeviceGetCount():
2597
+ c_count = c_uint()
2598
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetCount_v2")
2599
+ ret = fn(byref(c_count))
2600
+ _nvmlCheckReturn(ret)
2601
+ return c_count.value
2602
+
2603
+def nvmlDeviceGetHandleByIndex(index):
2604
+ c_index = c_uint(index)
2605
+ device = c_nvmlDevice_t()
2606
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetHandleByIndex_v2")
2607
+ ret = fn(c_index, byref(device))
2608
+ _nvmlCheckReturn(ret)
2609
+ return device
2610
+
2611
+@convertStrBytes
2612
+def nvmlDeviceGetHandleBySerial(serial):
2613
+ c_serial = c_char_p(serial)
2614
+ device = c_nvmlDevice_t()
2615
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetHandleBySerial")
2616
+ ret = fn(c_serial, byref(device))
2617
+ _nvmlCheckReturn(ret)
2618
+ return device
2619
+
2620
+@convertStrBytes
2621
+def nvmlDeviceGetHandleByUUID(uuid):
2622
+ c_uuid = c_char_p(uuid)
2623
+ device = c_nvmlDevice_t()
2624
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetHandleByUUID")
2625
+ ret = fn(c_uuid, byref(device))
2626
+ _nvmlCheckReturn(ret)
2627
+ return device
2628
+
2629
+@convertStrBytes
2630
+def nvmlDeviceGetHandleByPciBusId(pciBusId):
2631
+ c_busId = c_char_p(pciBusId)
2632
+ device = c_nvmlDevice_t()
2633
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetHandleByPciBusId_v2")
2634
+ ret = fn(c_busId, byref(device))
2635
+ _nvmlCheckReturn(ret)
2636
+ return device
2637
+
2638
+@convertStrBytes
2639
+def nvmlDeviceGetName(handle):
2640
+ c_name = create_string_buffer(NVML_DEVICE_NAME_V2_BUFFER_SIZE)
2641
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetName")
2642
+ ret = fn(handle, c_name, c_uint(NVML_DEVICE_NAME_V2_BUFFER_SIZE))
2643
+ _nvmlCheckReturn(ret)
2644
+ return c_name.value
2645
+
2646
+class c_nvmlDevicePerfModes_v1_t(_PrintableStructure):
2647
+ _fields_ = [
2648
+ ('version', c_uint),
2649
+ ('str', c_char * NVML_PERF_MODES_BUFFER_SIZE),
2650
+ ]
2651
+
2652
+nvmlDevicePerfModes_v1 = 0x1000804
2653
+
2654
+@convertStrBytes
2655
+def nvmlDeviceGetPerformanceModes(handle):
2656
+ perfModes = c_nvmlDevicePerfModes_v1_t()
2657
+ perfModes.version = nvmlDevicePerfModes_v1
2658
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetPerformanceModes")
2659
+ ret = fn(handle, byref(perfModes))
2660
+ _nvmlCheckReturn(ret)
2661
+ return perfModes.str
2662
+
2663
+class c_nvmlDeviceCurrentClockFreqs_v1_t(_PrintableStructure):
2664
+ _fields_ = [
2665
+ ('version', c_uint),
2666
+ ('str', c_char * NVML_PERF_MODES_BUFFER_SIZE),
2667
+ ]
2668
+
2669
+nvmlDeviceCurrentClockFreqs_v1 = 0x1000804
2670
+
2671
+@convertStrBytes
2672
+def nvmlDeviceGetCurrentClockFreqs(handle):
2673
+ currentClockFreqs = c_nvmlDeviceCurrentClockFreqs_v1_t()
2674
+ currentClockFreqs.version = nvmlDeviceCurrentClockFreqs_v1
2675
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetCurrentClockFreqs")
2676
+ ret = fn(handle, byref(currentClockFreqs))
2677
+ _nvmlCheckReturn(ret)
2678
+ return currentClockFreqs.str
2679
+
2680
+def nvmlDeviceGetBoardId(handle):
2681
+ c_id = c_uint();
2682
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetBoardId")
2683
+ ret = fn(handle, byref(c_id))
2684
+ _nvmlCheckReturn(ret)
2685
+ return c_id.value
2686
+
2687
+def nvmlDeviceGetMultiGpuBoard(handle):
2688
+ c_multiGpu = c_uint();
2689
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetMultiGpuBoard")
2690
+ ret = fn(handle, byref(c_multiGpu))
2691
+ _nvmlCheckReturn(ret)
2692
+ return c_multiGpu.value
2693
+
2694
+def nvmlDeviceGetBrand(handle):
2695
+ c_type = _nvmlBrandType_t()
2696
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetBrand")
2697
+ ret = fn(handle, byref(c_type))
2698
+ _nvmlCheckReturn(ret)
2699
+ return c_type.value
2700
+
2701
+def nvmlDeviceGetC2cModeInfoV1(handle):
2702
+ c_info = c_nvmlC2cModeInfo_v1_t()
2703
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetC2cModeInfoV")
2704
+ ret = fn(handle, byref(c_info))
2705
+ _nvmlCheckReturn(ret)
2706
+ return c_info
2707
+
2708
+def nvmlDeviceGetC2cModeInfoV(handle):
2709
+ return nvmlDeviceGetC2cModeInfoV1(handle)
2710
+
2711
+@convertStrBytes
2712
+def nvmlDeviceGetBoardPartNumber(handle):
2713
+ c_part_number = create_string_buffer(NVML_DEVICE_PART_NUMBER_BUFFER_SIZE)
2714
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetBoardPartNumber")
2715
+ ret = fn(handle, c_part_number, c_uint(NVML_DEVICE_PART_NUMBER_BUFFER_SIZE))
2716
+ _nvmlCheckReturn(ret)
2717
+ return c_part_number.value
2718
+
2719
+@convertStrBytes
2720
+def nvmlDeviceGetSerial(handle):
2721
+ c_serial = create_string_buffer(NVML_DEVICE_SERIAL_BUFFER_SIZE)
2722
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetSerial")
2723
+ ret = fn(handle, c_serial, c_uint(NVML_DEVICE_SERIAL_BUFFER_SIZE))
2724
+ _nvmlCheckReturn(ret)
2725
+ return c_serial.value
2726
+
2727
+def nvmlDeviceGetModuleId(handle, moduleId=c_uint()):
2728
+ isReference = type(moduleId) is not c_uint
2729
+ moduleIdRef = moduleId if isReference else byref(moduleId)
2730
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetModuleId")
2731
+ ret = fn(handle, moduleIdRef)
2732
+ if isReference:
2733
+ return ret
2734
+ else:
2735
+ _nvmlCheckReturn(ret)
2736
+ return moduleId.value
2737
+
2738
+def nvmlDeviceGetMemoryAffinity(handle, nodeSetSize, scope):
2739
+ affinity_array = c_ulonglong * nodeSetSize
2740
+ c_affinity = affinity_array()
2741
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetMemoryAffinity")
2742
+ ret = fn(handle, nodeSetSize, byref(c_affinity), _nvmlAffinityScope_t(scope))
2743
+ _nvmlCheckReturn(ret)
2744
+ return c_affinity
2745
+
2746
+def nvmlDeviceGetCpuAffinityWithinScope(handle, cpuSetSize, scope):
2747
+ affinity_array = c_ulonglong * cpuSetSize
2748
+ c_affinity = affinity_array()
2749
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetCpuAffinityWithinScope")
2750
+ ret = fn(handle, cpuSetSize, byref(c_affinity), _nvmlAffinityScope_t(scope))
2751
+ _nvmlCheckReturn(ret)
2752
+ return c_affinity
2753
+
2754
+def nvmlDeviceGetCpuAffinity(handle, cpuSetSize):
2755
+ affinity_array = c_ulonglong * cpuSetSize
2756
+ c_affinity = affinity_array()
2757
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetCpuAffinity")
2758
+ ret = fn(handle, cpuSetSize, byref(c_affinity))
2759
+ _nvmlCheckReturn(ret)
2760
+ return c_affinity
2761
+
2762
+def nvmlDeviceSetCpuAffinity(handle):
2763
+ fn = _nvmlGetFunctionPointer("nvmlDeviceSetCpuAffinity")
2764
+ ret = fn(handle)
2765
+ _nvmlCheckReturn(ret)
2766
+ return None
2767
+
2768
+def nvmlDeviceClearCpuAffinity(handle):
2769
+ fn = _nvmlGetFunctionPointer("nvmlDeviceClearCpuAffinity")
2770
+ ret = fn(handle)
2771
+ _nvmlCheckReturn(ret)
2772
+ return None
2773
+
2774
+def nvmlDeviceGetNumaNodeId(handle):
2775
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetNumaNodeId")
2776
+ node = c_int()
2777
+ ret = fn(handle, byref(node))
2778
+ _nvmlCheckReturn(ret)
2779
+ return node.value
2780
+
2781
+def nvmlDeviceGetMinorNumber(handle):
2782
+ c_minor_number = c_uint()
2783
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetMinorNumber")
2784
+ ret = fn(handle, byref(c_minor_number))
2785
+ _nvmlCheckReturn(ret)
2786
+ return c_minor_number.value
2787
+
2788
+@convertStrBytes
2789
+def nvmlDeviceGetUUID(handle):
2790
+ c_uuid = create_string_buffer(NVML_DEVICE_UUID_V2_BUFFER_SIZE)
2791
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetUUID")
2792
+ ret = fn(handle, c_uuid, c_uint(NVML_DEVICE_UUID_V2_BUFFER_SIZE))
2793
+ _nvmlCheckReturn(ret)
2794
+ return c_uuid.value
2795
+
2796
+@convertStrBytes
2797
+def nvmlDeviceGetInforomVersion(handle, infoRomObject):
2798
+ c_version = create_string_buffer(NVML_DEVICE_INFOROM_VERSION_BUFFER_SIZE)
2799
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetInforomVersion")
2800
+ ret = fn(handle, _nvmlInforomObject_t(infoRomObject),
2801
+ c_version, c_uint(NVML_DEVICE_INFOROM_VERSION_BUFFER_SIZE))
2802
+ _nvmlCheckReturn(ret)
2803
+ return c_version.value
2804
+
2805
+# Added in 4.304
2806
+@convertStrBytes
2807
+def nvmlDeviceGetInforomImageVersion(handle):
2808
+ c_version = create_string_buffer(NVML_DEVICE_INFOROM_VERSION_BUFFER_SIZE)
2809
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetInforomImageVersion")
2810
+ ret = fn(handle, c_version, c_uint(NVML_DEVICE_INFOROM_VERSION_BUFFER_SIZE))
2811
+ _nvmlCheckReturn(ret)
2812
+ return c_version.value
2813
+
2814
+# Added in 4.304
2815
+def nvmlDeviceGetInforomConfigurationChecksum(handle):
2816
+ c_checksum = c_uint()
2817
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetInforomConfigurationChecksum")
2818
+ ret = fn(handle, byref(c_checksum))
2819
+ _nvmlCheckReturn(ret)
2820
+ return c_checksum.value
2821
+
2822
+# Added in 4.304
2823
+def nvmlDeviceValidateInforom(handle):
2824
+ fn = _nvmlGetFunctionPointer("nvmlDeviceValidateInforom")
2825
+ ret = fn(handle)
2826
+ _nvmlCheckReturn(ret)
2827
+ return None
2828
+
2829
+def nvmlDeviceGetLastBBXFlushTime(handle):
2830
+ c_timestamp = c_ulonglong()
2831
+ c_durationUs = c_ulong()
2832
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetLastBBXFlushTime")
2833
+ ret = fn(handle, byref(c_timestamp), byref(c_durationUs))
2834
+ _nvmlCheckReturn(ret)
2835
+ return [c_timestamp.value, c_durationUs.value]
2836
+
2837
+def nvmlDeviceGetDisplayMode(handle):
2838
+ c_mode = _nvmlEnableState_t()
2839
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetDisplayMode")
2840
+ ret = fn(handle, byref(c_mode))
2841
+ _nvmlCheckReturn(ret)
2842
+ return c_mode.value
2843
+
2844
+def nvmlDeviceGetDisplayActive(handle):
2845
+ c_mode = _nvmlEnableState_t()
2846
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetDisplayActive")
2847
+ ret = fn(handle, byref(c_mode))
2848
+ _nvmlCheckReturn(ret)
2849
+ return c_mode.value
2850
+
2851
+
2852
+def nvmlDeviceGetPersistenceMode(handle):
2853
+ c_state = _nvmlEnableState_t()
2854
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetPersistenceMode")
2855
+ ret = fn(handle, byref(c_state))
2856
+ _nvmlCheckReturn(ret)
2857
+ return c_state.value
2858
+
2859
+def nvmlDeviceGetPciInfoExt(handle, c_info):
2860
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetPciInfoExt")
2861
+ ret = fn(handle, c_info)
2862
+ _nvmlCheckReturn(ret)
2863
+ return None
2864
+
2865
+def nvmlDeviceGetPciInfo_v3(handle):
2866
+ c_info = nvmlPciInfo_t()
2867
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetPciInfo_v3")
2868
+ ret = fn(handle, byref(c_info))
2869
+ _nvmlCheckReturn(ret)
2870
+ return c_info
2871
+
2872
+def nvmlDeviceGetPciInfo(handle):
2873
+ return nvmlDeviceGetPciInfo_v3(handle)
2874
+
2875
+def nvmlDeviceGetClockInfo(handle, type):
2876
+ c_clock = c_uint()
2877
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetClockInfo")
2878
+ ret = fn(handle, _nvmlClockType_t(type), byref(c_clock))
2879
+ _nvmlCheckReturn(ret)
2880
+ return c_clock.value
2881
+
2882
+# Added in 2.285
2883
+def nvmlDeviceGetMaxClockInfo(handle, type):
2884
+ c_clock = c_uint()
2885
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetMaxClockInfo")
2886
+ ret = fn(handle, _nvmlClockType_t(type), byref(c_clock))
2887
+ _nvmlCheckReturn(ret)
2888
+ return c_clock.value
2889
+
2890
+# Added in 4.304
2891
+def nvmlDeviceGetApplicationsClock(handle, type):
2892
+ c_clock = c_uint()
2893
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetApplicationsClock")
2894
+ ret = fn(handle, _nvmlClockType_t(type), byref(c_clock))
2895
+ _nvmlCheckReturn(ret)
2896
+ return c_clock.value
2897
+
2898
+def nvmlDeviceGetMaxCustomerBoostClock(handle, type):
2899
+ c_clock = c_uint()
2900
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetMaxCustomerBoostClock")
2901
+ ret = fn(handle, _nvmlClockType_t(type), byref(c_clock))
2902
+ _nvmlCheckReturn(ret)
2903
+ return c_clock.value
2904
+
2905
+def nvmlDeviceGetClock(handle, type, id):
2906
+ c_clock = c_uint()
2907
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetClock")
2908
+ ret = fn(handle, _nvmlClockType_t(type), _nvmlClockId_t(id), byref(c_clock))
2909
+ _nvmlCheckReturn(ret)
2910
+ return c_clock.value
2911
+
2912
+# Added in 5.319
2913
+def nvmlDeviceGetDefaultApplicationsClock(handle, type):
2914
+ c_clock = c_uint()
2915
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetDefaultApplicationsClock")
2916
+ ret = fn(handle, _nvmlClockType_t(type), byref(c_clock))
2917
+ _nvmlCheckReturn(ret)
2918
+ return c_clock.value
2919
+
2920
+# Added in 4.304
2921
+def nvmlDeviceGetSupportedMemoryClocks(handle):
2922
+ # first call to get the size
2923
+ c_count = c_uint(0)
2924
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetSupportedMemoryClocks")
2925
+ ret = fn(handle, byref(c_count), None)
2926
+
2927
+ if (ret == NVML_SUCCESS):
2928
+ # special case, no clocks
2929
+ return []
2930
+ elif (ret == NVML_ERROR_INSUFFICIENT_SIZE):
2931
+ # typical case
2932
+ clocks_array = c_uint * c_count.value
2933
+ c_clocks = clocks_array()
2934
+
2935
+ # make the call again
2936
+ ret = fn(handle, byref(c_count), c_clocks)
2937
+ _nvmlCheckReturn(ret)
2938
+
2939
+ procs = []
2940
+ for i in range(c_count.value):
2941
+ procs.append(c_clocks[i])
2942
+
2943
+ return procs
2944
+ else:
2945
+ # error case
2946
+ raise NVMLError(ret)
2947
+
2948
+# Added in 4.304
2949
+def nvmlDeviceGetSupportedGraphicsClocks(handle, memoryClockMHz):
2950
+ # first call to get the size
2951
+ c_count = c_uint(0)
2952
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetSupportedGraphicsClocks")
2953
+ ret = fn(handle, c_uint(memoryClockMHz), byref(c_count), None)
2954
+
2955
+ if (ret == NVML_SUCCESS):
2956
+ # special case, no clocks
2957
+ return []
2958
+ elif (ret == NVML_ERROR_INSUFFICIENT_SIZE):
2959
+ # typical case
2960
+ clocks_array = c_uint * c_count.value
2961
+ c_clocks = clocks_array()
2962
+
2963
+ # make the call again
2964
+ ret = fn(handle, c_uint(memoryClockMHz), byref(c_count), c_clocks)
2965
+ _nvmlCheckReturn(ret)
2966
+
2967
+ procs = []
2968
+ for i in range(c_count.value):
2969
+ procs.append(c_clocks[i])
2970
+
2971
+ return procs
2972
+ else:
2973
+ # error case
2974
+ raise NVMLError(ret)
2975
+
2976
+def nvmlDeviceGetFanSpeed(handle):
2977
+ c_speed = c_uint()
2978
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetFanSpeed")
2979
+ ret = fn(handle, byref(c_speed))
2980
+ _nvmlCheckReturn(ret)
2981
+ return c_speed.value
2982
+
2983
+def nvmlDeviceGetFanSpeed_v2(handle, fan):
2984
+ c_speed = c_uint()
2985
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetFanSpeed_v2")
2986
+ ret = fn(handle, fan, byref(c_speed))
2987
+ _nvmlCheckReturn(ret)
2988
+ return c_speed.value
2989
+
2990
+class c_nvmlFanSpeedInfo_t(_PrintableStructure):
2991
+ _fields_ = [
2992
+ ('version', c_uint),
2993
+ ('fan', c_uint),
2994
+ ('speed', c_uint),
2995
+ ]
2996
+
2997
+nvmlFanSpeedInfo_v1 = 0x100000C
2998
+
2999
+def nvmlDeviceGetFanSpeedRPM(handle):
3000
+ c_fanSpeed = c_nvmlFanSpeedInfo_t()
3001
+ c_fanSpeed.fan = 0
3002
+ c_fanSpeed.version = nvmlFanSpeedInfo_v1
3003
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetFanSpeedRPM")
3004
+ ret = fn(handle, byref(c_fanSpeed))
3005
+ _nvmlCheckReturn(ret)
3006
+ return c_fanSpeed.speed
3007
+
3008
+def nvmlDeviceGetTargetFanSpeed(handle, fan):
3009
+ c_speed = c_uint()
3010
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetTargetFanSpeed")
3011
+ ret = fn(handle, fan, byref(c_speed))
3012
+ _nvmlCheckReturn(ret)
3013
+ return c_speed.value
3014
+
3015
+def nvmlDeviceGetNumFans(device):
3016
+ c_numFans = c_uint()
3017
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetNumFans")
3018
+ ret = fn(device, byref(c_numFans))
3019
+ _nvmlCheckReturn(ret)
3020
+ return c_numFans.value
3021
+
3022
+def nvmlDeviceSetDefaultFanSpeed_v2(handle, index):
3023
+ fn = _nvmlGetFunctionPointer("nvmlDeviceSetDefaultFanSpeed_v2");
3024
+ ret = fn(handle, index)
3025
+ _nvmlCheckReturn(ret)
3026
+ return NVML_SUCCESS
3027
+
3028
+def nvmlDeviceGetMinMaxFanSpeed(handle, minSpeed=c_uint(), maxSpeed=c_uint()):
3029
+ isReference = (type(minSpeed) is not c_uint) or (type(maxSpeed) is not c_uint)
3030
+ minSpeedRef = minSpeed if isReference else byref(minSpeed)
3031
+ maxSpeedRef = maxSpeed if isReference else byref(maxSpeed)
3032
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetMinMaxFanSpeed")
3033
+ ret = fn(handle, minSpeedRef, maxSpeedRef)
3034
+ _nvmlCheckReturn(ret)
3035
+ return NVML_SUCCESS if isReference else [minSpeed.value, maxSpeed.value]
3036
+
3037
+def nvmlDeviceGetFanControlPolicy_v2(handle, fan, fanControlPolicy=c_uint()):
3038
+ isReference = type(fanControlPolicy) is not c_uint
3039
+ fanControlPolicyRef = fanControlPolicy if isReference else byref(fanControlPolicy)
3040
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetFanControlPolicy_v2")
3041
+ ret = fn(handle, fan, fanControlPolicyRef)
3042
+ _nvmlCheckReturn(ret)
3043
+ return NVML_SUCCESS if isReference else fanControlPolicy.value
3044
+
3045
+def nvmlDeviceSetFanControlPolicy(handle, fan, fanControlPolicy):
3046
+ fn = _nvmlGetFunctionPointer("nvmlDeviceSetFanControlPolicy")
3047
+ ret = fn(handle, fan, _nvmlFanControlPolicy_t(fanControlPolicy))
3048
+ _nvmlCheckReturn(ret)
3049
+ return NVML_SUCCESS
3050
+
3051
+class c_nvmlTemperature_v1_t(_PrintableStructure):
3052
+ _fields_ = [
3053
+ ('version', c_uint),
3054
+ ('sensorType', _nvmlTemperatureSensors_t),
3055
+ ('temperature', c_int),
3056
+ ]
3057
+nvmlTemperature_v1 = 0x100000C
3058
+
3059
+def nvmlDeviceGetTemperatureV1(handle, sensor):
3060
+ c_temp = c_nvmlTemperature_v1_t()
3061
+ c_temp.version = nvmlTemperature_v1
3062
+ c_temp.sensorType = _nvmlTemperatureSensors_t(sensor)
3063
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetTemperatureV")
3064
+ ret = fn(handle, byref(c_temp))
3065
+ _nvmlCheckReturn(ret)
3066
+ return c_temp.temperature
3067
+
3068
+def nvmlDeviceGetTemperatureV(handle, sensor, version=nvmlTemperature_v1):
3069
+ if version == nvmlTemperature_v1:
3070
+ return nvmlDeviceGetTemperatureV1(handle, sensor)
3071
+ else:
3072
+ raise NVMLError(NVML_ERROR_ARGUMENT_VERSION_MISMATCH)
3073
+
3074
+# DEPRECATED use nvmlDeviceGetTemperatureV instead
3075
+def nvmlDeviceGetTemperature(handle, sensor):
3076
+ c_temp = c_uint()
3077
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetTemperature")
3078
+ ret = fn(handle, _nvmlTemperatureSensors_t(sensor), byref(c_temp))
3079
+ _nvmlCheckReturn(ret)
3080
+ return c_temp.value
3081
+
3082
+def nvmlDeviceGetTemperatureThreshold(handle, threshold):
3083
+ c_temp = c_uint()
3084
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetTemperatureThreshold")
3085
+ ret = fn(handle, _nvmlTemperatureThresholds_t(threshold), byref(c_temp))
3086
+ _nvmlCheckReturn(ret)
3087
+ return c_temp.value
3088
+
3089
+def nvmlDeviceSetTemperatureThreshold(handle, threshold, temp):
3090
+ c_temp = c_uint()
3091
+ c_temp.value = temp
3092
+ fn = _nvmlGetFunctionPointer("nvmlDeviceSetTemperatureThreshold")
3093
+ ret = fn(handle, _nvmlTemperatureThresholds_t(threshold), byref(c_temp))
3094
+ _nvmlCheckReturn(ret)
3095
+ return None
3096
+
3097
+def nvmlDeviceGetMarginTemperature(handle):
3098
+ c_marginTempInfo = c_nvmlMarginTemperature_v1_t()
3099
+ c_marginTempInfo.version = nvmlMarginTemperature_v1
3100
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetMarginTemperature")
3101
+ ret = fn(handle, byref(c_marginTempInfo))
3102
+ _nvmlCheckReturn(ret)
3103
+ return c_marginTempInfo.marginTemperature
3104
+
3105
+# DEPRECATED use nvmlDeviceGetPerformanceState
3106
+def nvmlDeviceGetPowerState(handle):
3107
+ c_pstate = _nvmlPstates_t()
3108
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetPowerState")
3109
+ ret = fn(handle, byref(c_pstate))
3110
+ _nvmlCheckReturn(ret)
3111
+ return c_pstate.value
3112
+
3113
+def nvmlDeviceGetPerformanceState(handle):
3114
+ c_pstate = _nvmlPstates_t()
3115
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetPerformanceState")
3116
+ ret = fn(handle, byref(c_pstate))
3117
+ _nvmlCheckReturn(ret)
3118
+ return c_pstate.value
3119
+
3120
+def nvmlDeviceGetPowerManagementMode(handle):
3121
+ c_pcapMode = _nvmlEnableState_t()
3122
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetPowerManagementMode")
3123
+ ret = fn(handle, byref(c_pcapMode))
3124
+ _nvmlCheckReturn(ret)
3125
+ return c_pcapMode.value
3126
+
3127
+def nvmlDeviceGetPowerManagementLimit(handle):
3128
+ c_limit = c_uint()
3129
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetPowerManagementLimit")
3130
+ ret = fn(handle, byref(c_limit))
3131
+ _nvmlCheckReturn(ret)
3132
+ return c_limit.value
3133
+
3134
+# Added in 4.304
3135
+def nvmlDeviceGetPowerManagementLimitConstraints(handle):
3136
+ c_minLimit = c_uint()
3137
+ c_maxLimit = c_uint()
3138
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetPowerManagementLimitConstraints")
3139
+ ret = fn(handle, byref(c_minLimit), byref(c_maxLimit))
3140
+ _nvmlCheckReturn(ret)
3141
+ return [c_minLimit.value, c_maxLimit.value]
3142
+
3143
+# Added in 4.304
3144
+def nvmlDeviceGetPowerManagementDefaultLimit(handle):
3145
+ c_limit = c_uint()
3146
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetPowerManagementDefaultLimit")
3147
+ ret = fn(handle, byref(c_limit))
3148
+ _nvmlCheckReturn(ret)
3149
+ return c_limit.value
3150
+
3151
+
3152
+# Added in 331
3153
+def nvmlDeviceGetEnforcedPowerLimit(handle):
3154
+ c_limit = c_uint()
3155
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetEnforcedPowerLimit")
3156
+ ret = fn(handle, byref(c_limit))
3157
+ _nvmlCheckReturn(ret)
3158
+ return c_limit.value
3159
+
3160
+def nvmlDeviceGetPowerUsage(handle):
3161
+ c_watts = c_uint()
3162
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetPowerUsage")
3163
+ ret = fn(handle, byref(c_watts))
3164
+ _nvmlCheckReturn(ret)
3165
+ return c_watts.value
3166
+
3167
+def nvmlDeviceGetTotalEnergyConsumption(handle):
3168
+ c_millijoules = c_uint64()
3169
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetTotalEnergyConsumption")
3170
+ ret = fn(handle, byref(c_millijoules))
3171
+ _nvmlCheckReturn(ret)
3172
+ return c_millijoules.value
3173
+
3174
+# Added in 4.304
3175
+def nvmlDeviceGetGpuOperationMode(handle):
3176
+ c_currState = _nvmlGpuOperationMode_t()
3177
+ c_pendingState = _nvmlGpuOperationMode_t()
3178
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetGpuOperationMode")
3179
+ ret = fn(handle, byref(c_currState), byref(c_pendingState))
3180
+ _nvmlCheckReturn(ret)
3181
+ return [c_currState.value, c_pendingState.value]
3182
+
3183
+# Added in 4.304
3184
+def nvmlDeviceGetCurrentGpuOperationMode(handle):
3185
+ return nvmlDeviceGetGpuOperationMode(handle)[0]
3186
+
3187
+# Added in 4.304
3188
+def nvmlDeviceGetPendingGpuOperationMode(handle):
3189
+ return nvmlDeviceGetGpuOperationMode(handle)[1]
3190
+
3191
+def nvmlDeviceGetMemoryInfo(handle, version=None):
3192
+ if not version:
3193
+ c_memory = c_nvmlMemory_t()
3194
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetMemoryInfo")
3195
+ else:
3196
+ c_memory = c_nvmlMemory_v2_t()
3197
+ c_memory.version = version
3198
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetMemoryInfo_v2")
3199
+ ret = fn(handle, byref(c_memory))
3200
+ _nvmlCheckReturn(ret)
3201
+ return c_memory
3202
+
3203
+def nvmlDeviceGetBAR1MemoryInfo(handle):
3204
+ c_bar1_memory = c_nvmlBAR1Memory_t()
3205
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetBAR1MemoryInfo")
3206
+ ret = fn(handle, byref(c_bar1_memory))
3207
+ _nvmlCheckReturn(ret)
3208
+ return c_bar1_memory
3209
+
3210
+def nvmlDeviceGetComputeMode(handle):
3211
+ c_mode = _nvmlComputeMode_t()
3212
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetComputeMode")
3213
+ ret = fn(handle, byref(c_mode))
3214
+ _nvmlCheckReturn(ret)
3215
+ return c_mode.value
3216
+
3217
+def nvmlDeviceGetCudaComputeCapability(handle):
3218
+ c_major = c_int()
3219
+ c_minor = c_int()
3220
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetCudaComputeCapability")
3221
+ ret = fn(handle, byref(c_major), byref(c_minor))
3222
+ _nvmlCheckReturn(ret)
3223
+ return (c_major.value, c_minor.value)
3224
+
3225
+def nvmlDeviceGetEccMode(handle):
3226
+ c_currState = _nvmlEnableState_t()
3227
+ c_pendingState = _nvmlEnableState_t()
3228
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetEccMode")
3229
+ ret = fn(handle, byref(c_currState), byref(c_pendingState))
3230
+ _nvmlCheckReturn(ret)
3231
+ return [c_currState.value, c_pendingState.value]
3232
+
3233
+# added to API
3234
+def nvmlDeviceGetCurrentEccMode(handle):
3235
+ return nvmlDeviceGetEccMode(handle)[0]
3236
+
3237
+# added to API
3238
+def nvmlDeviceGetPendingEccMode(handle):
3239
+ return nvmlDeviceGetEccMode(handle)[1]
3240
+
3241
+def nvmlDeviceGetDefaultEccMode(handle):
3242
+ c_defaultState = _nvmlEnableState_t()
3243
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetDefaultEccMode")
3244
+ ret = fn(handle, byref(c_defaultState))
3245
+ _nvmlCheckReturn(ret)
3246
+ return [c_defaultState.value]
3247
+
3248
+def nvmlDeviceGetTotalEccErrors(handle, errorType, counterType):
3249
+ c_count = c_ulonglong()
3250
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetTotalEccErrors")
3251
+ ret = fn(handle, _nvmlMemoryErrorType_t(errorType),
3252
+ _nvmlEccCounterType_t(counterType), byref(c_count))
3253
+ _nvmlCheckReturn(ret)
3254
+ return c_count.value
3255
+
3256
+# This is deprecated, instead use nvmlDeviceGetMemoryErrorCounter
3257
+def nvmlDeviceGetDetailedEccErrors(handle, errorType, counterType):
3258
+ c_counts = c_nvmlEccErrorCounts_t()
3259
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetDetailedEccErrors")
3260
+ ret = fn(handle, _nvmlMemoryErrorType_t(errorType),
3261
+ _nvmlEccCounterType_t(counterType), byref(c_counts))
3262
+ _nvmlCheckReturn(ret)
3263
+ return c_counts
3264
+
3265
+# Added in 4.304
3266
+def nvmlDeviceGetMemoryErrorCounter(handle, errorType, counterType, locationType):
3267
+ c_count = c_ulonglong()
3268
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetMemoryErrorCounter")
3269
+ ret = fn(handle,
3270
+ _nvmlMemoryErrorType_t(errorType),
3271
+ _nvmlEccCounterType_t(counterType),
3272
+ _nvmlMemoryLocation_t(locationType),
3273
+ byref(c_count))
3274
+ _nvmlCheckReturn(ret)
3275
+ return c_count.value
3276
+
3277
+def nvmlDeviceGetUtilizationRates(handle):
3278
+ c_util = c_nvmlUtilization_t()
3279
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetUtilizationRates")
3280
+ ret = fn(handle, byref(c_util))
3281
+ _nvmlCheckReturn(ret)
3282
+ return c_util
3283
+
3284
+def nvmlDeviceGetEncoderUtilization(handle):
3285
+ c_util = c_uint()
3286
+ c_samplingPeriod = c_uint()
3287
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetEncoderUtilization")
3288
+ ret = fn(handle, byref(c_util), byref(c_samplingPeriod))
3289
+ _nvmlCheckReturn(ret)
3290
+ return [c_util.value, c_samplingPeriod.value]
3291
+
3292
+def nvmlDeviceGetDecoderUtilization(handle):
3293
+ c_util = c_uint()
3294
+ c_samplingPeriod = c_uint()
3295
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetDecoderUtilization")
3296
+ ret = fn(handle, byref(c_util), byref(c_samplingPeriod))
3297
+ _nvmlCheckReturn(ret)
3298
+ return [c_util.value, c_samplingPeriod.value]
3299
+
3300
+def nvmlDeviceGetJpgUtilization(handle):
3301
+ c_util = c_uint()
3302
+ c_samplingPeriod = c_uint()
3303
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetJpgUtilization")
3304
+ ret = fn(handle, byref(c_util), byref(c_samplingPeriod))
3305
+ _nvmlCheckReturn(ret)
3306
+ return [c_util.value, c_samplingPeriod.value]
3307
+
3308
+def nvmlDeviceGetOfaUtilization(handle):
3309
+ c_util = c_uint()
3310
+ c_samplingPeriod = c_uint()
3311
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetOfaUtilization")
3312
+ ret = fn(handle, byref(c_util), byref(c_samplingPeriod))
3313
+ _nvmlCheckReturn(ret)
3314
+ return [c_util.value, c_samplingPeriod.value]
3315
+
3316
+def nvmlDeviceGetPcieReplayCounter(handle):
3317
+ c_replay = c_uint()
3318
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetPcieReplayCounter")
3319
+ ret = fn(handle, byref(c_replay))
3320
+ _nvmlCheckReturn(ret)
3321
+ return c_replay.value
3322
+
3323
+def nvmlDeviceGetDriverModel(handle):
3324
+ c_currModel = _nvmlDriverModel_t()
3325
+ c_pendingModel = _nvmlDriverModel_t()
3326
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetDriverModel")
3327
+ ret = fn(handle, byref(c_currModel), byref(c_pendingModel))
3328
+ _nvmlCheckReturn(ret)
3329
+ return [c_currModel.value, c_pendingModel.value]
3330
+
3331
+# added to API
3332
+def nvmlDeviceGetCurrentDriverModel(handle):
3333
+ return nvmlDeviceGetDriverModel(handle)[0]
3334
+
3335
+# added to API
3336
+def nvmlDeviceGetPendingDriverModel(handle):
3337
+ return nvmlDeviceGetDriverModel(handle)[1]
3338
+
3339
+# Added in 2.285
3340
+@convertStrBytes
3341
+def nvmlDeviceGetVbiosVersion(handle):
3342
+ c_version = create_string_buffer(NVML_DEVICE_VBIOS_VERSION_BUFFER_SIZE)
3343
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetVbiosVersion")
3344
+ ret = fn(handle, c_version, c_uint(NVML_DEVICE_VBIOS_VERSION_BUFFER_SIZE))
3345
+ _nvmlCheckReturn(ret)
3346
+ return c_version.value
3347
+
3348
+# Added in 2.285
3349
+def nvmlDeviceGetComputeRunningProcesses_v2(handle):
3350
+ # first call to get the size
3351
+ c_count = c_uint(0)
3352
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetComputeRunningProcesses_v2")
3353
+ ret = fn(handle, byref(c_count), None)
3354
+ if (ret == NVML_SUCCESS):
3355
+ # special case, no running processes
3356
+ return []
3357
+ elif (ret == NVML_ERROR_INSUFFICIENT_SIZE):
3358
+ # typical case
3359
+ # oversize the array incase more processes are created
3360
+ c_count.value = c_count.value * 2 + 5
3361
+ proc_array = c_nvmlProcessInfo_v2_t * c_count.value
3362
+ c_procs = proc_array()
3363
+ # make the call again
3364
+ ret = fn(handle, byref(c_count), c_procs)
3365
+ _nvmlCheckReturn(ret)
3366
+ procs = []
3367
+ for i in range(c_count.value):
3368
+ # use an alternative struct for this object
3369
+ obj = nvmlStructToFriendlyObject(c_procs[i])
3370
+ if (obj.usedGpuMemory == NVML_VALUE_NOT_AVAILABLE_ulonglong.value):
3371
+ # special case for WDDM on Windows, see comment above
3372
+ obj.usedGpuMemory = None
3373
+ procs.append(obj)
3374
+ return procs
3375
+ else:
3376
+ # error case
3377
+ raise NVMLError(ret)
3378
+
3379
+# Added in 2.285
3380
+def nvmlDeviceGetComputeRunningProcesses_v3(handle):
3381
+ # first call to get the size
3382
+ c_count = c_uint(0)
3383
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetComputeRunningProcesses_v3")
3384
+ ret = fn(handle, byref(c_count), None)
3385
+
3386
+ if (ret == NVML_SUCCESS):
3387
+ # special case, no running processes
3388
+ return []
3389
+ elif (ret == NVML_ERROR_INSUFFICIENT_SIZE):
3390
+ # typical case
3391
+ # oversize the array incase more processes are created
3392
+ c_count.value = c_count.value * 2 + 5
3393
+ proc_array = c_nvmlProcessInfo_v3_t * c_count.value
3394
+ c_procs = proc_array()
3395
+
3396
+ # make the call again
3397
+ ret = fn(handle, byref(c_count), c_procs)
3398
+ _nvmlCheckReturn(ret)
3399
+
3400
+ procs = []
3401
+ for i in range(c_count.value):
3402
+ # use an alternative struct for this object
3403
+ obj = nvmlStructToFriendlyObject(c_procs[i])
3404
+ if (obj.usedGpuMemory == NVML_VALUE_NOT_AVAILABLE_ulonglong.value):
3405
+ # special case for WDDM on Windows, see comment above
3406
+ obj.usedGpuMemory = None
3407
+ procs.append(obj)
3408
+
3409
+ return procs
3410
+ else:
3411
+ # error case
3412
+ raise NVMLError(ret)
3413
+
3414
+@throwOnVersionMismatch
3415
+def nvmlDeviceGetComputeRunningProcesses(handle):
3416
+ return nvmlDeviceGetComputeRunningProcesses_v3(handle)
3417
+
3418
+def nvmlDeviceGetGraphicsRunningProcesses_v2(handle):
3419
+ # first call to get the size
3420
+ c_count = c_uint(0)
3421
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetGraphicsRunningProcesses_v2")
3422
+ ret = fn(handle, byref(c_count), None)
3423
+ if (ret == NVML_SUCCESS):
3424
+ # special case, no running processes
3425
+ return []
3426
+ elif (ret == NVML_ERROR_INSUFFICIENT_SIZE):
3427
+ # typical case
3428
+ # oversize the array incase more processes are created
3429
+ c_count.value = c_count.value * 2 + 5
3430
+ proc_array = c_nvmlProcessInfo_v2_t * c_count.value
3431
+ c_procs = proc_array()
3432
+ # make the call again
3433
+ ret = fn(handle, byref(c_count), c_procs)
3434
+ _nvmlCheckReturn(ret)
3435
+ procs = []
3436
+ for i in range(c_count.value):
3437
+ # use an alternative struct for this object
3438
+ obj = nvmlStructToFriendlyObject(c_procs[i])
3439
+ if (obj.usedGpuMemory == NVML_VALUE_NOT_AVAILABLE_ulonglong.value):
3440
+ # special case for WDDM on Windows, see comment above
3441
+ obj.usedGpuMemory = None
3442
+ procs.append(obj)
3443
+ return procs
3444
+ else:
3445
+ # error case
3446
+ raise NVMLError(ret)
3447
+
3448
+def nvmlDeviceGetGraphicsRunningProcesses_v3(handle):
3449
+ # first call to get the size
3450
+ c_count = c_uint(0)
3451
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetGraphicsRunningProcesses_v3")
3452
+ ret = fn(handle, byref(c_count), None)
3453
+
3454
+ if (ret == NVML_SUCCESS):
3455
+ # special case, no running processes
3456
+ return []
3457
+ elif (ret == NVML_ERROR_INSUFFICIENT_SIZE):
3458
+ # typical case
3459
+ # oversize the array incase more processes are created
3460
+ c_count.value = c_count.value * 2 + 5
3461
+ proc_array = c_nvmlProcessInfo_v3_t * c_count.value
3462
+ c_procs = proc_array()
3463
+
3464
+ # make the call again
3465
+ ret = fn(handle, byref(c_count), c_procs)
3466
+ _nvmlCheckReturn(ret)
3467
+
3468
+ procs = []
3469
+ for i in range(c_count.value):
3470
+ # use an alternative struct for this object
3471
+ obj = nvmlStructToFriendlyObject(c_procs[i])
3472
+ if (obj.usedGpuMemory == NVML_VALUE_NOT_AVAILABLE_ulonglong.value):
3473
+ # special case for WDDM on Windows, see comment above
3474
+ obj.usedGpuMemory = None
3475
+ procs.append(obj)
3476
+
3477
+ return procs
3478
+ else:
3479
+ # error case
3480
+ raise NVMLError(ret)
3481
+
3482
+@throwOnVersionMismatch
3483
+def nvmlDeviceGetGraphicsRunningProcesses(handle):
3484
+ return nvmlDeviceGetGraphicsRunningProcesses_v3(handle)
3485
+
3486
+@throwOnVersionMismatch
3487
+def nvmlDeviceGetMPSComputeRunningProcesses(handle):
3488
+ return nvmlDeviceGetMPSComputeRunningProcesses_v3(handle)
3489
+
3490
+def nvmlDeviceGetMPSComputeRunningProcesses_v2(handle):
3491
+ # first call to get the size
3492
+ c_count = c_uint(0)
3493
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetMPSComputeRunningProcesses_v2")
3494
+ ret = fn(handle, byref(c_count), None)
3495
+
3496
+ if (ret == NVML_SUCCESS):
3497
+ # special case, no running processes
3498
+ return []
3499
+ elif (ret == NVML_ERROR_INSUFFICIENT_SIZE):
3500
+ # typical case
3501
+ # oversize the array incase more processes are created
3502
+ c_count.value = c_count.value * 2 + 5
3503
+ proc_array = c_nvmlProcessInfo_v2_t * c_count.value
3504
+ c_procs = proc_array()
3505
+
3506
+ # make the call again
3507
+ ret = fn(handle, byref(c_count), c_procs)
3508
+ _nvmlCheckReturn(ret)
3509
+
3510
+ procs = []
3511
+ for i in range(c_count.value):
3512
+ # use an alternative struct for this object
3513
+ obj = nvmlStructToFriendlyObject(c_procs[i])
3514
+ if (obj.usedGpuMemory == NVML_VALUE_NOT_AVAILABLE_ulonglong.value):
3515
+ # special case for WDDM on Windows, see comment above
3516
+ obj.usedGpuMemory = None
3517
+ procs.append(obj)
3518
+
3519
+ return procs
3520
+ else:
3521
+ # error case
3522
+ raise NVMLError(ret)
3523
+
3524
+def nvmlDeviceGetMPSComputeRunningProcesses_v3(handle):
3525
+ # first call to get the size
3526
+ c_count = c_uint(0)
3527
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetMPSComputeRunningProcesses_v3")
3528
+ ret = fn(handle, byref(c_count), None)
3529
+
3530
+ if (ret == NVML_SUCCESS):
3531
+ # special case, no running processes
3532
+ return []
3533
+ elif (ret == NVML_ERROR_INSUFFICIENT_SIZE):
3534
+ # typical case
3535
+ # oversize the array incase more processes are created
3536
+ c_count.value = c_count.value * 2 + 5
3537
+ proc_array = c_nvmlProcessInfo_v3_t * c_count.value
3538
+ c_procs = proc_array()
3539
+
3540
+ # make the call again
3541
+ ret = fn(handle, byref(c_count), c_procs)
3542
+ _nvmlCheckReturn(ret)
3543
+
3544
+ procs = []
3545
+ for i in range(c_count.value):
3546
+ # use an alternative struct for this object
3547
+ obj = nvmlStructToFriendlyObject(c_procs[i])
3548
+ if (obj.usedGpuMemory == NVML_VALUE_NOT_AVAILABLE_ulonglong.value):
3549
+ # special case for WDDM on Windows, see comment above
3550
+ obj.usedGpuMemory = None
3551
+ procs.append(obj)
3552
+
3553
+ return procs
3554
+ else:
3555
+ # error case
3556
+ raise NVMLError(ret)
3557
+
3558
+def nvmlDeviceGetRunningProcessDetailList(handle, version, mode):
3559
+ c_processDetailList = c_nvmlProcessDetailList_t()
3560
+ c_processDetailList.version = version
3561
+ c_processDetailList.mode = mode
3562
+
3563
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetRunningProcessDetailList")
3564
+
3565
+ # first call to get the size
3566
+ ret = fn(handle, byref(c_processDetailList))
3567
+ if (ret == NVML_SUCCESS):
3568
+ # special case, no running processes
3569
+ return []
3570
+ elif (ret == NVML_ERROR_INSUFFICIENT_SIZE):
3571
+ c_procs = c_nvmlProcessDetail_v1_t * c_processDetailList.numProcArrayEntries
3572
+ c_processDetailList.procArray = cast((c_procs)(), POINTER(c_nvmlProcessDetail_v1_t))
3573
+
3574
+ # make the call again
3575
+ ret = fn(handle, byref(c_processDetailList))
3576
+ _nvmlCheckReturn(ret)
3577
+
3578
+ procs = []
3579
+ for i in range(c_processDetailList.numProcArrayEntries):
3580
+ # use an alternative struct for this object
3581
+ obj = c_processDetailList.procArray[i]
3582
+ if (obj.usedGpuMemory == NVML_VALUE_NOT_AVAILABLE_ulonglong.value):
3583
+ obj.usedGpuMemory = None
3584
+ if (obj.usedGpuCcProtectedMemory == NVML_VALUE_NOT_AVAILABLE_ulonglong.value):
3585
+ obj.usedGpuCcProtectedMemory = None
3586
+ procs.append(obj)
3587
+
3588
+ return procs
3589
+ else:
3590
+ # error case
3591
+ raise NVMLError(ret)
3592
+
3593
+def nvmlDeviceGetAutoBoostedClocksEnabled(handle):
3594
+ c_isEnabled = _nvmlEnableState_t()
3595
+ c_defaultIsEnabled = _nvmlEnableState_t()
3596
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetAutoBoostedClocksEnabled")
3597
+ ret = fn(handle, byref(c_isEnabled), byref(c_defaultIsEnabled))
3598
+ _nvmlCheckReturn(ret)
3599
+ return [c_isEnabled.value, c_defaultIsEnabled.value]
3600
+ #Throws NVML_ERROR_NOT_SUPPORTED if hardware doesn't support setting auto boosted clocks
3601
+
3602
+## Set functions
3603
+def nvmlUnitSetLedState(unit, color):
3604
+ fn = _nvmlGetFunctionPointer("nvmlUnitSetLedState")
3605
+ ret = fn(unit, _nvmlLedColor_t(color))
3606
+ _nvmlCheckReturn(ret)
3607
+ return None
3608
+
3609
+def nvmlDeviceSetPersistenceMode(handle, mode):
3610
+ fn = _nvmlGetFunctionPointer("nvmlDeviceSetPersistenceMode")
3611
+ ret = fn(handle, _nvmlEnableState_t(mode))
3612
+ _nvmlCheckReturn(ret)
3613
+ return None
3614
+
3615
+def nvmlDeviceSetComputeMode(handle, mode):
3616
+ fn = _nvmlGetFunctionPointer("nvmlDeviceSetComputeMode")
3617
+ ret = fn(handle, _nvmlComputeMode_t(mode))
3618
+ _nvmlCheckReturn(ret)
3619
+ return None
3620
+
3621
+def nvmlDeviceSetEccMode(handle, mode):
3622
+ fn = _nvmlGetFunctionPointer("nvmlDeviceSetEccMode")
3623
+ ret = fn(handle, _nvmlEnableState_t(mode))
3624
+ _nvmlCheckReturn(ret)
3625
+ return None
3626
+
3627
+def nvmlDeviceClearEccErrorCounts(handle, counterType):
3628
+ fn = _nvmlGetFunctionPointer("nvmlDeviceClearEccErrorCounts")
3629
+ ret = fn(handle, _nvmlEccCounterType_t(counterType))
3630
+ _nvmlCheckReturn(ret)
3631
+ return None
3632
+
3633
+def nvmlDeviceSetDriverModel(handle, model):
3634
+ fn = _nvmlGetFunctionPointer("nvmlDeviceSetDriverModel")
3635
+ ret = fn(handle, _nvmlDriverModel_t(model))
3636
+ _nvmlCheckReturn(ret)
3637
+ return None
3638
+
3639
+def nvmlDeviceSetAutoBoostedClocksEnabled(handle, enabled):
3640
+ fn = _nvmlGetFunctionPointer("nvmlDeviceSetAutoBoostedClocksEnabled")
3641
+ ret = fn(handle, _nvmlEnableState_t(enabled))
3642
+ _nvmlCheckReturn(ret)
3643
+ return None
3644
+ #Throws NVML_ERROR_NOT_SUPPORTED if hardware doesn't support setting auto boosted clocks
3645
+
3646
+def nvmlDeviceSetDefaultAutoBoostedClocksEnabled(handle, enabled, flags):
3647
+ fn = _nvmlGetFunctionPointer("nvmlDeviceSetDefaultAutoBoostedClocksEnabled")
3648
+ ret = fn(handle, _nvmlEnableState_t(enabled), c_uint(flags))
3649
+ _nvmlCheckReturn(ret)
3650
+ return None
3651
+ #Throws NVML_ERROR_NOT_SUPPORTED if hardware doesn't support setting auto boosted clocks
3652
+
3653
+def nvmlDeviceSetGpuLockedClocks(handle, minGpuClockMHz, maxGpuClockMHz):
3654
+ fn = _nvmlGetFunctionPointer("nvmlDeviceSetGpuLockedClocks")
3655
+ ret = fn(handle, c_uint(minGpuClockMHz), c_uint(maxGpuClockMHz))
3656
+ _nvmlCheckReturn(ret)
3657
+ return None
3658
+
3659
+def nvmlDeviceResetGpuLockedClocks(handle):
3660
+ fn = _nvmlGetFunctionPointer("nvmlDeviceResetGpuLockedClocks")
3661
+ ret = fn(handle)
3662
+ _nvmlCheckReturn(ret)
3663
+ return None
3664
+
3665
+def nvmlDeviceSetMemoryLockedClocks(handle, minMemClockMHz, maxMemClockMHz):
3666
+ fn = _nvmlGetFunctionPointer("nvmlDeviceSetMemoryLockedClocks")
3667
+ ret = fn(handle, c_uint(minMemClockMHz), c_uint(maxMemClockMHz))
3668
+ _nvmlCheckReturn(ret)
3669
+ return None
3670
+
3671
+def nvmlDeviceResetMemoryLockedClocks(handle):
3672
+ fn = _nvmlGetFunctionPointer("nvmlDeviceResetMemoryLockedClocks")
3673
+ ret = fn(handle)
3674
+ _nvmlCheckReturn(ret)
3675
+ return None
3676
+
3677
+def nvmlDeviceGetClkMonStatus(handle, c_clkMonInfo=nvmlClkMonStatus_t()):
3678
+ isReference = type(c_clkMonInfo) is not nvmlClkMonStatus_t
3679
+ c_clkMonInfoRef = c_clkMonInfo if isReference else byref(c_clkMonInfo)
3680
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetClkMonStatus")
3681
+ ret = fn(handle, c_clkMonInfoRef)
3682
+ _nvmlCheckReturn(ret)
3683
+ return NVML_SUCCESS if isReference else c_clkMonInfo
3684
+
3685
+# Added in 4.304
3686
+def nvmlDeviceSetApplicationsClocks(handle, maxMemClockMHz, maxGraphicsClockMHz):
3687
+ fn = _nvmlGetFunctionPointer("nvmlDeviceSetApplicationsClocks")
3688
+ ret = fn(handle, c_uint(maxMemClockMHz), c_uint(maxGraphicsClockMHz))
3689
+ _nvmlCheckReturn(ret)
3690
+ return None
3691
+
3692
+# Added in 4.304
3693
+def nvmlDeviceResetApplicationsClocks(handle):
3694
+ fn = _nvmlGetFunctionPointer("nvmlDeviceResetApplicationsClocks")
3695
+ ret = fn(handle)
3696
+ _nvmlCheckReturn(ret)
3697
+ return None
3698
+
3699
+# Added in 4.304
3700
+def nvmlDeviceSetPowerManagementLimit(handle, limit):
3701
+ fn = _nvmlGetFunctionPointer("nvmlDeviceSetPowerManagementLimit")
3702
+ ret = fn(handle, c_uint(limit))
3703
+ _nvmlCheckReturn(ret)
3704
+ return None
3705
+
3706
+# Added in 4.304
3707
+def nvmlDeviceSetGpuOperationMode(handle, mode):
3708
+ fn = _nvmlGetFunctionPointer("nvmlDeviceSetGpuOperationMode")
3709
+ ret = fn(handle, _nvmlGpuOperationMode_t(mode))
3710
+ _nvmlCheckReturn(ret)
3711
+ return None
3712
+
3713
+# Added in 2.285
3714
+def nvmlEventSetCreate():
3715
+ fn = _nvmlGetFunctionPointer("nvmlEventSetCreate")
3716
+ eventSet = c_nvmlEventSet_t()
3717
+ ret = fn(byref(eventSet))
3718
+ _nvmlCheckReturn(ret)
3719
+ return eventSet
3720
+
3721
+# Added in 2.285
3722
+def nvmlDeviceRegisterEvents(handle, eventTypes, eventSet):
3723
+ fn = _nvmlGetFunctionPointer("nvmlDeviceRegisterEvents")
3724
+ ret = fn(handle, c_ulonglong(eventTypes), eventSet)
3725
+ _nvmlCheckReturn(ret)
3726
+ return None
3727
+
3728
+# Added in 2.285
3729
+def nvmlDeviceGetSupportedEventTypes(handle):
3730
+ c_eventTypes = c_ulonglong()
3731
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetSupportedEventTypes")
3732
+ ret = fn(handle, byref(c_eventTypes))
3733
+ _nvmlCheckReturn(ret)
3734
+ return c_eventTypes.value
3735
+
3736
+# raises NVML_ERROR_TIMEOUT exception on timeout
3737
+def nvmlEventSetWait_v2(eventSet, timeoutms):
3738
+ fn = _nvmlGetFunctionPointer("nvmlEventSetWait_v2")
3739
+ data = c_nvmlEventData_t()
3740
+ ret = fn(eventSet, byref(data), c_uint(timeoutms))
3741
+ _nvmlCheckReturn(ret)
3742
+ return data
3743
+
3744
+def nvmlEventSetWait(eventSet, timeoutms):
3745
+ return nvmlEventSetWait_v2(eventSet, timeoutms)
3746
+
3747
+# Added in 2.285
3748
+def nvmlEventSetFree(eventSet):
3749
+ fn = _nvmlGetFunctionPointer("nvmlEventSetFree")
3750
+ ret = fn(eventSet)
3751
+ _nvmlCheckReturn(ret)
3752
+ return None
3753
+
3754
+# Added in 3.295
3755
+def nvmlDeviceOnSameBoard(handle1, handle2):
3756
+ fn = _nvmlGetFunctionPointer("nvmlDeviceOnSameBoard")
3757
+ onSameBoard = c_int()
3758
+ ret = fn(handle1, handle2, byref(onSameBoard))
3759
+ _nvmlCheckReturn(ret)
3760
+ return (onSameBoard.value != 0)
3761
+
3762
+# Added in 3.295
3763
+def nvmlDeviceGetCurrPcieLinkGeneration(handle):
3764
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetCurrPcieLinkGeneration")
3765
+ gen = c_uint()
3766
+ ret = fn(handle, byref(gen))
3767
+ _nvmlCheckReturn(ret)
3768
+ return gen.value
3769
+
3770
+# Added in 3.295
3771
+def nvmlDeviceGetMaxPcieLinkGeneration(handle):
3772
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetMaxPcieLinkGeneration")
3773
+ gen = c_uint()
3774
+ ret = fn(handle, byref(gen))
3775
+ _nvmlCheckReturn(ret)
3776
+ return gen.value
3777
+
3778
+# Added in 3.295
3779
+def nvmlDeviceGetCurrPcieLinkWidth(handle):
3780
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetCurrPcieLinkWidth")
3781
+ width = c_uint()
3782
+ ret = fn(handle, byref(width))
3783
+ _nvmlCheckReturn(ret)
3784
+ return width.value
3785
+
3786
+# Added in 3.295
3787
+def nvmlDeviceGetMaxPcieLinkWidth(handle):
3788
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetMaxPcieLinkWidth")
3789
+ width = c_uint()
3790
+ ret = fn(handle, byref(width))
3791
+ _nvmlCheckReturn(ret)
3792
+ return width.value
3793
+
3794
+def nvmlDeviceGetGpuMaxPcieLinkGeneration(handle):
3795
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetGpuMaxPcieLinkGeneration")
3796
+ gen = c_uint()
3797
+ ret = fn(handle, byref(gen))
3798
+ _nvmlCheckReturn(ret)
3799
+ return gen.value
3800
+
3801
+# Added in 4.304
3802
+def nvmlDeviceGetSupportedClocksThrottleReasons(handle):
3803
+ c_reasons= c_ulonglong()
3804
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetSupportedClocksThrottleReasons")
3805
+ ret = fn(handle, byref(c_reasons))
3806
+ _nvmlCheckReturn(ret)
3807
+ return c_reasons.value
3808
+
3809
+def nvmlDeviceGetSupportedClocksEventReasons(handle):
3810
+ c_reasons= c_ulonglong()
3811
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetSupportedClocksEventReasons")
3812
+ ret = fn(handle, byref(c_reasons))
3813
+ _nvmlCheckReturn(ret)
3814
+ return c_reasons.value
3815
+
3816
+# Added in 4.304
3817
+def nvmlDeviceGetCurrentClocksThrottleReasons(handle):
3818
+ c_reasons= c_ulonglong()
3819
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetCurrentClocksThrottleReasons")
3820
+ ret = fn(handle, byref(c_reasons))
3821
+ _nvmlCheckReturn(ret)
3822
+ return c_reasons.value
3823
+
3824
+def nvmlDeviceGetCurrentClocksEventReasons(handle):
3825
+ c_reasons= c_ulonglong()
3826
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetCurrentClocksEventReasons")
3827
+ ret = fn(handle, byref(c_reasons))
3828
+ _nvmlCheckReturn(ret)
3829
+ return c_reasons.value
3830
+
3831
+# Added in 5.319
3832
+def nvmlDeviceGetIndex(handle):
3833
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetIndex")
3834
+ c_index = c_uint()
3835
+ ret = fn(handle, byref(c_index))
3836
+ _nvmlCheckReturn(ret)
3837
+ return c_index.value
3838
+
3839
+# Added in 5.319
3840
+def nvmlDeviceGetAccountingMode(handle):
3841
+ c_mode = _nvmlEnableState_t()
3842
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetAccountingMode")
3843
+ ret = fn(handle, byref(c_mode))
3844
+ _nvmlCheckReturn(ret)
3845
+ return c_mode.value
3846
+
3847
+def nvmlDeviceSetAccountingMode(handle, mode):
3848
+ fn = _nvmlGetFunctionPointer("nvmlDeviceSetAccountingMode")
3849
+ ret = fn(handle, _nvmlEnableState_t(mode))
3850
+ _nvmlCheckReturn(ret)
3851
+ return None
3852
+
3853
+def nvmlDeviceClearAccountingPids(handle):
3854
+ fn = _nvmlGetFunctionPointer("nvmlDeviceClearAccountingPids")
3855
+ ret = fn(handle)
3856
+ _nvmlCheckReturn(ret)
3857
+ return None
3858
+
3859
+def nvmlDeviceGetAccountingStats(handle, pid):
3860
+ stats = c_nvmlAccountingStats_t()
3861
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetAccountingStats")
3862
+ ret = fn(handle, c_uint(pid), byref(stats))
3863
+ _nvmlCheckReturn(ret)
3864
+ if (stats.maxMemoryUsage == NVML_VALUE_NOT_AVAILABLE_ulonglong.value):
3865
+ # special case for WDDM on Windows, see comment above
3866
+ stats.maxMemoryUsage = None
3867
+ return stats
3868
+
3869
+def nvmlDeviceGetAccountingPids(handle):
3870
+ count = c_uint(nvmlDeviceGetAccountingBufferSize(handle))
3871
+ pids = (c_uint * count.value)()
3872
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetAccountingPids")
3873
+ ret = fn(handle, byref(count), pids)
3874
+ _nvmlCheckReturn(ret)
3875
+ return list(map(int, pids[0:count.value]))
3876
+
3877
+def nvmlDeviceGetAccountingBufferSize(handle):
3878
+ bufferSize = c_uint()
3879
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetAccountingBufferSize")
3880
+ ret = fn(handle, byref(bufferSize))
3881
+ _nvmlCheckReturn(ret)
3882
+ return int(bufferSize.value)
3883
+
3884
+def nvmlDeviceGetRetiredPages(device, sourceFilter):
3885
+ c_source = _nvmlPageRetirementCause_t(sourceFilter)
3886
+ c_count = c_uint(0)
3887
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetRetiredPages")
3888
+
3889
+ # First call will get the size
3890
+ ret = fn(device, c_source, byref(c_count), None)
3891
+
3892
+ # this should only fail with insufficient size
3893
+ if ((ret != NVML_SUCCESS) and
3894
+ (ret != NVML_ERROR_INSUFFICIENT_SIZE)):
3895
+ raise NVMLError(ret)
3896
+
3897
+ # call again with a buffer
3898
+ # oversize the array for the rare cases where additional pages
3899
+ # are retired between NVML calls
3900
+ c_count.value = c_count.value * 2 + 5
3901
+ page_array = c_ulonglong * c_count.value
3902
+ c_pages = page_array()
3903
+ ret = fn(device, c_source, byref(c_count), c_pages)
3904
+ _nvmlCheckReturn(ret)
3905
+ return list(map(int, c_pages[0:c_count.value]))
3906
+
3907
+def nvmlDeviceGetRetiredPages_v2(device, sourceFilter):
3908
+ c_source = _nvmlPageRetirementCause_t(sourceFilter)
3909
+ c_count = c_uint(0)
3910
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetRetiredPages_v2")
3911
+
3912
+ # First call will get the size
3913
+ ret = fn(device, c_source, byref(c_count), None)
3914
+
3915
+ # this should only fail with insufficient size
3916
+ if ((ret != NVML_SUCCESS) and
3917
+ (ret != NVML_ERROR_INSUFFICIENT_SIZE)):
3918
+ raise NVMLError(ret)
3919
+
3920
+ # call again with a buffer
3921
+ # oversize the array for the rare cases where additional pages
3922
+ # are retired between NVML calls
3923
+ c_count.value = c_count.value * 2 + 5
3924
+ page_array = c_ulonglong * c_count.value
3925
+ c_pages = page_array()
3926
+ times_array = c_ulonglong * c_count.value
3927
+ c_times = times_array()
3928
+ ret = fn(device, c_source, byref(c_count), c_pages, c_times)
3929
+ _nvmlCheckReturn(ret)
3930
+ return [ { 'address': int(c_pages[i]), 'timestamp': int(c_times[i]) } for i in range(c_count.value) ];
3931
+
3932
+def nvmlDeviceGetRetiredPagesPendingStatus(device):
3933
+ c_pending = _nvmlEnableState_t()
3934
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetRetiredPagesPendingStatus")
3935
+ ret = fn(device, byref(c_pending))
3936
+ _nvmlCheckReturn(ret)
3937
+ return int(c_pending.value)
3938
+
3939
+def nvmlDeviceGetAPIRestriction(device, apiType):
3940
+ c_permission = _nvmlEnableState_t()
3941
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetAPIRestriction")
3942
+ ret = fn(device, _nvmlRestrictedAPI_t(apiType), byref(c_permission))
3943
+ _nvmlCheckReturn(ret)
3944
+ return int(c_permission.value)
3945
+
3946
+def nvmlDeviceSetAPIRestriction(handle, apiType, isRestricted):
3947
+ fn = _nvmlGetFunctionPointer("nvmlDeviceSetAPIRestriction")
3948
+ ret = fn(handle, _nvmlRestrictedAPI_t(apiType), _nvmlEnableState_t(isRestricted))
3949
+ _nvmlCheckReturn(ret)
3950
+ return None
3951
+
3952
+def nvmlDeviceGetBridgeChipInfo(handle):
3953
+ bridgeHierarchy = c_nvmlBridgeChipHierarchy_t()
3954
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetBridgeChipInfo")
3955
+ ret = fn(handle, byref(bridgeHierarchy))
3956
+ _nvmlCheckReturn(ret)
3957
+ return bridgeHierarchy
3958
+
3959
+def nvmlDeviceGetSamples(device, sampling_type, timeStamp):
3960
+ c_sampling_type = _nvmlSamplingType_t(sampling_type)
3961
+ c_time_stamp = c_ulonglong(timeStamp)
3962
+ c_sample_count = c_uint(0)
3963
+ c_sample_value_type = _nvmlValueType_t()
3964
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetSamples")
3965
+
3966
+ ## First Call gets the size
3967
+ ret = fn(device, c_sampling_type, c_time_stamp, byref(c_sample_value_type), byref(c_sample_count), None)
3968
+
3969
+ # Stop if this fails
3970
+ if (ret != NVML_SUCCESS):
3971
+ raise NVMLError(ret)
3972
+
3973
+ sampleArray = c_sample_count.value * c_nvmlSample_t
3974
+ c_samples = sampleArray()
3975
+ ret = fn(device, c_sampling_type, c_time_stamp, byref(c_sample_value_type), byref(c_sample_count), c_samples)
3976
+ _nvmlCheckReturn(ret)
3977
+ return (c_sample_value_type.value, c_samples[0:c_sample_count.value])
3978
+
3979
+def nvmlDeviceGetViolationStatus(device, perfPolicyType):
3980
+ c_perfPolicy_type = _nvmlPerfPolicyType_t(perfPolicyType)
3981
+ c_violTime = c_nvmlViolationTime_t()
3982
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetViolationStatus")
3983
+
3984
+ ## Invoke the method to get violation time
3985
+ ret = fn(device, c_perfPolicy_type, byref(c_violTime))
3986
+ _nvmlCheckReturn(ret)
3987
+ return c_violTime
3988
+
3989
+def nvmlDeviceGetPcieThroughput(device, counter):
3990
+ c_util = c_uint()
3991
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetPcieThroughput")
3992
+ ret = fn(device, _nvmlPcieUtilCounter_t(counter), byref(c_util))
3993
+ _nvmlCheckReturn(ret)
3994
+ return c_util.value
3995
+
3996
+def nvmlSystemGetTopologyGpuSet(cpuNumber):
3997
+ c_count = c_uint(0)
3998
+ fn = _nvmlGetFunctionPointer("nvmlSystemGetTopologyGpuSet")
3999
+
4000
+ # First call will get the size
4001
+ ret = fn(cpuNumber, byref(c_count), None)
4002
+
4003
+ if ret != NVML_SUCCESS:
4004
+ raise NVMLError(ret)
4005
+ # call again with a buffer
4006
+ device_array = c_nvmlDevice_t * c_count.value
4007
+ c_devices = device_array()
4008
+ ret = fn(cpuNumber, byref(c_count), c_devices)
4009
+ _nvmlCheckReturn(ret)
4010
+ return list(c_devices[0:c_count.value])
4011
+
4012
+def nvmlDeviceGetTopologyNearestGpus(device, level):
4013
+ c_count = c_uint(0)
4014
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetTopologyNearestGpus")
4015
+
4016
+ # First call will get the size
4017
+ ret = fn(device, level, byref(c_count), None)
4018
+
4019
+ if ret != NVML_SUCCESS:
4020
+ raise NVMLError(ret)
4021
+
4022
+ # call again with a buffer
4023
+ device_array = c_nvmlDevice_t * c_count.value
4024
+ c_devices = device_array()
4025
+ ret = fn(device, level, byref(c_count), c_devices)
4026
+ _nvmlCheckReturn(ret)
4027
+ return list(c_devices[0:c_count.value])
4028
+
4029
+def nvmlDeviceGetTopologyCommonAncestor(device1, device2):
4030
+ c_level = _nvmlGpuTopologyLevel_t()
4031
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetTopologyCommonAncestor")
4032
+ ret = fn(device1, device2, byref(c_level))
4033
+ _nvmlCheckReturn(ret)
4034
+ return c_level.value
4035
+
4036
+def nvmlDeviceGetNvLinkUtilizationCounter(device, link, counter):
4037
+ c_rxcounter = c_ulonglong()
4038
+ c_txcounter = c_ulonglong()
4039
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetNvLinkUtilizationCounter")
4040
+ ret = fn(device, link, counter, byref(c_rxcounter), byref(c_txcounter))
4041
+ _nvmlCheckReturn(ret)
4042
+ return (c_rxcounter.value, c_txcounter.value)
4043
+
4044
+def nvmlDeviceFreezeNvLinkUtilizationCounter(device, link, counter, freeze):
4045
+ fn = _nvmlGetFunctionPointer("nvmlDeviceFreezeNvLinkUtilizationCounter")
4046
+ ret = fn(device, link, counter, freeze)
4047
+ _nvmlCheckReturn(ret)
4048
+ return None
4049
+
4050
+def nvmlDeviceResetNvLinkUtilizationCounter(device, link, counter):
4051
+ fn = _nvmlGetFunctionPointer("nvmlDeviceResetNvLinkUtilizationCounter")
4052
+ ret = fn(device, link, counter)
4053
+ _nvmlCheckReturn(ret)
4054
+ return None
4055
+
4056
+def nvmlDeviceSetNvLinkUtilizationControl(device, link, counter, control, reset):
4057
+ fn = _nvmlGetFunctionPointer("nvmlDeviceSetNvLinkUtilizationControl")
4058
+ ret = fn(device, link, counter, byref(control), reset)
4059
+ _nvmlCheckReturn(ret)
4060
+ return None
4061
+
4062
+def nvmlDeviceGetNvLinkUtilizationControl(device, link, counter):
4063
+ c_control = nvmlNvLinkUtilizationControl_t()
4064
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetNvLinkUtilizationControl")
4065
+ ret = fn(device, link, counter, byref(c_control))
4066
+ _nvmlCheckReturn(ret)
4067
+ return c_control
4068
+
4069
+def nvmlDeviceGetNvLinkCapability(device, link, capability):
4070
+ c_capResult = c_uint()
4071
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetNvLinkCapability")
4072
+ ret = fn(device, link, capability, byref(c_capResult))
4073
+ _nvmlCheckReturn(ret)
4074
+ return c_capResult.value
4075
+
4076
+def nvmlDeviceGetNvLinkErrorCounter(device, link, counter):
4077
+ c_result = c_ulonglong()
4078
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetNvLinkErrorCounter")
4079
+ ret = fn(device, link, counter, byref(c_result))
4080
+ _nvmlCheckReturn(ret)
4081
+ return c_result.value
4082
+
4083
+def nvmlDeviceResetNvLinkErrorCounters(device, link):
4084
+ fn = _nvmlGetFunctionPointer("nvmlDeviceResetNvLinkErrorCounters")
4085
+ ret = fn(device, link)
4086
+ _nvmlCheckReturn(ret)
4087
+ return None
4088
+
4089
+def nvmlDeviceGetNvLinkRemotePciInfo(device, link):
4090
+ c_pci = nvmlPciInfo_t()
4091
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetNvLinkRemotePciInfo_v2")
4092
+ ret = fn(device, link, byref(c_pci))
4093
+ _nvmlCheckReturn(ret)
4094
+ return c_pci
4095
+
4096
+def nvmlDeviceGetNvLinkRemoteDeviceType(handle, link):
4097
+ c_type = _nvmlNvLinkDeviceType_t()
4098
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetNvLinkRemoteDeviceType")
4099
+ ret = fn(handle, link, byref(c_type))
4100
+ _nvmlCheckReturn(ret)
4101
+ return c_type.value
4102
+
4103
+def nvmlDeviceGetNvLinkState(device, link):
4104
+ c_isActive = c_uint()
4105
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetNvLinkState")
4106
+ ret = fn(device, link, byref(c_isActive))
4107
+ _nvmlCheckReturn(ret)
4108
+ return c_isActive.value
4109
+
4110
+def nvmlDeviceGetNvLinkVersion(device, link):
4111
+ c_version = c_uint()
4112
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetNvLinkVersion")
4113
+ ret = fn(device, link, byref(c_version))
4114
+ _nvmlCheckReturn(ret)
4115
+ return c_version.value
4116
+
4117
+def nvmlDeviceModifyDrainState(pciInfo, newState):
4118
+ fn = _nvmlGetFunctionPointer("nvmlDeviceModifyDrainState")
4119
+ ret = fn(pointer(pciInfo), newState)
4120
+ _nvmlCheckReturn(ret)
4121
+ return None
4122
+
4123
+def nvmlDeviceQueryDrainState(pciInfo):
4124
+ c_newState = c_uint()
4125
+ fn = _nvmlGetFunctionPointer("nvmlDeviceQueryDrainState")
4126
+ ret = fn(pointer(pciInfo), byref(c_newState))
4127
+ _nvmlCheckReturn(ret)
4128
+ return c_newState.value
4129
+
4130
+def nvmlDeviceRemoveGpu(pciInfo):
4131
+ fn = _nvmlGetFunctionPointer("nvmlDeviceRemoveGpu")
4132
+ ret = fn(pointer(pciInfo))
4133
+ _nvmlCheckReturn(ret)
4134
+ return None
4135
+
4136
+def nvmlDeviceDiscoverGpus(pciInfo):
4137
+ fn = _nvmlGetFunctionPointer("nvmlDeviceDiscoverGpus")
4138
+ ret = fn(pointer(pciInfo))
4139
+ _nvmlCheckReturn(ret)
4140
+ return None
4141
+
4142
+def nvmlDeviceGetFieldValues(handle, fieldIds):
4143
+ values_arr = c_nvmlFieldValue_t * len(fieldIds)
4144
+ values = values_arr()
4145
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetFieldValues")
4146
+
4147
+ for i, fieldId in enumerate(fieldIds):
4148
+ try:
4149
+ (values[i].fieldId, values[i].scopeId) = fieldId
4150
+ except TypeError:
4151
+ values[i].fieldId = fieldId
4152
+
4153
+ ret = fn(handle, c_int32(len(fieldIds)), byref(values))
4154
+ _nvmlCheckReturn(ret)
4155
+ return values
4156
+
4157
+def nvmlDeviceClearFieldValues(handle, fieldIds):
4158
+ values_arr = c_nvmlFieldValue_t * len(fieldIds)
4159
+ values = values_arr()
4160
+ fn = _nvmlGetFunctionPointer("nvmlDeviceClearFieldValues")
4161
+
4162
+ for i, fieldId in enumerate(fieldIds):
4163
+ try:
4164
+ (values[i].fieldId, values[i].scopeId) = fieldId
4165
+ except TypeError:
4166
+ values[i].fieldId = fieldId
4167
+
4168
+ ret = fn(handle, c_int32(len(fieldIds)), byref(values))
4169
+ _nvmlCheckReturn(ret)
4170
+ return values
4171
+
4172
+def nvmlDeviceGetVirtualizationMode(handle):
4173
+ c_virtualization_mode = c_ulonglong()
4174
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetVirtualizationMode")
4175
+ ret = fn(handle, byref(c_virtualization_mode))
4176
+ _nvmlCheckReturn(ret)
4177
+ return c_virtualization_mode.value
4178
+
4179
+def nvmlDeviceSetVirtualizationMode(handle, virtualization_mode):
4180
+ fn = _nvmlGetFunctionPointer("nvmlDeviceSetVirtualizationMode")
4181
+ return fn(handle, virtualization_mode)
4182
+
4183
+def nvmlDeviceGetVgpuHeterogeneousMode(handle):
4184
+ c_vgpuHeterogeneousMode = c_nvmlVgpuHeterogeneousMode_v1_t(0)
4185
+ c_vgpuHeterogeneousMode.version = VgpuHeterogeneousMode_v1
4186
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetVgpuHeterogeneousMode")
4187
+ ret = fn(handle, byref(c_vgpuHeterogeneousMode))
4188
+ _nvmlCheckReturn(ret)
4189
+ return c_vgpuHeterogeneousMode.mode
4190
+
4191
+def nvmlDeviceSetVgpuHeterogeneousMode(handle, heterogeneous_mode):
4192
+ c_vgpuHeterogeneousMode = c_nvmlVgpuHeterogeneousMode_v1_t(0)
4193
+ c_vgpuHeterogeneousMode.version = VgpuHeterogeneousMode_v1
4194
+ c_vgpuHeterogeneousMode.mode = heterogeneous_mode
4195
+ fn = _nvmlGetFunctionPointer("nvmlDeviceSetVgpuHeterogeneousMode")
4196
+ ret = fn(handle, byref(c_vgpuHeterogeneousMode))
4197
+ _nvmlCheckReturn(ret)
4198
+ return NVML_SUCCESS
4199
+
4200
+def nvmlVgpuInstanceGetPlacementId(vgpuInstance):
4201
+ c_placement = c_nvmlVgpuPlacementId_v1_t(0)
4202
+ c_placement.version = VgpuPlacementId_v1
4203
+ fn = _nvmlGetFunctionPointer("nvmlVgpuInstanceGetPlacementId")
4204
+ ret = fn(vgpuInstance, byref(c_placement))
4205
+ _nvmlCheckReturn(ret)
4206
+ return c_placement.placementId
4207
+
4208
+def nvmlDeviceGetVgpuTypeSupportedPlacements(handle, vgpuTypeId, mode=0, version=1):
4209
+ c_max_instances = c_uint(0)
4210
+ fn = _nvmlGetFunctionPointer("nvmlVgpuTypeGetMaxInstances")
4211
+ ret = fn(handle, vgpuTypeId, byref(c_max_instances))
4212
+ _nvmlCheckReturn(ret)
4213
+
4214
+ if version == 2:
4215
+ c_vgpu_placements = c_nvmlVgpuPlacementList_v2_t()
4216
+ c_vgpu_placements.version = VgpuPlacementList_v2
4217
+ c_vgpu_placements.count = c_max_instances.value
4218
+ c_vgpu_placements.mode = mode
4219
+ elif version == 1:
4220
+ c_vgpu_placements = c_nvmlVgpuPlacementList_v1_t()
4221
+ c_vgpu_placements.version = VgpuPlacementList_v1
4222
+ else:
4223
+ raise NVMLError(NVML_ERROR_ARGUMENT_VERSION_MISMATCH)
4224
+
4225
+ c_placements = c_uint * c_max_instances.value
4226
+ c_vgpu_placements.placementIds = c_placements()
4227
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetVgpuTypeSupportedPlacements")
4228
+ ret = fn(handle, vgpuTypeId, byref(c_vgpu_placements))
4229
+ _nvmlCheckReturn(ret)
4230
+ return c_vgpu_placements
4231
+
4232
+def nvmlDeviceGetVgpuTypeCreatablePlacements(handle, vgpuTypeId, version=1):
4233
+ c_max_instances = c_uint(0)
4234
+ fn = _nvmlGetFunctionPointer("nvmlVgpuTypeGetMaxInstances")
4235
+ ret = fn(handle, vgpuTypeId, byref(c_max_instances))
4236
+ _nvmlCheckReturn(ret)
4237
+
4238
+ if version == 2:
4239
+ c_vgpu_placements = c_nvmlVgpuPlacementList_v2_t()
4240
+ c_vgpu_placements.version = VgpuPlacementList_v2
4241
+ c_vgpu_placements.count = c_max_instances.value
4242
+ elif version == 1:
4243
+ c_vgpu_placements = c_nvmlVgpuPlacementList_v1_t()
4244
+ c_vgpu_placements.version = VgpuPlacementList_v1
4245
+
4246
+ c_placements = c_uint * c_max_instances.value
4247
+ c_vgpu_placements.placementIds = c_placements()
4248
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetVgpuTypeCreatablePlacements")
4249
+ ret = fn(handle, vgpuTypeId, byref(c_vgpu_placements))
4250
+ _nvmlCheckReturn(ret)
4251
+ return c_vgpu_placements
4252
+
4253
+def nvmlGetVgpuDriverCapabilities(capability):
4254
+ c_capResult = c_uint()
4255
+ fn = _nvmlGetFunctionPointer("nvmlGetVgpuDriverCapabilities")
4256
+ ret = fn(_nvmlVgpuDriverCapability_t(capability), byref(c_capResult))
4257
+ _nvmlCheckReturn(ret)
4258
+ return c_capResult.value
4259
+
4260
+def nvmlDeviceGetVgpuCapabilities(handle, capability):
4261
+ c_capResult = c_uint()
4262
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetVgpuCapabilities")
4263
+ ret = fn(handle, _nvmlDeviceVgpuCapability_t(capability), byref(c_capResult))
4264
+ _nvmlCheckReturn(ret)
4265
+ return c_capResult.value
4266
+
4267
+def nvmlDeviceSetVgpuCapabilities(handle, capability, state):
4268
+ fn = _nvmlGetFunctionPointer("nvmlDeviceSetVgpuCapabilities")
4269
+ ret = fn(handle, _nvmlDeviceVgpuCapability_t(capability), state)
4270
+ _nvmlCheckReturn(ret)
4271
+ return NVML_SUCCESS
4272
+
4273
+def nvmlDeviceGetSupportedVgpus(handle):
4274
+ # first call to get the size
4275
+ c_vgpu_count = c_uint(0)
4276
+
4277
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetSupportedVgpus")
4278
+ ret = fn(handle, byref(c_vgpu_count), None)
4279
+
4280
+ if (ret == NVML_SUCCESS):
4281
+ # special case, no supported vGPUs
4282
+ return []
4283
+ elif (ret == NVML_ERROR_INSUFFICIENT_SIZE):
4284
+ # typical case
4285
+ vgpu_type_ids_array = _nvmlVgpuTypeId_t * c_vgpu_count.value
4286
+ c_vgpu_type_ids = vgpu_type_ids_array()
4287
+
4288
+ # make the call again
4289
+ ret = fn(handle, byref(c_vgpu_count), c_vgpu_type_ids)
4290
+ _nvmlCheckReturn(ret)
4291
+ vgpus = []
4292
+ for i in range(c_vgpu_count.value):
4293
+ vgpus.append(c_vgpu_type_ids[i])
4294
+ return vgpus
4295
+ else:
4296
+ # error case
4297
+ raise NVMLError(ret)
4298
+
4299
+def nvmlDeviceGetCreatableVgpus(handle):
4300
+ # first call to get the size
4301
+ c_vgpu_count = c_uint(0)
4302
+
4303
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetCreatableVgpus")
4304
+ ret = fn(handle, byref(c_vgpu_count), None)
4305
+
4306
+ if (ret == NVML_SUCCESS):
4307
+ # special case, no supported vGPUs
4308
+ return []
4309
+ elif (ret == NVML_ERROR_INSUFFICIENT_SIZE):
4310
+ # typical case
4311
+ vgpu_type_ids_array = _nvmlVgpuTypeId_t * c_vgpu_count.value
4312
+ c_vgpu_type_ids = vgpu_type_ids_array()
4313
+
4314
+ # make the call again
4315
+ ret = fn(handle, byref(c_vgpu_count), c_vgpu_type_ids)
4316
+ _nvmlCheckReturn(ret)
4317
+ vgpus = []
4318
+ for i in range(c_vgpu_count.value):
4319
+ vgpus.append(c_vgpu_type_ids[i])
4320
+ return vgpus
4321
+ else:
4322
+ # error case
4323
+ raise NVMLError(ret)
4324
+
4325
+def nvmlVgpuTypeGetGpuInstanceProfileId(vgpuTypeId):
4326
+ c_profile_id = c_uint(0)
4327
+ fn = _nvmlGetFunctionPointer("nvmlVgpuTypeGetGpuInstanceProfileId")
4328
+ ret = fn(vgpuTypeId, byref(c_profile_id))
4329
+ _nvmlCheckReturn(ret)
4330
+ return (c_profile_id.value)
4331
+
4332
+@convertStrBytes
4333
+def nvmlVgpuTypeGetClass(vgpuTypeId):
4334
+ c_class = create_string_buffer(NVML_DEVICE_NAME_BUFFER_SIZE)
4335
+ c_buffer_size = c_uint(NVML_DEVICE_NAME_BUFFER_SIZE)
4336
+ fn = _nvmlGetFunctionPointer("nvmlVgpuTypeGetClass")
4337
+ ret = fn(vgpuTypeId, c_class, byref(c_buffer_size))
4338
+ _nvmlCheckReturn(ret)
4339
+ return c_class.value
4340
+
4341
+@convertStrBytes
4342
+def nvmlVgpuTypeGetName(vgpuTypeId):
4343
+ c_name = create_string_buffer(NVML_DEVICE_NAME_BUFFER_SIZE)
4344
+ c_buffer_size = c_uint(NVML_DEVICE_NAME_BUFFER_SIZE)
4345
+ fn = _nvmlGetFunctionPointer("nvmlVgpuTypeGetName")
4346
+ ret = fn(vgpuTypeId, c_name, byref(c_buffer_size))
4347
+ _nvmlCheckReturn(ret)
4348
+ return c_name.value
4349
+
4350
+def nvmlVgpuTypeGetDeviceID(vgpuTypeId):
4351
+ c_device_id = c_ulonglong(0)
4352
+ c_subsystem_id = c_ulonglong(0)
4353
+ fn = _nvmlGetFunctionPointer("nvmlVgpuTypeGetDeviceID")
4354
+ ret = fn(vgpuTypeId, byref(c_device_id), byref(c_subsystem_id))
4355
+ _nvmlCheckReturn(ret)
4356
+ return (c_device_id.value, c_subsystem_id.value)
4357
+
4358
+def nvmlVgpuTypeGetFramebufferSize(vgpuTypeId):
4359
+ c_fb_size = c_ulonglong(0)
4360
+ fn = _nvmlGetFunctionPointer("nvmlVgpuTypeGetFramebufferSize")
4361
+ ret = fn(vgpuTypeId, byref(c_fb_size))
4362
+ _nvmlCheckReturn(ret)
4363
+ return c_fb_size.value
4364
+
4365
+def nvmlVgpuTypeGetNumDisplayHeads(vgpuTypeId):
4366
+ c_num_heads = c_uint(0)
4367
+ fn = _nvmlGetFunctionPointer("nvmlVgpuTypeGetNumDisplayHeads")
4368
+ ret = fn(vgpuTypeId, byref(c_num_heads))
4369
+ _nvmlCheckReturn(ret)
4370
+ return c_num_heads.value
4371
+
4372
+def nvmlVgpuTypeGetResolution(vgpuTypeId):
4373
+ c_xdim = c_uint(0)
4374
+ c_ydim = c_uint(0)
4375
+ fn = _nvmlGetFunctionPointer("nvmlVgpuTypeGetResolution")
4376
+ ret = fn(vgpuTypeId, 0, byref(c_xdim), byref(c_ydim))
4377
+ _nvmlCheckReturn(ret)
4378
+ return (c_xdim.value, c_ydim.value)
4379
+
4380
+@convertStrBytes
4381
+def nvmlVgpuTypeGetLicense(vgpuTypeId):
4382
+ c_license = create_string_buffer(NVML_GRID_LICENSE_BUFFER_SIZE)
4383
+ c_buffer_size = c_uint(NVML_GRID_LICENSE_BUFFER_SIZE)
4384
+ fn = _nvmlGetFunctionPointer("nvmlVgpuTypeGetLicense")
4385
+ ret = fn(vgpuTypeId, c_license, c_buffer_size)
4386
+ _nvmlCheckReturn(ret)
4387
+ return c_license.value
4388
+
4389
+def nvmlVgpuTypeGetFrameRateLimit(vgpuTypeId):
4390
+ c_frl_config = c_uint(0)
4391
+ fn = _nvmlGetFunctionPointer("nvmlVgpuTypeGetFrameRateLimit")
4392
+ ret = fn(vgpuTypeId, byref(c_frl_config))
4393
+ _nvmlCheckReturn(ret)
4394
+ return c_frl_config.value
4395
+
4396
+def nvmlVgpuTypeGetGspHeapSize(vgpuTypeId):
4397
+ c_gsp_heap = c_uint(0)
4398
+ fn = _nvmlGetFunctionPointer("nvmlVgpuTypeGetGspHeapSize")
4399
+ ret = fn(vgpuTypeId, byref(c_gsp_heap))
4400
+ _nvmlCheckReturn(ret)
4401
+ return c_gsp_heap.value
4402
+
4403
+def nvmlVgpuTypeGetFbReservation(vgpuTypeId):
4404
+ c_fb_reservation = c_uint(0)
4405
+ fn = _nvmlGetFunctionPointer("nvmlVgpuTypeGetFbReservation")
4406
+ ret = fn(vgpuTypeId, byref(c_fb_reservation))
4407
+ _nvmlCheckReturn(ret)
4408
+ return c_fb_reservation.value
4409
+
4410
+def nvmlVgpuInstanceGetRuntimeStateSize(vgpuInstance):
4411
+ c_runtime_state = nvmlVgpuRuntimeState_v1_t()
4412
+ c_runtime_state.version = VgpuRuntimeState_v1
4413
+ fn = _nvmlGetFunctionPointer("nvmlVgpuInstanceGetRuntimeStateSize")
4414
+ ret = fn(vgpuInstance, byref(c_runtime_state))
4415
+ _nvmlCheckReturn(ret)
4416
+ return c_runtime_state
4417
+
4418
+def nvmlVgpuTypeGetMaxInstances(handle, vgpuTypeId):
4419
+ c_max_instances = c_uint(0)
4420
+ fn = _nvmlGetFunctionPointer("nvmlVgpuTypeGetMaxInstances")
4421
+ ret = fn(handle, vgpuTypeId, byref(c_max_instances))
4422
+ _nvmlCheckReturn(ret)
4423
+ return c_max_instances.value
4424
+
4425
+def nvmlVgpuTypeGetMaxInstancesPerVm(vgpuTypeId):
4426
+ c_max_instances_per_vm = c_uint(0)
4427
+ fn = _nvmlGetFunctionPointer("nvmlVgpuTypeGetMaxInstancesPerVm")
4428
+ ret = fn(vgpuTypeId, byref(c_max_instances_per_vm))
4429
+ _nvmlCheckReturn(ret)
4430
+ return c_max_instances_per_vm.value
4431
+
4432
+def nvmlVgpuTypeGetBAR1Info(vgpuTypeId):
4433
+ c_bar1Info = c_nvmlVgpuTypeBar1Info_v1_t(0)
4434
+ c_bar1Info.version = VgpuTypeBar1Info_v1
4435
+ fn = _nvmlGetFunctionPointer("nvmlVgpuTypeGetBAR1Info")
4436
+ ret = fn(vgpuTypeId, byref(c_bar1Info))
4437
+ _nvmlCheckReturn(ret)
4438
+ return c_bar1Info
4439
+
4440
+def nvmlDeviceGetActiveVgpus(handle):
4441
+ # first call to get the size
4442
+ c_vgpu_count = c_uint(0)
4443
+
4444
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetActiveVgpus")
4445
+ ret = fn(handle, byref(c_vgpu_count), None)
4446
+
4447
+ if (ret == NVML_SUCCESS):
4448
+ # special case, no active vGPUs
4449
+ return []
4450
+ elif (ret == NVML_ERROR_INSUFFICIENT_SIZE):
4451
+ # typical case
4452
+ vgpu_instance_array = _nvmlVgpuInstance_t * c_vgpu_count.value
4453
+ c_vgpu_instances = vgpu_instance_array()
4454
+
4455
+ # make the call again
4456
+ ret = fn(handle, byref(c_vgpu_count), c_vgpu_instances)
4457
+ _nvmlCheckReturn(ret)
4458
+ vgpus = []
4459
+ for i in range(c_vgpu_count.value):
4460
+ vgpus.append(c_vgpu_instances[i])
4461
+ return vgpus
4462
+ else:
4463
+ # error case
4464
+ raise NVMLError(ret)
4465
+
4466
+@convertStrBytes
4467
+def nvmlVgpuInstanceGetVmID(vgpuInstance):
4468
+ c_vm_id = create_string_buffer(NVML_DEVICE_UUID_BUFFER_SIZE)
4469
+ c_buffer_size = c_uint(NVML_GRID_LICENSE_BUFFER_SIZE)
4470
+ c_vm_id_type = c_uint(0)
4471
+ fn = _nvmlGetFunctionPointer("nvmlVgpuInstanceGetVmID")
4472
+ ret = fn(vgpuInstance, byref(c_vm_id), c_buffer_size, byref(c_vm_id_type))
4473
+ _nvmlCheckReturn(ret)
4474
+ return (c_vm_id.value, c_vm_id_type.value)
4475
+
4476
+@convertStrBytes
4477
+def nvmlVgpuInstanceGetUUID(vgpuInstance):
4478
+ c_uuid = create_string_buffer(NVML_DEVICE_UUID_BUFFER_SIZE)
4479
+ c_buffer_size = c_uint(NVML_DEVICE_UUID_BUFFER_SIZE)
4480
+ fn = _nvmlGetFunctionPointer("nvmlVgpuInstanceGetUUID")
4481
+ ret = fn(vgpuInstance, byref(c_uuid), c_buffer_size)
4482
+ _nvmlCheckReturn(ret)
4483
+ return c_uuid.value
4484
+
4485
+@convertStrBytes
4486
+def nvmlVgpuInstanceGetMdevUUID(vgpuInstance):
4487
+ c_uuid = create_string_buffer(NVML_DEVICE_UUID_BUFFER_SIZE)
4488
+ c_buffer_size = c_uint(NVML_DEVICE_UUID_BUFFER_SIZE)
4489
+ fn = _nvmlGetFunctionPointer("nvmlVgpuInstanceGetMdevUUID")
4490
+ ret = fn(vgpuInstance, byref(c_uuid), c_buffer_size)
4491
+ _nvmlCheckReturn(ret)
4492
+ return c_uuid.value
4493
+
4494
+@convertStrBytes
4495
+def nvmlVgpuInstanceGetVmDriverVersion(vgpuInstance):
4496
+ c_driver_version = create_string_buffer(NVML_SYSTEM_DRIVER_VERSION_BUFFER_SIZE)
4497
+ c_buffer_size = c_uint(NVML_SYSTEM_DRIVER_VERSION_BUFFER_SIZE)
4498
+ fn = _nvmlGetFunctionPointer("nvmlVgpuInstanceGetVmDriverVersion")
4499
+ ret = fn(vgpuInstance, byref(c_driver_version), c_buffer_size)
4500
+ _nvmlCheckReturn(ret)
4501
+ return c_driver_version.value
4502
+
4503
+def nvmlVgpuInstanceGetLicenseStatus(vgpuInstance):
4504
+ c_license_status = c_uint(0)
4505
+ fn = _nvmlGetFunctionPointer("nvmlVgpuInstanceGetLicenseStatus")
4506
+ ret = fn(vgpuInstance, byref(c_license_status))
4507
+ _nvmlCheckReturn(ret)
4508
+ return c_license_status.value
4509
+
4510
+def nvmlVgpuInstanceGetLicenseInfo_v2(vgpuInstance):
4511
+ fn = _nvmlGetFunctionPointer("nvmlVgpuInstanceGetLicenseInfo_v2")
4512
+ c_license_info = c_nvmlVgpuLicenseInfo_t()
4513
+ ret = fn(vgpuInstance, byref(c_license_info))
4514
+ _nvmlCheckReturn(ret)
4515
+ return c_license_info
4516
+
4517
+def nvmlVgpuInstanceGetLicenseInfo(vgpuInstance):
4518
+ return nvmlVgpuInstanceGetLicenseInfo_v2(vgpuInstance)
4519
+
4520
+def nvmlVgpuInstanceGetFrameRateLimit(vgpuInstance):
4521
+ c_frl = c_uint(0)
4522
+ fn = _nvmlGetFunctionPointer("nvmlVgpuInstanceGetFrameRateLimit")
4523
+ ret = fn(vgpuInstance, byref(c_frl))
4524
+ _nvmlCheckReturn(ret)
4525
+ return c_frl.value
4526
+
4527
+def nvmlVgpuInstanceGetEccMode(vgpuInstance):
4528
+ c_mode = _nvmlEnableState_t()
4529
+ fn = _nvmlGetFunctionPointer("nvmlVgpuInstanceGetEccMode")
4530
+ ret = fn(vgpuInstance, byref(c_mode))
4531
+ _nvmlCheckReturn(ret)
4532
+ return c_mode.value
4533
+
4534
+def nvmlVgpuInstanceGetType(vgpuInstance):
4535
+ c_vgpu_type = c_uint(0)
4536
+ fn = _nvmlGetFunctionPointer("nvmlVgpuInstanceGetType")
4537
+ ret = fn(vgpuInstance, byref(c_vgpu_type))
4538
+ _nvmlCheckReturn(ret)
4539
+ return c_vgpu_type.value
4540
+
4541
+def nvmlVgpuInstanceGetEncoderCapacity(vgpuInstance):
4542
+ c_encoder_capacity = c_ulonglong(0)
4543
+ fn = _nvmlGetFunctionPointer("nvmlVgpuInstanceGetEncoderCapacity")
4544
+ ret = fn(vgpuInstance, byref(c_encoder_capacity))
4545
+ _nvmlCheckReturn(ret)
4546
+ return c_encoder_capacity.value
4547
+
4548
+def nvmlVgpuInstanceSetEncoderCapacity(vgpuInstance, encoder_capacity):
4549
+ fn = _nvmlGetFunctionPointer("nvmlVgpuInstanceSetEncoderCapacity")
4550
+ return fn(vgpuInstance, encoder_capacity)
4551
+
4552
+def nvmlVgpuInstanceGetFbUsage(vgpuInstance):
4553
+ c_fb_usage = c_uint(0)
4554
+ fn = _nvmlGetFunctionPointer("nvmlVgpuInstanceGetFbUsage")
4555
+ ret = fn(vgpuInstance, byref(c_fb_usage))
4556
+ _nvmlCheckReturn(ret)
4557
+ return c_fb_usage.value
4558
+
4559
+def nvmlVgpuTypeGetCapabilities(vgpuTypeId, capability):
4560
+ c_cap_result = c_uint(0)
4561
+ fn = _nvmlGetFunctionPointer("nvmlVgpuTypeGetCapabilities")
4562
+ ret = fn(vgpuTypeId, _nvmlVgpuCapability_t(capability), byref(c_cap_result))
4563
+ _nvmlCheckReturn(ret)
4564
+ return (c_cap_result.value)
4565
+
4566
+def nvmlVgpuInstanceGetGpuInstanceId(vgpuInstance):
4567
+ c_id = c_uint(0)
4568
+ fn = _nvmlGetFunctionPointer("nvmlVgpuInstanceGetGpuInstanceId")
4569
+ ret = fn(vgpuInstance, byref(c_id))
4570
+ _nvmlCheckReturn(ret)
4571
+ return (c_id.value)
4572
+
4573
+@convertStrBytes
4574
+def nvmlVgpuInstanceGetGpuPciId(vgpuInstance):
4575
+ c_vgpuPciId = create_string_buffer(NVML_DEVICE_PCI_BUS_ID_BUFFER_SIZE)
4576
+ fn = _nvmlGetFunctionPointer("nvmlVgpuInstanceGetGpuPciId")
4577
+ ret = fn(vgpuInstance, c_vgpuPciId, byref(c_uint(NVML_DEVICE_PCI_BUS_ID_BUFFER_SIZE)))
4578
+ _nvmlCheckReturn(ret)
4579
+ return c_vgpuPciId.value
4580
+
4581
+def nvmlDeviceGetVgpuUtilization(handle, timeStamp):
4582
+ # first call to get the size
4583
+ c_vgpu_count = c_uint(0)
4584
+ c_time_stamp = c_ulonglong(timeStamp)
4585
+ c_sample_value_type = _nvmlValueType_t()
4586
+
4587
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetVgpuUtilization")
4588
+ ret = fn(handle, c_time_stamp, byref(c_sample_value_type), byref(c_vgpu_count), None)
4589
+
4590
+ if (ret == NVML_SUCCESS):
4591
+ # special case, no active vGPUs
4592
+ return []
4593
+ elif (ret == NVML_ERROR_INSUFFICIENT_SIZE):
4594
+ # typical case
4595
+ sampleArray = c_vgpu_count.value * c_nvmlVgpuInstanceUtilizationSample_t
4596
+ c_samples = sampleArray()
4597
+
4598
+ # make the call again
4599
+ ret = fn(handle, c_time_stamp, byref(c_sample_value_type), byref(c_vgpu_count), c_samples)
4600
+ _nvmlCheckReturn(ret)
4601
+
4602
+ return c_samples[0:c_vgpu_count.value]
4603
+ else:
4604
+ # error case
4605
+ raise NVMLError(ret)
4606
+
4607
+def nvmlDeviceGetVgpuInstancesUtilizationInfo(handle, timeStamp):
4608
+ # first call to get the size
4609
+ c_time_stamp = c_ulonglong(timeStamp)
4610
+ c_vgpuUtilInfo = c_nvmlVgpuInstancesUtilizationInfo_v1_t(0)
4611
+ c_vgpuUtilInfo.version = VgpuInstancesUtilizationInfo_v1
4612
+ c_vgpuUtilInfo.sampleValType = _nvmlValueType_t()
4613
+ c_vgpuUtilInfo.vgpuInstanceCount = c_uint(0)
4614
+ c_vgpuUtilInfo.lastSeenTimeStamp = c_time_stamp
4615
+
4616
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetVgpuInstancesUtilizationInfo")
4617
+ ret = fn(handle, byref(c_vgpuUtilInfo))
4618
+
4619
+ if (ret == NVML_SUCCESS):
4620
+ # special case, no active vGPUs
4621
+ return []
4622
+ elif (ret == NVML_ERROR_INSUFFICIENT_SIZE):
4623
+ # typical case
4624
+ sampleArray = c_vgpuUtilInfo.vgpuInstanceCount * c_nvmlVgpuInstanceUtilizationInfo_v1_t
4625
+ c_samples = sampleArray()
4626
+ c_vgpuUtilInfo.vgpuUtilArray = c_samples
4627
+
4628
+ # make the call again
4629
+ ret = fn(handle, byref(c_vgpuUtilInfo))
4630
+ _nvmlCheckReturn(ret)
4631
+
4632
+ return c_samples[0:c_vgpuUtilInfo.vgpuInstanceCount]
4633
+ else:
4634
+ # error case
4635
+ raise NVMLError(ret)
4636
+
4637
+def nvmlDeviceGetP2PStatus(device1, device2, p2pIndex):
4638
+ c_p2pstatus = _nvmlGpuP2PStatus_t()
4639
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetP2PStatus")
4640
+ ret = fn(device1, device2,p2pIndex, byref(c_p2pstatus))
4641
+ _nvmlCheckReturn(ret)
4642
+ return c_p2pstatus.value
4643
+
4644
+def nvmlDeviceGetGridLicensableFeatures_v4(handle):
4645
+ c_get_grid_licensable_features = c_nvmlGridLicensableFeatures_v4_t()
4646
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetGridLicensableFeatures_v4")
4647
+ ret = fn(handle, byref(c_get_grid_licensable_features))
4648
+ _nvmlCheckReturn(ret)
4649
+
4650
+ return (c_get_grid_licensable_features)
4651
+
4652
+def nvmlDeviceGetGridLicensableFeatures(handle):
4653
+ return nvmlDeviceGetGridLicensableFeatures_v4(handle)
4654
+
4655
+def nvmlDeviceGetGspFirmwareVersion(handle, version=None):
4656
+ isUserDefined = version is not None
4657
+ if not isUserDefined:
4658
+ version = (c_char * NVML_GSP_FIRMWARE_VERSION_BUF_SIZE)()
4659
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetGspFirmwareVersion")
4660
+ ret = fn(handle, version)
4661
+ _nvmlCheckReturn(ret)
4662
+ return NVML_SUCCESS if isUserDefined else version.value
4663
+
4664
+def nvmlDeviceGetGspFirmwareMode(handle, isEnabled=c_uint(), defaultMode=c_uint()):
4665
+ isReference = type(isEnabled) is not c_uint
4666
+ isEnabledRef = isEnabled if isReference else byref(isEnabled)
4667
+ defaultModeRef = defaultMode if isReference else byref(defaultMode)
4668
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetGspFirmwareMode")
4669
+ ret = fn(handle, isEnabledRef, defaultModeRef)
4670
+ _nvmlCheckReturn(ret)
4671
+ return NVML_SUCCESS if isReference else [isEnabled.value, defaultMode.value]
4672
+
4673
+def nvmlDeviceGetEncoderCapacity(handle, encoderQueryType):
4674
+ c_encoder_capacity = c_ulonglong(0)
4675
+ c_encoderQuery_type = _nvmlEncoderQueryType_t(encoderQueryType)
4676
+
4677
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetEncoderCapacity")
4678
+ ret = fn(handle, c_encoderQuery_type, byref(c_encoder_capacity))
4679
+ _nvmlCheckReturn(ret)
4680
+ return c_encoder_capacity.value
4681
+
4682
+def nvmlDeviceGetVgpuProcessUtilization(handle, timeStamp):
4683
+ # first call to get the size
4684
+ c_vgpu_count = c_uint(0)
4685
+ c_time_stamp = c_ulonglong(timeStamp)
4686
+
4687
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetVgpuProcessUtilization")
4688
+ ret = fn(handle, c_time_stamp, byref(c_vgpu_count), None)
4689
+
4690
+ if (ret == NVML_SUCCESS):
4691
+ # special case, no active vGPUs
4692
+ return []
4693
+ elif (ret == NVML_ERROR_INSUFFICIENT_SIZE):
4694
+ # typical case
4695
+ sampleArray = c_vgpu_count.value * c_nvmlVgpuProcessUtilizationSample_t
4696
+ c_samples = sampleArray()
4697
+
4698
+ # make the call again
4699
+ ret = fn(handle, c_time_stamp, byref(c_vgpu_count), c_samples)
4700
+ _nvmlCheckReturn(ret)
4701
+
4702
+ return c_samples[0:c_vgpu_count.value]
4703
+ else:
4704
+ # error case
4705
+ raise NVMLError(ret)
4706
+
4707
+def nvmlDeviceGetVgpuProcessesUtilizationInfo(handle, timeStamp):
4708
+ # first call to get the size
4709
+ c_time_stamp = c_ulonglong(timeStamp)
4710
+ c_vgpuProcUtilInfo = c_nvmlVgpuProcessesUtilizationInfo_v1_t(0)
4711
+ c_vgpuProcUtilInfo.version = VgpuProcessesUtilizationInfo_v1
4712
+ c_vgpuProcUtilInfo.vgpuProcessCount = c_uint(0)
4713
+ c_vgpuProcUtilInfo.lastSeenTimeStamp = c_time_stamp
4714
+
4715
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetVgpuProcessesUtilizationInfo")
4716
+ ret = fn(handle, byref(c_vgpuProcUtilInfo))
4717
+
4718
+ if (ret == NVML_SUCCESS):
4719
+ # special case, no active vGPUs
4720
+ return []
4721
+ elif (ret == NVML_ERROR_INSUFFICIENT_SIZE):
4722
+ # typical case
4723
+ sampleArray = c_vgpuProcUtilInfo.vgpuProcessCount * c_nvmlVgpuProcessUtilizationInfo_v1_t
4724
+ c_samples = sampleArray()
4725
+ c_vgpuProcUtilInfo.vgpuProcUtilArray = c_samples
4726
+
4727
+ # make the call again
4728
+ ret = fn(handle, byref(c_vgpuProcUtilInfo))
4729
+ _nvmlCheckReturn(ret)
4730
+
4731
+ return c_samples[0:c_vgpuProcUtilInfo.vgpuProcessCount]
4732
+ else:
4733
+ # error case
4734
+ raise NVMLError(ret)
4735
+
4736
+def nvmlDeviceGetEncoderStats(handle):
4737
+ c_encoderCount = c_ulonglong(0)
4738
+ c_encodeFps = c_ulonglong(0)
4739
+ c_encoderLatency = c_ulonglong(0)
4740
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetEncoderStats")
4741
+ ret = fn(handle, byref(c_encoderCount), byref(c_encodeFps), byref(c_encoderLatency))
4742
+ _nvmlCheckReturn(ret)
4743
+ return (c_encoderCount.value, c_encodeFps.value, c_encoderLatency.value)
4744
+
4745
+def nvmlDeviceGetEncoderSessions(handle):
4746
+ # first call to get the size
4747
+ c_session_count = c_uint(0)
4748
+
4749
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetEncoderSessions")
4750
+ ret = fn(handle, byref(c_session_count), None)
4751
+
4752
+ if (ret == NVML_SUCCESS):
4753
+ if (c_session_count.value != 0):
4754
+ # typical case
4755
+ session_array = c_nvmlEncoderSession_t * c_session_count.value
4756
+ c_sessions = session_array()
4757
+
4758
+ # make the call again
4759
+ ret = fn(handle, byref(c_session_count), c_sessions)
4760
+ _nvmlCheckReturn(ret)
4761
+ sessions = []
4762
+ for i in range(c_session_count.value):
4763
+ sessions.append(c_sessions[i])
4764
+ return sessions
4765
+ else:
4766
+ return [] # no active sessions
4767
+ else:
4768
+ # error case
4769
+ raise NVMLError(ret)
4770
+
4771
+def nvmlDeviceGetFBCStats(handle):
4772
+ c_fbcStats = c_nvmlFBCStats_t()
4773
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetFBCStats")
4774
+ ret = fn(handle, byref(c_fbcStats))
4775
+ _nvmlCheckReturn(ret)
4776
+ return c_fbcStats
4777
+
4778
+def nvmlDeviceGetFBCSessions(handle):
4779
+ # first call to get the size
4780
+ c_session_count = c_uint(0)
4781
+
4782
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetFBCSessions")
4783
+ ret = fn(handle, byref(c_session_count), None)
4784
+
4785
+ if (ret == NVML_SUCCESS):
4786
+ if (c_session_count.value != 0):
4787
+ # typical case
4788
+ session_array = c_nvmlFBCSession_t * c_session_count.value
4789
+ c_sessions = session_array()
4790
+
4791
+ # make the call again
4792
+ ret = fn(handle, byref(c_session_count), c_sessions)
4793
+ _nvmlCheckReturn(ret)
4794
+ sessions = []
4795
+ for i in range(c_session_count.value):
4796
+ sessions.append(c_sessions[i])
4797
+ return sessions
4798
+ else:
4799
+ return [] # no active sessions
4800
+ else:
4801
+ # error case
4802
+ raise NVMLError(ret)
4803
+
4804
+def nvmlVgpuInstanceGetEncoderStats(vgpuInstance):
4805
+ c_encoderCount = c_ulonglong(0)
4806
+ c_encodeFps = c_ulonglong(0)
4807
+ c_encoderLatency = c_ulonglong(0)
4808
+ fn = _nvmlGetFunctionPointer("nvmlVgpuInstanceGetEncoderStats")
4809
+ ret = fn(vgpuInstance, byref(c_encoderCount), byref(c_encodeFps), byref(c_encoderLatency))
4810
+ _nvmlCheckReturn(ret)
4811
+ return (c_encoderCount.value, c_encodeFps.value, c_encoderLatency.value)
4812
+
4813
+def nvmlVgpuInstanceGetEncoderSessions(vgpuInstance):
4814
+ # first call to get the size
4815
+ c_session_count = c_uint(0)
4816
+
4817
+ fn = _nvmlGetFunctionPointer("nvmlVgpuInstanceGetEncoderSessions")
4818
+ ret = fn(vgpuInstance, byref(c_session_count), None)
4819
+
4820
+ if (ret == NVML_SUCCESS):
4821
+ if (c_session_count.value != 0):
4822
+ # typical case
4823
+ session_array = c_nvmlEncoderSession_t * c_session_count.value
4824
+ c_sessions = session_array()
4825
+
4826
+ # make the call again
4827
+ ret = fn(vgpuInstance, byref(c_session_count), c_sessions)
4828
+ _nvmlCheckReturn(ret)
4829
+ sessions = []
4830
+ for i in range(c_session_count.value):
4831
+ sessions.append(c_sessions[i])
4832
+ return sessions
4833
+ else:
4834
+ return [] # no active sessions
4835
+ else:
4836
+ # error case
4837
+ raise NVMLError(ret)
4838
+
4839
+def nvmlVgpuInstanceGetFBCStats(vgpuInstance):
4840
+ c_fbcStats = c_nvmlFBCStats_t()
4841
+ fn = _nvmlGetFunctionPointer("nvmlVgpuInstanceGetFBCStats")
4842
+ ret = fn(vgpuInstance, byref(c_fbcStats))
4843
+ _nvmlCheckReturn(ret)
4844
+ return c_fbcStats
4845
+
4846
+def nvmlVgpuInstanceGetFBCSessions(vgpuInstance):
4847
+ # first call to get the size
4848
+ c_session_count = c_uint(0)
4849
+
4850
+ fn = _nvmlGetFunctionPointer("nvmlVgpuInstanceGetFBCSessions")
4851
+ ret = fn(vgpuInstance, byref(c_session_count), None)
4852
+
4853
+ if (ret == NVML_SUCCESS):
4854
+ if (c_session_count.value != 0):
4855
+ # typical case
4856
+ session_array = c_nvmlFBCSession_t * c_session_count.value
4857
+ c_sessions = session_array()
4858
+
4859
+ # make the call again
4860
+ ret = fn(vgpuInstance, byref(c_session_count), c_sessions)
4861
+ _nvmlCheckReturn(ret)
4862
+ sessions = []
4863
+ for i in range(c_session_count.value):
4864
+ sessions.append(c_sessions[i])
4865
+ return sessions
4866
+ else:
4867
+ return [] # no active sessions
4868
+ else:
4869
+ # error case
4870
+ raise NVMLError(ret)
4871
+
4872
+def nvmlDeviceGetProcessUtilization(handle, timeStamp):
4873
+ # first call to get the size
4874
+ c_count = c_uint(0)
4875
+ c_time_stamp = c_ulonglong(timeStamp)
4876
+
4877
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetProcessUtilization")
4878
+ ret = fn(handle, None, byref(c_count), c_time_stamp)
4879
+
4880
+ if (ret == NVML_ERROR_INSUFFICIENT_SIZE):
4881
+ # typical case
4882
+ sampleArray = c_count.value * c_nvmlProcessUtilizationSample_t
4883
+ c_samples = sampleArray()
4884
+
4885
+ # make the call again
4886
+ ret = fn(handle, c_samples, byref(c_count), c_time_stamp)
4887
+ _nvmlCheckReturn(ret)
4888
+
4889
+ return c_samples[0:c_count.value]
4890
+ else:
4891
+ # error case
4892
+ raise NVMLError(ret)
4893
+
4894
+def nvmlDeviceGetProcessesUtilizationInfo(handle, timeStamp):
4895
+ # first call to get the size
4896
+ c_time_stamp = c_ulonglong(timeStamp)
4897
+ c_processesUtilInfo = c_nvmlProcessesUtilizationInfo_v1_t(0)
4898
+ c_processesUtilInfo.version = ProcessesUtilizationInfo_v1
4899
+ c_processesUtilInfo.processSamplesCount = c_uint(0)
4900
+ c_processesUtilInfo.lastSeenTimeStamp = c_time_stamp
4901
+
4902
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetProcessesUtilizationInfo")
4903
+ ret = fn(handle, byref(c_processesUtilInfo))
4904
+
4905
+ if (ret == NVML_ERROR_INSUFFICIENT_SIZE):
4906
+ # typical case
4907
+ sampleArray = c_processesUtilInfo.processSamplesCount * c_nvmlProcessUtilizationInfo_v1_t
4908
+ c_samples = sampleArray()
4909
+ c_processesUtilInfo.procUtilArray = c_samples
4910
+
4911
+ # make the call again
4912
+ ret = fn(handle, byref(c_processesUtilInfo))
4913
+ _nvmlCheckReturn(ret)
4914
+
4915
+ return c_samples[0:c_processesUtilInfo.processSamplesCount]
4916
+ else:
4917
+ # error case
4918
+ raise NVMLError(ret)
4919
+
4920
+def nvmlVgpuInstanceGetMetadata(vgpuInstance):
4921
+ fn = _nvmlGetFunctionPointer("nvmlVgpuInstanceGetMetadata")
4922
+ c_vgpuMetadata = c_nvmlVgpuMetadata_t()
4923
+ c_bufferSize = c_uint(0)
4924
+ # Make the first NVML API call to get the c_bufferSize value.
4925
+ # We have already allocated required buffer above.
4926
+ ret = fn(vgpuInstance, byref(c_vgpuMetadata), byref(c_bufferSize))
4927
+ if (ret == NVML_ERROR_INSUFFICIENT_SIZE):
4928
+ ret = fn(vgpuInstance, byref(c_vgpuMetadata), byref(c_bufferSize))
4929
+ _nvmlCheckReturn(ret)
4930
+ else:
4931
+ raise NVMLError(ret)
4932
+ return c_vgpuMetadata
4933
+
4934
+def nvmlDeviceGetVgpuMetadata(handle):
4935
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetVgpuMetadata")
4936
+ c_vgpuPgpuMetadata = c_nvmlVgpuPgpuMetadata_t()
4937
+ c_bufferSize = c_uint(0)
4938
+ # Make the first NVML API call to get the c_bufferSize value.
4939
+ # We have already allocated required buffer above.
4940
+ ret = fn(handle, byref(c_vgpuPgpuMetadata), byref(c_bufferSize))
4941
+ if (ret == NVML_ERROR_INSUFFICIENT_SIZE):
4942
+ ret = fn(handle, byref(c_vgpuPgpuMetadata), byref(c_bufferSize))
4943
+ _nvmlCheckReturn(ret)
4944
+ else:
4945
+ raise NVMLError(ret)
4946
+ return c_vgpuPgpuMetadata
4947
+
4948
+def nvmlGetVgpuCompatibility(vgpuMetadata, pgpuMetadata):
4949
+ fn = _nvmlGetFunctionPointer("nvmlGetVgpuCompatibility")
4950
+ c_vgpuPgpuCompatibility = c_nvmlVgpuPgpuCompatibility_t()
4951
+ ret = fn(byref(vgpuMetadata), byref(pgpuMetadata), byref(c_vgpuPgpuCompatibility))
4952
+ _nvmlCheckReturn(ret)
4953
+ return c_vgpuPgpuCompatibility
4954
+
4955
+@convertStrBytes
4956
+def nvmlDeviceGetPgpuMetadataString(handle):
4957
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetPgpuMetadataString")
4958
+ c_pgpuMetadata = create_string_buffer(NVML_VGPU_PGPU_METADATA_OPAQUE_DATA_SIZE)
4959
+ c_bufferSize = c_uint(0)
4960
+ # Make the first NVML API call to get the c_bufferSize value.
4961
+ # We have already allocated required buffer above.
4962
+ ret = fn(handle, byref(c_pgpuMetadata), byref(c_bufferSize))
4963
+ if (ret == NVML_ERROR_INSUFFICIENT_SIZE):
4964
+ ret = fn(handle, byref(c_pgpuMetadata), byref(c_bufferSize))
4965
+ _nvmlCheckReturn(ret)
4966
+ else:
4967
+ raise NVMLError(ret)
4968
+ return (c_pgpuMetadata.value, c_bufferSize.value)
4969
+
4970
+def nvmlDeviceGetVgpuSchedulerLog(handle):
4971
+ c_vgpu_sched_log = c_nvmlVgpuSchedulerLog_t()
4972
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetVgpuSchedulerLog")
4973
+ ret = fn(handle, byref(c_vgpu_sched_log))
4974
+ _nvmlCheckReturn(ret)
4975
+ return c_vgpu_sched_log
4976
+
4977
+def nvmlDeviceGetVgpuSchedulerState(handle):
4978
+ c_vgpu_sched_state = c_nvmlVgpuSchedulerGetState_t()
4979
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetVgpuSchedulerState")
4980
+ ret = fn(handle, byref(c_vgpu_sched_state))
4981
+ _nvmlCheckReturn(ret)
4982
+ return c_vgpu_sched_state
4983
+
4984
+def nvmlDeviceGetVgpuSchedulerCapabilities(handle):
4985
+ c_vgpu_sched_caps = c_nvmlVgpuSchedulerCapabilities_t()
4986
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetVgpuSchedulerCapabilities")
4987
+ ret = fn(handle, byref(c_vgpu_sched_caps))
4988
+ _nvmlCheckReturn(ret)
4989
+ return c_vgpu_sched_caps
4990
+
4991
+def nvmlDeviceSetVgpuSchedulerState(handle, sched_state):
4992
+ fn = _nvmlGetFunctionPointer("nvmlDeviceSetVgpuSchedulerState")
4993
+ ret = fn(handle, byref(sched_state))
4994
+ _nvmlCheckReturn(ret)
4995
+ return NVML_SUCCESS
4996
+
4997
+def nvmlSetVgpuVersion(vgpuVersion):
4998
+ fn = _nvmlGetFunctionPointer("nvmlSetVgpuVersion")
4999
+ ret = fn(byref(vgpuVersion))
This file is too large to show in full.
vllm/utils.py
+9
-30
@@ -2239,34 +2239,13 @@ def import_pynvml():
2239
This causes errors when both of them are installed.
2240
Starting from version 12.0, it migrates to a new module
2241
named `pynvml_utils` to avoid the conflict.
2242
-
2243
- TL;DR: if users have pynvml<12.0 installed, it will cause problems.
2244
- Otherwise, `import pynvml` will import the correct module.
2245
- We take the safest approach here, to manually import the correct
2246
- `pynvml.py` module from the `nvidia-ml-py` package.
2242
+ It is so confusing that many packages in the community use the
2243
+ unofficial one by mistake, and we have to handle this case.
2244
+ For example, `nvcr.io/nvidia/pytorch:24.12-py3` uses the unofficial
2245
+ one, and it will cause errors, see the issue
2246
+ https://github.com/vllm-project/vllm/issues/12847 for example.
2247
+ After all the troubles, we decide to copy the official `pynvml`
2248
+ module to our codebase, and use it directly.
2249
"""
2248
- if TYPE_CHECKING:
2249
- import pynvml
2250
- return pynvml
2251
- if "pynvml" in sys.modules:
2252
- import pynvml
2253
- if pynvml.__file__.endswith("__init__.py"):
2254
- # this is pynvml < 12.0
2255
- raise RuntimeError(
2256
- "You are using a deprecated `pynvml` package. "
2257
- "Please uninstall `pynvml` or upgrade to at least"
2258
- " version 12.0. See https://pypi.org/project/pynvml "
2259
- "for more information.")
2260
- return sys.modules["pynvml"]
2261
- import importlib.util
2262
- import os
2263
- import site
2264
- for site_dir in site.getsitepackages():
2265
- pynvml_path = os.path.join(site_dir, "pynvml.py")
2266
- if os.path.exists(pynvml_path):
2267
- spec = importlib.util.spec_from_file_location(
2268
- "pynvml", pynvml_path)
2269
- pynvml = importlib.util.module_from_spec(spec)
2270
- sys.modules["pynvml"] = pynvml
2271
- spec.loader.exec_module(pynvml)
2272
- return pynvml
2250
+ import vllm.third_party.pynvml as pynvml
2251
+ return pynvml