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