wandb 0.18.2__py3-none-musllinux_1_2_x86_64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (827) hide show
  1. package_readme.md +89 -0
  2. wandb/__init__.py +245 -0
  3. wandb/__init__.pyi +1139 -0
  4. wandb/__main__.py +3 -0
  5. wandb/_globals.py +19 -0
  6. wandb/agents/__init__.py +0 -0
  7. wandb/agents/pyagent.py +363 -0
  8. wandb/analytics/__init__.py +3 -0
  9. wandb/analytics/sentry.py +266 -0
  10. wandb/apis/__init__.py +48 -0
  11. wandb/apis/attrs.py +40 -0
  12. wandb/apis/importers/__init__.py +1 -0
  13. wandb/apis/importers/internals/internal.py +385 -0
  14. wandb/apis/importers/internals/protocols.py +99 -0
  15. wandb/apis/importers/internals/util.py +78 -0
  16. wandb/apis/importers/mlflow.py +254 -0
  17. wandb/apis/importers/validation.py +108 -0
  18. wandb/apis/importers/wandb.py +1603 -0
  19. wandb/apis/internal.py +232 -0
  20. wandb/apis/normalize.py +89 -0
  21. wandb/apis/paginator.py +81 -0
  22. wandb/apis/public/__init__.py +34 -0
  23. wandb/apis/public/api.py +1305 -0
  24. wandb/apis/public/artifacts.py +1090 -0
  25. wandb/apis/public/const.py +4 -0
  26. wandb/apis/public/files.py +195 -0
  27. wandb/apis/public/history.py +149 -0
  28. wandb/apis/public/jobs.py +659 -0
  29. wandb/apis/public/projects.py +154 -0
  30. wandb/apis/public/query_generator.py +166 -0
  31. wandb/apis/public/reports.py +469 -0
  32. wandb/apis/public/runs.py +914 -0
  33. wandb/apis/public/sweeps.py +240 -0
  34. wandb/apis/public/teams.py +198 -0
  35. wandb/apis/public/users.py +136 -0
  36. wandb/apis/reports/__init__.py +1 -0
  37. wandb/apis/reports/v1/__init__.py +8 -0
  38. wandb/apis/reports/v2/__init__.py +8 -0
  39. wandb/apis/workspaces/__init__.py +8 -0
  40. wandb/beta/workflows.py +288 -0
  41. wandb/bin/nvidia_gpu_stats +0 -0
  42. wandb/bin/wandb-core +0 -0
  43. wandb/cli/__init__.py +0 -0
  44. wandb/cli/cli.py +3004 -0
  45. wandb/data_types.py +63 -0
  46. wandb/docker/__init__.py +342 -0
  47. wandb/docker/auth.py +436 -0
  48. wandb/docker/wandb-entrypoint.sh +33 -0
  49. wandb/docker/www_authenticate.py +94 -0
  50. wandb/env.py +514 -0
  51. wandb/errors/__init__.py +17 -0
  52. wandb/errors/errors.py +37 -0
  53. wandb/errors/term.py +103 -0
  54. wandb/errors/util.py +57 -0
  55. wandb/errors/warnings.py +2 -0
  56. wandb/filesync/__init__.py +0 -0
  57. wandb/filesync/dir_watcher.py +403 -0
  58. wandb/filesync/stats.py +100 -0
  59. wandb/filesync/step_checksum.py +142 -0
  60. wandb/filesync/step_prepare.py +179 -0
  61. wandb/filesync/step_upload.py +290 -0
  62. wandb/filesync/upload_job.py +142 -0
  63. wandb/integration/__init__.py +0 -0
  64. wandb/integration/catboost/__init__.py +5 -0
  65. wandb/integration/catboost/catboost.py +178 -0
  66. wandb/integration/cohere/__init__.py +3 -0
  67. wandb/integration/cohere/cohere.py +21 -0
  68. wandb/integration/cohere/resolver.py +347 -0
  69. wandb/integration/diffusers/__init__.py +3 -0
  70. wandb/integration/diffusers/autologger.py +76 -0
  71. wandb/integration/diffusers/pipeline_resolver.py +50 -0
  72. wandb/integration/diffusers/resolvers/__init__.py +9 -0
  73. wandb/integration/diffusers/resolvers/multimodal.py +882 -0
  74. wandb/integration/diffusers/resolvers/utils.py +102 -0
  75. wandb/integration/fastai/__init__.py +249 -0
  76. wandb/integration/gym/__init__.py +105 -0
  77. wandb/integration/huggingface/__init__.py +3 -0
  78. wandb/integration/huggingface/huggingface.py +18 -0
  79. wandb/integration/huggingface/resolver.py +213 -0
  80. wandb/integration/keras/__init__.py +11 -0
  81. wandb/integration/keras/callbacks/__init__.py +5 -0
  82. wandb/integration/keras/callbacks/metrics_logger.py +136 -0
  83. wandb/integration/keras/callbacks/model_checkpoint.py +195 -0
  84. wandb/integration/keras/callbacks/tables_builder.py +226 -0
  85. wandb/integration/keras/keras.py +1091 -0
  86. wandb/integration/kfp/__init__.py +6 -0
  87. wandb/integration/kfp/helpers.py +28 -0
  88. wandb/integration/kfp/kfp_patch.py +324 -0
  89. wandb/integration/kfp/wandb_logging.py +182 -0
  90. wandb/integration/langchain/__init__.py +3 -0
  91. wandb/integration/langchain/wandb_tracer.py +48 -0
  92. wandb/integration/lightgbm/__init__.py +239 -0
  93. wandb/integration/lightning/__init__.py +0 -0
  94. wandb/integration/lightning/fabric/__init__.py +3 -0
  95. wandb/integration/lightning/fabric/logger.py +762 -0
  96. wandb/integration/magic.py +556 -0
  97. wandb/integration/metaflow/__init__.py +3 -0
  98. wandb/integration/metaflow/metaflow.py +383 -0
  99. wandb/integration/openai/__init__.py +3 -0
  100. wandb/integration/openai/fine_tuning.py +480 -0
  101. wandb/integration/openai/openai.py +22 -0
  102. wandb/integration/openai/resolver.py +240 -0
  103. wandb/integration/prodigy/__init__.py +3 -0
  104. wandb/integration/prodigy/prodigy.py +299 -0
  105. wandb/integration/sacred/__init__.py +117 -0
  106. wandb/integration/sagemaker/__init__.py +12 -0
  107. wandb/integration/sagemaker/auth.py +28 -0
  108. wandb/integration/sagemaker/config.py +49 -0
  109. wandb/integration/sagemaker/files.py +3 -0
  110. wandb/integration/sagemaker/resources.py +34 -0
  111. wandb/integration/sb3/__init__.py +3 -0
  112. wandb/integration/sb3/sb3.py +153 -0
  113. wandb/integration/sklearn/__init__.py +37 -0
  114. wandb/integration/sklearn/calculate/__init__.py +32 -0
  115. wandb/integration/sklearn/calculate/calibration_curves.py +125 -0
  116. wandb/integration/sklearn/calculate/class_proportions.py +68 -0
  117. wandb/integration/sklearn/calculate/confusion_matrix.py +93 -0
  118. wandb/integration/sklearn/calculate/decision_boundaries.py +40 -0
  119. wandb/integration/sklearn/calculate/elbow_curve.py +55 -0
  120. wandb/integration/sklearn/calculate/feature_importances.py +67 -0
  121. wandb/integration/sklearn/calculate/learning_curve.py +64 -0
  122. wandb/integration/sklearn/calculate/outlier_candidates.py +69 -0
  123. wandb/integration/sklearn/calculate/residuals.py +86 -0
  124. wandb/integration/sklearn/calculate/silhouette.py +118 -0
  125. wandb/integration/sklearn/calculate/summary_metrics.py +62 -0
  126. wandb/integration/sklearn/plot/__init__.py +35 -0
  127. wandb/integration/sklearn/plot/classifier.py +329 -0
  128. wandb/integration/sklearn/plot/clusterer.py +146 -0
  129. wandb/integration/sklearn/plot/regressor.py +121 -0
  130. wandb/integration/sklearn/plot/shared.py +91 -0
  131. wandb/integration/sklearn/utils.py +183 -0
  132. wandb/integration/tensorboard/__init__.py +10 -0
  133. wandb/integration/tensorboard/log.py +355 -0
  134. wandb/integration/tensorboard/monkeypatch.py +185 -0
  135. wandb/integration/tensorflow/__init__.py +5 -0
  136. wandb/integration/tensorflow/estimator_hook.py +54 -0
  137. wandb/integration/torch/__init__.py +0 -0
  138. wandb/integration/torch/wandb_torch.py +554 -0
  139. wandb/integration/ultralytics/__init__.py +11 -0
  140. wandb/integration/ultralytics/bbox_utils.py +208 -0
  141. wandb/integration/ultralytics/callback.py +524 -0
  142. wandb/integration/ultralytics/classification_utils.py +83 -0
  143. wandb/integration/ultralytics/mask_utils.py +202 -0
  144. wandb/integration/ultralytics/pose_utils.py +103 -0
  145. wandb/integration/xgboost/__init__.py +11 -0
  146. wandb/integration/xgboost/xgboost.py +189 -0
  147. wandb/integration/yolov8/__init__.py +0 -0
  148. wandb/integration/yolov8/yolov8.py +284 -0
  149. wandb/jupyter.py +515 -0
  150. wandb/magic.py +3 -0
  151. wandb/mpmain/__init__.py +0 -0
  152. wandb/mpmain/__main__.py +1 -0
  153. wandb/old/__init__.py +0 -0
  154. wandb/old/core.py +53 -0
  155. wandb/old/settings.py +173 -0
  156. wandb/old/summary.py +440 -0
  157. wandb/plot/__init__.py +19 -0
  158. wandb/plot/bar.py +45 -0
  159. wandb/plot/confusion_matrix.py +100 -0
  160. wandb/plot/histogram.py +39 -0
  161. wandb/plot/line.py +43 -0
  162. wandb/plot/line_series.py +88 -0
  163. wandb/plot/pr_curve.py +136 -0
  164. wandb/plot/roc_curve.py +118 -0
  165. wandb/plot/scatter.py +32 -0
  166. wandb/plot/utils.py +183 -0
  167. wandb/plot/viz.py +123 -0
  168. wandb/proto/__init__.py +0 -0
  169. wandb/proto/v3/__init__.py +0 -0
  170. wandb/proto/v3/wandb_base_pb2.py +55 -0
  171. wandb/proto/v3/wandb_internal_pb2.py +1608 -0
  172. wandb/proto/v3/wandb_server_pb2.py +208 -0
  173. wandb/proto/v3/wandb_settings_pb2.py +112 -0
  174. wandb/proto/v3/wandb_telemetry_pb2.py +106 -0
  175. wandb/proto/v4/__init__.py +0 -0
  176. wandb/proto/v4/wandb_base_pb2.py +30 -0
  177. wandb/proto/v4/wandb_internal_pb2.py +360 -0
  178. wandb/proto/v4/wandb_server_pb2.py +63 -0
  179. wandb/proto/v4/wandb_settings_pb2.py +45 -0
  180. wandb/proto/v4/wandb_telemetry_pb2.py +41 -0
  181. wandb/proto/v5/wandb_base_pb2.py +31 -0
  182. wandb/proto/v5/wandb_internal_pb2.py +361 -0
  183. wandb/proto/v5/wandb_server_pb2.py +64 -0
  184. wandb/proto/v5/wandb_settings_pb2.py +46 -0
  185. wandb/proto/v5/wandb_telemetry_pb2.py +42 -0
  186. wandb/proto/wandb_base_pb2.py +10 -0
  187. wandb/proto/wandb_deprecated.py +53 -0
  188. wandb/proto/wandb_generate_deprecated.py +34 -0
  189. wandb/proto/wandb_generate_proto.py +49 -0
  190. wandb/proto/wandb_internal_pb2.py +16 -0
  191. wandb/proto/wandb_server_pb2.py +10 -0
  192. wandb/proto/wandb_settings_pb2.py +10 -0
  193. wandb/proto/wandb_telemetry_pb2.py +10 -0
  194. wandb/py.typed +0 -0
  195. wandb/sdk/__init__.py +37 -0
  196. wandb/sdk/artifacts/__init__.py +0 -0
  197. wandb/sdk/artifacts/_validators.py +90 -0
  198. wandb/sdk/artifacts/artifact.py +2389 -0
  199. wandb/sdk/artifacts/artifact_download_logger.py +43 -0
  200. wandb/sdk/artifacts/artifact_file_cache.py +253 -0
  201. wandb/sdk/artifacts/artifact_instance_cache.py +17 -0
  202. wandb/sdk/artifacts/artifact_manifest.py +74 -0
  203. wandb/sdk/artifacts/artifact_manifest_entry.py +249 -0
  204. wandb/sdk/artifacts/artifact_manifests/__init__.py +0 -0
  205. wandb/sdk/artifacts/artifact_manifests/artifact_manifest_v1.py +92 -0
  206. wandb/sdk/artifacts/artifact_saver.py +269 -0
  207. wandb/sdk/artifacts/artifact_state.py +11 -0
  208. wandb/sdk/artifacts/artifact_ttl.py +7 -0
  209. wandb/sdk/artifacts/exceptions.py +57 -0
  210. wandb/sdk/artifacts/staging.py +25 -0
  211. wandb/sdk/artifacts/storage_handler.py +62 -0
  212. wandb/sdk/artifacts/storage_handlers/__init__.py +0 -0
  213. wandb/sdk/artifacts/storage_handlers/azure_handler.py +208 -0
  214. wandb/sdk/artifacts/storage_handlers/gcs_handler.py +228 -0
  215. wandb/sdk/artifacts/storage_handlers/http_handler.py +114 -0
  216. wandb/sdk/artifacts/storage_handlers/local_file_handler.py +141 -0
  217. wandb/sdk/artifacts/storage_handlers/multi_handler.py +56 -0
  218. wandb/sdk/artifacts/storage_handlers/s3_handler.py +300 -0
  219. wandb/sdk/artifacts/storage_handlers/tracking_handler.py +72 -0
  220. wandb/sdk/artifacts/storage_handlers/wb_artifact_handler.py +135 -0
  221. wandb/sdk/artifacts/storage_handlers/wb_local_artifact_handler.py +74 -0
  222. wandb/sdk/artifacts/storage_layout.py +6 -0
  223. wandb/sdk/artifacts/storage_policies/__init__.py +4 -0
  224. wandb/sdk/artifacts/storage_policies/register.py +1 -0
  225. wandb/sdk/artifacts/storage_policies/wandb_storage_policy.py +378 -0
  226. wandb/sdk/artifacts/storage_policy.py +72 -0
  227. wandb/sdk/backend/__init__.py +0 -0
  228. wandb/sdk/backend/backend.py +222 -0
  229. wandb/sdk/data_types/__init__.py +0 -0
  230. wandb/sdk/data_types/_dtypes.py +914 -0
  231. wandb/sdk/data_types/_private.py +10 -0
  232. wandb/sdk/data_types/audio.py +165 -0
  233. wandb/sdk/data_types/base_types/__init__.py +0 -0
  234. wandb/sdk/data_types/base_types/json_metadata.py +55 -0
  235. wandb/sdk/data_types/base_types/media.py +315 -0
  236. wandb/sdk/data_types/base_types/wb_value.py +272 -0
  237. wandb/sdk/data_types/bokeh.py +70 -0
  238. wandb/sdk/data_types/graph.py +405 -0
  239. wandb/sdk/data_types/helper_types/__init__.py +0 -0
  240. wandb/sdk/data_types/helper_types/bounding_boxes_2d.py +295 -0
  241. wandb/sdk/data_types/helper_types/classes.py +159 -0
  242. wandb/sdk/data_types/helper_types/image_mask.py +235 -0
  243. wandb/sdk/data_types/histogram.py +96 -0
  244. wandb/sdk/data_types/html.py +115 -0
  245. wandb/sdk/data_types/image.py +845 -0
  246. wandb/sdk/data_types/molecule.py +241 -0
  247. wandb/sdk/data_types/object_3d.py +474 -0
  248. wandb/sdk/data_types/plotly.py +82 -0
  249. wandb/sdk/data_types/saved_model.py +446 -0
  250. wandb/sdk/data_types/table.py +1204 -0
  251. wandb/sdk/data_types/trace_tree.py +438 -0
  252. wandb/sdk/data_types/utils.py +229 -0
  253. wandb/sdk/data_types/video.py +247 -0
  254. wandb/sdk/integration_utils/__init__.py +0 -0
  255. wandb/sdk/integration_utils/auto_logging.py +239 -0
  256. wandb/sdk/integration_utils/data_logging.py +475 -0
  257. wandb/sdk/interface/__init__.py +0 -0
  258. wandb/sdk/interface/constants.py +4 -0
  259. wandb/sdk/interface/interface.py +972 -0
  260. wandb/sdk/interface/interface_queue.py +59 -0
  261. wandb/sdk/interface/interface_relay.py +53 -0
  262. wandb/sdk/interface/interface_shared.py +537 -0
  263. wandb/sdk/interface/interface_sock.py +61 -0
  264. wandb/sdk/interface/message_future.py +27 -0
  265. wandb/sdk/interface/message_future_poll.py +50 -0
  266. wandb/sdk/interface/router.py +118 -0
  267. wandb/sdk/interface/router_queue.py +44 -0
  268. wandb/sdk/interface/router_relay.py +39 -0
  269. wandb/sdk/interface/router_sock.py +36 -0
  270. wandb/sdk/interface/summary_record.py +67 -0
  271. wandb/sdk/internal/__init__.py +0 -0
  272. wandb/sdk/internal/context.py +89 -0
  273. wandb/sdk/internal/datastore.py +297 -0
  274. wandb/sdk/internal/file_pusher.py +181 -0
  275. wandb/sdk/internal/file_stream.py +695 -0
  276. wandb/sdk/internal/flow_control.py +263 -0
  277. wandb/sdk/internal/handler.py +901 -0
  278. wandb/sdk/internal/internal.py +417 -0
  279. wandb/sdk/internal/internal_api.py +4358 -0
  280. wandb/sdk/internal/internal_util.py +100 -0
  281. wandb/sdk/internal/job_builder.py +629 -0
  282. wandb/sdk/internal/profiler.py +78 -0
  283. wandb/sdk/internal/progress.py +83 -0
  284. wandb/sdk/internal/run.py +25 -0
  285. wandb/sdk/internal/sample.py +70 -0
  286. wandb/sdk/internal/sender.py +1686 -0
  287. wandb/sdk/internal/sender_config.py +197 -0
  288. wandb/sdk/internal/settings_static.py +90 -0
  289. wandb/sdk/internal/system/__init__.py +0 -0
  290. wandb/sdk/internal/system/assets/__init__.py +27 -0
  291. wandb/sdk/internal/system/assets/aggregators.py +37 -0
  292. wandb/sdk/internal/system/assets/asset_registry.py +20 -0
  293. wandb/sdk/internal/system/assets/cpu.py +163 -0
  294. wandb/sdk/internal/system/assets/disk.py +210 -0
  295. wandb/sdk/internal/system/assets/gpu.py +416 -0
  296. wandb/sdk/internal/system/assets/gpu_amd.py +239 -0
  297. wandb/sdk/internal/system/assets/gpu_apple.py +177 -0
  298. wandb/sdk/internal/system/assets/interfaces.py +207 -0
  299. wandb/sdk/internal/system/assets/ipu.py +177 -0
  300. wandb/sdk/internal/system/assets/memory.py +166 -0
  301. wandb/sdk/internal/system/assets/network.py +125 -0
  302. wandb/sdk/internal/system/assets/open_metrics.py +299 -0
  303. wandb/sdk/internal/system/assets/tpu.py +154 -0
  304. wandb/sdk/internal/system/assets/trainium.py +399 -0
  305. wandb/sdk/internal/system/env_probe_helpers.py +13 -0
  306. wandb/sdk/internal/system/system_info.py +249 -0
  307. wandb/sdk/internal/system/system_monitor.py +229 -0
  308. wandb/sdk/internal/tb_watcher.py +518 -0
  309. wandb/sdk/internal/thread_local_settings.py +18 -0
  310. wandb/sdk/internal/writer.py +206 -0
  311. wandb/sdk/launch/__init__.py +14 -0
  312. wandb/sdk/launch/_launch.py +330 -0
  313. wandb/sdk/launch/_launch_add.py +255 -0
  314. wandb/sdk/launch/_project_spec.py +566 -0
  315. wandb/sdk/launch/agent/__init__.py +5 -0
  316. wandb/sdk/launch/agent/agent.py +924 -0
  317. wandb/sdk/launch/agent/config.py +296 -0
  318. wandb/sdk/launch/agent/job_status_tracker.py +53 -0
  319. wandb/sdk/launch/agent/run_queue_item_file_saver.py +45 -0
  320. wandb/sdk/launch/builder/__init__.py +0 -0
  321. wandb/sdk/launch/builder/abstract.py +156 -0
  322. wandb/sdk/launch/builder/build.py +297 -0
  323. wandb/sdk/launch/builder/context_manager.py +235 -0
  324. wandb/sdk/launch/builder/docker_builder.py +177 -0
  325. wandb/sdk/launch/builder/kaniko_builder.py +595 -0
  326. wandb/sdk/launch/builder/noop.py +58 -0
  327. wandb/sdk/launch/builder/templates/_wandb_bootstrap.py +188 -0
  328. wandb/sdk/launch/builder/templates/dockerfile.py +92 -0
  329. wandb/sdk/launch/create_job.py +528 -0
  330. wandb/sdk/launch/environment/abstract.py +29 -0
  331. wandb/sdk/launch/environment/aws_environment.py +322 -0
  332. wandb/sdk/launch/environment/azure_environment.py +105 -0
  333. wandb/sdk/launch/environment/gcp_environment.py +335 -0
  334. wandb/sdk/launch/environment/local_environment.py +66 -0
  335. wandb/sdk/launch/errors.py +19 -0
  336. wandb/sdk/launch/git_reference.py +109 -0
  337. wandb/sdk/launch/inputs/files.py +148 -0
  338. wandb/sdk/launch/inputs/internal.py +315 -0
  339. wandb/sdk/launch/inputs/manage.py +113 -0
  340. wandb/sdk/launch/inputs/schema.py +39 -0
  341. wandb/sdk/launch/loader.py +249 -0
  342. wandb/sdk/launch/registry/abstract.py +48 -0
  343. wandb/sdk/launch/registry/anon.py +29 -0
  344. wandb/sdk/launch/registry/azure_container_registry.py +124 -0
  345. wandb/sdk/launch/registry/elastic_container_registry.py +192 -0
  346. wandb/sdk/launch/registry/google_artifact_registry.py +219 -0
  347. wandb/sdk/launch/registry/local_registry.py +67 -0
  348. wandb/sdk/launch/runner/__init__.py +0 -0
  349. wandb/sdk/launch/runner/abstract.py +195 -0
  350. wandb/sdk/launch/runner/kubernetes_monitor.py +474 -0
  351. wandb/sdk/launch/runner/kubernetes_runner.py +963 -0
  352. wandb/sdk/launch/runner/local_container.py +301 -0
  353. wandb/sdk/launch/runner/local_process.py +78 -0
  354. wandb/sdk/launch/runner/sagemaker_runner.py +426 -0
  355. wandb/sdk/launch/runner/vertex_runner.py +230 -0
  356. wandb/sdk/launch/sweeps/__init__.py +39 -0
  357. wandb/sdk/launch/sweeps/scheduler.py +742 -0
  358. wandb/sdk/launch/sweeps/scheduler_sweep.py +91 -0
  359. wandb/sdk/launch/sweeps/utils.py +316 -0
  360. wandb/sdk/launch/utils.py +746 -0
  361. wandb/sdk/launch/wandb_reference.py +138 -0
  362. wandb/sdk/lib/__init__.py +5 -0
  363. wandb/sdk/lib/_settings_toposort_generate.py +159 -0
  364. wandb/sdk/lib/_settings_toposort_generated.py +250 -0
  365. wandb/sdk/lib/_wburls_generate.py +25 -0
  366. wandb/sdk/lib/_wburls_generated.py +22 -0
  367. wandb/sdk/lib/apikey.py +273 -0
  368. wandb/sdk/lib/capped_dict.py +26 -0
  369. wandb/sdk/lib/config_util.py +101 -0
  370. wandb/sdk/lib/credentials.py +141 -0
  371. wandb/sdk/lib/deprecate.py +42 -0
  372. wandb/sdk/lib/disabled.py +29 -0
  373. wandb/sdk/lib/exit_hooks.py +54 -0
  374. wandb/sdk/lib/file_stream_utils.py +118 -0
  375. wandb/sdk/lib/filenames.py +64 -0
  376. wandb/sdk/lib/filesystem.py +372 -0
  377. wandb/sdk/lib/fsm.py +174 -0
  378. wandb/sdk/lib/gitlib.py +239 -0
  379. wandb/sdk/lib/gql_request.py +65 -0
  380. wandb/sdk/lib/handler_util.py +21 -0
  381. wandb/sdk/lib/hashutil.py +84 -0
  382. wandb/sdk/lib/import_hooks.py +275 -0
  383. wandb/sdk/lib/ipython.py +146 -0
  384. wandb/sdk/lib/json_util.py +80 -0
  385. wandb/sdk/lib/lazyloader.py +63 -0
  386. wandb/sdk/lib/mailbox.py +460 -0
  387. wandb/sdk/lib/module.py +69 -0
  388. wandb/sdk/lib/paths.py +106 -0
  389. wandb/sdk/lib/preinit.py +42 -0
  390. wandb/sdk/lib/printer.py +313 -0
  391. wandb/sdk/lib/proto_util.py +90 -0
  392. wandb/sdk/lib/redirect.py +845 -0
  393. wandb/sdk/lib/reporting.py +99 -0
  394. wandb/sdk/lib/retry.py +289 -0
  395. wandb/sdk/lib/run_moment.py +78 -0
  396. wandb/sdk/lib/runid.py +12 -0
  397. wandb/sdk/lib/server.py +52 -0
  398. wandb/sdk/lib/service_connection.py +216 -0
  399. wandb/sdk/lib/service_token.py +94 -0
  400. wandb/sdk/lib/sock_client.py +295 -0
  401. wandb/sdk/lib/sparkline.py +45 -0
  402. wandb/sdk/lib/telemetry.py +100 -0
  403. wandb/sdk/lib/timed_input.py +133 -0
  404. wandb/sdk/lib/timer.py +19 -0
  405. wandb/sdk/lib/tracelog.py +255 -0
  406. wandb/sdk/lib/wburls.py +46 -0
  407. wandb/sdk/service/__init__.py +0 -0
  408. wandb/sdk/service/_startup_debug.py +22 -0
  409. wandb/sdk/service/port_file.py +53 -0
  410. wandb/sdk/service/server.py +116 -0
  411. wandb/sdk/service/server_sock.py +276 -0
  412. wandb/sdk/service/service.py +242 -0
  413. wandb/sdk/service/streams.py +417 -0
  414. wandb/sdk/verify/__init__.py +0 -0
  415. wandb/sdk/verify/verify.py +501 -0
  416. wandb/sdk/wandb_alerts.py +12 -0
  417. wandb/sdk/wandb_config.py +322 -0
  418. wandb/sdk/wandb_helper.py +54 -0
  419. wandb/sdk/wandb_init.py +1266 -0
  420. wandb/sdk/wandb_login.py +349 -0
  421. wandb/sdk/wandb_metric.py +110 -0
  422. wandb/sdk/wandb_require.py +97 -0
  423. wandb/sdk/wandb_require_helpers.py +44 -0
  424. wandb/sdk/wandb_run.py +4236 -0
  425. wandb/sdk/wandb_settings.py +2001 -0
  426. wandb/sdk/wandb_setup.py +409 -0
  427. wandb/sdk/wandb_summary.py +150 -0
  428. wandb/sdk/wandb_sweep.py +119 -0
  429. wandb/sdk/wandb_sync.py +81 -0
  430. wandb/sdk/wandb_watch.py +144 -0
  431. wandb/sklearn.py +35 -0
  432. wandb/sync/__init__.py +3 -0
  433. wandb/sync/sync.py +443 -0
  434. wandb/trigger.py +29 -0
  435. wandb/util.py +1956 -0
  436. wandb/vendor/__init__.py +0 -0
  437. wandb/vendor/gql-0.2.0/setup.py +40 -0
  438. wandb/vendor/gql-0.2.0/tests/__init__.py +0 -0
  439. wandb/vendor/gql-0.2.0/tests/starwars/__init__.py +0 -0
  440. wandb/vendor/gql-0.2.0/tests/starwars/fixtures.py +96 -0
  441. wandb/vendor/gql-0.2.0/tests/starwars/schema.py +146 -0
  442. wandb/vendor/gql-0.2.0/tests/starwars/test_dsl.py +293 -0
  443. wandb/vendor/gql-0.2.0/tests/starwars/test_query.py +355 -0
  444. wandb/vendor/gql-0.2.0/tests/starwars/test_validation.py +171 -0
  445. wandb/vendor/gql-0.2.0/tests/test_client.py +31 -0
  446. wandb/vendor/gql-0.2.0/tests/test_transport.py +89 -0
  447. wandb/vendor/gql-0.2.0/wandb_gql/__init__.py +4 -0
  448. wandb/vendor/gql-0.2.0/wandb_gql/client.py +75 -0
  449. wandb/vendor/gql-0.2.0/wandb_gql/dsl.py +152 -0
  450. wandb/vendor/gql-0.2.0/wandb_gql/gql.py +10 -0
  451. wandb/vendor/gql-0.2.0/wandb_gql/transport/__init__.py +0 -0
  452. wandb/vendor/gql-0.2.0/wandb_gql/transport/http.py +6 -0
  453. wandb/vendor/gql-0.2.0/wandb_gql/transport/local_schema.py +15 -0
  454. wandb/vendor/gql-0.2.0/wandb_gql/transport/requests.py +46 -0
  455. wandb/vendor/gql-0.2.0/wandb_gql/utils.py +21 -0
  456. wandb/vendor/graphql-core-1.1/setup.py +86 -0
  457. wandb/vendor/graphql-core-1.1/wandb_graphql/__init__.py +287 -0
  458. wandb/vendor/graphql-core-1.1/wandb_graphql/error/__init__.py +6 -0
  459. wandb/vendor/graphql-core-1.1/wandb_graphql/error/base.py +42 -0
  460. wandb/vendor/graphql-core-1.1/wandb_graphql/error/format_error.py +11 -0
  461. wandb/vendor/graphql-core-1.1/wandb_graphql/error/located_error.py +29 -0
  462. wandb/vendor/graphql-core-1.1/wandb_graphql/error/syntax_error.py +36 -0
  463. wandb/vendor/graphql-core-1.1/wandb_graphql/execution/__init__.py +26 -0
  464. wandb/vendor/graphql-core-1.1/wandb_graphql/execution/base.py +311 -0
  465. wandb/vendor/graphql-core-1.1/wandb_graphql/execution/executor.py +398 -0
  466. wandb/vendor/graphql-core-1.1/wandb_graphql/execution/executors/__init__.py +0 -0
  467. wandb/vendor/graphql-core-1.1/wandb_graphql/execution/executors/asyncio.py +53 -0
  468. wandb/vendor/graphql-core-1.1/wandb_graphql/execution/executors/gevent.py +22 -0
  469. wandb/vendor/graphql-core-1.1/wandb_graphql/execution/executors/process.py +32 -0
  470. wandb/vendor/graphql-core-1.1/wandb_graphql/execution/executors/sync.py +7 -0
  471. wandb/vendor/graphql-core-1.1/wandb_graphql/execution/executors/thread.py +35 -0
  472. wandb/vendor/graphql-core-1.1/wandb_graphql/execution/executors/utils.py +6 -0
  473. wandb/vendor/graphql-core-1.1/wandb_graphql/execution/experimental/__init__.py +0 -0
  474. wandb/vendor/graphql-core-1.1/wandb_graphql/execution/experimental/executor.py +66 -0
  475. wandb/vendor/graphql-core-1.1/wandb_graphql/execution/experimental/fragment.py +252 -0
  476. wandb/vendor/graphql-core-1.1/wandb_graphql/execution/experimental/resolver.py +151 -0
  477. wandb/vendor/graphql-core-1.1/wandb_graphql/execution/experimental/utils.py +7 -0
  478. wandb/vendor/graphql-core-1.1/wandb_graphql/execution/middleware.py +57 -0
  479. wandb/vendor/graphql-core-1.1/wandb_graphql/execution/values.py +145 -0
  480. wandb/vendor/graphql-core-1.1/wandb_graphql/graphql.py +60 -0
  481. wandb/vendor/graphql-core-1.1/wandb_graphql/language/__init__.py +0 -0
  482. wandb/vendor/graphql-core-1.1/wandb_graphql/language/ast.py +1349 -0
  483. wandb/vendor/graphql-core-1.1/wandb_graphql/language/base.py +19 -0
  484. wandb/vendor/graphql-core-1.1/wandb_graphql/language/lexer.py +435 -0
  485. wandb/vendor/graphql-core-1.1/wandb_graphql/language/location.py +30 -0
  486. wandb/vendor/graphql-core-1.1/wandb_graphql/language/parser.py +779 -0
  487. wandb/vendor/graphql-core-1.1/wandb_graphql/language/printer.py +193 -0
  488. wandb/vendor/graphql-core-1.1/wandb_graphql/language/source.py +18 -0
  489. wandb/vendor/graphql-core-1.1/wandb_graphql/language/visitor.py +222 -0
  490. wandb/vendor/graphql-core-1.1/wandb_graphql/language/visitor_meta.py +82 -0
  491. wandb/vendor/graphql-core-1.1/wandb_graphql/pyutils/__init__.py +0 -0
  492. wandb/vendor/graphql-core-1.1/wandb_graphql/pyutils/cached_property.py +17 -0
  493. wandb/vendor/graphql-core-1.1/wandb_graphql/pyutils/contain_subset.py +28 -0
  494. wandb/vendor/graphql-core-1.1/wandb_graphql/pyutils/default_ordered_dict.py +40 -0
  495. wandb/vendor/graphql-core-1.1/wandb_graphql/pyutils/ordereddict.py +8 -0
  496. wandb/vendor/graphql-core-1.1/wandb_graphql/pyutils/pair_set.py +43 -0
  497. wandb/vendor/graphql-core-1.1/wandb_graphql/pyutils/version.py +78 -0
  498. wandb/vendor/graphql-core-1.1/wandb_graphql/type/__init__.py +67 -0
  499. wandb/vendor/graphql-core-1.1/wandb_graphql/type/definition.py +619 -0
  500. wandb/vendor/graphql-core-1.1/wandb_graphql/type/directives.py +132 -0
  501. wandb/vendor/graphql-core-1.1/wandb_graphql/type/introspection.py +440 -0
  502. wandb/vendor/graphql-core-1.1/wandb_graphql/type/scalars.py +131 -0
  503. wandb/vendor/graphql-core-1.1/wandb_graphql/type/schema.py +100 -0
  504. wandb/vendor/graphql-core-1.1/wandb_graphql/type/typemap.py +145 -0
  505. wandb/vendor/graphql-core-1.1/wandb_graphql/utils/__init__.py +0 -0
  506. wandb/vendor/graphql-core-1.1/wandb_graphql/utils/assert_valid_name.py +9 -0
  507. wandb/vendor/graphql-core-1.1/wandb_graphql/utils/ast_from_value.py +65 -0
  508. wandb/vendor/graphql-core-1.1/wandb_graphql/utils/ast_to_code.py +49 -0
  509. wandb/vendor/graphql-core-1.1/wandb_graphql/utils/ast_to_dict.py +24 -0
  510. wandb/vendor/graphql-core-1.1/wandb_graphql/utils/base.py +75 -0
  511. wandb/vendor/graphql-core-1.1/wandb_graphql/utils/build_ast_schema.py +291 -0
  512. wandb/vendor/graphql-core-1.1/wandb_graphql/utils/build_client_schema.py +250 -0
  513. wandb/vendor/graphql-core-1.1/wandb_graphql/utils/concat_ast.py +9 -0
  514. wandb/vendor/graphql-core-1.1/wandb_graphql/utils/extend_schema.py +357 -0
  515. wandb/vendor/graphql-core-1.1/wandb_graphql/utils/get_field_def.py +27 -0
  516. wandb/vendor/graphql-core-1.1/wandb_graphql/utils/get_operation_ast.py +21 -0
  517. wandb/vendor/graphql-core-1.1/wandb_graphql/utils/introspection_query.py +90 -0
  518. wandb/vendor/graphql-core-1.1/wandb_graphql/utils/is_valid_literal_value.py +67 -0
  519. wandb/vendor/graphql-core-1.1/wandb_graphql/utils/is_valid_value.py +66 -0
  520. wandb/vendor/graphql-core-1.1/wandb_graphql/utils/quoted_or_list.py +21 -0
  521. wandb/vendor/graphql-core-1.1/wandb_graphql/utils/schema_printer.py +168 -0
  522. wandb/vendor/graphql-core-1.1/wandb_graphql/utils/suggestion_list.py +56 -0
  523. wandb/vendor/graphql-core-1.1/wandb_graphql/utils/type_comparators.py +69 -0
  524. wandb/vendor/graphql-core-1.1/wandb_graphql/utils/type_from_ast.py +21 -0
  525. wandb/vendor/graphql-core-1.1/wandb_graphql/utils/type_info.py +149 -0
  526. wandb/vendor/graphql-core-1.1/wandb_graphql/utils/value_from_ast.py +69 -0
  527. wandb/vendor/graphql-core-1.1/wandb_graphql/validation/__init__.py +4 -0
  528. wandb/vendor/graphql-core-1.1/wandb_graphql/validation/rules/__init__.py +79 -0
  529. wandb/vendor/graphql-core-1.1/wandb_graphql/validation/rules/arguments_of_correct_type.py +24 -0
  530. wandb/vendor/graphql-core-1.1/wandb_graphql/validation/rules/base.py +8 -0
  531. wandb/vendor/graphql-core-1.1/wandb_graphql/validation/rules/default_values_of_correct_type.py +44 -0
  532. wandb/vendor/graphql-core-1.1/wandb_graphql/validation/rules/fields_on_correct_type.py +113 -0
  533. wandb/vendor/graphql-core-1.1/wandb_graphql/validation/rules/fragments_on_composite_types.py +33 -0
  534. wandb/vendor/graphql-core-1.1/wandb_graphql/validation/rules/known_argument_names.py +70 -0
  535. wandb/vendor/graphql-core-1.1/wandb_graphql/validation/rules/known_directives.py +97 -0
  536. wandb/vendor/graphql-core-1.1/wandb_graphql/validation/rules/known_fragment_names.py +19 -0
  537. wandb/vendor/graphql-core-1.1/wandb_graphql/validation/rules/known_type_names.py +43 -0
  538. wandb/vendor/graphql-core-1.1/wandb_graphql/validation/rules/lone_anonymous_operation.py +23 -0
  539. wandb/vendor/graphql-core-1.1/wandb_graphql/validation/rules/no_fragment_cycles.py +59 -0
  540. wandb/vendor/graphql-core-1.1/wandb_graphql/validation/rules/no_undefined_variables.py +36 -0
  541. wandb/vendor/graphql-core-1.1/wandb_graphql/validation/rules/no_unused_fragments.py +38 -0
  542. wandb/vendor/graphql-core-1.1/wandb_graphql/validation/rules/no_unused_variables.py +37 -0
  543. wandb/vendor/graphql-core-1.1/wandb_graphql/validation/rules/overlapping_fields_can_be_merged.py +529 -0
  544. wandb/vendor/graphql-core-1.1/wandb_graphql/validation/rules/possible_fragment_spreads.py +44 -0
  545. wandb/vendor/graphql-core-1.1/wandb_graphql/validation/rules/provided_non_null_arguments.py +46 -0
  546. wandb/vendor/graphql-core-1.1/wandb_graphql/validation/rules/scalar_leafs.py +33 -0
  547. wandb/vendor/graphql-core-1.1/wandb_graphql/validation/rules/unique_argument_names.py +32 -0
  548. wandb/vendor/graphql-core-1.1/wandb_graphql/validation/rules/unique_fragment_names.py +28 -0
  549. wandb/vendor/graphql-core-1.1/wandb_graphql/validation/rules/unique_input_field_names.py +33 -0
  550. wandb/vendor/graphql-core-1.1/wandb_graphql/validation/rules/unique_operation_names.py +31 -0
  551. wandb/vendor/graphql-core-1.1/wandb_graphql/validation/rules/unique_variable_names.py +27 -0
  552. wandb/vendor/graphql-core-1.1/wandb_graphql/validation/rules/variables_are_input_types.py +21 -0
  553. wandb/vendor/graphql-core-1.1/wandb_graphql/validation/rules/variables_in_allowed_position.py +53 -0
  554. wandb/vendor/graphql-core-1.1/wandb_graphql/validation/validation.py +158 -0
  555. wandb/vendor/promise-2.3.0/conftest.py +30 -0
  556. wandb/vendor/promise-2.3.0/setup.py +64 -0
  557. wandb/vendor/promise-2.3.0/tests/__init__.py +0 -0
  558. wandb/vendor/promise-2.3.0/tests/conftest.py +8 -0
  559. wandb/vendor/promise-2.3.0/tests/test_awaitable.py +32 -0
  560. wandb/vendor/promise-2.3.0/tests/test_awaitable_35.py +47 -0
  561. wandb/vendor/promise-2.3.0/tests/test_benchmark.py +116 -0
  562. wandb/vendor/promise-2.3.0/tests/test_complex_threads.py +23 -0
  563. wandb/vendor/promise-2.3.0/tests/test_dataloader.py +452 -0
  564. wandb/vendor/promise-2.3.0/tests/test_dataloader_awaitable_35.py +99 -0
  565. wandb/vendor/promise-2.3.0/tests/test_dataloader_extra.py +65 -0
  566. wandb/vendor/promise-2.3.0/tests/test_extra.py +670 -0
  567. wandb/vendor/promise-2.3.0/tests/test_issues.py +132 -0
  568. wandb/vendor/promise-2.3.0/tests/test_promise_list.py +70 -0
  569. wandb/vendor/promise-2.3.0/tests/test_spec.py +584 -0
  570. wandb/vendor/promise-2.3.0/tests/test_thread_safety.py +115 -0
  571. wandb/vendor/promise-2.3.0/tests/utils.py +3 -0
  572. wandb/vendor/promise-2.3.0/wandb_promise/__init__.py +38 -0
  573. wandb/vendor/promise-2.3.0/wandb_promise/async_.py +135 -0
  574. wandb/vendor/promise-2.3.0/wandb_promise/compat.py +32 -0
  575. wandb/vendor/promise-2.3.0/wandb_promise/dataloader.py +326 -0
  576. wandb/vendor/promise-2.3.0/wandb_promise/iterate_promise.py +12 -0
  577. wandb/vendor/promise-2.3.0/wandb_promise/promise.py +848 -0
  578. wandb/vendor/promise-2.3.0/wandb_promise/promise_list.py +151 -0
  579. wandb/vendor/promise-2.3.0/wandb_promise/pyutils/__init__.py +0 -0
  580. wandb/vendor/promise-2.3.0/wandb_promise/pyutils/version.py +83 -0
  581. wandb/vendor/promise-2.3.0/wandb_promise/schedulers/__init__.py +0 -0
  582. wandb/vendor/promise-2.3.0/wandb_promise/schedulers/asyncio.py +22 -0
  583. wandb/vendor/promise-2.3.0/wandb_promise/schedulers/gevent.py +21 -0
  584. wandb/vendor/promise-2.3.0/wandb_promise/schedulers/immediate.py +27 -0
  585. wandb/vendor/promise-2.3.0/wandb_promise/schedulers/thread.py +18 -0
  586. wandb/vendor/promise-2.3.0/wandb_promise/utils.py +56 -0
  587. wandb/vendor/pygments/__init__.py +90 -0
  588. wandb/vendor/pygments/cmdline.py +568 -0
  589. wandb/vendor/pygments/console.py +74 -0
  590. wandb/vendor/pygments/filter.py +74 -0
  591. wandb/vendor/pygments/filters/__init__.py +350 -0
  592. wandb/vendor/pygments/formatter.py +95 -0
  593. wandb/vendor/pygments/formatters/__init__.py +153 -0
  594. wandb/vendor/pygments/formatters/_mapping.py +85 -0
  595. wandb/vendor/pygments/formatters/bbcode.py +109 -0
  596. wandb/vendor/pygments/formatters/html.py +851 -0
  597. wandb/vendor/pygments/formatters/img.py +600 -0
  598. wandb/vendor/pygments/formatters/irc.py +182 -0
  599. wandb/vendor/pygments/formatters/latex.py +482 -0
  600. wandb/vendor/pygments/formatters/other.py +160 -0
  601. wandb/vendor/pygments/formatters/rtf.py +147 -0
  602. wandb/vendor/pygments/formatters/svg.py +153 -0
  603. wandb/vendor/pygments/formatters/terminal.py +136 -0
  604. wandb/vendor/pygments/formatters/terminal256.py +309 -0
  605. wandb/vendor/pygments/lexer.py +871 -0
  606. wandb/vendor/pygments/lexers/__init__.py +329 -0
  607. wandb/vendor/pygments/lexers/_asy_builtins.py +1645 -0
  608. wandb/vendor/pygments/lexers/_cl_builtins.py +232 -0
  609. wandb/vendor/pygments/lexers/_cocoa_builtins.py +72 -0
  610. wandb/vendor/pygments/lexers/_csound_builtins.py +1346 -0
  611. wandb/vendor/pygments/lexers/_lasso_builtins.py +5327 -0
  612. wandb/vendor/pygments/lexers/_lua_builtins.py +295 -0
  613. wandb/vendor/pygments/lexers/_mapping.py +500 -0
  614. wandb/vendor/pygments/lexers/_mql_builtins.py +1172 -0
  615. wandb/vendor/pygments/lexers/_openedge_builtins.py +2547 -0
  616. wandb/vendor/pygments/lexers/_php_builtins.py +4756 -0
  617. wandb/vendor/pygments/lexers/_postgres_builtins.py +621 -0
  618. wandb/vendor/pygments/lexers/_scilab_builtins.py +3094 -0
  619. wandb/vendor/pygments/lexers/_sourcemod_builtins.py +1163 -0
  620. wandb/vendor/pygments/lexers/_stan_builtins.py +532 -0
  621. wandb/vendor/pygments/lexers/_stata_builtins.py +419 -0
  622. wandb/vendor/pygments/lexers/_tsql_builtins.py +1004 -0
  623. wandb/vendor/pygments/lexers/_vim_builtins.py +1939 -0
  624. wandb/vendor/pygments/lexers/actionscript.py +240 -0
  625. wandb/vendor/pygments/lexers/agile.py +24 -0
  626. wandb/vendor/pygments/lexers/algebra.py +221 -0
  627. wandb/vendor/pygments/lexers/ambient.py +76 -0
  628. wandb/vendor/pygments/lexers/ampl.py +87 -0
  629. wandb/vendor/pygments/lexers/apl.py +101 -0
  630. wandb/vendor/pygments/lexers/archetype.py +318 -0
  631. wandb/vendor/pygments/lexers/asm.py +641 -0
  632. wandb/vendor/pygments/lexers/automation.py +374 -0
  633. wandb/vendor/pygments/lexers/basic.py +500 -0
  634. wandb/vendor/pygments/lexers/bibtex.py +160 -0
  635. wandb/vendor/pygments/lexers/business.py +612 -0
  636. wandb/vendor/pygments/lexers/c_cpp.py +252 -0
  637. wandb/vendor/pygments/lexers/c_like.py +541 -0
  638. wandb/vendor/pygments/lexers/capnproto.py +78 -0
  639. wandb/vendor/pygments/lexers/chapel.py +102 -0
  640. wandb/vendor/pygments/lexers/clean.py +288 -0
  641. wandb/vendor/pygments/lexers/compiled.py +34 -0
  642. wandb/vendor/pygments/lexers/configs.py +833 -0
  643. wandb/vendor/pygments/lexers/console.py +114 -0
  644. wandb/vendor/pygments/lexers/crystal.py +393 -0
  645. wandb/vendor/pygments/lexers/csound.py +366 -0
  646. wandb/vendor/pygments/lexers/css.py +689 -0
  647. wandb/vendor/pygments/lexers/d.py +251 -0
  648. wandb/vendor/pygments/lexers/dalvik.py +125 -0
  649. wandb/vendor/pygments/lexers/data.py +555 -0
  650. wandb/vendor/pygments/lexers/diff.py +165 -0
  651. wandb/vendor/pygments/lexers/dotnet.py +691 -0
  652. wandb/vendor/pygments/lexers/dsls.py +878 -0
  653. wandb/vendor/pygments/lexers/dylan.py +289 -0
  654. wandb/vendor/pygments/lexers/ecl.py +125 -0
  655. wandb/vendor/pygments/lexers/eiffel.py +65 -0
  656. wandb/vendor/pygments/lexers/elm.py +121 -0
  657. wandb/vendor/pygments/lexers/erlang.py +533 -0
  658. wandb/vendor/pygments/lexers/esoteric.py +277 -0
  659. wandb/vendor/pygments/lexers/ezhil.py +69 -0
  660. wandb/vendor/pygments/lexers/factor.py +344 -0
  661. wandb/vendor/pygments/lexers/fantom.py +250 -0
  662. wandb/vendor/pygments/lexers/felix.py +273 -0
  663. wandb/vendor/pygments/lexers/forth.py +177 -0
  664. wandb/vendor/pygments/lexers/fortran.py +205 -0
  665. wandb/vendor/pygments/lexers/foxpro.py +428 -0
  666. wandb/vendor/pygments/lexers/functional.py +21 -0
  667. wandb/vendor/pygments/lexers/go.py +101 -0
  668. wandb/vendor/pygments/lexers/grammar_notation.py +213 -0
  669. wandb/vendor/pygments/lexers/graph.py +80 -0
  670. wandb/vendor/pygments/lexers/graphics.py +553 -0
  671. wandb/vendor/pygments/lexers/haskell.py +843 -0
  672. wandb/vendor/pygments/lexers/haxe.py +936 -0
  673. wandb/vendor/pygments/lexers/hdl.py +382 -0
  674. wandb/vendor/pygments/lexers/hexdump.py +103 -0
  675. wandb/vendor/pygments/lexers/html.py +602 -0
  676. wandb/vendor/pygments/lexers/idl.py +270 -0
  677. wandb/vendor/pygments/lexers/igor.py +288 -0
  678. wandb/vendor/pygments/lexers/inferno.py +96 -0
  679. wandb/vendor/pygments/lexers/installers.py +322 -0
  680. wandb/vendor/pygments/lexers/int_fiction.py +1343 -0
  681. wandb/vendor/pygments/lexers/iolang.py +63 -0
  682. wandb/vendor/pygments/lexers/j.py +146 -0
  683. wandb/vendor/pygments/lexers/javascript.py +1525 -0
  684. wandb/vendor/pygments/lexers/julia.py +333 -0
  685. wandb/vendor/pygments/lexers/jvm.py +1573 -0
  686. wandb/vendor/pygments/lexers/lisp.py +2621 -0
  687. wandb/vendor/pygments/lexers/make.py +202 -0
  688. wandb/vendor/pygments/lexers/markup.py +595 -0
  689. wandb/vendor/pygments/lexers/math.py +21 -0
  690. wandb/vendor/pygments/lexers/matlab.py +663 -0
  691. wandb/vendor/pygments/lexers/ml.py +769 -0
  692. wandb/vendor/pygments/lexers/modeling.py +358 -0
  693. wandb/vendor/pygments/lexers/modula2.py +1561 -0
  694. wandb/vendor/pygments/lexers/monte.py +204 -0
  695. wandb/vendor/pygments/lexers/ncl.py +894 -0
  696. wandb/vendor/pygments/lexers/nimrod.py +159 -0
  697. wandb/vendor/pygments/lexers/nit.py +64 -0
  698. wandb/vendor/pygments/lexers/nix.py +136 -0
  699. wandb/vendor/pygments/lexers/oberon.py +105 -0
  700. wandb/vendor/pygments/lexers/objective.py +504 -0
  701. wandb/vendor/pygments/lexers/ooc.py +85 -0
  702. wandb/vendor/pygments/lexers/other.py +41 -0
  703. wandb/vendor/pygments/lexers/parasail.py +79 -0
  704. wandb/vendor/pygments/lexers/parsers.py +835 -0
  705. wandb/vendor/pygments/lexers/pascal.py +644 -0
  706. wandb/vendor/pygments/lexers/pawn.py +199 -0
  707. wandb/vendor/pygments/lexers/perl.py +620 -0
  708. wandb/vendor/pygments/lexers/php.py +267 -0
  709. wandb/vendor/pygments/lexers/praat.py +294 -0
  710. wandb/vendor/pygments/lexers/prolog.py +306 -0
  711. wandb/vendor/pygments/lexers/python.py +939 -0
  712. wandb/vendor/pygments/lexers/qvt.py +152 -0
  713. wandb/vendor/pygments/lexers/r.py +453 -0
  714. wandb/vendor/pygments/lexers/rdf.py +270 -0
  715. wandb/vendor/pygments/lexers/rebol.py +431 -0
  716. wandb/vendor/pygments/lexers/resource.py +85 -0
  717. wandb/vendor/pygments/lexers/rnc.py +67 -0
  718. wandb/vendor/pygments/lexers/roboconf.py +82 -0
  719. wandb/vendor/pygments/lexers/robotframework.py +560 -0
  720. wandb/vendor/pygments/lexers/ruby.py +519 -0
  721. wandb/vendor/pygments/lexers/rust.py +220 -0
  722. wandb/vendor/pygments/lexers/sas.py +228 -0
  723. wandb/vendor/pygments/lexers/scripting.py +1222 -0
  724. wandb/vendor/pygments/lexers/shell.py +794 -0
  725. wandb/vendor/pygments/lexers/smalltalk.py +195 -0
  726. wandb/vendor/pygments/lexers/smv.py +79 -0
  727. wandb/vendor/pygments/lexers/snobol.py +83 -0
  728. wandb/vendor/pygments/lexers/special.py +103 -0
  729. wandb/vendor/pygments/lexers/sql.py +681 -0
  730. wandb/vendor/pygments/lexers/stata.py +108 -0
  731. wandb/vendor/pygments/lexers/supercollider.py +90 -0
  732. wandb/vendor/pygments/lexers/tcl.py +145 -0
  733. wandb/vendor/pygments/lexers/templates.py +2283 -0
  734. wandb/vendor/pygments/lexers/testing.py +207 -0
  735. wandb/vendor/pygments/lexers/text.py +25 -0
  736. wandb/vendor/pygments/lexers/textedit.py +169 -0
  737. wandb/vendor/pygments/lexers/textfmts.py +297 -0
  738. wandb/vendor/pygments/lexers/theorem.py +458 -0
  739. wandb/vendor/pygments/lexers/trafficscript.py +54 -0
  740. wandb/vendor/pygments/lexers/typoscript.py +226 -0
  741. wandb/vendor/pygments/lexers/urbi.py +133 -0
  742. wandb/vendor/pygments/lexers/varnish.py +190 -0
  743. wandb/vendor/pygments/lexers/verification.py +111 -0
  744. wandb/vendor/pygments/lexers/web.py +24 -0
  745. wandb/vendor/pygments/lexers/webmisc.py +988 -0
  746. wandb/vendor/pygments/lexers/whiley.py +116 -0
  747. wandb/vendor/pygments/lexers/x10.py +69 -0
  748. wandb/vendor/pygments/modeline.py +44 -0
  749. wandb/vendor/pygments/plugin.py +68 -0
  750. wandb/vendor/pygments/regexopt.py +92 -0
  751. wandb/vendor/pygments/scanner.py +105 -0
  752. wandb/vendor/pygments/sphinxext.py +158 -0
  753. wandb/vendor/pygments/style.py +155 -0
  754. wandb/vendor/pygments/styles/__init__.py +80 -0
  755. wandb/vendor/pygments/styles/abap.py +29 -0
  756. wandb/vendor/pygments/styles/algol.py +63 -0
  757. wandb/vendor/pygments/styles/algol_nu.py +63 -0
  758. wandb/vendor/pygments/styles/arduino.py +98 -0
  759. wandb/vendor/pygments/styles/autumn.py +65 -0
  760. wandb/vendor/pygments/styles/borland.py +51 -0
  761. wandb/vendor/pygments/styles/bw.py +49 -0
  762. wandb/vendor/pygments/styles/colorful.py +81 -0
  763. wandb/vendor/pygments/styles/default.py +73 -0
  764. wandb/vendor/pygments/styles/emacs.py +72 -0
  765. wandb/vendor/pygments/styles/friendly.py +72 -0
  766. wandb/vendor/pygments/styles/fruity.py +42 -0
  767. wandb/vendor/pygments/styles/igor.py +29 -0
  768. wandb/vendor/pygments/styles/lovelace.py +97 -0
  769. wandb/vendor/pygments/styles/manni.py +75 -0
  770. wandb/vendor/pygments/styles/monokai.py +106 -0
  771. wandb/vendor/pygments/styles/murphy.py +80 -0
  772. wandb/vendor/pygments/styles/native.py +65 -0
  773. wandb/vendor/pygments/styles/paraiso_dark.py +125 -0
  774. wandb/vendor/pygments/styles/paraiso_light.py +125 -0
  775. wandb/vendor/pygments/styles/pastie.py +75 -0
  776. wandb/vendor/pygments/styles/perldoc.py +69 -0
  777. wandb/vendor/pygments/styles/rainbow_dash.py +89 -0
  778. wandb/vendor/pygments/styles/rrt.py +33 -0
  779. wandb/vendor/pygments/styles/sas.py +44 -0
  780. wandb/vendor/pygments/styles/stata.py +40 -0
  781. wandb/vendor/pygments/styles/tango.py +141 -0
  782. wandb/vendor/pygments/styles/trac.py +63 -0
  783. wandb/vendor/pygments/styles/vim.py +63 -0
  784. wandb/vendor/pygments/styles/vs.py +38 -0
  785. wandb/vendor/pygments/styles/xcode.py +51 -0
  786. wandb/vendor/pygments/token.py +213 -0
  787. wandb/vendor/pygments/unistring.py +217 -0
  788. wandb/vendor/pygments/util.py +388 -0
  789. wandb/vendor/pynvml/__init__.py +0 -0
  790. wandb/vendor/pynvml/pynvml.py +4779 -0
  791. wandb/vendor/watchdog_0_9_0/wandb_watchdog/__init__.py +17 -0
  792. wandb/vendor/watchdog_0_9_0/wandb_watchdog/events.py +615 -0
  793. wandb/vendor/watchdog_0_9_0/wandb_watchdog/observers/__init__.py +98 -0
  794. wandb/vendor/watchdog_0_9_0/wandb_watchdog/observers/api.py +369 -0
  795. wandb/vendor/watchdog_0_9_0/wandb_watchdog/observers/fsevents.py +172 -0
  796. wandb/vendor/watchdog_0_9_0/wandb_watchdog/observers/fsevents2.py +239 -0
  797. wandb/vendor/watchdog_0_9_0/wandb_watchdog/observers/inotify.py +218 -0
  798. wandb/vendor/watchdog_0_9_0/wandb_watchdog/observers/inotify_buffer.py +81 -0
  799. wandb/vendor/watchdog_0_9_0/wandb_watchdog/observers/inotify_c.py +575 -0
  800. wandb/vendor/watchdog_0_9_0/wandb_watchdog/observers/kqueue.py +730 -0
  801. wandb/vendor/watchdog_0_9_0/wandb_watchdog/observers/polling.py +145 -0
  802. wandb/vendor/watchdog_0_9_0/wandb_watchdog/observers/read_directory_changes.py +133 -0
  803. wandb/vendor/watchdog_0_9_0/wandb_watchdog/observers/winapi.py +348 -0
  804. wandb/vendor/watchdog_0_9_0/wandb_watchdog/patterns.py +265 -0
  805. wandb/vendor/watchdog_0_9_0/wandb_watchdog/tricks/__init__.py +174 -0
  806. wandb/vendor/watchdog_0_9_0/wandb_watchdog/utils/__init__.py +151 -0
  807. wandb/vendor/watchdog_0_9_0/wandb_watchdog/utils/bricks.py +249 -0
  808. wandb/vendor/watchdog_0_9_0/wandb_watchdog/utils/compat.py +29 -0
  809. wandb/vendor/watchdog_0_9_0/wandb_watchdog/utils/decorators.py +198 -0
  810. wandb/vendor/watchdog_0_9_0/wandb_watchdog/utils/delayed_queue.py +88 -0
  811. wandb/vendor/watchdog_0_9_0/wandb_watchdog/utils/dirsnapshot.py +293 -0
  812. wandb/vendor/watchdog_0_9_0/wandb_watchdog/utils/echo.py +157 -0
  813. wandb/vendor/watchdog_0_9_0/wandb_watchdog/utils/event_backport.py +41 -0
  814. wandb/vendor/watchdog_0_9_0/wandb_watchdog/utils/importlib2.py +40 -0
  815. wandb/vendor/watchdog_0_9_0/wandb_watchdog/utils/platform.py +57 -0
  816. wandb/vendor/watchdog_0_9_0/wandb_watchdog/utils/unicode_paths.py +64 -0
  817. wandb/vendor/watchdog_0_9_0/wandb_watchdog/utils/win32stat.py +123 -0
  818. wandb/vendor/watchdog_0_9_0/wandb_watchdog/version.py +28 -0
  819. wandb/vendor/watchdog_0_9_0/wandb_watchdog/watchmedo.py +577 -0
  820. wandb/wandb_agent.py +588 -0
  821. wandb/wandb_controller.py +721 -0
  822. wandb/wandb_run.py +9 -0
  823. wandb-0.18.2.dist-info/METADATA +213 -0
  824. wandb-0.18.2.dist-info/RECORD +827 -0
  825. wandb-0.18.2.dist-info/WHEEL +5 -0
  826. wandb-0.18.2.dist-info/entry_points.txt +3 -0
  827. wandb-0.18.2.dist-info/licenses/LICENSE +21 -0
@@ -0,0 +1,4779 @@
1
+ #####
2
+ #
3
+ # Based on nvidia-ml-py version 11.515.48
4
+ # Sourced from https://pypi.org/project/nvidia-ml-py/
5
+ # Modifications:
6
+ # - Added `NVML_DLL_PATH` env var check to the library initialization path
7
+ # - Applied black formatting to improve readability
8
+ # - Try different versions ("_v3", "_v2", "") of the functions:
9
+ # nvmlDeviceGetComputeRunningProcesses,
10
+ # nvmlDeviceGetGraphicsRunningProcesses, and
11
+ # nvmlDeviceGetMPSComputeRunningProcesses
12
+ #
13
+ # Copyright (c) 2011-2022, NVIDIA Corporation. All rights reserved.
14
+ #
15
+ # Redistribution and use in source and binary forms, with or without
16
+ # modification, are permitted provided that the following conditions are met:
17
+ #
18
+ # * Redistributions of source code must retain the above copyright notice,
19
+ # this list of conditions and the following disclaimer.
20
+ # * Redistributions in binary form must reproduce the above copyright
21
+ # notice, this list of conditions and the following disclaimer in the
22
+ # documentation and/or other materials provided with the distribution.
23
+ # * Neither the name of the NVIDIA Corporation nor the names of its
24
+ # contributors may be used to endorse or promote products derived from
25
+ # this software without specific prior written permission.
26
+ #
27
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
28
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
30
+ # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
31
+ # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32
+ # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33
+ # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34
+ # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35
+ # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36
+ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
37
+ # THE POSSIBILITY OF SUCH DAMAGE.
38
+ #####
39
+
40
+ ##
41
+ # Python bindings for the NVML library
42
+ ##
43
+ from ctypes import *
44
+ from ctypes.util import find_library
45
+ from functools import wraps
46
+ import sys
47
+ import os
48
+ import threading
49
+ import string
50
+
51
+ ## C Type mappings ##
52
+ ## Enums
53
+ _nvmlEnableState_t = c_uint
54
+ NVML_FEATURE_DISABLED = 0
55
+ NVML_FEATURE_ENABLED = 1
56
+
57
+ _nvmlBrandType_t = c_uint
58
+ NVML_BRAND_UNKNOWN = 0
59
+ NVML_BRAND_QUADRO = 1
60
+ NVML_BRAND_TESLA = 2
61
+ NVML_BRAND_NVS = 3
62
+ NVML_BRAND_GRID = (
63
+ 4 # Deprecated from API reporting. Keeping definition for backward compatibility.
64
+ )
65
+ NVML_BRAND_GEFORCE = 5
66
+ NVML_BRAND_TITAN = 6
67
+ NVML_BRAND_NVIDIA_VAPPS = 7 # NVIDIA Virtual Applications
68
+ NVML_BRAND_NVIDIA_VPC = 8 # NVIDIA Virtual PC
69
+ NVML_BRAND_NVIDIA_VCS = 9 # NVIDIA Virtual Compute Server
70
+ NVML_BRAND_NVIDIA_VWS = 10 # NVIDIA RTX Virtual Workstation
71
+ NVML_BRAND_NVIDIA_CLOUD_GAMING = 11 # NVIDIA Cloud Gaming
72
+ NVML_BRAND_NVIDIA_VGAMING = NVML_BRAND_NVIDIA_CLOUD_GAMING # Deprecated from API reporting. Keeping definition for backward compatibility.
73
+ NVML_BRAND_QUADRO_RTX = 12
74
+ NVML_BRAND_NVIDIA_RTX = 13
75
+ NVML_BRAND_NVIDIA = 14
76
+ NVML_BRAND_GEFORCE_RTX = 15 # Unused
77
+ NVML_BRAND_TITAN_RTX = 16 # Unused
78
+ NVML_BRAND_COUNT = 17
79
+
80
+ _nvmlTemperatureThresholds_t = c_uint
81
+ NVML_TEMPERATURE_THRESHOLD_SHUTDOWN = 0
82
+ NVML_TEMPERATURE_THRESHOLD_SLOWDOWN = 1
83
+ NVML_TEMPERATURE_THRESHOLD_MEM_MAX = 2
84
+ NVML_TEMPERATURE_THRESHOLD_GPU_MAX = 3
85
+ NVML_TEMPERATURE_THRESHOLD_ACOUSTIC_MIN = 4
86
+ NVML_TEMPERATURE_THRESHOLD_ACOUSTIC_CURR = 5
87
+ NVML_TEMPERATURE_THRESHOLD_ACOUSTIC_MAX = 6
88
+ NVML_TEMPERATURE_THRESHOLD_COUNT = 7
89
+
90
+ _nvmlTemperatureSensors_t = c_uint
91
+ NVML_TEMPERATURE_GPU = 0
92
+ NVML_TEMPERATURE_COUNT = 1
93
+
94
+ _nvmlComputeMode_t = c_uint
95
+ NVML_COMPUTEMODE_DEFAULT = 0
96
+ NVML_COMPUTEMODE_EXCLUSIVE_THREAD = 1 ## Support Removed
97
+ NVML_COMPUTEMODE_PROHIBITED = 2
98
+ NVML_COMPUTEMODE_EXCLUSIVE_PROCESS = 3
99
+ NVML_COMPUTEMODE_COUNT = 4
100
+
101
+ _nvmlMemoryLocation_t = c_uint
102
+ NVML_MEMORY_LOCATION_L1_CACHE = 0
103
+ NVML_MEMORY_LOCATION_L2_CACHE = 1
104
+ NVML_MEMORY_LOCATION_DEVICE_MEMORY = 2
105
+ NVML_MEMORY_LOCATION_DRAM = 2
106
+ NVML_MEMORY_LOCATION_REGISTER_FILE = 3
107
+ NVML_MEMORY_LOCATION_TEXTURE_MEMORY = 4
108
+ NVML_MEMORY_LOCATION_TEXTURE_SHM = 5
109
+ NVML_MEMORY_LOCATION_CBU = 6
110
+ NVML_MEMORY_LOCATION_SRAM = 7
111
+ NVML_MEMORY_LOCATION_COUNT = 8
112
+
113
+ NVML_NVLINK_MAX_LINKS = 12
114
+
115
+ # For backwards compatibility, maintain the incorrectly-named "LANES" define
116
+ NVML_NVLINK_MAX_LANES = NVML_NVLINK_MAX_LINKS
117
+
118
+ _nvmlNvLinkErrorCounter_t = c_uint
119
+ NVML_NVLINK_ERROR_DL_REPLAY = 0
120
+ NVML_NVLINK_ERROR_DL_RECOVERY = 1
121
+ NVML_NVLINK_ERROR_DL_CRC_FLIT = 2
122
+ NVML_NVLINK_ERROR_DL_CRC_DATA = 3
123
+ NVML_NVLINK_ERROR_DL_ECC_DATA = 4
124
+ NVML_NVLINK_ERROR_COUNT = 5
125
+
126
+ _nvmlNvLinkEccLaneErrorCounter_t = c_uint
127
+ NVML_NVLINK_ERROR_DL_ECC_LANE0 = 0
128
+ NVML_NVLINK_ERROR_DL_ECC_LANE1 = 1
129
+ NVML_NVLINK_ERROR_DL_ECC_LANE2 = 2
130
+ NVML_NVLINK_ERROR_DL_ECC_LANE3 = 3
131
+ NVML_NVLINK_ERROR_DL_ECC_COUNT = 5
132
+
133
+ _nvmlNvLinkCapability_t = c_uint
134
+ NVML_NVLINK_CAP_P2P_SUPPORTED = 0
135
+ NVML_NVLINK_CAP_SYSMEM_ACCESS = 1
136
+ NVML_NVLINK_CAP_P2P_ATOMICS = 2
137
+ NVML_NVLINK_CAP_SYSMEM_ATOMICS = 3
138
+ NVML_NVLINK_CAP_SLI_BRIDGE = 4
139
+ NVML_NVLINK_CAP_VALID = 5
140
+ NVML_NVLINK_CAP_COUNT = 6
141
+
142
+ _nvmlNvLinkUtilizationCountPktTypes_t = c_uint
143
+ NVML_NVLINK_COUNTER_PKTFILTER_NOP = 0x1
144
+ NVML_NVLINK_COUNTER_PKTFILTER_READ = 0x2
145
+ NVML_NVLINK_COUNTER_PKTFILTER_WRITE = 0x4
146
+ NVML_NVLINK_COUNTER_PKTFILTER_RATOM = 0x8
147
+ NVML_NVLINK_COUNTER_PKTFILTER_NRATOM = 0x10
148
+ NVML_NVLINK_COUNTER_PKTFILTER_FLUSH = 0x20
149
+ NVML_NVLINK_COUNTER_PKTFILTER_RESPDATA = 0x40
150
+ NVML_NVLINK_COUNTER_PKTFILTER_RESPNODATA = 0x80
151
+ NVML_NVLINK_COUNTER_PKTFILTER_ALL = 0xFF
152
+
153
+ _nvmlNvLinkUtilizationCountUnits_t = c_uint
154
+ NVML_NVLINK_COUNTER_UNIT_CYCLES = 0
155
+ NVML_NVLINK_COUNTER_UNIT_PACKETS = 1
156
+ NVML_NVLINK_COUNTER_UNIT_BYTES = 2
157
+ NVML_NVLINK_COUNTER_UNIT_RESERVED = 3
158
+ NVML_NVLINK_COUNTER_UNIT_COUNT = 4
159
+
160
+ _nvmlNvLinkDeviceType_t = c_uint
161
+ NVML_NVLINK_DEVICE_TYPE_GPU = 0x00
162
+ NVML_NVLINK_DEVICE_TYPE_IBMNPU = 0x01
163
+ NVML_NVLINK_DEVICE_TYPE_SWITCH = 0x02
164
+ NVML_NVLINK_DEVICE_TYPE_UNKNOWN = 0xFF
165
+
166
+ # These are deprecated, instead use _nvmlMemoryErrorType_t
167
+ _nvmlEccBitType_t = c_uint
168
+ NVML_SINGLE_BIT_ECC = 0
169
+ NVML_DOUBLE_BIT_ECC = 1
170
+ NVML_ECC_ERROR_TYPE_COUNT = 2
171
+
172
+ _nvmlEccCounterType_t = c_uint
173
+ NVML_VOLATILE_ECC = 0
174
+ NVML_AGGREGATE_ECC = 1
175
+ NVML_ECC_COUNTER_TYPE_COUNT = 2
176
+
177
+ _nvmlMemoryErrorType_t = c_uint
178
+ NVML_MEMORY_ERROR_TYPE_CORRECTED = 0
179
+ NVML_MEMORY_ERROR_TYPE_UNCORRECTED = 1
180
+ NVML_MEMORY_ERROR_TYPE_COUNT = 2
181
+
182
+ _nvmlClockType_t = c_uint
183
+ NVML_CLOCK_GRAPHICS = 0
184
+ NVML_CLOCK_SM = 1
185
+ NVML_CLOCK_MEM = 2
186
+ NVML_CLOCK_VIDEO = 3
187
+ NVML_CLOCK_COUNT = 4
188
+
189
+ _nvmlClockId_t = c_uint
190
+ NVML_CLOCK_ID_CURRENT = 0
191
+ NVML_CLOCK_ID_APP_CLOCK_TARGET = 1
192
+ NVML_CLOCK_ID_APP_CLOCK_DEFAULT = 2
193
+ NVML_CLOCK_ID_CUSTOMER_BOOST_MAX = 3
194
+ NVML_CLOCK_ID_COUNT = 4
195
+
196
+ _nvmlDriverModel_t = c_uint
197
+ NVML_DRIVER_WDDM = 0
198
+ NVML_DRIVER_WDM = 1
199
+
200
+ NVML_MAX_GPU_PERF_PSTATES = 16
201
+
202
+ _nvmlPstates_t = c_uint
203
+ NVML_PSTATE_0 = 0
204
+ NVML_PSTATE_1 = 1
205
+ NVML_PSTATE_2 = 2
206
+ NVML_PSTATE_3 = 3
207
+ NVML_PSTATE_4 = 4
208
+ NVML_PSTATE_5 = 5
209
+ NVML_PSTATE_6 = 6
210
+ NVML_PSTATE_7 = 7
211
+ NVML_PSTATE_8 = 8
212
+ NVML_PSTATE_9 = 9
213
+ NVML_PSTATE_10 = 10
214
+ NVML_PSTATE_11 = 11
215
+ NVML_PSTATE_12 = 12
216
+ NVML_PSTATE_13 = 13
217
+ NVML_PSTATE_14 = 14
218
+ NVML_PSTATE_15 = 15
219
+ NVML_PSTATE_UNKNOWN = 32
220
+
221
+ _nvmlInforomObject_t = c_uint
222
+ NVML_INFOROM_OEM = 0
223
+ NVML_INFOROM_ECC = 1
224
+ NVML_INFOROM_POWER = 2
225
+ NVML_INFOROM_COUNT = 3
226
+
227
+ _nvmlReturn_t = c_uint
228
+ NVML_SUCCESS = 0
229
+ NVML_ERROR_UNINITIALIZED = 1
230
+ NVML_ERROR_INVALID_ARGUMENT = 2
231
+ NVML_ERROR_NOT_SUPPORTED = 3
232
+ NVML_ERROR_NO_PERMISSION = 4
233
+ NVML_ERROR_ALREADY_INITIALIZED = 5
234
+ NVML_ERROR_NOT_FOUND = 6
235
+ NVML_ERROR_INSUFFICIENT_SIZE = 7
236
+ NVML_ERROR_INSUFFICIENT_POWER = 8
237
+ NVML_ERROR_DRIVER_NOT_LOADED = 9
238
+ NVML_ERROR_TIMEOUT = 10
239
+ NVML_ERROR_IRQ_ISSUE = 11
240
+ NVML_ERROR_LIBRARY_NOT_FOUND = 12
241
+ NVML_ERROR_FUNCTION_NOT_FOUND = 13
242
+ NVML_ERROR_CORRUPTED_INFOROM = 14
243
+ NVML_ERROR_GPU_IS_LOST = 15
244
+ NVML_ERROR_RESET_REQUIRED = 16
245
+ NVML_ERROR_OPERATING_SYSTEM = 17
246
+ NVML_ERROR_LIB_RM_VERSION_MISMATCH = 18
247
+ NVML_ERROR_IN_USE = 19
248
+ NVML_ERROR_MEMORY = 20
249
+ NVML_ERROR_NO_DATA = 21
250
+ NVML_ERROR_VGPU_ECC_NOT_SUPPORTED = 22
251
+ NVML_ERROR_INSUFFICIENT_RESOURCES = 23
252
+ NVML_ERROR_FREQ_NOT_SUPPORTED = 24
253
+ NVML_ERROR_UNKNOWN = 999
254
+
255
+ _nvmlFanState_t = c_uint
256
+ NVML_FAN_NORMAL = 0
257
+ NVML_FAN_FAILED = 1
258
+
259
+ _nvmlLedColor_t = c_uint
260
+ NVML_LED_COLOR_GREEN = 0
261
+ NVML_LED_COLOR_AMBER = 1
262
+
263
+ _nvmlGpuOperationMode_t = c_uint
264
+ NVML_GOM_ALL_ON = 0
265
+ NVML_GOM_COMPUTE = 1
266
+ NVML_GOM_LOW_DP = 2
267
+
268
+ _nvmlPageRetirementCause_t = c_uint
269
+ NVML_PAGE_RETIREMENT_CAUSE_MULTIPLE_SINGLE_BIT_ECC_ERRORS = 0
270
+ NVML_PAGE_RETIREMENT_CAUSE_DOUBLE_BIT_ECC_ERROR = 1
271
+ NVML_PAGE_RETIREMENT_CAUSE_COUNT = 2
272
+
273
+ _nvmlRestrictedAPI_t = c_uint
274
+ NVML_RESTRICTED_API_SET_APPLICATION_CLOCKS = 0
275
+ NVML_RESTRICTED_API_SET_AUTO_BOOSTED_CLOCKS = 1
276
+ NVML_RESTRICTED_API_COUNT = 2
277
+
278
+ _nvmlBridgeChipType_t = c_uint
279
+ NVML_BRIDGE_CHIP_PLX = 0
280
+ NVML_BRIDGE_CHIP_BRO4 = 1
281
+ NVML_MAX_PHYSICAL_BRIDGE = 128
282
+
283
+ _nvmlValueType_t = c_uint
284
+ NVML_VALUE_TYPE_DOUBLE = 0
285
+ NVML_VALUE_TYPE_UNSIGNED_INT = 1
286
+ NVML_VALUE_TYPE_UNSIGNED_LONG = 2
287
+ NVML_VALUE_TYPE_UNSIGNED_LONG_LONG = 3
288
+ NVML_VALUE_TYPE_SIGNED_LONG_LONG = 4
289
+ NVML_VALUE_TYPE_COUNT = 5
290
+
291
+ _nvmlPerfPolicyType_t = c_uint
292
+ NVML_PERF_POLICY_POWER = 0
293
+ NVML_PERF_POLICY_THERMAL = 1
294
+ NVML_PERF_POLICY_SYNC_BOOST = 2
295
+ NVML_PERF_POLICY_BOARD_LIMIT = 3
296
+ NVML_PERF_POLICY_LOW_UTILIZATION = 4
297
+ NVML_PERF_POLICY_RELIABILITY = 5
298
+ NVML_PERF_POLICY_TOTAL_APP_CLOCKS = 10
299
+ NVML_PERF_POLICY_TOTAL_BASE_CLOCKS = 11
300
+ NVML_PERF_POLICY_COUNT = 12
301
+
302
+ _nvmlEncoderQueryType_t = c_uint
303
+ NVML_ENCODER_QUERY_H264 = 0
304
+ NVML_ENCODER_QUERY_HEVC = 1
305
+
306
+ _nvmlFBCSessionType_t = c_uint
307
+ NVML_FBC_SESSION_TYPE_UNKNOWN = 0
308
+ NVML_FBC_SESSION_TYPE_TOSYS = 1
309
+ NVML_FBC_SESSION_TYPE_CUDA = 2
310
+ NVML_FBC_SESSION_TYPE_VID = 3
311
+ NVML_FBC_SESSION_TYPE_HWENC = 4
312
+
313
+ _nvmlDetachGpuState_t = c_uint
314
+ NVML_DETACH_GPU_KEEP = 0
315
+ NVML_DETACH_GPU_REMOVE = 1
316
+
317
+ _nvmlPcieLinkState_t = c_uint
318
+ NVML_PCIE_LINK_KEEP = 0
319
+ NVML_PCIE_LINK_SHUT_DOWN = 1
320
+
321
+ _nvmlSamplingType_t = c_uint
322
+ NVML_TOTAL_POWER_SAMPLES = 0
323
+ NVML_GPU_UTILIZATION_SAMPLES = 1
324
+ NVML_MEMORY_UTILIZATION_SAMPLES = 2
325
+ NVML_ENC_UTILIZATION_SAMPLES = 3
326
+ NVML_DEC_UTILIZATION_SAMPLES = 4
327
+ NVML_PROCESSOR_CLK_SAMPLES = 5
328
+ NVML_MEMORY_CLK_SAMPLES = 6
329
+ NVML_SAMPLINGTYPE_COUNT = 7
330
+
331
+ _nvmlPcieUtilCounter_t = c_uint
332
+ NVML_PCIE_UTIL_TX_BYTES = 0
333
+ NVML_PCIE_UTIL_RX_BYTES = 1
334
+ NVML_PCIE_UTIL_COUNT = 2
335
+
336
+ _nvmlGpuTopologyLevel_t = c_uint
337
+ NVML_TOPOLOGY_INTERNAL = 0
338
+ NVML_TOPOLOGY_SINGLE = 10
339
+ NVML_TOPOLOGY_MULTIPLE = 20
340
+ NVML_TOPOLOGY_HOSTBRIDGE = 30
341
+ NVML_TOPOLOGY_NODE = 40
342
+ NVML_TOPOLOGY_CPU = NVML_TOPOLOGY_NODE
343
+ NVML_TOPOLOGY_SYSTEM = 50
344
+
345
+ _nvmlGpuP2PCapsIndex_t = c_uint
346
+ NVML_P2P_CAPS_INDEX_READ = (0,)
347
+ NVML_P2P_CAPS_INDEX_WRITE = 1
348
+ NVML_P2P_CAPS_INDEX_NVLINK = 2
349
+ NVML_P2P_CAPS_INDEX_ATOMICS = 3
350
+ NVML_P2P_CAPS_INDEX_PROP = 4
351
+ NVML_P2P_CAPS_INDEX_LOOPBACK = 5
352
+ NVML_P2P_CAPS_INDEX_UNKNOWN = 6
353
+
354
+ _nvmlGpuP2PStatus_t = c_uint
355
+ NVML_P2P_STATUS_OK = 0
356
+ NVML_P2P_STATUS_CHIPSET_NOT_SUPPORED = 1
357
+ NVML_P2P_STATUS_GPU_NOT_SUPPORTED = 2
358
+ NVML_P2P_STATUS_IOH_TOPOLOGY_NOT_SUPPORTED = 3
359
+ NVML_P2P_STATUS_DISABLED_BY_REGKEY = 4
360
+ NVML_P2P_STATUS_NOT_SUPPORTED = 5
361
+ NVML_P2P_STATUS_UNKNOWN = 6
362
+
363
+ _nvmlDeviceArchitecture_t = c_uint
364
+ NVML_DEVICE_ARCH_KEPLER = 2
365
+ NVML_DEVICE_ARCH_MAXWELL = 3
366
+ NVML_DEVICE_ARCH_PASCAL = 4
367
+ NVML_DEVICE_ARCH_VOLTA = 5
368
+ NVML_DEVICE_ARCH_TURING = 6
369
+ NVML_DEVICE_ARCH_AMPERE = 7
370
+ NVML_DEVICE_ARCH_UNKNOWN = 0xFFFFFFFF
371
+
372
+ # PCI bus Types
373
+ _nvmlBusType_t = c_uint
374
+ NVML_BUS_TYPE_UNKNOWN = 0
375
+ NVML_BUS_TYPE_PCI = 1
376
+ NVML_BUS_TYPE_PCIE = 2
377
+ NVML_BUS_TYPE_FPCI = 3
378
+ NVML_BUS_TYPE_AGP = 4
379
+
380
+ _nvmlPowerSource_t = c_uint
381
+ NVML_POWER_SOURCE_AC = 0x00000000
382
+ NVML_POWER_SOURCE_BATTERY = 0x00000001
383
+
384
+ _nvmlAdaptiveClockInfoStatus_t = c_uint
385
+ NVML_ADAPTIVE_CLOCKING_INFO_STATUS_DISABLED = 0x00000000
386
+ NVML_ADAPTIVE_CLOCKING_INFO_STATUS_ENABLED = 0x00000001
387
+
388
+ _nvmlClockLimitId_t = c_uint
389
+ NVML_CLOCK_LIMIT_ID_RANGE_START = 0xFFFFFF00
390
+ NVML_CLOCK_LIMIT_ID_TDP = 0xFFFFFF01
391
+ NVML_CLOCK_LIMIT_ID_UNLIMITED = 0xFFFFFF02
392
+
393
+ _nvmlPcieLinkMaxSpeed_t = c_uint
394
+ NVML_PCIE_LINK_MAX_SPEED_INVALID = 0x00000000
395
+ NVML_PCIE_LINK_MAX_SPEED_2500MBPS = 0x00000001
396
+ NVML_PCIE_LINK_MAX_SPEED_5000MBPS = 0x00000002
397
+ NVML_PCIE_LINK_MAX_SPEED_8000MBPS = 0x00000003
398
+ NVML_PCIE_LINK_MAX_SPEED_16000MBPS = 0x00000004
399
+ NVML_PCIE_LINK_MAX_SPEED_32000MBPS = 0x00000005
400
+
401
+ _nvmlAffinityScope_t = c_uint
402
+ NVML_AFFINITY_SCOPE_NODE = 0
403
+ NVML_AFFINITY_SCOPE_SOCKET = 1
404
+
405
+ # C preprocessor defined values
406
+ nvmlFlagDefault = 0
407
+ nvmlFlagForce = 1
408
+ NVML_INIT_FLAG_NO_GPUS = 1
409
+ NVML_INIT_FLAG_NO_ATTACH = 2
410
+
411
+ NVML_MAX_GPC_COUNT = 32
412
+
413
+ # buffer size
414
+ NVML_DEVICE_INFOROM_VERSION_BUFFER_SIZE = 16
415
+ NVML_DEVICE_UUID_BUFFER_SIZE = 80
416
+ NVML_DEVICE_UUID_V2_BUFFER_SIZE = 96
417
+ NVML_SYSTEM_DRIVER_VERSION_BUFFER_SIZE = 80
418
+ NVML_SYSTEM_NVML_VERSION_BUFFER_SIZE = 80
419
+ NVML_DEVICE_NAME_BUFFER_SIZE = 64
420
+ NVML_DEVICE_NAME_V2_BUFFER_SIZE = 96
421
+ NVML_DEVICE_SERIAL_BUFFER_SIZE = 30
422
+ NVML_DEVICE_PART_NUMBER_BUFFER_SIZE = 80
423
+ NVML_DEVICE_VBIOS_VERSION_BUFFER_SIZE = 32
424
+ NVML_DEVICE_PCI_BUS_ID_BUFFER_SIZE = 32
425
+ NVML_DEVICE_PCI_BUS_ID_BUFFER_V2_SIZE = 16
426
+ NVML_GRID_LICENSE_BUFFER_SIZE = 128
427
+ NVML_VGPU_NAME_BUFFER_SIZE = 64
428
+ NVML_GRID_LICENSE_FEATURE_MAX_COUNT = 3
429
+ NVML_VGPU_METADATA_OPAQUE_DATA_SIZE = sizeof(c_uint) + 256
430
+ NVML_VGPU_PGPU_METADATA_OPAQUE_DATA_SIZE = 256
431
+
432
+ # Format strings
433
+ NVML_DEVICE_PCI_BUS_ID_LEGACY_FMT = "%04X:%02X:%02X.0"
434
+ NVML_DEVICE_PCI_BUS_ID_FMT = "%08X:%02X:%02X.0"
435
+
436
+ NVML_VALUE_NOT_AVAILABLE_ulonglong = c_ulonglong(-1)
437
+ NVML_VALUE_NOT_AVAILABLE_uint = c_uint(-1)
438
+
439
+ """
440
+ Field Identifiers.
441
+
442
+ All Identifiers pertain to a device. Each ID is only used once and is guaranteed never to change.
443
+ """
444
+ NVML_FI_DEV_ECC_CURRENT = 1 # Current ECC mode. 1=Active. 0=Inactive
445
+ NVML_FI_DEV_ECC_PENDING = 2 # Pending ECC mode. 1=Active. 0=Inactive
446
+
447
+ # ECC Count Totals
448
+ NVML_FI_DEV_ECC_SBE_VOL_TOTAL = 3 # Total single bit volatile ECC errors
449
+ NVML_FI_DEV_ECC_DBE_VOL_TOTAL = 4 # Total double bit volatile ECC errors
450
+ NVML_FI_DEV_ECC_SBE_AGG_TOTAL = 5 # Total single bit aggregate (persistent) ECC errors
451
+ NVML_FI_DEV_ECC_DBE_AGG_TOTAL = 6 # Total double bit aggregate (persistent) ECC errors
452
+ # Individual ECC locations
453
+ NVML_FI_DEV_ECC_SBE_VOL_L1 = 7 # L1 cache single bit volatile ECC errors
454
+ NVML_FI_DEV_ECC_DBE_VOL_L1 = 8 # L1 cache double bit volatile ECC errors
455
+ NVML_FI_DEV_ECC_SBE_VOL_L2 = 9 # L2 cache single bit volatile ECC errors
456
+ NVML_FI_DEV_ECC_DBE_VOL_L2 = 10 # L2 cache double bit volatile ECC errors
457
+ NVML_FI_DEV_ECC_SBE_VOL_DEV = 11 # Device memory single bit volatile ECC errors
458
+ NVML_FI_DEV_ECC_DBE_VOL_DEV = 12 # Device memory double bit volatile ECC errors
459
+ NVML_FI_DEV_ECC_SBE_VOL_REG = 13 # Register file single bit volatile ECC errors
460
+ NVML_FI_DEV_ECC_DBE_VOL_REG = 14 # Register file double bit volatile ECC errors
461
+ NVML_FI_DEV_ECC_SBE_VOL_TEX = 15 # Texture memory single bit volatile ECC errors
462
+ NVML_FI_DEV_ECC_DBE_VOL_TEX = 16 # Texture memory double bit volatile ECC errors
463
+ NVML_FI_DEV_ECC_DBE_VOL_CBU = 17 # CBU double bit volatile ECC errors
464
+ NVML_FI_DEV_ECC_SBE_AGG_L1 = 18 # L1 cache single bit aggregate (persistent) ECC errors
465
+ NVML_FI_DEV_ECC_DBE_AGG_L1 = 19 # L1 cache double bit aggregate (persistent) ECC errors
466
+ NVML_FI_DEV_ECC_SBE_AGG_L2 = 20 # L2 cache single bit aggregate (persistent) ECC errors
467
+ NVML_FI_DEV_ECC_DBE_AGG_L2 = 21 # L2 cache double bit aggregate (persistent) ECC errors
468
+ NVML_FI_DEV_ECC_SBE_AGG_DEV = (
469
+ 22 # Device memory single bit aggregate (persistent) ECC errors
470
+ )
471
+ NVML_FI_DEV_ECC_DBE_AGG_DEV = (
472
+ 23 # Device memory double bit aggregate (persistent) ECC errors
473
+ )
474
+ NVML_FI_DEV_ECC_SBE_AGG_REG = (
475
+ 24 # Register File single bit aggregate (persistent) ECC errors
476
+ )
477
+ NVML_FI_DEV_ECC_DBE_AGG_REG = (
478
+ 25 # Register File double bit aggregate (persistent) ECC errors
479
+ )
480
+ NVML_FI_DEV_ECC_SBE_AGG_TEX = (
481
+ 26 # Texture memory single bit aggregate (persistent) ECC errors
482
+ )
483
+ NVML_FI_DEV_ECC_DBE_AGG_TEX = (
484
+ 27 # Texture memory double bit aggregate (persistent) ECC errors
485
+ )
486
+ NVML_FI_DEV_ECC_DBE_AGG_CBU = 28 # CBU double bit aggregate ECC errors
487
+
488
+ # Page Retirement
489
+ NVML_FI_DEV_RETIRED_SBE = 29 # Number of retired pages because of single bit errors
490
+ NVML_FI_DEV_RETIRED_DBE = 30 # Number of retired pages because of double bit errors
491
+ NVML_FI_DEV_RETIRED_PENDING = 31 # If any pages are pending retirement. 1=yes. 0=no.
492
+
493
+ # NvLink Flit Error Counters
494
+ NVML_FI_DEV_NVLINK_CRC_FLIT_ERROR_COUNT_L0 = (
495
+ 32 # NVLink flow control CRC Error Counter for Lane 0
496
+ )
497
+ NVML_FI_DEV_NVLINK_CRC_FLIT_ERROR_COUNT_L1 = (
498
+ 33 # NVLink flow control CRC Error Counter for Lane 1
499
+ )
500
+ NVML_FI_DEV_NVLINK_CRC_FLIT_ERROR_COUNT_L2 = (
501
+ 34 # NVLink flow control CRC Error Counter for Lane 2
502
+ )
503
+ NVML_FI_DEV_NVLINK_CRC_FLIT_ERROR_COUNT_L3 = (
504
+ 35 # NVLink flow control CRC Error Counter for Lane 3
505
+ )
506
+ NVML_FI_DEV_NVLINK_CRC_FLIT_ERROR_COUNT_L4 = (
507
+ 36 # NVLink flow control CRC Error Counter for Lane 4
508
+ )
509
+ NVML_FI_DEV_NVLINK_CRC_FLIT_ERROR_COUNT_L5 = (
510
+ 37 # NVLink flow control CRC Error Counter for Lane 5
511
+ )
512
+ NVML_FI_DEV_NVLINK_CRC_FLIT_ERROR_COUNT_TOTAL = (
513
+ 38 # NVLink flow control CRC Error Counter total for all Lanes
514
+ )
515
+
516
+ # NvLink CRC Data Error Counters
517
+ NVML_FI_DEV_NVLINK_CRC_DATA_ERROR_COUNT_L0 = (
518
+ 39 # NVLink data CRC Error Counter for Lane 0
519
+ )
520
+ NVML_FI_DEV_NVLINK_CRC_DATA_ERROR_COUNT_L1 = (
521
+ 40 # NVLink data CRC Error Counter for Lane 1
522
+ )
523
+ NVML_FI_DEV_NVLINK_CRC_DATA_ERROR_COUNT_L2 = (
524
+ 41 # NVLink data CRC Error Counter for Lane 2
525
+ )
526
+ NVML_FI_DEV_NVLINK_CRC_DATA_ERROR_COUNT_L3 = (
527
+ 42 # NVLink data CRC Error Counter for Lane 3
528
+ )
529
+ NVML_FI_DEV_NVLINK_CRC_DATA_ERROR_COUNT_L4 = (
530
+ 43 # NVLink data CRC Error Counter for Lane 4
531
+ )
532
+ NVML_FI_DEV_NVLINK_CRC_DATA_ERROR_COUNT_L5 = (
533
+ 44 # NVLink data CRC Error Counter for Lane 5
534
+ )
535
+ NVML_FI_DEV_NVLINK_CRC_DATA_ERROR_COUNT_TOTAL = (
536
+ 45 # NvLink data CRC Error Counter total for all Lanes
537
+ )
538
+
539
+ # NvLink Replay Error Counters
540
+ NVML_FI_DEV_NVLINK_REPLAY_ERROR_COUNT_L0 = 46 # NVLink Replay Error Counter for Lane 0
541
+ NVML_FI_DEV_NVLINK_REPLAY_ERROR_COUNT_L1 = 47 # NVLink Replay Error Counter for Lane 1
542
+ NVML_FI_DEV_NVLINK_REPLAY_ERROR_COUNT_L2 = 48 # NVLink Replay Error Counter for Lane 2
543
+ NVML_FI_DEV_NVLINK_REPLAY_ERROR_COUNT_L3 = 49 # NVLink Replay Error Counter for Lane 3
544
+ NVML_FI_DEV_NVLINK_REPLAY_ERROR_COUNT_L4 = 50 # NVLink Replay Error Counter for Lane 4
545
+ NVML_FI_DEV_NVLINK_REPLAY_ERROR_COUNT_L5 = 51 # NVLink Replay Error Counter for Lane 5
546
+ NVML_FI_DEV_NVLINK_REPLAY_ERROR_COUNT_TOTAL = (
547
+ 52 # NVLink Replay Error Counter total for all Lanes
548
+ )
549
+
550
+ # NvLink Recovery Error Counters
551
+ NVML_FI_DEV_NVLINK_RECOVERY_ERROR_COUNT_L0 = (
552
+ 53 # NVLink Recovery Error Counter for Lane 0
553
+ )
554
+ NVML_FI_DEV_NVLINK_RECOVERY_ERROR_COUNT_L1 = (
555
+ 54 # NVLink Recovery Error Counter for Lane 1
556
+ )
557
+ NVML_FI_DEV_NVLINK_RECOVERY_ERROR_COUNT_L2 = (
558
+ 55 # NVLink Recovery Error Counter for Lane 2
559
+ )
560
+ NVML_FI_DEV_NVLINK_RECOVERY_ERROR_COUNT_L3 = (
561
+ 56 # NVLink Recovery Error Counter for Lane 3
562
+ )
563
+ NVML_FI_DEV_NVLINK_RECOVERY_ERROR_COUNT_L4 = (
564
+ 57 # NVLink Recovery Error Counter for Lane 4
565
+ )
566
+ NVML_FI_DEV_NVLINK_RECOVERY_ERROR_COUNT_L5 = (
567
+ 58 # NVLink Recovery Error Counter for Lane 5
568
+ )
569
+ NVML_FI_DEV_NVLINK_RECOVERY_ERROR_COUNT_TOTAL = (
570
+ 59 # NVLink Recovery Error Counter total for all Lanes
571
+ )
572
+
573
+ # NvLink Bandwidth Counters
574
+ NVML_FI_DEV_NVLINK_BANDWIDTH_C0_L0 = (
575
+ 60 # NVLink Bandwidth Counter for Counter Set 0, Lane 0
576
+ )
577
+ NVML_FI_DEV_NVLINK_BANDWIDTH_C0_L1 = (
578
+ 61 # NVLink Bandwidth Counter for Counter Set 0, Lane 1
579
+ )
580
+ NVML_FI_DEV_NVLINK_BANDWIDTH_C0_L2 = (
581
+ 62 # NVLink Bandwidth Counter for Counter Set 0, Lane 2
582
+ )
583
+ NVML_FI_DEV_NVLINK_BANDWIDTH_C0_L3 = (
584
+ 63 # NVLink Bandwidth Counter for Counter Set 0, Lane 3
585
+ )
586
+ NVML_FI_DEV_NVLINK_BANDWIDTH_C0_L4 = (
587
+ 64 # NVLink Bandwidth Counter for Counter Set 0, Lane 4
588
+ )
589
+ NVML_FI_DEV_NVLINK_BANDWIDTH_C0_L5 = (
590
+ 65 # NVLink Bandwidth Counter for Counter Set 0, Lane 5
591
+ )
592
+ NVML_FI_DEV_NVLINK_BANDWIDTH_C0_TOTAL = (
593
+ 66 # NVLink Bandwidth Counter Total for Counter Set 0, All Lanes
594
+ )
595
+
596
+ # NvLink Bandwidth Counters
597
+ NVML_FI_DEV_NVLINK_BANDWIDTH_C1_L0 = (
598
+ 67 # NVLink Bandwidth Counter for Counter Set 1, Lane 0
599
+ )
600
+ NVML_FI_DEV_NVLINK_BANDWIDTH_C1_L1 = (
601
+ 68 # NVLink Bandwidth Counter for Counter Set 1, Lane 1
602
+ )
603
+ NVML_FI_DEV_NVLINK_BANDWIDTH_C1_L2 = (
604
+ 69 # NVLink Bandwidth Counter for Counter Set 1, Lane 2
605
+ )
606
+ NVML_FI_DEV_NVLINK_BANDWIDTH_C1_L3 = (
607
+ 70 # NVLink Bandwidth Counter for Counter Set 1, Lane 3
608
+ )
609
+ NVML_FI_DEV_NVLINK_BANDWIDTH_C1_L4 = (
610
+ 71 # NVLink Bandwidth Counter for Counter Set 1, Lane 4
611
+ )
612
+ NVML_FI_DEV_NVLINK_BANDWIDTH_C1_L5 = (
613
+ 72 # NVLink Bandwidth Counter for Counter Set 1, Lane 5
614
+ )
615
+ NVML_FI_DEV_NVLINK_BANDWIDTH_C1_TOTAL = (
616
+ 73 # NVLink Bandwidth Counter Total for Counter Set 1, All Lanes
617
+ )
618
+
619
+ # Perf Policy Counters
620
+ NVML_FI_DEV_PERF_POLICY_POWER = 74 # Perf Policy Counter for Power Policy
621
+ NVML_FI_DEV_PERF_POLICY_THERMAL = 75 # Perf Policy Counter for Thermal Policy
622
+ NVML_FI_DEV_PERF_POLICY_SYNC_BOOST = 76 # Perf Policy Counter for Sync boost Policy
623
+ NVML_FI_DEV_PERF_POLICY_BOARD_LIMIT = 77 # Perf Policy Counter for Board Limit
624
+ NVML_FI_DEV_PERF_POLICY_LOW_UTILIZATION = (
625
+ 78 # Perf Policy Counter for Low GPU Utilization Policy
626
+ )
627
+ NVML_FI_DEV_PERF_POLICY_RELIABILITY = 79 # Perf Policy Counter for Reliability Policy
628
+ NVML_FI_DEV_PERF_POLICY_TOTAL_APP_CLOCKS = (
629
+ 80 # Perf Policy Counter for Total App Clock Policy
630
+ )
631
+ NVML_FI_DEV_PERF_POLICY_TOTAL_BASE_CLOCKS = (
632
+ 81 # Perf Policy Counter for Total Base Clocks Policy
633
+ )
634
+
635
+ # Memory temperatures
636
+ NVML_FI_DEV_MEMORY_TEMP = 82 # Memory temperature for the device
637
+
638
+ # Energy Counter
639
+ NVML_FI_DEV_TOTAL_ENERGY_CONSUMPTION = (
640
+ 83 # Total energy consumption for the GPU in mJ since the driver was last reloaded
641
+ )
642
+
643
+ # NVLink Speed
644
+ NVML_FI_DEV_NVLINK_SPEED_MBPS_L0 = 84
645
+ NVML_FI_DEV_NVLINK_SPEED_MBPS_L1 = 85
646
+ NVML_FI_DEV_NVLINK_SPEED_MBPS_L2 = 86
647
+ NVML_FI_DEV_NVLINK_SPEED_MBPS_L3 = 87
648
+ NVML_FI_DEV_NVLINK_SPEED_MBPS_L4 = 88
649
+ NVML_FI_DEV_NVLINK_SPEED_MBPS_L5 = 89
650
+ NVML_FI_DEV_NVLINK_SPEED_MBPS_COMMON = 90
651
+
652
+ # NVLink Link Count
653
+ NVML_FI_DEV_NVLINK_LINK_COUNT = 91
654
+
655
+ # Page Retirement pending fields
656
+ NVML_FI_DEV_RETIRED_PENDING_SBE = 92
657
+ NVML_FI_DEV_RETIRED_PENDING_DBE = 93
658
+
659
+ # PCIe replay and replay rollover counters
660
+ NVML_FI_DEV_PCIE_REPLAY_COUNTER = 94
661
+ NVML_FI_DEV_PCIE_REPLAY_ROLLOVER_COUNTER = 95
662
+
663
+ # NvLink Flit Error Counters
664
+ NVML_FI_DEV_NVLINK_CRC_FLIT_ERROR_COUNT_L6 = (
665
+ 96 # NVLink flow control CRC Error Counter for Lane 6
666
+ )
667
+ NVML_FI_DEV_NVLINK_CRC_FLIT_ERROR_COUNT_L7 = (
668
+ 97 # NVLink flow control CRC Error Counter for Lane 7
669
+ )
670
+ NVML_FI_DEV_NVLINK_CRC_FLIT_ERROR_COUNT_L8 = (
671
+ 98 # NVLink flow control CRC Error Counter for Lane 8
672
+ )
673
+ NVML_FI_DEV_NVLINK_CRC_FLIT_ERROR_COUNT_L9 = (
674
+ 99 # NVLink flow control CRC Error Counter for Lane 9
675
+ )
676
+ NVML_FI_DEV_NVLINK_CRC_FLIT_ERROR_COUNT_L10 = (
677
+ 100 # NVLink flow control CRC Error Counter for Lane 10
678
+ )
679
+ NVML_FI_DEV_NVLINK_CRC_FLIT_ERROR_COUNT_L11 = (
680
+ 101 # NVLink flow control CRC Error Counter for Lane 11
681
+ )
682
+
683
+ # NvLink CRC Data Error Counters
684
+ NVML_FI_DEV_NVLINK_CRC_DATA_ERROR_COUNT_L6 = (
685
+ 102 # NVLink data CRC Error Counter for Lane 6
686
+ )
687
+ NVML_FI_DEV_NVLINK_CRC_DATA_ERROR_COUNT_L7 = (
688
+ 103 # NVLink data CRC Error Counter for Lane 7
689
+ )
690
+ NVML_FI_DEV_NVLINK_CRC_DATA_ERROR_COUNT_L8 = (
691
+ 104 # NVLink data CRC Error Counter for Lane 8
692
+ )
693
+ NVML_FI_DEV_NVLINK_CRC_DATA_ERROR_COUNT_L9 = (
694
+ 105 # NVLink data CRC Error Counter for Lane 9
695
+ )
696
+ NVML_FI_DEV_NVLINK_CRC_DATA_ERROR_COUNT_L10 = (
697
+ 106 # NVLink data CRC Error Counter for Lane 10
698
+ )
699
+ NVML_FI_DEV_NVLINK_CRC_DATA_ERROR_COUNT_L11 = (
700
+ 107 # NVLink data CRC Error Counter for Lane 11
701
+ )
702
+
703
+ # NvLink Replay Error Counters
704
+ NVML_FI_DEV_NVLINK_REPLAY_ERROR_COUNT_L6 = 108 # NVLink Replay Error Counter for Lane 6
705
+ NVML_FI_DEV_NVLINK_REPLAY_ERROR_COUNT_L7 = 109 # NVLink Replay Error Counter for Lane 7
706
+ NVML_FI_DEV_NVLINK_REPLAY_ERROR_COUNT_L8 = 110 # NVLink Replay Error Counter for Lane 8
707
+ NVML_FI_DEV_NVLINK_REPLAY_ERROR_COUNT_L9 = 111 # NVLink Replay Error Counter for Lane 9
708
+ NVML_FI_DEV_NVLINK_REPLAY_ERROR_COUNT_L10 = (
709
+ 112 # NVLink Replay Error Counter for Lane 10
710
+ )
711
+ NVML_FI_DEV_NVLINK_REPLAY_ERROR_COUNT_L11 = (
712
+ 113 # NVLink Replay Error Counter for Lane 11
713
+ )
714
+
715
+ # NvLink Recovery Error Counters
716
+ NVML_FI_DEV_NVLINK_RECOVERY_ERROR_COUNT_L6 = (
717
+ 114 # NVLink Recovery Error Counter for Lane 6
718
+ )
719
+ NVML_FI_DEV_NVLINK_RECOVERY_ERROR_COUNT_L7 = (
720
+ 115 # NVLink Recovery Error Counter for Lane 7
721
+ )
722
+ NVML_FI_DEV_NVLINK_RECOVERY_ERROR_COUNT_L8 = (
723
+ 116 # NVLink Recovery Error Counter for Lane 8
724
+ )
725
+ NVML_FI_DEV_NVLINK_RECOVERY_ERROR_COUNT_L9 = (
726
+ 117 # NVLink Recovery Error Counter for Lane 9
727
+ )
728
+ NVML_FI_DEV_NVLINK_RECOVERY_ERROR_COUNT_L10 = (
729
+ 118 # NVLink Recovery Error Counter for Lane 10
730
+ )
731
+ NVML_FI_DEV_NVLINK_RECOVERY_ERROR_COUNT_L11 = (
732
+ 119 # NVLink Recovery Error Counter for Lane 11
733
+ )
734
+
735
+ # NvLink Bandwidth Counters
736
+ NVML_FI_DEV_NVLINK_BANDWIDTH_C0_L6 = (
737
+ 120 # NVLink Bandwidth Counter for Counter Set 0, Lane 6
738
+ )
739
+ NVML_FI_DEV_NVLINK_BANDWIDTH_C0_L7 = (
740
+ 121 # NVLink Bandwidth Counter for Counter Set 0, Lane 7
741
+ )
742
+ NVML_FI_DEV_NVLINK_BANDWIDTH_C0_L8 = (
743
+ 122 # NVLink Bandwidth Counter for Counter Set 0, Lane 8
744
+ )
745
+ NVML_FI_DEV_NVLINK_BANDWIDTH_C0_L9 = (
746
+ 123 # NVLink Bandwidth Counter for Counter Set 0, Lane 9
747
+ )
748
+ NVML_FI_DEV_NVLINK_BANDWIDTH_C0_L10 = (
749
+ 124 # NVLink Bandwidth Counter for Counter Set 0, Lane 10
750
+ )
751
+ NVML_FI_DEV_NVLINK_BANDWIDTH_C0_L11 = (
752
+ 125 # NVLink Bandwidth Counter for Counter Set 0, Lane 11
753
+ )
754
+
755
+ # NvLink Bandwidth Counters
756
+ NVML_FI_DEV_NVLINK_BANDWIDTH_C1_L6 = (
757
+ 126 # NVLink Bandwidth Counter for Counter Set 1, Lane 6
758
+ )
759
+ NVML_FI_DEV_NVLINK_BANDWIDTH_C1_L7 = (
760
+ 127 # NVLink Bandwidth Counter for Counter Set 1, Lane 7
761
+ )
762
+ NVML_FI_DEV_NVLINK_BANDWIDTH_C1_L8 = (
763
+ 128 # NVLink Bandwidth Counter for Counter Set 1, Lane 8
764
+ )
765
+ NVML_FI_DEV_NVLINK_BANDWIDTH_C1_L9 = (
766
+ 129 # NVLink Bandwidth Counter for Counter Set 1, Lane 9
767
+ )
768
+ NVML_FI_DEV_NVLINK_BANDWIDTH_C1_L10 = (
769
+ 130 # NVLink Bandwidth Counter for Counter Set 1, Lane 10
770
+ )
771
+ NVML_FI_DEV_NVLINK_BANDWIDTH_C1_L11 = (
772
+ 131 # NVLink Bandwidth Counter for Counter Set 1, Lane 11
773
+ )
774
+
775
+ # NVLink Speed
776
+ NVML_FI_DEV_NVLINK_SPEED_MBPS_L6 = 132
777
+ NVML_FI_DEV_NVLINK_SPEED_MBPS_L7 = 133
778
+ NVML_FI_DEV_NVLINK_SPEED_MBPS_L8 = 134
779
+ NVML_FI_DEV_NVLINK_SPEED_MBPS_L9 = 135
780
+ NVML_FI_DEV_NVLINK_SPEED_MBPS_L10 = 136
781
+ NVML_FI_DEV_NVLINK_SPEED_MBPS_L11 = 137
782
+
783
+ # NVLink Throughput Counters
784
+ NVML_FI_DEV_NVLINK_THROUGHPUT_DATA_TX = 138 # NVLink TX Data throughput in KiB
785
+ NVML_FI_DEV_NVLINK_THROUGHPUT_DATA_RX = 139 # NVLink RX Data throughput in KiB
786
+ NVML_FI_DEV_NVLINK_THROUGHPUT_RAW_TX = 140 # NVLink TX Data + protocol overhead in KiB
787
+ NVML_FI_DEV_NVLINK_THROUGHPUT_RAW_RX = 141 # NVLink RX Data + protocol overhead in KiB
788
+
789
+ # Row Remapper
790
+ NVML_FI_DEV_REMAPPED_COR = 142
791
+ NVML_FI_DEV_REMAPPED_UNC = 143
792
+ NVML_FI_DEV_REMAPPED_PENDING = 144
793
+ NVML_FI_DEV_REMAPPED_FAILURE = 145
794
+
795
+ # Remote device NVLink ID
796
+ NVML_FI_DEV_NVLINK_REMOTE_NVLINK_ID = 146
797
+
798
+ # Number of NVLinks connected to NVSwitch
799
+ NVML_FI_DEV_NVSWITCH_CONNECTED_LINK_COUNT = 147
800
+
801
+ # NvLink ECC Data Error Counters
802
+ NVML_FI_DEV_NVLINK_ECC_DATA_ERROR_COUNT_L0 = (
803
+ 148 # < NVLink data ECC Error Counter for Link 0
804
+ )
805
+ NVML_FI_DEV_NVLINK_ECC_DATA_ERROR_COUNT_L1 = (
806
+ 149 # < NVLink data ECC Error Counter for Link 1
807
+ )
808
+ NVML_FI_DEV_NVLINK_ECC_DATA_ERROR_COUNT_L2 = (
809
+ 150 # < NVLink data ECC Error Counter for Link 2
810
+ )
811
+ NVML_FI_DEV_NVLINK_ECC_DATA_ERROR_COUNT_L3 = (
812
+ 151 # < NVLink data ECC Error Counter for Link 3
813
+ )
814
+ NVML_FI_DEV_NVLINK_ECC_DATA_ERROR_COUNT_L4 = (
815
+ 152 # < NVLink data ECC Error Counter for Link 4
816
+ )
817
+ NVML_FI_DEV_NVLINK_ECC_DATA_ERROR_COUNT_L5 = (
818
+ 153 # < NVLink data ECC Error Counter for Link 5
819
+ )
820
+ NVML_FI_DEV_NVLINK_ECC_DATA_ERROR_COUNT_L6 = (
821
+ 154 # < NVLink data ECC Error Counter for Link 6
822
+ )
823
+ NVML_FI_DEV_NVLINK_ECC_DATA_ERROR_COUNT_L7 = (
824
+ 155 # < NVLink data ECC Error Counter for Link 7
825
+ )
826
+ NVML_FI_DEV_NVLINK_ECC_DATA_ERROR_COUNT_L8 = (
827
+ 156 # < NVLink data ECC Error Counter for Link 8
828
+ )
829
+ NVML_FI_DEV_NVLINK_ECC_DATA_ERROR_COUNT_L9 = (
830
+ 157 # < NVLink data ECC Error Counter for Link 9
831
+ )
832
+ NVML_FI_DEV_NVLINK_ECC_DATA_ERROR_COUNT_L10 = (
833
+ 158 # < NVLink data ECC Error Counter for Link 10
834
+ )
835
+ NVML_FI_DEV_NVLINK_ECC_DATA_ERROR_COUNT_L11 = (
836
+ 159 # < NVLink data ECC Error Counter for Link 11
837
+ )
838
+ NVML_FI_DEV_NVLINK_ECC_DATA_ERROR_COUNT_TOTAL = (
839
+ 160 # < NvLink data ECC Error Counter total for all Links
840
+ )
841
+
842
+ NVML_FI_MAX = 161 # One greater than the largest field ID defined above
843
+
844
+ ## Enums needed for the method nvmlDeviceGetVirtualizationMode and nvmlDeviceSetVirtualizationMode
845
+ NVML_GPU_VIRTUALIZATION_MODE_NONE = 0 # Represents Bare Metal GPU
846
+ NVML_GPU_VIRTUALIZATION_MODE_PASSTHROUGH = (
847
+ 1 # Device is associated with GPU-Passthorugh
848
+ )
849
+ NVML_GPU_VIRTUALIZATION_MODE_VGPU = (
850
+ 2 # Device is associated with vGPU inside virtual machine.
851
+ )
852
+ NVML_GPU_VIRTUALIZATION_MODE_HOST_VGPU = (
853
+ 3 # Device is associated with VGX hypervisor in vGPU mode
854
+ )
855
+ NVML_GPU_VIRTUALIZATION_MODE_HOST_VSGA = (
856
+ 4 # Device is associated with VGX hypervisor in vSGA mode
857
+ )
858
+
859
+ ## Lib loading ##
860
+ nvmlLib = None
861
+ libLoadLock = threading.Lock()
862
+ _nvmlLib_refcount = 0 # Incremented on each nvmlInit and decremented on nvmlShutdown
863
+
864
+ ## vGPU Management
865
+ _nvmlVgpuTypeId_t = c_uint
866
+ _nvmlVgpuInstance_t = c_uint
867
+
868
+ _nvmlVgpuVmIdType_t = c_uint
869
+ NVML_VGPU_VM_ID_DOMAIN_ID = 0
870
+ NVML_VGPU_VM_ID_UUID = 1
871
+
872
+ _nvmlGridLicenseFeatureCode_t = c_uint
873
+ NVML_GRID_LICENSE_FEATURE_CODE_UNKNOWN = 0
874
+ NVML_GRID_LICENSE_FEATURE_CODE_VGPU = 1
875
+ NVML_GRID_LICENSE_FEATURE_CODE_NVIDIA_RTX = 2
876
+ NVML_GRID_LICENSE_FEATURE_CODE_VWORKSTATION = (
877
+ 2 # deprecated, use NVML_GRID_LICENSE_FEATURE_CODE_NVIDIA_RTX.
878
+ )
879
+ NVML_GRID_LICENSE_FEATURE_CODE_GAMING = 3
880
+ NVML_GRID_LICENSE_FEATURE_CODE_COMPUTE = 4
881
+
882
+ _nvmlGridLicenseExpiryStatus_t = c_uint8
883
+ NVML_GRID_LICENSE_EXPIRY_NOT_AVAILABLE = (0,) # Expiry information not available
884
+ NVML_GRID_LICENSE_EXPIRY_INVALID = (1,) # Invalid expiry or error fetching expiry
885
+ NVML_GRID_LICENSE_EXPIRY_VALID = (2,) # Valid expiry
886
+ NVML_GRID_LICENSE_EXPIRY_NOT_APPLICABLE = (3,) # Expiry not applicable
887
+ NVML_GRID_LICENSE_EXPIRY_PERMANENT = (4,) # Permanent expiry
888
+
889
+ _nvmlVgpuCapability_t = c_uint
890
+ NVML_VGPU_CAP_NVLINK_P2P = 0 # vGPU P2P over NVLink is supported
891
+ NVML_VGPU_CAP_GPUDIRECT = 1 # GPUDirect capability is supported
892
+ NVML_VGPU_CAP_COUNT = 2
893
+
894
+ _nvmlVgpuGuestInfoState_t = c_uint
895
+ NVML_VGPU_INSTANCE_GUEST_INFO_STATE_UNINITIALIZED = 0
896
+ NVML_VGPU_INSTANCE_GUEST_INFO_STATE_INITIALIZED = 1
897
+
898
+ _nvmlVgpuVmCompatibility_t = c_uint
899
+ NVML_VGPU_VM_COMPATIBILITY_NONE = 0x0
900
+ NVML_VGPU_VM_COMPATIBILITY_COLD = 0x1
901
+ NVML_VGPU_VM_COMPATIBILITY_HIBERNATE = 0x2
902
+ NVML_VGPU_VM_COMPATIBILITY_SLEEP = 0x4
903
+ NVML_VGPU_VM_COMPATIBILITY_LIVE = 0x8
904
+
905
+ _nvmlVgpuPgpuCompatibilityLimitCode_t = c_uint
906
+ NVML_VGPU_COMPATIBILITY_LIMIT_NONE = 0x0
907
+ NVML_VGPU_COMPATIBILITY_LIMIT_HOST_DRIVER = 0x1
908
+ NVML_VGPU_COMPATIBILITY_LIMIT_GUEST_DRIVER = 0x2
909
+ NVML_VGPU_COMPATIBILITY_LIMIT_GPU = 0x4
910
+ NVML_VGPU_COMPATIBILITY_LIMIT_OTHER = 0x80000000
911
+
912
+ _nvmlHostVgpuMode_t = c_uint
913
+ NVML_HOST_VGPU_MODE_NON_SRIOV = 0
914
+ NVML_HOST_VGPU_MODE_SRIOV = 1
915
+
916
+ # GSP firmware
917
+ NVML_GSP_FIRMWARE_VERSION_BUF_SIZE = 0x40
918
+
919
+
920
+ ## Error Checking ##
921
+ class NVMLError(Exception):
922
+ _valClassMapping = dict() # type: ignore
923
+ # List of currently known error codes
924
+ _errcode_to_string = {
925
+ NVML_ERROR_UNINITIALIZED: "Uninitialized",
926
+ NVML_ERROR_INVALID_ARGUMENT: "Invalid Argument",
927
+ NVML_ERROR_NOT_SUPPORTED: "Not Supported",
928
+ NVML_ERROR_NO_PERMISSION: "Insufficient Permissions",
929
+ NVML_ERROR_ALREADY_INITIALIZED: "Already Initialized",
930
+ NVML_ERROR_NOT_FOUND: "Not Found",
931
+ NVML_ERROR_INSUFFICIENT_SIZE: "Insufficient Size",
932
+ NVML_ERROR_INSUFFICIENT_POWER: "Insufficient External Power",
933
+ NVML_ERROR_DRIVER_NOT_LOADED: "Driver Not Loaded",
934
+ NVML_ERROR_TIMEOUT: "Timeout",
935
+ NVML_ERROR_IRQ_ISSUE: "Interrupt Request Issue",
936
+ NVML_ERROR_LIBRARY_NOT_FOUND: "NVML Shared Library Not Found",
937
+ NVML_ERROR_FUNCTION_NOT_FOUND: "Function Not Found",
938
+ NVML_ERROR_CORRUPTED_INFOROM: "Corrupted infoROM",
939
+ NVML_ERROR_GPU_IS_LOST: "GPU is lost",
940
+ NVML_ERROR_RESET_REQUIRED: "GPU requires restart",
941
+ NVML_ERROR_OPERATING_SYSTEM: "The operating system has blocked the request.",
942
+ NVML_ERROR_LIB_RM_VERSION_MISMATCH: "RM has detected an NVML/RM version mismatch.",
943
+ NVML_ERROR_MEMORY: "Insufficient Memory",
944
+ NVML_ERROR_UNKNOWN: "Unknown Error",
945
+ }
946
+
947
+ def __new__(typ, value):
948
+ """
949
+ Maps value to a proper subclass of NVMLError.
950
+ See _extractNVMLErrorsAsClasses function for more details
951
+ """
952
+ if typ == NVMLError:
953
+ typ = NVMLError._valClassMapping.get(value, typ)
954
+ obj = Exception.__new__(typ)
955
+ obj.value = value
956
+ return obj
957
+
958
+ def __str__(self):
959
+ try:
960
+ if self.value not in NVMLError._errcode_to_string:
961
+ NVMLError._errcode_to_string[self.value] = str(
962
+ nvmlErrorString(self.value)
963
+ )
964
+ return NVMLError._errcode_to_string[self.value]
965
+ except NVMLError:
966
+ return "NVML Error with code %d" % self.value
967
+
968
+ def __eq__(self, other):
969
+ return self.value == other.value
970
+
971
+
972
+ def nvmlExceptionClass(nvmlErrorCode):
973
+ if nvmlErrorCode not in NVMLError._valClassMapping:
974
+ raise ValueError("nvmlErrorCode %s is not valid" % nvmlErrorCode)
975
+ return NVMLError._valClassMapping[nvmlErrorCode]
976
+
977
+
978
+ def _extractNVMLErrorsAsClasses():
979
+ """
980
+ Generates a hierarchy of classes on top of NVMLError class.
981
+
982
+ Each NVML Error gets a new NVMLError subclass. This way try,except blocks can filter appropriate
983
+ exceptions more easily.
984
+
985
+ NVMLError is a parent class. Each NVML_ERROR_* gets it's own subclass.
986
+ e.g. NVML_ERROR_ALREADY_INITIALIZED will be turned into NVMLError_AlreadyInitialized
987
+ """
988
+ this_module = sys.modules[__name__]
989
+ nvmlErrorsNames = [x for x in dir(this_module) if x.startswith("NVML_ERROR_")]
990
+ for err_name in nvmlErrorsNames:
991
+ # e.g. Turn NVML_ERROR_ALREADY_INITIALIZED into NVMLError_AlreadyInitialized
992
+ class_name = "NVMLError_" + string.capwords(
993
+ err_name.replace("NVML_ERROR_", ""), "_"
994
+ ).replace("_", "")
995
+ err_val = getattr(this_module, err_name)
996
+
997
+ def gen_new(val):
998
+ def new(typ):
999
+ obj = NVMLError.__new__(typ, val)
1000
+ return obj
1001
+
1002
+ return new
1003
+
1004
+ new_error_class = type(class_name, (NVMLError,), {"__new__": gen_new(err_val)})
1005
+ new_error_class.__module__ = __name__
1006
+ setattr(this_module, class_name, new_error_class)
1007
+ NVMLError._valClassMapping[err_val] = new_error_class
1008
+
1009
+
1010
+ _extractNVMLErrorsAsClasses()
1011
+
1012
+
1013
+ def _nvmlCheckReturn(ret):
1014
+ if ret != NVML_SUCCESS:
1015
+ raise NVMLError(ret)
1016
+ return ret
1017
+
1018
+
1019
+ ## Function access ##
1020
+ _nvmlGetFunctionPointer_cache = ( # type: ignore
1021
+ dict()
1022
+ ) # function pointers are cached to prevent unnecessary libLoadLock locking
1023
+
1024
+
1025
+ def _nvmlGetFunctionPointer(name):
1026
+ global nvmlLib
1027
+
1028
+ if name in _nvmlGetFunctionPointer_cache:
1029
+ return _nvmlGetFunctionPointer_cache[name]
1030
+
1031
+ libLoadLock.acquire()
1032
+ try:
1033
+ # ensure library was loaded
1034
+ if nvmlLib == None:
1035
+ raise NVMLError(NVML_ERROR_UNINITIALIZED)
1036
+ try:
1037
+ _nvmlGetFunctionPointer_cache[name] = getattr(nvmlLib, name)
1038
+ return _nvmlGetFunctionPointer_cache[name]
1039
+ except AttributeError:
1040
+ raise NVMLError(NVML_ERROR_FUNCTION_NOT_FOUND)
1041
+ finally:
1042
+ # lock is always freed
1043
+ libLoadLock.release()
1044
+
1045
+
1046
+ ## Alternative object
1047
+ # Allows the object to be printed
1048
+ # Allows mismatched types to be assigned
1049
+ # - like None when the Structure variant requires c_uint
1050
+ class nvmlFriendlyObject:
1051
+ def __init__(self, dictionary):
1052
+ for x in dictionary:
1053
+ setattr(self, x, dictionary[x])
1054
+
1055
+ def __str__(self):
1056
+ return self.__dict__.__str__()
1057
+
1058
+
1059
+ def nvmlStructToFriendlyObject(struct):
1060
+ d = {}
1061
+ for x in struct._fields_:
1062
+ key = x[0]
1063
+ value = getattr(struct, key)
1064
+ # only need to convert from bytes if bytes, no need to check python version.
1065
+ d[key] = value.decode() if isinstance(value, bytes) else value
1066
+ obj = nvmlFriendlyObject(d)
1067
+ return obj
1068
+
1069
+
1070
+ # pack the object so it can be passed to the NVML library
1071
+ def nvmlFriendlyObjectToStruct(obj, model):
1072
+ for x in model._fields_:
1073
+ key = x[0]
1074
+ value = obj.__dict__[key]
1075
+ # any c_char_p in python3 needs to be bytes, default encoding works fine.
1076
+ setattr(model, key, value.encode())
1077
+ return model
1078
+
1079
+
1080
+ ## Unit structures
1081
+ class struct_c_nvmlUnit_t(Structure):
1082
+ pass # opaque handle
1083
+
1084
+
1085
+ c_nvmlUnit_t = POINTER(struct_c_nvmlUnit_t)
1086
+
1087
+
1088
+ class _PrintableStructure(Structure):
1089
+ """
1090
+ Abstract class that produces nicer __str__ output than ctypes.Structure.
1091
+ e.g. instead of:
1092
+ >>> print str(obj)
1093
+ <class_name object at 0x7fdf82fef9e0>
1094
+ this class will print
1095
+ class_name(field_name: formatted_value, field_name: formatted_value)
1096
+
1097
+ _fmt_ dictionary of <str _field_ name> -> <str format>
1098
+ e.g. class that has _field_ 'hex_value', c_uint could be formatted with
1099
+ _fmt_ = {"hex_value" : "%08X"}
1100
+ to produce nicer output.
1101
+ Default fomratting string for all fields can be set with key "<default>" like:
1102
+ _fmt_ = {"<default>" : "%d MHz"} # e.g all values are numbers in MHz.
1103
+ If not set it's assumed to be just "%s"
1104
+
1105
+ Exact format of returned str from this class is subject to change in the future.
1106
+ """
1107
+
1108
+ _fmt_ = {} # type: ignore
1109
+
1110
+ def __str__(self):
1111
+ result = []
1112
+ for x in self._fields_:
1113
+ key = x[0]
1114
+ value = getattr(self, key)
1115
+ fmt = "%s"
1116
+ if key in self._fmt_:
1117
+ fmt = self._fmt_[key]
1118
+ elif "<default>" in self._fmt_:
1119
+ fmt = self._fmt_["<default>"]
1120
+ result.append(("%s: " + fmt) % (key, value))
1121
+ return self.__class__.__name__ + "(" + ", ".join(result) + ")"
1122
+
1123
+ def __getattribute__(self, name):
1124
+ res = super().__getattribute__(name)
1125
+ # need to convert bytes to unicode for python3 don't need to for python2
1126
+ # Python 2 strings are of both str and bytes
1127
+ # Python 3 strings are not of type bytes
1128
+ # ctypes should convert everything to the correct values otherwise
1129
+ if isinstance(res, bytes):
1130
+ if isinstance(res, str):
1131
+ return res
1132
+ return res.decode()
1133
+ return res
1134
+
1135
+ def __setattr__(self, name, value):
1136
+ if isinstance(value, str):
1137
+ # encoding a python2 string returns the same value, since python2 strings are bytes already
1138
+ # bytes passed in python3 will be ignored.
1139
+ value = value.encode()
1140
+ super().__setattr__(name, value)
1141
+
1142
+
1143
+ class c_nvmlUnitInfo_t(_PrintableStructure):
1144
+ _fields_ = [
1145
+ ("name", c_char * 96),
1146
+ ("id", c_char * 96),
1147
+ ("serial", c_char * 96),
1148
+ ("firmwareVersion", c_char * 96),
1149
+ ]
1150
+
1151
+
1152
+ class c_nvmlLedState_t(_PrintableStructure):
1153
+ _fields_ = [
1154
+ ("cause", c_char * 256),
1155
+ ("color", _nvmlLedColor_t),
1156
+ ]
1157
+
1158
+
1159
+ class c_nvmlPSUInfo_t(_PrintableStructure):
1160
+ _fields_ = [
1161
+ ("state", c_char * 256),
1162
+ ("current", c_uint),
1163
+ ("voltage", c_uint),
1164
+ ("power", c_uint),
1165
+ ]
1166
+
1167
+
1168
+ class c_nvmlUnitFanInfo_t(_PrintableStructure):
1169
+ _fields_ = [
1170
+ ("speed", c_uint),
1171
+ ("state", _nvmlFanState_t),
1172
+ ]
1173
+
1174
+
1175
+ class c_nvmlUnitFanSpeeds_t(_PrintableStructure):
1176
+ _fields_ = [("fans", c_nvmlUnitFanInfo_t * 24), ("count", c_uint)]
1177
+
1178
+
1179
+ ## Device structures
1180
+ class struct_c_nvmlDevice_t(Structure):
1181
+ pass # opaque handle
1182
+
1183
+
1184
+ c_nvmlDevice_t = POINTER(struct_c_nvmlDevice_t)
1185
+
1186
+
1187
+ # Legacy pciInfo used for _v1 and _v2
1188
+ class nvmlPciInfo_v2_t(_PrintableStructure):
1189
+ _fields_ = [
1190
+ ("busId", c_char * NVML_DEVICE_PCI_BUS_ID_BUFFER_V2_SIZE),
1191
+ ("domain", c_uint),
1192
+ ("bus", c_uint),
1193
+ ("device", c_uint),
1194
+ ("pciDeviceId", c_uint),
1195
+ # Added in 2.285
1196
+ ("pciSubSystemId", c_uint),
1197
+ ("reserved0", c_uint),
1198
+ ("reserved1", c_uint),
1199
+ ("reserved2", c_uint),
1200
+ ("reserved3", c_uint),
1201
+ ]
1202
+ _fmt_ = {
1203
+ "domain": "0x%04X",
1204
+ "bus": "0x%02X",
1205
+ "device": "0x%02X",
1206
+ "pciDeviceId": "0x%08X",
1207
+ "pciSubSystemId": "0x%08X",
1208
+ }
1209
+
1210
+
1211
+ class nvmlPciInfo_t(_PrintableStructure):
1212
+ _fields_ = [
1213
+ # Moved to the new busId location below
1214
+ ("busIdLegacy", c_char * NVML_DEVICE_PCI_BUS_ID_BUFFER_V2_SIZE),
1215
+ ("domain", c_uint),
1216
+ ("bus", c_uint),
1217
+ ("device", c_uint),
1218
+ ("pciDeviceId", c_uint),
1219
+ # Added in 2.285
1220
+ ("pciSubSystemId", c_uint),
1221
+ # New busId replaced the long deprecated and reserved fields with a
1222
+ # field of the same size in 9.0
1223
+ ("busId", c_char * NVML_DEVICE_PCI_BUS_ID_BUFFER_SIZE),
1224
+ ]
1225
+ _fmt_ = {
1226
+ "domain": "0x%08X",
1227
+ "bus": "0x%02X",
1228
+ "device": "0x%02X",
1229
+ "pciDeviceId": "0x%08X",
1230
+ "pciSubSystemId": "0x%08X",
1231
+ }
1232
+
1233
+
1234
+ class c_nvmlExcludedDeviceInfo_t(_PrintableStructure):
1235
+ _fields_ = [("pci", nvmlPciInfo_t), ("uuid", c_char * NVML_DEVICE_UUID_BUFFER_SIZE)]
1236
+
1237
+
1238
+ class nvmlNvLinkUtilizationControl_t(_PrintableStructure):
1239
+ _fields_ = [
1240
+ ("units", _nvmlNvLinkUtilizationCountUnits_t),
1241
+ ("pktfilter", _nvmlNvLinkUtilizationCountPktTypes_t),
1242
+ ]
1243
+
1244
+
1245
+ class c_nvmlMemory_t(_PrintableStructure):
1246
+ _fields_ = [
1247
+ ("total", c_ulonglong),
1248
+ ("free", c_ulonglong),
1249
+ ("used", c_ulonglong),
1250
+ ]
1251
+ _fmt_ = {"<default>": "%d B"}
1252
+
1253
+
1254
+ class c_nvmlMemory_v2_t(_PrintableStructure):
1255
+ _fields_ = [
1256
+ ("version", c_uint),
1257
+ ("total", c_ulonglong),
1258
+ ("reserved", c_ulonglong),
1259
+ ("free", c_ulonglong),
1260
+ ("used", c_ulonglong),
1261
+ ]
1262
+ _fmt_ = {"<default>": "%d B"}
1263
+
1264
+
1265
+ nvmlMemory_v2 = 0x02000028
1266
+
1267
+
1268
+ class c_nvmlBAR1Memory_t(_PrintableStructure):
1269
+ _fields_ = [
1270
+ ("bar1Total", c_ulonglong),
1271
+ ("bar1Free", c_ulonglong),
1272
+ ("bar1Used", c_ulonglong),
1273
+ ]
1274
+ _fmt_ = {"<default>": "%d B"}
1275
+
1276
+
1277
+ class nvmlClkMonFaultInfo_t(Structure):
1278
+ _fields_ = [("clkApiDomain", c_uint), ("clkDomainFaultMask", c_uint)]
1279
+
1280
+
1281
+ class nvmlClkMonStatus_t(Structure):
1282
+ _fields_ = [
1283
+ ("bGlobalStatus", c_uint),
1284
+ ("clkMonListSize", c_uint),
1285
+ ("clkMonList", nvmlClkMonFaultInfo_t),
1286
+ ]
1287
+
1288
+
1289
+ # On Windows with the WDDM driver, usedGpuMemory is reported as None
1290
+ # Code that processes this structure should check for None, I.E.
1291
+ #
1292
+ # if (info.usedGpuMemory == None):
1293
+ # # TODO handle the error
1294
+ # pass
1295
+ # else:
1296
+ # print("Using %d MiB of memory" % (info.usedGpuMemory / 1024 / 1024))
1297
+ # endif
1298
+ #
1299
+ # See NVML documentation for more information
1300
+ class c_nvmlProcessInfo_t(_PrintableStructure):
1301
+ _fields_ = [
1302
+ ("pid", c_uint),
1303
+ ("usedGpuMemory", c_ulonglong),
1304
+ ("gpuInstanceId", c_uint),
1305
+ ("computeInstanceId", c_uint),
1306
+ ]
1307
+ _fmt_ = {
1308
+ "usedGpuMemory": "%d B",
1309
+ }
1310
+
1311
+
1312
+ class c_nvmlBridgeChipInfo_t(_PrintableStructure):
1313
+ _fields_ = [
1314
+ ("type", _nvmlBridgeChipType_t),
1315
+ ("fwVersion", c_uint),
1316
+ ]
1317
+
1318
+
1319
+ class c_nvmlBridgeChipHierarchy_t(_PrintableStructure):
1320
+ _fields_ = [
1321
+ ("bridgeCount", c_uint),
1322
+ ("bridgeChipInfo", c_nvmlBridgeChipInfo_t * 128),
1323
+ ]
1324
+
1325
+
1326
+ class c_nvmlEccErrorCounts_t(_PrintableStructure):
1327
+ _fields_ = [
1328
+ ("l1Cache", c_ulonglong),
1329
+ ("l2Cache", c_ulonglong),
1330
+ ("deviceMemory", c_ulonglong),
1331
+ ("registerFile", c_ulonglong),
1332
+ ]
1333
+
1334
+
1335
+ class c_nvmlUtilization_t(_PrintableStructure):
1336
+ _fields_ = [
1337
+ ("gpu", c_uint),
1338
+ ("memory", c_uint),
1339
+ ]
1340
+ _fmt_ = {"<default>": "%d %%"}
1341
+
1342
+
1343
+ # Added in 2.285
1344
+ class c_nvmlHwbcEntry_t(_PrintableStructure):
1345
+ _fields_ = [
1346
+ ("hwbcId", c_uint),
1347
+ ("firmwareVersion", c_char * 32),
1348
+ ]
1349
+
1350
+
1351
+ class c_nvmlValue_t(Union):
1352
+ _fields_ = [
1353
+ ("dVal", c_double),
1354
+ ("uiVal", c_uint),
1355
+ ("ulVal", c_ulong),
1356
+ ("ullVal", c_ulonglong),
1357
+ ("sllVal", c_longlong),
1358
+ ]
1359
+
1360
+
1361
+ class c_nvmlSample_t(_PrintableStructure):
1362
+ _fields_ = [
1363
+ ("timeStamp", c_ulonglong),
1364
+ ("sampleValue", c_nvmlValue_t),
1365
+ ]
1366
+
1367
+
1368
+ class c_nvmlViolationTime_t(_PrintableStructure):
1369
+ _fields_ = [
1370
+ ("referenceTime", c_ulonglong),
1371
+ ("violationTime", c_ulonglong),
1372
+ ]
1373
+
1374
+
1375
+ class c_nvmlFieldValue_t(_PrintableStructure):
1376
+ _fields_ = [
1377
+ ("fieldId", c_uint32),
1378
+ ("scopeId", c_uint32),
1379
+ ("timestamp", c_int64),
1380
+ ("latencyUsec", c_int64),
1381
+ ("valueType", _nvmlValueType_t),
1382
+ ("nvmlReturn", _nvmlReturn_t),
1383
+ ("value", c_nvmlValue_t),
1384
+ ]
1385
+
1386
+
1387
+ class c_nvmlVgpuInstanceUtilizationSample_t(_PrintableStructure):
1388
+ _fields_ = [
1389
+ ("vgpuInstance", _nvmlVgpuInstance_t),
1390
+ ("timeStamp", c_ulonglong),
1391
+ ("smUtil", c_nvmlValue_t),
1392
+ ("memUtil", c_nvmlValue_t),
1393
+ ("encUtil", c_nvmlValue_t),
1394
+ ("decUtil", c_nvmlValue_t),
1395
+ ]
1396
+
1397
+
1398
+ class c_nvmlVgpuProcessUtilizationSample_t(_PrintableStructure):
1399
+ _fields_ = [
1400
+ ("vgpuInstance", _nvmlVgpuInstance_t),
1401
+ ("pid", c_uint),
1402
+ ("processName", c_char * NVML_VGPU_NAME_BUFFER_SIZE),
1403
+ ("timeStamp", c_ulonglong),
1404
+ ("smUtil", c_uint),
1405
+ ("memUtil", c_uint),
1406
+ ("encUtil", c_uint),
1407
+ ("decUtil", c_uint),
1408
+ ]
1409
+
1410
+
1411
+ class c_nvmlVgpuLicenseExpiry_t(_PrintableStructure):
1412
+ _fields_ = [
1413
+ ("year", c_uint32),
1414
+ ("month", c_uint16),
1415
+ ("day", c_uint16),
1416
+ ("hour", c_uint16),
1417
+ ("min", c_uint16),
1418
+ ("sec", c_uint16),
1419
+ ("status", c_uint8),
1420
+ ]
1421
+
1422
+
1423
+ NVML_GRID_LICENSE_STATE_UNKNOWN = 0
1424
+ NVML_GRID_LICENSE_STATE_UNINITIALIZED = 1
1425
+ NVML_GRID_LICENSE_STATE_UNLICENSED_UNRESTRICTED = 2
1426
+ NVML_GRID_LICENSE_STATE_UNLICENSED_RESTRICTED = 3
1427
+ NVML_GRID_LICENSE_STATE_UNLICENSED = 4
1428
+ NVML_GRID_LICENSE_STATE_LICENSED = 5
1429
+
1430
+
1431
+ class c_nvmlVgpuLicenseInfo_t(_PrintableStructure):
1432
+ _fields_ = [
1433
+ ("isLicensed", c_uint8),
1434
+ ("licenseExpiry", c_nvmlVgpuLicenseExpiry_t),
1435
+ ("currentState", c_uint),
1436
+ ]
1437
+
1438
+
1439
+ class c_nvmlEncoderSession_t(_PrintableStructure):
1440
+ _fields_ = [
1441
+ ("sessionId", c_uint),
1442
+ ("pid", c_uint),
1443
+ ("vgpuInstance", _nvmlVgpuInstance_t),
1444
+ ("codecType", c_uint),
1445
+ ("hResolution", c_uint),
1446
+ ("vResolution", c_uint),
1447
+ ("averageFps", c_uint),
1448
+ ("encodeLatency", c_uint),
1449
+ ]
1450
+
1451
+
1452
+ class c_nvmlProcessUtilizationSample_t(_PrintableStructure):
1453
+ _fields_ = [
1454
+ ("pid", c_uint),
1455
+ ("timeStamp", c_ulonglong),
1456
+ ("smUtil", c_uint),
1457
+ ("memUtil", c_uint),
1458
+ ("encUtil", c_uint),
1459
+ ("decUtil", c_uint),
1460
+ ]
1461
+
1462
+
1463
+ class c_nvmlGridLicenseExpiry_t(_PrintableStructure):
1464
+ _fields_ = [
1465
+ ("year", c_uint32),
1466
+ ("month", c_uint16),
1467
+ ("day", c_uint16),
1468
+ ("hour", c_uint16),
1469
+ ("min", c_uint16),
1470
+ ("sec", c_uint16),
1471
+ ("status", c_uint8),
1472
+ ]
1473
+
1474
+
1475
+ class c_nvmlGridLicensableFeature_v4_t(_PrintableStructure):
1476
+ _fields_ = [
1477
+ ("featureCode", _nvmlGridLicenseFeatureCode_t),
1478
+ ("featureState", c_uint),
1479
+ ("licenseInfo", c_char * NVML_GRID_LICENSE_BUFFER_SIZE),
1480
+ ("productName", c_char * NVML_GRID_LICENSE_BUFFER_SIZE),
1481
+ ("featureEnabled", c_uint),
1482
+ ("licenseExpiry", c_nvmlGridLicenseExpiry_t),
1483
+ ]
1484
+
1485
+
1486
+ class c_nvmlGridLicensableFeatures_v4_t(_PrintableStructure):
1487
+ _fields_ = [
1488
+ ("isGridLicenseSupported", c_int),
1489
+ ("licensableFeaturesCount", c_uint),
1490
+ (
1491
+ "gridLicensableFeatures",
1492
+ c_nvmlGridLicensableFeature_v4_t * NVML_GRID_LICENSE_FEATURE_MAX_COUNT,
1493
+ ),
1494
+ ]
1495
+
1496
+
1497
+ class c_nvmlGridLicensableFeature_v3_t(_PrintableStructure):
1498
+ _fields_ = [
1499
+ ("featureCode", _nvmlGridLicenseFeatureCode_t),
1500
+ ("featureState", c_uint),
1501
+ ("licenseInfo", c_char * NVML_GRID_LICENSE_BUFFER_SIZE),
1502
+ ("productName", c_char * NVML_GRID_LICENSE_BUFFER_SIZE),
1503
+ ("featureEnabled", c_uint),
1504
+ ]
1505
+
1506
+
1507
+ class c_nvmlGridLicensableFeatures_v3_t(_PrintableStructure):
1508
+ _fields_ = [
1509
+ ("isGridLicenseSupported", c_int),
1510
+ ("licensableFeaturesCount", c_uint),
1511
+ (
1512
+ "gridLicensableFeatures",
1513
+ c_nvmlGridLicensableFeature_v3_t * NVML_GRID_LICENSE_FEATURE_MAX_COUNT,
1514
+ ),
1515
+ ]
1516
+
1517
+
1518
+ class c_nvmlGridLicensableFeature_v2_t(_PrintableStructure):
1519
+ _fields_ = [
1520
+ ("featureCode", _nvmlGridLicenseFeatureCode_t),
1521
+ ("featureState", c_uint),
1522
+ ("licenseInfo", c_char * NVML_GRID_LICENSE_BUFFER_SIZE),
1523
+ ("productName", c_char * NVML_GRID_LICENSE_BUFFER_SIZE),
1524
+ ]
1525
+
1526
+
1527
+ class c_nvmlGridLicensableFeatures_v2_t(_PrintableStructure):
1528
+ _fields_ = [
1529
+ ("isGridLicenseSupported", c_int),
1530
+ ("licensableFeaturesCount", c_uint),
1531
+ (
1532
+ "gridLicensableFeatures",
1533
+ c_nvmlGridLicensableFeature_v2_t * NVML_GRID_LICENSE_FEATURE_MAX_COUNT,
1534
+ ),
1535
+ ]
1536
+
1537
+
1538
+ class c_nvmlGridLicensableFeature_t(_PrintableStructure):
1539
+ _fields_ = [
1540
+ ("featureCode", _nvmlGridLicenseFeatureCode_t),
1541
+ ("featureState", c_uint),
1542
+ ("licenseInfo", c_char * NVML_GRID_LICENSE_BUFFER_SIZE),
1543
+ ]
1544
+
1545
+
1546
+ class c_nvmlGridLicensableFeatures_t(_PrintableStructure):
1547
+ _fields_ = [
1548
+ ("isGridLicenseSupported", c_int),
1549
+ ("licensableFeaturesCount", c_uint),
1550
+ (
1551
+ "gridLicensableFeatures",
1552
+ c_nvmlGridLicensableFeature_t * NVML_GRID_LICENSE_FEATURE_MAX_COUNT,
1553
+ ),
1554
+ ]
1555
+
1556
+
1557
+ ## Event structures
1558
+ class struct_c_nvmlEventSet_t(Structure):
1559
+ pass # opaque handle
1560
+
1561
+
1562
+ c_nvmlEventSet_t = POINTER(struct_c_nvmlEventSet_t)
1563
+
1564
+ nvmlEventTypeSingleBitEccError = 0x0000000000000001
1565
+ nvmlEventTypeDoubleBitEccError = 0x0000000000000002
1566
+ nvmlEventTypePState = 0x0000000000000004
1567
+ nvmlEventTypeXidCriticalError = 0x0000000000000008
1568
+ nvmlEventTypeClock = 0x0000000000000010
1569
+ nvmlEventTypePowerSourceChange = 0x0000000000000080
1570
+ nvmlEventMigConfigChange = 0x0000000000000100
1571
+ nvmlEventTypeNone = 0x0000000000000000
1572
+ nvmlEventTypeAll = (
1573
+ nvmlEventTypeNone
1574
+ | nvmlEventTypeSingleBitEccError
1575
+ | nvmlEventTypeDoubleBitEccError
1576
+ | nvmlEventTypePState
1577
+ | nvmlEventTypeClock
1578
+ | nvmlEventTypePowerSourceChange
1579
+ | nvmlEventTypeXidCriticalError
1580
+ | nvmlEventMigConfigChange
1581
+ )
1582
+
1583
+ ## Clock Throttle Reasons defines
1584
+ nvmlClocksThrottleReasonGpuIdle = 0x0000000000000001
1585
+ nvmlClocksThrottleReasonApplicationsClocksSetting = 0x0000000000000002
1586
+ nvmlClocksThrottleReasonUserDefinedClocks = nvmlClocksThrottleReasonApplicationsClocksSetting # deprecated, use nvmlClocksThrottleReasonApplicationsClocksSetting
1587
+ nvmlClocksThrottleReasonSwPowerCap = 0x0000000000000004
1588
+ nvmlClocksThrottleReasonHwSlowdown = 0x0000000000000008
1589
+ nvmlClocksThrottleReasonSyncBoost = 0x0000000000000010
1590
+ nvmlClocksThrottleReasonSwThermalSlowdown = 0x0000000000000020
1591
+ nvmlClocksThrottleReasonHwThermalSlowdown = 0x0000000000000040
1592
+ nvmlClocksThrottleReasonHwPowerBrakeSlowdown = 0x0000000000000080
1593
+ nvmlClocksThrottleReasonDisplayClockSetting = 0x0000000000000100
1594
+ nvmlClocksThrottleReasonNone = 0x0000000000000000
1595
+ nvmlClocksThrottleReasonAll = (
1596
+ nvmlClocksThrottleReasonNone
1597
+ | nvmlClocksThrottleReasonGpuIdle
1598
+ | nvmlClocksThrottleReasonApplicationsClocksSetting
1599
+ | nvmlClocksThrottleReasonSwPowerCap
1600
+ | nvmlClocksThrottleReasonHwSlowdown
1601
+ | nvmlClocksThrottleReasonSyncBoost
1602
+ | nvmlClocksThrottleReasonSwThermalSlowdown
1603
+ | nvmlClocksThrottleReasonHwThermalSlowdown
1604
+ | nvmlClocksThrottleReasonHwPowerBrakeSlowdown
1605
+ | nvmlClocksThrottleReasonDisplayClockSetting
1606
+ )
1607
+
1608
+
1609
+ class c_nvmlEventData_t(_PrintableStructure):
1610
+ _fields_ = [
1611
+ ("device", c_nvmlDevice_t),
1612
+ ("eventType", c_ulonglong),
1613
+ ("eventData", c_ulonglong),
1614
+ ("gpuInstanceId", c_uint),
1615
+ ("computeInstanceId", c_uint),
1616
+ ]
1617
+ _fmt_ = {"eventType": "0x%08X"}
1618
+
1619
+
1620
+ class c_nvmlAccountingStats_t(_PrintableStructure):
1621
+ _fields_ = [
1622
+ ("gpuUtilization", c_uint),
1623
+ ("memoryUtilization", c_uint),
1624
+ ("maxMemoryUsage", c_ulonglong),
1625
+ ("time", c_ulonglong),
1626
+ ("startTime", c_ulonglong),
1627
+ ("isRunning", c_uint),
1628
+ ("reserved", c_uint * 5),
1629
+ ]
1630
+
1631
+
1632
+ class c_nvmlVgpuVersion_t(Structure):
1633
+ _fields_ = [("minVersion", c_uint), ("maxVersion", c_uint)]
1634
+
1635
+
1636
+ class c_nvmlVgpuMetadata_t(Structure):
1637
+ _fields_ = [
1638
+ ("version", c_uint),
1639
+ ("revision", c_uint),
1640
+ ("guestInfoState", _nvmlVgpuGuestInfoState_t),
1641
+ ("guestDriverVersion", c_char * NVML_SYSTEM_DRIVER_VERSION_BUFFER_SIZE),
1642
+ ("hostDriverVersion", c_char * NVML_SYSTEM_DRIVER_VERSION_BUFFER_SIZE),
1643
+ ("reserved", c_uint * 6),
1644
+ ("vgpuVirtualizationCaps", c_uint),
1645
+ ("guestVgpuVersion", c_uint),
1646
+ ("opaqueDataSize", c_uint),
1647
+ ("opaqueData", c_char * NVML_VGPU_METADATA_OPAQUE_DATA_SIZE),
1648
+ ]
1649
+
1650
+
1651
+ class c_nvmlVgpuPgpuMetadata_t(Structure):
1652
+ _fields_ = [
1653
+ ("version", c_uint),
1654
+ ("revision", c_uint),
1655
+ ("hostDriverVersion", c_char * NVML_SYSTEM_DRIVER_VERSION_BUFFER_SIZE),
1656
+ ("pgpuVirtualizationCaps", c_uint),
1657
+ ("reserved", c_uint * 5),
1658
+ ("hostSupportedVgpuRange", c_nvmlVgpuVersion_t),
1659
+ ("opaqueDataSize", c_uint),
1660
+ ("opaqueData", c_char * NVML_VGPU_PGPU_METADATA_OPAQUE_DATA_SIZE),
1661
+ ]
1662
+
1663
+
1664
+ class c_nvmlVgpuPgpuCompatibility_t(Structure):
1665
+ _fields_ = [
1666
+ ("vgpuVmCompatibility", _nvmlVgpuVmCompatibility_t),
1667
+ ("compatibilityLimitCode", _nvmlVgpuPgpuCompatibilityLimitCode_t),
1668
+ ]
1669
+
1670
+
1671
+ class c_nvmlFBCStats_t(Structure):
1672
+ _fields_ = [
1673
+ ("sessionsCount", c_uint),
1674
+ ("averageFPS", c_uint),
1675
+ ("averageLatency", c_uint),
1676
+ ]
1677
+
1678
+
1679
+ class c_nvmlFBCSession_t(_PrintableStructure):
1680
+ _fields_ = [
1681
+ ("sessionId", c_uint),
1682
+ ("pid", c_uint),
1683
+ ("vgpuInstance", _nvmlVgpuInstance_t),
1684
+ ("displayOrdinal", c_uint),
1685
+ ("sessionType", c_uint),
1686
+ ("sessionFlags", c_uint),
1687
+ ("hMaxResolution", c_uint),
1688
+ ("vMaxResolution", c_uint),
1689
+ ("hResolution", c_uint),
1690
+ ("vResolution", c_uint),
1691
+ ("averageFPS", c_uint),
1692
+ ("averageLatency", c_uint),
1693
+ ]
1694
+
1695
+
1696
+ NVML_DEVICE_MIG_DISABLE = 0x0
1697
+ NVML_DEVICE_MIG_ENABLE = 0x1
1698
+
1699
+ NVML_GPU_INSTANCE_PROFILE_1_SLICE = 0x0
1700
+ NVML_GPU_INSTANCE_PROFILE_2_SLICE = 0x1
1701
+ NVML_GPU_INSTANCE_PROFILE_3_SLICE = 0x2
1702
+ NVML_GPU_INSTANCE_PROFILE_4_SLICE = 0x3
1703
+ NVML_GPU_INSTANCE_PROFILE_7_SLICE = 0x4
1704
+ NVML_GPU_INSTANCE_PROFILE_8_SLICE = 0x5
1705
+ NVML_GPU_INSTANCE_PROFILE_6_SLICE = 0x6
1706
+ NVML_GPU_INSTANCE_PROFILE_1_SLICE_REV1 = 0x7
1707
+ NVML_GPU_INSTANCE_PROFILE_COUNT = 0x8
1708
+
1709
+
1710
+ class c_nvmlGpuInstancePlacement_t(Structure):
1711
+ _fields_ = [("start", c_uint), ("size", c_uint)]
1712
+
1713
+
1714
+ class c_nvmlGpuInstanceProfileInfo_t(Structure):
1715
+ _fields_ = [
1716
+ ("id", c_uint),
1717
+ ("isP2pSupported", c_uint),
1718
+ ("sliceCount", c_uint),
1719
+ ("instanceCount", c_uint),
1720
+ ("multiprocessorCount", c_uint),
1721
+ ("copyEngineCount", c_uint),
1722
+ ("decoderCount", c_uint),
1723
+ ("encoderCount", c_uint),
1724
+ ("jpegCount", c_uint),
1725
+ ("ofaCount", c_uint),
1726
+ ("memorySizeMB", c_ulonglong),
1727
+ ]
1728
+
1729
+
1730
+ nvmlGpuInstanceProfileInfo_v2 = 0x02000098
1731
+
1732
+
1733
+ class c_nvmlGpuInstanceProfileInfo_v2_t(Structure):
1734
+ _fields_ = [
1735
+ ("version", c_uint),
1736
+ ("id", c_uint),
1737
+ ("isP2pSupported", c_uint),
1738
+ ("sliceCount", c_uint),
1739
+ ("instanceCount", c_uint),
1740
+ ("multiprocessorCount", c_uint),
1741
+ ("copyEngineCount", c_uint),
1742
+ ("decoderCount", c_uint),
1743
+ ("encoderCount", c_uint),
1744
+ ("jpegCount", c_uint),
1745
+ ("ofaCount", c_uint),
1746
+ ("memorySizeMB", c_ulonglong),
1747
+ ("name", c_char * NVML_DEVICE_NAME_V2_BUFFER_SIZE),
1748
+ ]
1749
+
1750
+ def __init__(self):
1751
+ super().__init__(version=nvmlGpuInstanceProfileInfo_v2)
1752
+
1753
+
1754
+ class c_nvmlGpuInstanceInfo_t(Structure):
1755
+ _fields_ = [
1756
+ ("device", c_nvmlDevice_t),
1757
+ ("id", c_uint),
1758
+ ("profileId", c_uint),
1759
+ ("placement", c_nvmlGpuInstancePlacement_t),
1760
+ ]
1761
+
1762
+
1763
+ class struct_c_nvmlGpuInstance_t(Structure):
1764
+ pass # opaque handle
1765
+
1766
+
1767
+ c_nvmlGpuInstance_t = POINTER(struct_c_nvmlGpuInstance_t)
1768
+
1769
+ NVML_COMPUTE_INSTANCE_PROFILE_1_SLICE = 0x0
1770
+ NVML_COMPUTE_INSTANCE_PROFILE_2_SLICE = 0x1
1771
+ NVML_COMPUTE_INSTANCE_PROFILE_3_SLICE = 0x2
1772
+ NVML_COMPUTE_INSTANCE_PROFILE_4_SLICE = 0x3
1773
+ NVML_COMPUTE_INSTANCE_PROFILE_7_SLICE = 0x4
1774
+ NVML_COMPUTE_INSTANCE_PROFILE_8_SLICE = 0x5
1775
+ NVML_COMPUTE_INSTANCE_PROFILE_6_SLICE = 0x6
1776
+ NVML_COMPUTE_INSTANCE_PROFILE_COUNT = 0x7
1777
+
1778
+ NVML_COMPUTE_INSTANCE_ENGINE_PROFILE_SHARED = 0x0
1779
+ NVML_COMPUTE_INSTANCE_ENGINE_PROFILE_COUNT = 0x1
1780
+
1781
+
1782
+ class c_nvmlComputeInstancePlacement_t(Structure):
1783
+ _fields_ = [("start", c_uint), ("size", c_uint)]
1784
+
1785
+
1786
+ class c_nvmlComputeInstanceProfileInfo_t(Structure):
1787
+ _fields_ = [
1788
+ ("id", c_uint),
1789
+ ("sliceCount", c_uint),
1790
+ ("instanceCount", c_uint),
1791
+ ("multiprocessorCount", c_uint),
1792
+ ("sharedCopyEngineCount", c_uint),
1793
+ ("sharedDecoderCount", c_uint),
1794
+ ("sharedEncoderCount", c_uint),
1795
+ ("sharedJpegCount", c_uint),
1796
+ ("sharedOfaCount", c_uint),
1797
+ ]
1798
+
1799
+
1800
+ nvmlComputeInstanceProfileInfo_v2 = 0x02000088
1801
+
1802
+
1803
+ class c_nvmlComputeInstanceProfileInfo_v2_t(Structure):
1804
+ _fields_ = [
1805
+ ("version", c_uint),
1806
+ ("id", c_uint),
1807
+ ("sliceCount", c_uint),
1808
+ ("instanceCount", c_uint),
1809
+ ("multiprocessorCount", c_uint),
1810
+ ("sharedCopyEngineCount", c_uint),
1811
+ ("sharedDecoderCount", c_uint),
1812
+ ("sharedEncoderCount", c_uint),
1813
+ ("sharedJpegCount", c_uint),
1814
+ ("sharedOfaCount", c_uint),
1815
+ ("name", c_char * NVML_DEVICE_NAME_V2_BUFFER_SIZE),
1816
+ ]
1817
+
1818
+ def __init__(self):
1819
+ super().__init__(version=nvmlComputeInstanceProfileInfo_v2)
1820
+
1821
+
1822
+ class c_nvmlComputeInstanceInfo_t(Structure):
1823
+ _fields_ = [
1824
+ ("device", c_nvmlDevice_t),
1825
+ ("gpuInstance", c_nvmlGpuInstance_t),
1826
+ ("id", c_uint),
1827
+ ("profileId", c_uint),
1828
+ ("placement", c_nvmlComputeInstancePlacement_t),
1829
+ ]
1830
+
1831
+
1832
+ NVML_MAX_GPU_UTILIZATIONS = 8
1833
+ NVML_GPU_UTILIZATION_DOMAIN_GPU = 0
1834
+ NVML_GPU_UTILIZATION_DOMAIN_FB = 1
1835
+ NVML_GPU_UTILIZATION_DOMAIN_VID = 2
1836
+ NVML_GPU_UTILIZATION_DOMAIN_BUS = 3
1837
+
1838
+
1839
+ class c_nvmlGpuDynamicPstatesUtilization_t(Structure):
1840
+ _fields_ = [
1841
+ ("bIsPresent", c_uint, 1),
1842
+ ("percentage", c_uint),
1843
+ ("incThreshold", c_uint),
1844
+ ("decThreshold", c_uint),
1845
+ ]
1846
+
1847
+
1848
+ class c_nvmlGpuDynamicPstatesInfo_t(Structure):
1849
+ _fields_ = [
1850
+ ("flags", c_uint),
1851
+ (
1852
+ "utilization",
1853
+ c_nvmlGpuDynamicPstatesUtilization_t * NVML_MAX_GPU_UTILIZATIONS,
1854
+ ),
1855
+ ]
1856
+
1857
+
1858
+ NVML_MAX_THERMAL_SENSORS_PER_GPU = 3
1859
+
1860
+ NVML_THERMAL_TARGET_NONE = 0
1861
+ NVML_THERMAL_TARGET_GPU = 1
1862
+ NVML_THERMAL_TARGET_MEMORY = 2
1863
+ NVML_THERMAL_TARGET_POWER_SUPPLY = 4
1864
+ NVML_THERMAL_TARGET_BOARD = 8
1865
+ NVML_THERMAL_TARGET_VCD_BOARD = 9
1866
+ NVML_THERMAL_TARGET_VCD_INLET = 10
1867
+ NVML_THERMAL_TARGET_VCD_OUTLET = 11
1868
+ NVML_THERMAL_TARGET_ALL = 15
1869
+ NVML_THERMAL_TARGET_UNKNOWN = -1
1870
+
1871
+ NVML_THERMAL_CONTROLLER_NONE = 0
1872
+ NVML_THERMAL_CONTROLLER_GPU_INTERNAL = 1
1873
+ NVML_THERMAL_CONTROLLER_ADM1032 = 2
1874
+ NVML_THERMAL_CONTROLLER_ADT7461 = 3
1875
+ NVML_THERMAL_CONTROLLER_MAX6649 = 4
1876
+ NVML_THERMAL_CONTROLLER_MAX1617 = 5
1877
+ NVML_THERMAL_CONTROLLER_LM99 = 6
1878
+ NVML_THERMAL_CONTROLLER_LM89 = 7
1879
+ NVML_THERMAL_CONTROLLER_LM64 = 8
1880
+ NVML_THERMAL_CONTROLLER_G781 = 9
1881
+ NVML_THERMAL_CONTROLLER_ADT7473 = 10
1882
+ NVML_THERMAL_CONTROLLER_SBMAX6649 = 11
1883
+ NVML_THERMAL_CONTROLLER_VBIOSEVT = 12
1884
+ NVML_THERMAL_CONTROLLER_OS = 13
1885
+ NVML_THERMAL_CONTROLLER_NVSYSCON_CANOAS = 14
1886
+ NVML_THERMAL_CONTROLLER_NVSYSCON_E551 = 15
1887
+ NVML_THERMAL_CONTROLLER_MAX6649R = 16
1888
+ NVML_THERMAL_CONTROLLER_ADT7473S = 17
1889
+ NVML_THERMAL_CONTROLLER_UNKNOWN = -1
1890
+
1891
+
1892
+ class c_nvmlGpuThermalSensor_t(Structure):
1893
+ _fields_ = [
1894
+ ("controller", c_int),
1895
+ ("defaultMinTemp", c_uint),
1896
+ ("defaultMaxTemp", c_uint),
1897
+ ("currentTemp", c_uint),
1898
+ ("target", c_int),
1899
+ ]
1900
+
1901
+
1902
+ class c_nvmlGpuThermalSettings_t(Structure):
1903
+ _fields_ = [
1904
+ ("count", c_uint),
1905
+ ("sensor", c_nvmlGpuThermalSensor_t * NVML_MAX_THERMAL_SENSORS_PER_GPU),
1906
+ ]
1907
+
1908
+
1909
+ class struct_c_nvmlComputeInstance_t(Structure):
1910
+ pass # opaque handle
1911
+
1912
+
1913
+ c_nvmlComputeInstance_t = POINTER(struct_c_nvmlComputeInstance_t)
1914
+
1915
+
1916
+ class c_nvmlDeviceAttributes(Structure):
1917
+ _fields_ = [
1918
+ ("multiprocessorCount", c_uint),
1919
+ ("sharedCopyEngineCount", c_uint),
1920
+ ("sharedDecoderCount", c_uint),
1921
+ ("sharedEncoderCount", c_uint),
1922
+ ("sharedJpegCount", c_uint),
1923
+ ("sharedOfaCount", c_uint),
1924
+ ("gpuInstanceSliceCount", c_uint),
1925
+ ("computeInstanceSliceCount", c_uint),
1926
+ ("memorySizeMB", c_ulonglong),
1927
+ ]
1928
+
1929
+
1930
+ class c_nvmlRowRemapperHistogramValues(Structure):
1931
+ _fields_ = [
1932
+ ("max", c_uint),
1933
+ ("high", c_uint),
1934
+ ("partial", c_uint),
1935
+ ("low", c_uint),
1936
+ ("none", c_uint),
1937
+ ]
1938
+
1939
+
1940
+ ## string/bytes conversion for ease of use
1941
+ def convertStrBytes(func):
1942
+ """
1943
+ In python 3, strings are unicode instead of bytes, and need to be converted for ctypes
1944
+ Args from caller: (1, 'string', <__main__.c_nvmlDevice_t at 0xFFFFFFFF>)
1945
+ Args passed to function: (1, b'string', <__main__.c_nvmlDevice_t at 0xFFFFFFFF)>
1946
+ ----
1947
+ Returned from function: b'returned string'
1948
+ Returned to caller: 'returned string'
1949
+ """
1950
+
1951
+ @wraps(func)
1952
+ def wrapper(*args, **kwargs):
1953
+ # encoding a str returns bytes in python 2 and 3
1954
+ args = [arg.encode() if isinstance(arg, str) else arg for arg in args]
1955
+ res = func(*args, **kwargs)
1956
+ # In python 2, str and bytes are the same
1957
+ # In python 3, str is unicode and should be decoded.
1958
+ # Ctypes handles most conversions, this only effects c_char and char arrays.
1959
+ if isinstance(res, bytes):
1960
+ if isinstance(res, str):
1961
+ return res
1962
+ return res.decode()
1963
+ return res
1964
+
1965
+ return wrapper
1966
+ return func
1967
+
1968
+
1969
+ ## C function wrappers ##
1970
+ def nvmlInitWithFlags(flags):
1971
+ _LoadNvmlLibrary()
1972
+
1973
+ #
1974
+ # Initialize the library
1975
+ #
1976
+ fn = _nvmlGetFunctionPointer("nvmlInitWithFlags")
1977
+ ret = fn(flags)
1978
+ _nvmlCheckReturn(ret)
1979
+
1980
+ # Atomically update refcount
1981
+ global _nvmlLib_refcount
1982
+ libLoadLock.acquire()
1983
+ _nvmlLib_refcount += 1
1984
+ libLoadLock.release()
1985
+ return None
1986
+
1987
+
1988
+ def nvmlInit():
1989
+ nvmlInitWithFlags(0)
1990
+ return None
1991
+
1992
+
1993
+ def _LoadNvmlLibrary():
1994
+ """
1995
+ Load the library if it isn't loaded already
1996
+ """
1997
+ global nvmlLib
1998
+
1999
+ if nvmlLib is None:
2000
+ # lock to ensure only one caller loads the library
2001
+ libLoadLock.acquire()
2002
+
2003
+ try:
2004
+ # ensure the library still isn't loaded
2005
+ if nvmlLib is None:
2006
+ if sys.platform[:3] == "win":
2007
+ # cdecl calling convention
2008
+ # First, check for nvml.dll in System32 first for DCH drivers.
2009
+ # If nvml.dll is not found in System32, it should be in ProgramFiles
2010
+ # load nvml.dll from %ProgramFiles%/NVIDIA Corporation/NVSMI/nvml.dll
2011
+ search_paths = [
2012
+ os.path.join(
2013
+ os.getenv("WINDIR", "C:/Windows"), "System32/nvml.dll"
2014
+ ),
2015
+ os.path.join(
2016
+ os.getenv("ProgramFiles", "C:/Program Files"),
2017
+ "NVIDIA Corporation/NVSMI/nvml.dll",
2018
+ ),
2019
+ ]
2020
+ # Finally, it may be overridden by an environment variable
2021
+ nvml_path = os.getenv("NVML_DLL_PATH")
2022
+ if nvml_path is not None:
2023
+ search_paths.append(nvml_path)
2024
+ for dll_path in search_paths:
2025
+ try:
2026
+ nvmlLib = CDLL(dll_path)
2027
+ except OSError as ose:
2028
+ continue
2029
+ break
2030
+ else:
2031
+ # assume linux
2032
+ try:
2033
+ nvmlLib = CDLL("libnvidia-ml.so.1")
2034
+ except OSError as ose:
2035
+ _nvmlCheckReturn(NVML_ERROR_LIBRARY_NOT_FOUND)
2036
+ if nvmlLib is None:
2037
+ _nvmlCheckReturn(NVML_ERROR_LIBRARY_NOT_FOUND)
2038
+ finally:
2039
+ # lock is always freed
2040
+ libLoadLock.release()
2041
+
2042
+
2043
+ def nvmlShutdown():
2044
+ #
2045
+ # Leave the library loaded, but shutdown the interface
2046
+ #
2047
+ fn = _nvmlGetFunctionPointer("nvmlShutdown")
2048
+ ret = fn()
2049
+ _nvmlCheckReturn(ret)
2050
+
2051
+ # Atomically update refcount
2052
+ global _nvmlLib_refcount
2053
+ libLoadLock.acquire()
2054
+ if 0 < _nvmlLib_refcount:
2055
+ _nvmlLib_refcount -= 1
2056
+ libLoadLock.release()
2057
+ return None
2058
+
2059
+
2060
+ # Added in 2.285
2061
+ @convertStrBytes
2062
+ def nvmlErrorString(result):
2063
+ fn = _nvmlGetFunctionPointer("nvmlErrorString")
2064
+ fn.restype = c_char_p # otherwise return is an int
2065
+ ret = fn(result)
2066
+ return ret
2067
+
2068
+
2069
+ # Added in 2.285
2070
+ @convertStrBytes
2071
+ def nvmlSystemGetNVMLVersion():
2072
+ c_version = create_string_buffer(NVML_SYSTEM_NVML_VERSION_BUFFER_SIZE)
2073
+ fn = _nvmlGetFunctionPointer("nvmlSystemGetNVMLVersion")
2074
+ ret = fn(c_version, c_uint(NVML_SYSTEM_NVML_VERSION_BUFFER_SIZE))
2075
+ _nvmlCheckReturn(ret)
2076
+ return c_version.value
2077
+
2078
+
2079
+ def nvmlSystemGetCudaDriverVersion():
2080
+ c_cuda_version = c_int()
2081
+ fn = _nvmlGetFunctionPointer("nvmlSystemGetCudaDriverVersion")
2082
+ ret = fn(byref(c_cuda_version))
2083
+ _nvmlCheckReturn(ret)
2084
+ return c_cuda_version.value
2085
+
2086
+
2087
+ def nvmlSystemGetCudaDriverVersion_v2():
2088
+ c_cuda_version = c_int()
2089
+ fn = _nvmlGetFunctionPointer("nvmlSystemGetCudaDriverVersion_v2")
2090
+ ret = fn(byref(c_cuda_version))
2091
+ _nvmlCheckReturn(ret)
2092
+ return c_cuda_version.value
2093
+
2094
+
2095
+ # Added in 2.285
2096
+ @convertStrBytes
2097
+ def nvmlSystemGetProcessName(pid):
2098
+ c_name = create_string_buffer(1024)
2099
+ fn = _nvmlGetFunctionPointer("nvmlSystemGetProcessName")
2100
+ ret = fn(c_uint(pid), c_name, c_uint(1024))
2101
+ _nvmlCheckReturn(ret)
2102
+ return c_name.value
2103
+
2104
+
2105
+ @convertStrBytes
2106
+ def nvmlSystemGetDriverVersion():
2107
+ c_version = create_string_buffer(NVML_SYSTEM_DRIVER_VERSION_BUFFER_SIZE)
2108
+ fn = _nvmlGetFunctionPointer("nvmlSystemGetDriverVersion")
2109
+ ret = fn(c_version, c_uint(NVML_SYSTEM_DRIVER_VERSION_BUFFER_SIZE))
2110
+ _nvmlCheckReturn(ret)
2111
+ return c_version.value
2112
+
2113
+
2114
+ # Added in 2.285
2115
+ def nvmlSystemGetHicVersion():
2116
+ c_count = c_uint(0)
2117
+ hics = None
2118
+ fn = _nvmlGetFunctionPointer("nvmlSystemGetHicVersion")
2119
+
2120
+ # get the count
2121
+ ret = fn(byref(c_count), None)
2122
+
2123
+ # this should only fail with insufficient size
2124
+ if (ret != NVML_SUCCESS) and (ret != NVML_ERROR_INSUFFICIENT_SIZE):
2125
+ raise NVMLError(ret)
2126
+
2127
+ # If there are no hics
2128
+ if c_count.value == 0:
2129
+ return []
2130
+
2131
+ hic_array = c_nvmlHwbcEntry_t * c_count.value
2132
+ hics = hic_array()
2133
+ ret = fn(byref(c_count), hics)
2134
+ _nvmlCheckReturn(ret)
2135
+ return hics
2136
+
2137
+
2138
+ ## Unit get functions
2139
+ def nvmlUnitGetCount():
2140
+ c_count = c_uint()
2141
+ fn = _nvmlGetFunctionPointer("nvmlUnitGetCount")
2142
+ ret = fn(byref(c_count))
2143
+ _nvmlCheckReturn(ret)
2144
+ return c_count.value
2145
+
2146
+
2147
+ def nvmlUnitGetHandleByIndex(index):
2148
+ c_index = c_uint(index)
2149
+ unit = c_nvmlUnit_t()
2150
+ fn = _nvmlGetFunctionPointer("nvmlUnitGetHandleByIndex")
2151
+ ret = fn(c_index, byref(unit))
2152
+ _nvmlCheckReturn(ret)
2153
+ return unit
2154
+
2155
+
2156
+ def nvmlUnitGetUnitInfo(unit):
2157
+ c_info = c_nvmlUnitInfo_t()
2158
+ fn = _nvmlGetFunctionPointer("nvmlUnitGetUnitInfo")
2159
+ ret = fn(unit, byref(c_info))
2160
+ _nvmlCheckReturn(ret)
2161
+ return c_info
2162
+
2163
+
2164
+ def nvmlUnitGetLedState(unit):
2165
+ c_state = c_nvmlLedState_t()
2166
+ fn = _nvmlGetFunctionPointer("nvmlUnitGetLedState")
2167
+ ret = fn(unit, byref(c_state))
2168
+ _nvmlCheckReturn(ret)
2169
+ return c_state
2170
+
2171
+
2172
+ def nvmlUnitGetPsuInfo(unit):
2173
+ c_info = c_nvmlPSUInfo_t()
2174
+ fn = _nvmlGetFunctionPointer("nvmlUnitGetPsuInfo")
2175
+ ret = fn(unit, byref(c_info))
2176
+ _nvmlCheckReturn(ret)
2177
+ return c_info
2178
+
2179
+
2180
+ def nvmlUnitGetTemperature(unit, type):
2181
+ c_temp = c_uint()
2182
+ fn = _nvmlGetFunctionPointer("nvmlUnitGetTemperature")
2183
+ ret = fn(unit, c_uint(type), byref(c_temp))
2184
+ _nvmlCheckReturn(ret)
2185
+ return c_temp.value
2186
+
2187
+
2188
+ def nvmlUnitGetFanSpeedInfo(unit):
2189
+ c_speeds = c_nvmlUnitFanSpeeds_t()
2190
+ fn = _nvmlGetFunctionPointer("nvmlUnitGetFanSpeedInfo")
2191
+ ret = fn(unit, byref(c_speeds))
2192
+ _nvmlCheckReturn(ret)
2193
+ return c_speeds
2194
+
2195
+
2196
+ # added to API
2197
+ def nvmlUnitGetDeviceCount(unit):
2198
+ c_count = c_uint(0)
2199
+ # query the unit to determine device count
2200
+ fn = _nvmlGetFunctionPointer("nvmlUnitGetDevices")
2201
+ ret = fn(unit, byref(c_count), None)
2202
+ if ret == NVML_ERROR_INSUFFICIENT_SIZE:
2203
+ ret = NVML_SUCCESS
2204
+ _nvmlCheckReturn(ret)
2205
+ return c_count.value
2206
+
2207
+
2208
+ def nvmlUnitGetDevices(unit):
2209
+ c_count = c_uint(nvmlUnitGetDeviceCount(unit))
2210
+ device_array = c_nvmlDevice_t * c_count.value
2211
+ c_devices = device_array()
2212
+ fn = _nvmlGetFunctionPointer("nvmlUnitGetDevices")
2213
+ ret = fn(unit, byref(c_count), c_devices)
2214
+ _nvmlCheckReturn(ret)
2215
+ return c_devices
2216
+
2217
+
2218
+ ## Device get functions
2219
+ def nvmlDeviceGetCount():
2220
+ c_count = c_uint()
2221
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetCount_v2")
2222
+ ret = fn(byref(c_count))
2223
+ _nvmlCheckReturn(ret)
2224
+ return c_count.value
2225
+
2226
+
2227
+ def nvmlDeviceGetHandleByIndex(index):
2228
+ c_index = c_uint(index)
2229
+ device = c_nvmlDevice_t()
2230
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetHandleByIndex_v2")
2231
+ ret = fn(c_index, byref(device))
2232
+ _nvmlCheckReturn(ret)
2233
+ return device
2234
+
2235
+
2236
+ @convertStrBytes
2237
+ def nvmlDeviceGetHandleBySerial(serial):
2238
+ c_serial = c_char_p(serial)
2239
+ device = c_nvmlDevice_t()
2240
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetHandleBySerial")
2241
+ ret = fn(c_serial, byref(device))
2242
+ _nvmlCheckReturn(ret)
2243
+ return device
2244
+
2245
+
2246
+ @convertStrBytes
2247
+ def nvmlDeviceGetHandleByUUID(uuid):
2248
+ c_uuid = c_char_p(uuid)
2249
+ device = c_nvmlDevice_t()
2250
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetHandleByUUID")
2251
+ ret = fn(c_uuid, byref(device))
2252
+ _nvmlCheckReturn(ret)
2253
+ return device
2254
+
2255
+
2256
+ @convertStrBytes
2257
+ def nvmlDeviceGetHandleByPciBusId(pciBusId):
2258
+ c_busId = c_char_p(pciBusId)
2259
+ device = c_nvmlDevice_t()
2260
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetHandleByPciBusId_v2")
2261
+ ret = fn(c_busId, byref(device))
2262
+ _nvmlCheckReturn(ret)
2263
+ return device
2264
+
2265
+
2266
+ @convertStrBytes
2267
+ def nvmlDeviceGetName(handle):
2268
+ c_name = create_string_buffer(NVML_DEVICE_NAME_V2_BUFFER_SIZE)
2269
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetName")
2270
+ ret = fn(handle, c_name, c_uint(NVML_DEVICE_NAME_V2_BUFFER_SIZE))
2271
+ _nvmlCheckReturn(ret)
2272
+ return c_name.value
2273
+
2274
+
2275
+ def nvmlDeviceGetBoardId(handle):
2276
+ c_id = c_uint()
2277
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetBoardId")
2278
+ ret = fn(handle, byref(c_id))
2279
+ _nvmlCheckReturn(ret)
2280
+ return c_id.value
2281
+
2282
+
2283
+ def nvmlDeviceGetMultiGpuBoard(handle):
2284
+ c_multiGpu = c_uint()
2285
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetMultiGpuBoard")
2286
+ ret = fn(handle, byref(c_multiGpu))
2287
+ _nvmlCheckReturn(ret)
2288
+ return c_multiGpu.value
2289
+
2290
+
2291
+ def nvmlDeviceGetBrand(handle):
2292
+ c_type = _nvmlBrandType_t()
2293
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetBrand")
2294
+ ret = fn(handle, byref(c_type))
2295
+ _nvmlCheckReturn(ret)
2296
+ return c_type.value
2297
+
2298
+
2299
+ @convertStrBytes
2300
+ def nvmlDeviceGetBoardPartNumber(handle):
2301
+ c_part_number = create_string_buffer(NVML_DEVICE_PART_NUMBER_BUFFER_SIZE)
2302
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetBoardPartNumber")
2303
+ ret = fn(handle, c_part_number, c_uint(NVML_DEVICE_PART_NUMBER_BUFFER_SIZE))
2304
+ _nvmlCheckReturn(ret)
2305
+ return c_part_number.value
2306
+
2307
+
2308
+ @convertStrBytes
2309
+ def nvmlDeviceGetSerial(handle):
2310
+ c_serial = create_string_buffer(NVML_DEVICE_SERIAL_BUFFER_SIZE)
2311
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetSerial")
2312
+ ret = fn(handle, c_serial, c_uint(NVML_DEVICE_SERIAL_BUFFER_SIZE))
2313
+ _nvmlCheckReturn(ret)
2314
+ return c_serial.value
2315
+
2316
+
2317
+ def nvmlDeviceGetMemoryAffinity(handle, nodeSetSize, scope):
2318
+ affinity_array = c_ulonglong * nodeSetSize
2319
+ c_affinity = affinity_array()
2320
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetMemoryAffinity")
2321
+ ret = fn(handle, nodeSetSize, byref(c_affinity), _nvmlAffinityScope_t(scope))
2322
+ _nvmlCheckReturn(ret)
2323
+ return c_affinity
2324
+
2325
+
2326
+ def nvmlDeviceGetCpuAffinityWithinScope(handle, cpuSetSize, scope):
2327
+ affinity_array = c_ulonglong * cpuSetSize
2328
+ c_affinity = affinity_array()
2329
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetCpuAffinityWithinScope")
2330
+ ret = fn(handle, cpuSetSize, byref(c_affinity), _nvmlAffinityScope_t(scope))
2331
+ _nvmlCheckReturn(ret)
2332
+ return c_affinity
2333
+
2334
+
2335
+ def nvmlDeviceGetCpuAffinity(handle, cpuSetSize):
2336
+ affinity_array = c_ulonglong * cpuSetSize
2337
+ c_affinity = affinity_array()
2338
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetCpuAffinity")
2339
+ ret = fn(handle, cpuSetSize, byref(c_affinity))
2340
+ _nvmlCheckReturn(ret)
2341
+ return c_affinity
2342
+
2343
+
2344
+ def nvmlDeviceSetCpuAffinity(handle):
2345
+ fn = _nvmlGetFunctionPointer("nvmlDeviceSetCpuAffinity")
2346
+ ret = fn(handle)
2347
+ _nvmlCheckReturn(ret)
2348
+ return None
2349
+
2350
+
2351
+ def nvmlDeviceClearCpuAffinity(handle):
2352
+ fn = _nvmlGetFunctionPointer("nvmlDeviceClearCpuAffinity")
2353
+ ret = fn(handle)
2354
+ _nvmlCheckReturn(ret)
2355
+ return None
2356
+
2357
+
2358
+ def nvmlDeviceGetMinorNumber(handle):
2359
+ c_minor_number = c_uint()
2360
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetMinorNumber")
2361
+ ret = fn(handle, byref(c_minor_number))
2362
+ _nvmlCheckReturn(ret)
2363
+ return c_minor_number.value
2364
+
2365
+
2366
+ @convertStrBytes
2367
+ def nvmlDeviceGetUUID(handle):
2368
+ c_uuid = create_string_buffer(NVML_DEVICE_UUID_V2_BUFFER_SIZE)
2369
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetUUID")
2370
+ ret = fn(handle, c_uuid, c_uint(NVML_DEVICE_UUID_V2_BUFFER_SIZE))
2371
+ _nvmlCheckReturn(ret)
2372
+ return c_uuid.value
2373
+
2374
+
2375
+ @convertStrBytes
2376
+ def nvmlDeviceGetInforomVersion(handle, infoRomObject):
2377
+ c_version = create_string_buffer(NVML_DEVICE_INFOROM_VERSION_BUFFER_SIZE)
2378
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetInforomVersion")
2379
+ ret = fn(
2380
+ handle,
2381
+ _nvmlInforomObject_t(infoRomObject),
2382
+ c_version,
2383
+ c_uint(NVML_DEVICE_INFOROM_VERSION_BUFFER_SIZE),
2384
+ )
2385
+ _nvmlCheckReturn(ret)
2386
+ return c_version.value
2387
+
2388
+
2389
+ # Added in 4.304
2390
+ @convertStrBytes
2391
+ def nvmlDeviceGetInforomImageVersion(handle):
2392
+ c_version = create_string_buffer(NVML_DEVICE_INFOROM_VERSION_BUFFER_SIZE)
2393
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetInforomImageVersion")
2394
+ ret = fn(handle, c_version, c_uint(NVML_DEVICE_INFOROM_VERSION_BUFFER_SIZE))
2395
+ _nvmlCheckReturn(ret)
2396
+ return c_version.value
2397
+
2398
+
2399
+ # Added in 4.304
2400
+ def nvmlDeviceGetInforomConfigurationChecksum(handle):
2401
+ c_checksum = c_uint()
2402
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetInforomConfigurationChecksum")
2403
+ ret = fn(handle, byref(c_checksum))
2404
+ _nvmlCheckReturn(ret)
2405
+ return c_checksum.value
2406
+
2407
+
2408
+ # Added in 4.304
2409
+ def nvmlDeviceValidateInforom(handle):
2410
+ fn = _nvmlGetFunctionPointer("nvmlDeviceValidateInforom")
2411
+ ret = fn(handle)
2412
+ _nvmlCheckReturn(ret)
2413
+ return None
2414
+
2415
+
2416
+ def nvmlDeviceGetDisplayMode(handle):
2417
+ c_mode = _nvmlEnableState_t()
2418
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetDisplayMode")
2419
+ ret = fn(handle, byref(c_mode))
2420
+ _nvmlCheckReturn(ret)
2421
+ return c_mode.value
2422
+
2423
+
2424
+ def nvmlDeviceGetDisplayActive(handle):
2425
+ c_mode = _nvmlEnableState_t()
2426
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetDisplayActive")
2427
+ ret = fn(handle, byref(c_mode))
2428
+ _nvmlCheckReturn(ret)
2429
+ return c_mode.value
2430
+
2431
+
2432
+ def nvmlDeviceGetPersistenceMode(handle):
2433
+ c_state = _nvmlEnableState_t()
2434
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetPersistenceMode")
2435
+ ret = fn(handle, byref(c_state))
2436
+ _nvmlCheckReturn(ret)
2437
+ return c_state.value
2438
+
2439
+
2440
+ def nvmlDeviceGetPciInfo_v3(handle):
2441
+ c_info = nvmlPciInfo_t()
2442
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetPciInfo_v3")
2443
+ ret = fn(handle, byref(c_info))
2444
+ _nvmlCheckReturn(ret)
2445
+ return c_info
2446
+
2447
+
2448
+ def nvmlDeviceGetPciInfo(handle):
2449
+ return nvmlDeviceGetPciInfo_v3(handle)
2450
+
2451
+
2452
+ def nvmlDeviceGetClockInfo(handle, type):
2453
+ c_clock = c_uint()
2454
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetClockInfo")
2455
+ ret = fn(handle, _nvmlClockType_t(type), byref(c_clock))
2456
+ _nvmlCheckReturn(ret)
2457
+ return c_clock.value
2458
+
2459
+
2460
+ # Added in 2.285
2461
+ def nvmlDeviceGetMaxClockInfo(handle, type):
2462
+ c_clock = c_uint()
2463
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetMaxClockInfo")
2464
+ ret = fn(handle, _nvmlClockType_t(type), byref(c_clock))
2465
+ _nvmlCheckReturn(ret)
2466
+ return c_clock.value
2467
+
2468
+
2469
+ # Added in 4.304
2470
+ def nvmlDeviceGetApplicationsClock(handle, type):
2471
+ c_clock = c_uint()
2472
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetApplicationsClock")
2473
+ ret = fn(handle, _nvmlClockType_t(type), byref(c_clock))
2474
+ _nvmlCheckReturn(ret)
2475
+ return c_clock.value
2476
+
2477
+
2478
+ def nvmlDeviceGetMaxCustomerBoostClock(handle, type):
2479
+ c_clock = c_uint()
2480
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetMaxCustomerBoostClock")
2481
+ ret = fn(handle, _nvmlClockType_t(type), byref(c_clock))
2482
+ _nvmlCheckReturn(ret)
2483
+ return c_clock.value
2484
+
2485
+
2486
+ def nvmlDeviceGetClock(handle, type, id):
2487
+ c_clock = c_uint()
2488
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetClock")
2489
+ ret = fn(handle, _nvmlClockType_t(type), _nvmlClockId_t(id), byref(c_clock))
2490
+ _nvmlCheckReturn(ret)
2491
+ return c_clock.value
2492
+
2493
+
2494
+ # Added in 5.319
2495
+ def nvmlDeviceGetDefaultApplicationsClock(handle, type):
2496
+ c_clock = c_uint()
2497
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetDefaultApplicationsClock")
2498
+ ret = fn(handle, _nvmlClockType_t(type), byref(c_clock))
2499
+ _nvmlCheckReturn(ret)
2500
+ return c_clock.value
2501
+
2502
+
2503
+ # Added in 4.304
2504
+ def nvmlDeviceGetSupportedMemoryClocks(handle):
2505
+ # first call to get the size
2506
+ c_count = c_uint(0)
2507
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetSupportedMemoryClocks")
2508
+ ret = fn(handle, byref(c_count), None)
2509
+
2510
+ if ret == NVML_SUCCESS:
2511
+ # special case, no clocks
2512
+ return []
2513
+ elif ret == NVML_ERROR_INSUFFICIENT_SIZE:
2514
+ # typical case
2515
+ clocks_array = c_uint * c_count.value
2516
+ c_clocks = clocks_array()
2517
+
2518
+ # make the call again
2519
+ ret = fn(handle, byref(c_count), c_clocks)
2520
+ _nvmlCheckReturn(ret)
2521
+
2522
+ procs = []
2523
+ for i in range(c_count.value):
2524
+ procs.append(c_clocks[i])
2525
+
2526
+ return procs
2527
+ else:
2528
+ # error case
2529
+ raise NVMLError(ret)
2530
+
2531
+
2532
+ # Added in 4.304
2533
+ def nvmlDeviceGetSupportedGraphicsClocks(handle, memoryClockMHz):
2534
+ # first call to get the size
2535
+ c_count = c_uint(0)
2536
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetSupportedGraphicsClocks")
2537
+ ret = fn(handle, c_uint(memoryClockMHz), byref(c_count), None)
2538
+
2539
+ if ret == NVML_SUCCESS:
2540
+ # special case, no clocks
2541
+ return []
2542
+ elif ret == NVML_ERROR_INSUFFICIENT_SIZE:
2543
+ # typical case
2544
+ clocks_array = c_uint * c_count.value
2545
+ c_clocks = clocks_array()
2546
+
2547
+ # make the call again
2548
+ ret = fn(handle, c_uint(memoryClockMHz), byref(c_count), c_clocks)
2549
+ _nvmlCheckReturn(ret)
2550
+
2551
+ procs = []
2552
+ for i in range(c_count.value):
2553
+ procs.append(c_clocks[i])
2554
+
2555
+ return procs
2556
+ else:
2557
+ # error case
2558
+ raise NVMLError(ret)
2559
+
2560
+
2561
+ def nvmlDeviceGetFanSpeed(handle):
2562
+ c_speed = c_uint()
2563
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetFanSpeed")
2564
+ ret = fn(handle, byref(c_speed))
2565
+ _nvmlCheckReturn(ret)
2566
+ return c_speed.value
2567
+
2568
+
2569
+ def nvmlDeviceGetFanSpeed_v2(handle, fan):
2570
+ c_speed = c_uint()
2571
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetFanSpeed_v2")
2572
+ ret = fn(handle, fan, byref(c_speed))
2573
+ _nvmlCheckReturn(ret)
2574
+ return c_speed.value
2575
+
2576
+
2577
+ def nvmlDeviceGetNumFans(device):
2578
+ c_numFans = c_uint()
2579
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetNumFans")
2580
+ ret = fn(device, byref(c_numFans))
2581
+ _nvmlCheckReturn(ret)
2582
+ return c_numFans.value
2583
+
2584
+
2585
+ def nvmlDeviceSetDefaultFanSpeed_v2(handle, index):
2586
+ fn = _nvmlGetFunctionPointer("nvmlDeviceSetDefaultFanSpeed_v2")
2587
+ ret = fn(handle, index)
2588
+ _nvmlCheckReturn(ret)
2589
+ return ret
2590
+
2591
+
2592
+ def nvmlDeviceGetMinMaxFanSpeed(handle, minSpeed, maxSpeed):
2593
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetMinMaxFanSpeed")
2594
+ ret = fn(handle, minSpeed, maxSpeed)
2595
+ _nvmlCheckReturn(ret)
2596
+ return ret
2597
+
2598
+
2599
+ def nvmlDeviceGetTemperature(handle, sensor):
2600
+ c_temp = c_uint()
2601
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetTemperature")
2602
+ ret = fn(handle, _nvmlTemperatureSensors_t(sensor), byref(c_temp))
2603
+ _nvmlCheckReturn(ret)
2604
+ return c_temp.value
2605
+
2606
+
2607
+ def nvmlDeviceGetTemperatureThreshold(handle, threshold):
2608
+ c_temp = c_uint()
2609
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetTemperatureThreshold")
2610
+ ret = fn(handle, _nvmlTemperatureThresholds_t(threshold), byref(c_temp))
2611
+ _nvmlCheckReturn(ret)
2612
+ return c_temp.value
2613
+
2614
+
2615
+ def nvmlDeviceSetTemperatureThreshold(handle, threshold):
2616
+ c_temp = c_uint()
2617
+ fn = _nvmlGetFunctionPointer("nvmlDeviceSetTemperatureThreshold")
2618
+ ret = fn(handle, _nvmlTemperatureThresholds_t(threshold), byref(c_temp))
2619
+ _nvmlCheckReturn(ret)
2620
+ return None
2621
+
2622
+
2623
+ # DEPRECATED use nvmlDeviceGetPerformanceState
2624
+ def nvmlDeviceGetPowerState(handle):
2625
+ c_pstate = _nvmlPstates_t()
2626
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetPowerState")
2627
+ ret = fn(handle, byref(c_pstate))
2628
+ _nvmlCheckReturn(ret)
2629
+ return c_pstate.value
2630
+
2631
+
2632
+ def nvmlDeviceGetPerformanceState(handle):
2633
+ c_pstate = _nvmlPstates_t()
2634
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetPerformanceState")
2635
+ ret = fn(handle, byref(c_pstate))
2636
+ _nvmlCheckReturn(ret)
2637
+ return c_pstate.value
2638
+
2639
+
2640
+ def nvmlDeviceGetPowerManagementMode(handle):
2641
+ c_pcapMode = _nvmlEnableState_t()
2642
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetPowerManagementMode")
2643
+ ret = fn(handle, byref(c_pcapMode))
2644
+ _nvmlCheckReturn(ret)
2645
+ return c_pcapMode.value
2646
+
2647
+
2648
+ def nvmlDeviceGetPowerManagementLimit(handle):
2649
+ c_limit = c_uint()
2650
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetPowerManagementLimit")
2651
+ ret = fn(handle, byref(c_limit))
2652
+ _nvmlCheckReturn(ret)
2653
+ return c_limit.value
2654
+
2655
+
2656
+ # Added in 4.304
2657
+ def nvmlDeviceGetPowerManagementLimitConstraints(handle):
2658
+ c_minLimit = c_uint()
2659
+ c_maxLimit = c_uint()
2660
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetPowerManagementLimitConstraints")
2661
+ ret = fn(handle, byref(c_minLimit), byref(c_maxLimit))
2662
+ _nvmlCheckReturn(ret)
2663
+ return [c_minLimit.value, c_maxLimit.value]
2664
+
2665
+
2666
+ # Added in 4.304
2667
+ def nvmlDeviceGetPowerManagementDefaultLimit(handle):
2668
+ c_limit = c_uint()
2669
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetPowerManagementDefaultLimit")
2670
+ ret = fn(handle, byref(c_limit))
2671
+ _nvmlCheckReturn(ret)
2672
+ return c_limit.value
2673
+
2674
+
2675
+ # Added in 331
2676
+ def nvmlDeviceGetEnforcedPowerLimit(handle):
2677
+ c_limit = c_uint()
2678
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetEnforcedPowerLimit")
2679
+ ret = fn(handle, byref(c_limit))
2680
+ _nvmlCheckReturn(ret)
2681
+ return c_limit.value
2682
+
2683
+
2684
+ def nvmlDeviceGetPowerUsage(handle):
2685
+ c_watts = c_uint()
2686
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetPowerUsage")
2687
+ ret = fn(handle, byref(c_watts))
2688
+ _nvmlCheckReturn(ret)
2689
+ return c_watts.value
2690
+
2691
+
2692
+ def nvmlDeviceGetTotalEnergyConsumption(handle):
2693
+ c_millijoules = c_uint64()
2694
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetTotalEnergyConsumption")
2695
+ ret = fn(handle, byref(c_millijoules))
2696
+ _nvmlCheckReturn(ret)
2697
+ return c_millijoules.value
2698
+
2699
+
2700
+ # Added in 4.304
2701
+ def nvmlDeviceGetGpuOperationMode(handle):
2702
+ c_currState = _nvmlGpuOperationMode_t()
2703
+ c_pendingState = _nvmlGpuOperationMode_t()
2704
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetGpuOperationMode")
2705
+ ret = fn(handle, byref(c_currState), byref(c_pendingState))
2706
+ _nvmlCheckReturn(ret)
2707
+ return [c_currState.value, c_pendingState.value]
2708
+
2709
+
2710
+ # Added in 4.304
2711
+ def nvmlDeviceGetCurrentGpuOperationMode(handle):
2712
+ return nvmlDeviceGetGpuOperationMode(handle)[0]
2713
+
2714
+
2715
+ # Added in 4.304
2716
+ def nvmlDeviceGetPendingGpuOperationMode(handle):
2717
+ return nvmlDeviceGetGpuOperationMode(handle)[1]
2718
+
2719
+
2720
+ def nvmlDeviceGetMemoryInfo(handle, version=None):
2721
+ if not version:
2722
+ c_memory = c_nvmlMemory_t()
2723
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetMemoryInfo")
2724
+ else:
2725
+ c_memory = c_nvmlMemory_v2_t()
2726
+ c_memory.version = version
2727
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetMemoryInfo_v2")
2728
+ ret = fn(handle, byref(c_memory))
2729
+ _nvmlCheckReturn(ret)
2730
+ return c_memory
2731
+
2732
+
2733
+ def nvmlDeviceGetBAR1MemoryInfo(handle):
2734
+ c_bar1_memory = c_nvmlBAR1Memory_t()
2735
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetBAR1MemoryInfo")
2736
+ ret = fn(handle, byref(c_bar1_memory))
2737
+ _nvmlCheckReturn(ret)
2738
+ return c_bar1_memory
2739
+
2740
+
2741
+ def nvmlDeviceGetComputeMode(handle):
2742
+ c_mode = _nvmlComputeMode_t()
2743
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetComputeMode")
2744
+ ret = fn(handle, byref(c_mode))
2745
+ _nvmlCheckReturn(ret)
2746
+ return c_mode.value
2747
+
2748
+
2749
+ def nvmlDeviceGetCudaComputeCapability(handle):
2750
+ c_major = c_int()
2751
+ c_minor = c_int()
2752
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetCudaComputeCapability")
2753
+ ret = fn(handle, byref(c_major), byref(c_minor))
2754
+ _nvmlCheckReturn(ret)
2755
+ return (c_major.value, c_minor.value)
2756
+
2757
+
2758
+ def nvmlDeviceGetEccMode(handle):
2759
+ c_currState = _nvmlEnableState_t()
2760
+ c_pendingState = _nvmlEnableState_t()
2761
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetEccMode")
2762
+ ret = fn(handle, byref(c_currState), byref(c_pendingState))
2763
+ _nvmlCheckReturn(ret)
2764
+ return [c_currState.value, c_pendingState.value]
2765
+
2766
+
2767
+ # added to API
2768
+ def nvmlDeviceGetCurrentEccMode(handle):
2769
+ return nvmlDeviceGetEccMode(handle)[0]
2770
+
2771
+
2772
+ # added to API
2773
+ def nvmlDeviceGetPendingEccMode(handle):
2774
+ return nvmlDeviceGetEccMode(handle)[1]
2775
+
2776
+
2777
+ def nvmlDeviceGetDefaultEccMode(handle):
2778
+ c_defaultState = _nvmlEnableState_t()
2779
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetDefaultEccMode")
2780
+ ret = fn(handle, byref(c_defaultState))
2781
+ _nvmlCheckReturn(ret)
2782
+ return [c_defaultState.value]
2783
+
2784
+
2785
+ def nvmlDeviceGetTotalEccErrors(handle, errorType, counterType):
2786
+ c_count = c_ulonglong()
2787
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetTotalEccErrors")
2788
+ ret = fn(
2789
+ handle,
2790
+ _nvmlMemoryErrorType_t(errorType),
2791
+ _nvmlEccCounterType_t(counterType),
2792
+ byref(c_count),
2793
+ )
2794
+ _nvmlCheckReturn(ret)
2795
+ return c_count.value
2796
+
2797
+
2798
+ # This is deprecated, instead use nvmlDeviceGetMemoryErrorCounter
2799
+ def nvmlDeviceGetDetailedEccErrors(handle, errorType, counterType):
2800
+ c_counts = c_nvmlEccErrorCounts_t()
2801
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetDetailedEccErrors")
2802
+ ret = fn(
2803
+ handle,
2804
+ _nvmlMemoryErrorType_t(errorType),
2805
+ _nvmlEccCounterType_t(counterType),
2806
+ byref(c_counts),
2807
+ )
2808
+ _nvmlCheckReturn(ret)
2809
+ return c_counts
2810
+
2811
+
2812
+ # Added in 4.304
2813
+ def nvmlDeviceGetMemoryErrorCounter(handle, errorType, counterType, locationType):
2814
+ c_count = c_ulonglong()
2815
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetMemoryErrorCounter")
2816
+ ret = fn(
2817
+ handle,
2818
+ _nvmlMemoryErrorType_t(errorType),
2819
+ _nvmlEccCounterType_t(counterType),
2820
+ _nvmlMemoryLocation_t(locationType),
2821
+ byref(c_count),
2822
+ )
2823
+ _nvmlCheckReturn(ret)
2824
+ return c_count.value
2825
+
2826
+
2827
+ def nvmlDeviceGetUtilizationRates(handle):
2828
+ c_util = c_nvmlUtilization_t()
2829
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetUtilizationRates")
2830
+ ret = fn(handle, byref(c_util))
2831
+ _nvmlCheckReturn(ret)
2832
+ return c_util
2833
+
2834
+
2835
+ def nvmlDeviceGetEncoderUtilization(handle):
2836
+ c_util = c_uint()
2837
+ c_samplingPeriod = c_uint()
2838
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetEncoderUtilization")
2839
+ ret = fn(handle, byref(c_util), byref(c_samplingPeriod))
2840
+ _nvmlCheckReturn(ret)
2841
+ return [c_util.value, c_samplingPeriod.value]
2842
+
2843
+
2844
+ def nvmlDeviceGetDecoderUtilization(handle):
2845
+ c_util = c_uint()
2846
+ c_samplingPeriod = c_uint()
2847
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetDecoderUtilization")
2848
+ ret = fn(handle, byref(c_util), byref(c_samplingPeriod))
2849
+ _nvmlCheckReturn(ret)
2850
+ return [c_util.value, c_samplingPeriod.value]
2851
+
2852
+
2853
+ def nvmlDeviceGetPcieReplayCounter(handle):
2854
+ c_replay = c_uint()
2855
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetPcieReplayCounter")
2856
+ ret = fn(handle, byref(c_replay))
2857
+ _nvmlCheckReturn(ret)
2858
+ return c_replay.value
2859
+
2860
+
2861
+ def nvmlDeviceGetDriverModel(handle):
2862
+ c_currModel = _nvmlDriverModel_t()
2863
+ c_pendingModel = _nvmlDriverModel_t()
2864
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetDriverModel")
2865
+ ret = fn(handle, byref(c_currModel), byref(c_pendingModel))
2866
+ _nvmlCheckReturn(ret)
2867
+ return [c_currModel.value, c_pendingModel.value]
2868
+
2869
+
2870
+ # added to API
2871
+ def nvmlDeviceGetCurrentDriverModel(handle):
2872
+ return nvmlDeviceGetDriverModel(handle)[0]
2873
+
2874
+
2875
+ # added to API
2876
+ def nvmlDeviceGetPendingDriverModel(handle):
2877
+ return nvmlDeviceGetDriverModel(handle)[1]
2878
+
2879
+
2880
+ # Added in 2.285
2881
+ @convertStrBytes
2882
+ def nvmlDeviceGetVbiosVersion(handle):
2883
+ c_version = create_string_buffer(NVML_DEVICE_VBIOS_VERSION_BUFFER_SIZE)
2884
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetVbiosVersion")
2885
+ ret = fn(handle, c_version, c_uint(NVML_DEVICE_VBIOS_VERSION_BUFFER_SIZE))
2886
+ _nvmlCheckReturn(ret)
2887
+ return c_version.value
2888
+
2889
+
2890
+ # Added in 2.285
2891
+ def nvmlDeviceGetComputeRunningProcesses_v3(handle):
2892
+ # first call to get the size
2893
+ c_count = c_uint(0)
2894
+ fn = None
2895
+ for suffix in ("_v3", "_v2", ""):
2896
+ try:
2897
+ fn = _nvmlGetFunctionPointer(
2898
+ f"nvmlDeviceGetComputeRunningProcesses{suffix}"
2899
+ )
2900
+ break
2901
+ except NVMLError:
2902
+ pass
2903
+ if fn is None:
2904
+ raise NVMLError(NVML_ERROR_FUNCTION_NOT_FOUND)
2905
+ ret = fn(handle, byref(c_count), None)
2906
+
2907
+ if ret == NVML_SUCCESS:
2908
+ # special case, no running processes
2909
+ return []
2910
+ elif ret == NVML_ERROR_INSUFFICIENT_SIZE:
2911
+ # typical case
2912
+ # oversize the array incase more processes are created
2913
+ c_count.value = c_count.value * 2 + 5
2914
+ proc_array = c_nvmlProcessInfo_t * c_count.value
2915
+ c_procs = proc_array()
2916
+
2917
+ # make the call again
2918
+ ret = fn(handle, byref(c_count), c_procs)
2919
+ _nvmlCheckReturn(ret)
2920
+
2921
+ procs = []
2922
+ for i in range(c_count.value):
2923
+ # use an alternative struct for this object
2924
+ obj = nvmlStructToFriendlyObject(c_procs[i])
2925
+ if obj.usedGpuMemory == NVML_VALUE_NOT_AVAILABLE_ulonglong.value:
2926
+ # special case for WDDM on Windows, see comment above
2927
+ obj.usedGpuMemory = None
2928
+ procs.append(obj)
2929
+
2930
+ return procs
2931
+ else:
2932
+ # error case
2933
+ raise NVMLError(ret)
2934
+
2935
+
2936
+ def nvmlDeviceGetComputeRunningProcesses(handle):
2937
+ return nvmlDeviceGetComputeRunningProcesses_v3(handle)
2938
+
2939
+
2940
+ def nvmlDeviceGetGraphicsRunningProcesses_v3(handle):
2941
+ # first call to get the size
2942
+ c_count = c_uint(0)
2943
+ fn = None
2944
+ for suffix in ("_v3", "_v2", ""):
2945
+ try:
2946
+ fn = _nvmlGetFunctionPointer(
2947
+ f"nvmlDeviceGetGraphicsRunningProcesses{suffix}"
2948
+ )
2949
+ break
2950
+ except NVMLError:
2951
+ pass
2952
+ if fn is None:
2953
+ raise NVMLError(NVML_ERROR_FUNCTION_NOT_FOUND)
2954
+ ret = fn(handle, byref(c_count), None)
2955
+
2956
+ if ret == NVML_SUCCESS:
2957
+ # special case, no running processes
2958
+ return []
2959
+ elif ret == NVML_ERROR_INSUFFICIENT_SIZE:
2960
+ # typical case
2961
+ # oversize the array incase more processes are created
2962
+ c_count.value = c_count.value * 2 + 5
2963
+ proc_array = c_nvmlProcessInfo_t * c_count.value
2964
+ c_procs = proc_array()
2965
+
2966
+ # make the call again
2967
+ ret = fn(handle, byref(c_count), c_procs)
2968
+ _nvmlCheckReturn(ret)
2969
+
2970
+ procs = []
2971
+ for i in range(c_count.value):
2972
+ # use an alternative struct for this object
2973
+ obj = nvmlStructToFriendlyObject(c_procs[i])
2974
+ if obj.usedGpuMemory == NVML_VALUE_NOT_AVAILABLE_ulonglong.value:
2975
+ # special case for WDDM on Windows, see comment above
2976
+ obj.usedGpuMemory = None
2977
+ procs.append(obj)
2978
+
2979
+ return procs
2980
+ else:
2981
+ # error case
2982
+ raise NVMLError(ret)
2983
+
2984
+
2985
+ def nvmlDeviceGetGraphicsRunningProcesses(handle):
2986
+ return nvmlDeviceGetGraphicsRunningProcesses_v3(handle)
2987
+
2988
+
2989
+ def nvmlDeviceGetMPSComputeRunningProcesses(handle):
2990
+ return nvmlDeviceGetMPSComputeRunningProcesses_v3(handle)
2991
+
2992
+
2993
+ def nvmlDeviceGetMPSComputeRunningProcesses_v3(handle):
2994
+ # first call to get the size
2995
+ c_count = c_uint(0)
2996
+ fn = None
2997
+ for suffix in ("_v3", "_v2", ""):
2998
+ try:
2999
+ fn = _nvmlGetFunctionPointer(
3000
+ f"nvmlDeviceGetMPSComputeRunningProcesses{suffix}"
3001
+ )
3002
+ break
3003
+ except NVMLError:
3004
+ pass
3005
+ if fn is None:
3006
+ raise NVMLError(NVML_ERROR_FUNCTION_NOT_FOUND)
3007
+
3008
+ ret = fn(handle, byref(c_count), None)
3009
+
3010
+ if ret == NVML_SUCCESS:
3011
+ # special case, no running processes
3012
+ return []
3013
+ elif ret == NVML_ERROR_INSUFFICIENT_SIZE:
3014
+ # typical case
3015
+ # oversize the array incase more processes are created
3016
+ c_count.value = c_count.value * 2 + 5
3017
+ proc_array = c_nvmlProcessInfo_t * c_count.value
3018
+ c_procs = proc_array()
3019
+
3020
+ # make the call again
3021
+ ret = fn(handle, byref(c_count), c_procs)
3022
+ _nvmlCheckReturn(ret)
3023
+
3024
+ procs = []
3025
+ for i in range(c_count.value):
3026
+ # use an alternative struct for this object
3027
+ obj = nvmlStructToFriendlyObject(c_procs[i])
3028
+ if obj.usedGpuMemory == NVML_VALUE_NOT_AVAILABLE_ulonglong.value:
3029
+ # special case for WDDM on Windows, see comment above
3030
+ obj.usedGpuMemory = None
3031
+ procs.append(obj)
3032
+
3033
+ return procs
3034
+ else:
3035
+ # error case
3036
+ raise NVMLError(ret)
3037
+
3038
+
3039
+ def nvmlDeviceGetAutoBoostedClocksEnabled(handle):
3040
+ c_isEnabled = _nvmlEnableState_t()
3041
+ c_defaultIsEnabled = _nvmlEnableState_t()
3042
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetAutoBoostedClocksEnabled")
3043
+ ret = fn(handle, byref(c_isEnabled), byref(c_defaultIsEnabled))
3044
+ _nvmlCheckReturn(ret)
3045
+ return [c_isEnabled.value, c_defaultIsEnabled.value]
3046
+ # Throws NVML_ERROR_NOT_SUPPORTED if hardware doesn't support setting auto boosted clocks
3047
+
3048
+
3049
+ ## Set functions
3050
+ def nvmlUnitSetLedState(unit, color):
3051
+ fn = _nvmlGetFunctionPointer("nvmlUnitSetLedState")
3052
+ ret = fn(unit, _nvmlLedColor_t(color))
3053
+ _nvmlCheckReturn(ret)
3054
+ return None
3055
+
3056
+
3057
+ def nvmlDeviceSetPersistenceMode(handle, mode):
3058
+ fn = _nvmlGetFunctionPointer("nvmlDeviceSetPersistenceMode")
3059
+ ret = fn(handle, _nvmlEnableState_t(mode))
3060
+ _nvmlCheckReturn(ret)
3061
+ return None
3062
+
3063
+
3064
+ def nvmlDeviceSetComputeMode(handle, mode):
3065
+ fn = _nvmlGetFunctionPointer("nvmlDeviceSetComputeMode")
3066
+ ret = fn(handle, _nvmlComputeMode_t(mode))
3067
+ _nvmlCheckReturn(ret)
3068
+ return None
3069
+
3070
+
3071
+ def nvmlDeviceSetEccMode(handle, mode):
3072
+ fn = _nvmlGetFunctionPointer("nvmlDeviceSetEccMode")
3073
+ ret = fn(handle, _nvmlEnableState_t(mode))
3074
+ _nvmlCheckReturn(ret)
3075
+ return None
3076
+
3077
+
3078
+ def nvmlDeviceClearEccErrorCounts(handle, counterType):
3079
+ fn = _nvmlGetFunctionPointer("nvmlDeviceClearEccErrorCounts")
3080
+ ret = fn(handle, _nvmlEccCounterType_t(counterType))
3081
+ _nvmlCheckReturn(ret)
3082
+ return None
3083
+
3084
+
3085
+ def nvmlDeviceSetDriverModel(handle, model):
3086
+ fn = _nvmlGetFunctionPointer("nvmlDeviceSetDriverModel")
3087
+ ret = fn(handle, _nvmlDriverModel_t(model))
3088
+ _nvmlCheckReturn(ret)
3089
+ return None
3090
+
3091
+
3092
+ def nvmlDeviceSetAutoBoostedClocksEnabled(handle, enabled):
3093
+ fn = _nvmlGetFunctionPointer("nvmlDeviceSetAutoBoostedClocksEnabled")
3094
+ ret = fn(handle, _nvmlEnableState_t(enabled))
3095
+ _nvmlCheckReturn(ret)
3096
+ return None
3097
+ # Throws NVML_ERROR_NOT_SUPPORTED if hardware doesn't support setting auto boosted clocks
3098
+
3099
+
3100
+ def nvmlDeviceSetDefaultAutoBoostedClocksEnabled(handle, enabled, flags):
3101
+ fn = _nvmlGetFunctionPointer("nvmlDeviceSetDefaultAutoBoostedClocksEnabled")
3102
+ ret = fn(handle, _nvmlEnableState_t(enabled), c_uint(flags))
3103
+ _nvmlCheckReturn(ret)
3104
+ return None
3105
+ # Throws NVML_ERROR_NOT_SUPPORTED if hardware doesn't support setting auto boosted clocks
3106
+
3107
+
3108
+ def nvmlDeviceSetGpuLockedClocks(handle, minGpuClockMHz, maxGpuClockMHz):
3109
+ fn = _nvmlGetFunctionPointer("nvmlDeviceSetGpuLockedClocks")
3110
+ ret = fn(handle, c_uint(minGpuClockMHz), c_uint(maxGpuClockMHz))
3111
+ _nvmlCheckReturn(ret)
3112
+ return None
3113
+
3114
+
3115
+ def nvmlDeviceResetGpuLockedClocks(handle):
3116
+ fn = _nvmlGetFunctionPointer("nvmlDeviceResetGpuLockedClocks")
3117
+ ret = fn(handle)
3118
+ _nvmlCheckReturn(ret)
3119
+ return None
3120
+
3121
+
3122
+ def nvmlDeviceSetMemoryLockedClocks(handle, minMemClockMHz, maxMemClockMHz):
3123
+ fn = _nvmlGetFunctionPointer("nvmlDeviceSetMemoryLockedClocks")
3124
+ ret = fn(handle, c_uint(minMemClockMHz), c_uint(maxMemClockMHz))
3125
+ _nvmlCheckReturn(ret)
3126
+ return None
3127
+
3128
+
3129
+ def nvmlDeviceResetMemoryLockedClocks(handle):
3130
+ fn = _nvmlGetFunctionPointer("nvmlDeviceResetMemoryLockedClocks")
3131
+ ret = fn(handle)
3132
+ _nvmlCheckReturn(ret)
3133
+ return None
3134
+
3135
+
3136
+ def nvmlDeviceGetClkMonStatus(handle, c_clkMonInfo):
3137
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetClkMonStatus")
3138
+ ret = fn(handle, c_clkMonInfo)
3139
+ return ret
3140
+
3141
+
3142
+ # Added in 4.304
3143
+ def nvmlDeviceSetApplicationsClocks(handle, maxMemClockMHz, maxGraphicsClockMHz):
3144
+ fn = _nvmlGetFunctionPointer("nvmlDeviceSetApplicationsClocks")
3145
+ ret = fn(handle, c_uint(maxMemClockMHz), c_uint(maxGraphicsClockMHz))
3146
+ _nvmlCheckReturn(ret)
3147
+ return None
3148
+
3149
+
3150
+ # Added in 4.304
3151
+ def nvmlDeviceResetApplicationsClocks(handle):
3152
+ fn = _nvmlGetFunctionPointer("nvmlDeviceResetApplicationsClocks")
3153
+ ret = fn(handle)
3154
+ _nvmlCheckReturn(ret)
3155
+ return None
3156
+
3157
+
3158
+ # Added in 4.304
3159
+ def nvmlDeviceSetPowerManagementLimit(handle, limit):
3160
+ fn = _nvmlGetFunctionPointer("nvmlDeviceSetPowerManagementLimit")
3161
+ ret = fn(handle, c_uint(limit))
3162
+ _nvmlCheckReturn(ret)
3163
+ return None
3164
+
3165
+
3166
+ # Added in 4.304
3167
+ def nvmlDeviceSetGpuOperationMode(handle, mode):
3168
+ fn = _nvmlGetFunctionPointer("nvmlDeviceSetGpuOperationMode")
3169
+ ret = fn(handle, _nvmlGpuOperationMode_t(mode))
3170
+ _nvmlCheckReturn(ret)
3171
+ return None
3172
+
3173
+
3174
+ # Added in 2.285
3175
+ def nvmlEventSetCreate():
3176
+ fn = _nvmlGetFunctionPointer("nvmlEventSetCreate")
3177
+ eventSet = c_nvmlEventSet_t()
3178
+ ret = fn(byref(eventSet))
3179
+ _nvmlCheckReturn(ret)
3180
+ return eventSet
3181
+
3182
+
3183
+ # Added in 2.285
3184
+ def nvmlDeviceRegisterEvents(handle, eventTypes, eventSet):
3185
+ fn = _nvmlGetFunctionPointer("nvmlDeviceRegisterEvents")
3186
+ ret = fn(handle, c_ulonglong(eventTypes), eventSet)
3187
+ _nvmlCheckReturn(ret)
3188
+ return None
3189
+
3190
+
3191
+ # Added in 2.285
3192
+ def nvmlDeviceGetSupportedEventTypes(handle):
3193
+ c_eventTypes = c_ulonglong()
3194
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetSupportedEventTypes")
3195
+ ret = fn(handle, byref(c_eventTypes))
3196
+ _nvmlCheckReturn(ret)
3197
+ return c_eventTypes.value
3198
+
3199
+
3200
+ # raises NVML_ERROR_TIMEOUT exception on timeout
3201
+ def nvmlEventSetWait_v2(eventSet, timeoutms):
3202
+ fn = _nvmlGetFunctionPointer("nvmlEventSetWait_v2")
3203
+ data = c_nvmlEventData_t()
3204
+ ret = fn(eventSet, byref(data), c_uint(timeoutms))
3205
+ _nvmlCheckReturn(ret)
3206
+ return data
3207
+
3208
+
3209
+ def nvmlEventSetWait(eventSet, timeoutms):
3210
+ return nvmlEventSetWait_v2(eventSet, timeoutms)
3211
+
3212
+
3213
+ # Added in 2.285
3214
+ def nvmlEventSetFree(eventSet):
3215
+ fn = _nvmlGetFunctionPointer("nvmlEventSetFree")
3216
+ ret = fn(eventSet)
3217
+ _nvmlCheckReturn(ret)
3218
+ return None
3219
+
3220
+
3221
+ # Added in 3.295
3222
+ def nvmlDeviceOnSameBoard(handle1, handle2):
3223
+ fn = _nvmlGetFunctionPointer("nvmlDeviceOnSameBoard")
3224
+ onSameBoard = c_int()
3225
+ ret = fn(handle1, handle2, byref(onSameBoard))
3226
+ _nvmlCheckReturn(ret)
3227
+ return onSameBoard.value != 0
3228
+
3229
+
3230
+ # Added in 3.295
3231
+ def nvmlDeviceGetCurrPcieLinkGeneration(handle):
3232
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetCurrPcieLinkGeneration")
3233
+ gen = c_uint()
3234
+ ret = fn(handle, byref(gen))
3235
+ _nvmlCheckReturn(ret)
3236
+ return gen.value
3237
+
3238
+
3239
+ # Added in 3.295
3240
+ def nvmlDeviceGetMaxPcieLinkGeneration(handle):
3241
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetMaxPcieLinkGeneration")
3242
+ gen = c_uint()
3243
+ ret = fn(handle, byref(gen))
3244
+ _nvmlCheckReturn(ret)
3245
+ return gen.value
3246
+
3247
+
3248
+ # Added in 3.295
3249
+ def nvmlDeviceGetCurrPcieLinkWidth(handle):
3250
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetCurrPcieLinkWidth")
3251
+ width = c_uint()
3252
+ ret = fn(handle, byref(width))
3253
+ _nvmlCheckReturn(ret)
3254
+ return width.value
3255
+
3256
+
3257
+ # Added in 3.295
3258
+ def nvmlDeviceGetMaxPcieLinkWidth(handle):
3259
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetMaxPcieLinkWidth")
3260
+ width = c_uint()
3261
+ ret = fn(handle, byref(width))
3262
+ _nvmlCheckReturn(ret)
3263
+ return width.value
3264
+
3265
+
3266
+ # Added in 4.304
3267
+ def nvmlDeviceGetSupportedClocksThrottleReasons(handle):
3268
+ c_reasons = c_ulonglong()
3269
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetSupportedClocksThrottleReasons")
3270
+ ret = fn(handle, byref(c_reasons))
3271
+ _nvmlCheckReturn(ret)
3272
+ return c_reasons.value
3273
+
3274
+
3275
+ # Added in 4.304
3276
+ def nvmlDeviceGetCurrentClocksThrottleReasons(handle):
3277
+ c_reasons = c_ulonglong()
3278
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetCurrentClocksThrottleReasons")
3279
+ ret = fn(handle, byref(c_reasons))
3280
+ _nvmlCheckReturn(ret)
3281
+ return c_reasons.value
3282
+
3283
+
3284
+ # Added in 5.319
3285
+ def nvmlDeviceGetIndex(handle):
3286
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetIndex")
3287
+ c_index = c_uint()
3288
+ ret = fn(handle, byref(c_index))
3289
+ _nvmlCheckReturn(ret)
3290
+ return c_index.value
3291
+
3292
+
3293
+ # Added in 5.319
3294
+ def nvmlDeviceGetAccountingMode(handle):
3295
+ c_mode = _nvmlEnableState_t()
3296
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetAccountingMode")
3297
+ ret = fn(handle, byref(c_mode))
3298
+ _nvmlCheckReturn(ret)
3299
+ return c_mode.value
3300
+
3301
+
3302
+ def nvmlDeviceSetAccountingMode(handle, mode):
3303
+ fn = _nvmlGetFunctionPointer("nvmlDeviceSetAccountingMode")
3304
+ ret = fn(handle, _nvmlEnableState_t(mode))
3305
+ _nvmlCheckReturn(ret)
3306
+ return None
3307
+
3308
+
3309
+ def nvmlDeviceClearAccountingPids(handle):
3310
+ fn = _nvmlGetFunctionPointer("nvmlDeviceClearAccountingPids")
3311
+ ret = fn(handle)
3312
+ _nvmlCheckReturn(ret)
3313
+ return None
3314
+
3315
+
3316
+ def nvmlDeviceGetAccountingStats(handle, pid):
3317
+ stats = c_nvmlAccountingStats_t()
3318
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetAccountingStats")
3319
+ ret = fn(handle, c_uint(pid), byref(stats))
3320
+ _nvmlCheckReturn(ret)
3321
+ if stats.maxMemoryUsage == NVML_VALUE_NOT_AVAILABLE_ulonglong.value:
3322
+ # special case for WDDM on Windows, see comment above
3323
+ stats.maxMemoryUsage = None
3324
+ return stats
3325
+
3326
+
3327
+ def nvmlDeviceGetAccountingPids(handle):
3328
+ count = c_uint(nvmlDeviceGetAccountingBufferSize(handle))
3329
+ pids = (c_uint * count.value)()
3330
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetAccountingPids")
3331
+ ret = fn(handle, byref(count), pids)
3332
+ _nvmlCheckReturn(ret)
3333
+ return list(map(int, pids[0 : count.value]))
3334
+
3335
+
3336
+ def nvmlDeviceGetAccountingBufferSize(handle):
3337
+ bufferSize = c_uint()
3338
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetAccountingBufferSize")
3339
+ ret = fn(handle, byref(bufferSize))
3340
+ _nvmlCheckReturn(ret)
3341
+ return int(bufferSize.value)
3342
+
3343
+
3344
+ def nvmlDeviceGetRetiredPages(device, sourceFilter):
3345
+ c_source = _nvmlPageRetirementCause_t(sourceFilter)
3346
+ c_count = c_uint(0)
3347
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetRetiredPages")
3348
+
3349
+ # First call will get the size
3350
+ ret = fn(device, c_source, byref(c_count), None)
3351
+
3352
+ # this should only fail with insufficient size
3353
+ if (ret != NVML_SUCCESS) and (ret != NVML_ERROR_INSUFFICIENT_SIZE):
3354
+ raise NVMLError(ret)
3355
+
3356
+ # call again with a buffer
3357
+ # oversize the array for the rare cases where additional pages
3358
+ # are retired between NVML calls
3359
+ c_count.value = c_count.value * 2 + 5
3360
+ page_array = c_ulonglong * c_count.value
3361
+ c_pages = page_array()
3362
+ ret = fn(device, c_source, byref(c_count), c_pages)
3363
+ _nvmlCheckReturn(ret)
3364
+ return list(map(int, c_pages[0 : c_count.value]))
3365
+
3366
+
3367
+ def nvmlDeviceGetRetiredPages_v2(device, sourceFilter):
3368
+ c_source = _nvmlPageRetirementCause_t(sourceFilter)
3369
+ c_count = c_uint(0)
3370
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetRetiredPages_v2")
3371
+
3372
+ # First call will get the size
3373
+ ret = fn(device, c_source, byref(c_count), None)
3374
+
3375
+ # this should only fail with insufficient size
3376
+ if (ret != NVML_SUCCESS) and (ret != NVML_ERROR_INSUFFICIENT_SIZE):
3377
+ raise NVMLError(ret)
3378
+
3379
+ # call again with a buffer
3380
+ # oversize the array for the rare cases where additional pages
3381
+ # are retired between NVML calls
3382
+ c_count.value = c_count.value * 2 + 5
3383
+ page_array = c_ulonglong * c_count.value
3384
+ c_pages = page_array()
3385
+ times_array = c_ulonglong * c_count.value
3386
+ c_times = times_array()
3387
+ ret = fn(device, c_source, byref(c_count), c_pages, c_times)
3388
+ _nvmlCheckReturn(ret)
3389
+ return [
3390
+ {"address": int(c_pages[i]), "timestamp": int(c_times[i])}
3391
+ for i in range(c_count.value)
3392
+ ]
3393
+
3394
+
3395
+ def nvmlDeviceGetRetiredPagesPendingStatus(device):
3396
+ c_pending = _nvmlEnableState_t()
3397
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetRetiredPagesPendingStatus")
3398
+ ret = fn(device, byref(c_pending))
3399
+ _nvmlCheckReturn(ret)
3400
+ return int(c_pending.value)
3401
+
3402
+
3403
+ def nvmlDeviceGetAPIRestriction(device, apiType):
3404
+ c_permission = _nvmlEnableState_t()
3405
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetAPIRestriction")
3406
+ ret = fn(device, _nvmlRestrictedAPI_t(apiType), byref(c_permission))
3407
+ _nvmlCheckReturn(ret)
3408
+ return int(c_permission.value)
3409
+
3410
+
3411
+ def nvmlDeviceSetAPIRestriction(handle, apiType, isRestricted):
3412
+ fn = _nvmlGetFunctionPointer("nvmlDeviceSetAPIRestriction")
3413
+ ret = fn(handle, _nvmlRestrictedAPI_t(apiType), _nvmlEnableState_t(isRestricted))
3414
+ _nvmlCheckReturn(ret)
3415
+ return None
3416
+
3417
+
3418
+ def nvmlDeviceGetBridgeChipInfo(handle):
3419
+ bridgeHierarchy = c_nvmlBridgeChipHierarchy_t()
3420
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetBridgeChipInfo")
3421
+ ret = fn(handle, byref(bridgeHierarchy))
3422
+ _nvmlCheckReturn(ret)
3423
+ return bridgeHierarchy
3424
+
3425
+
3426
+ def nvmlDeviceGetSamples(device, sampling_type, timeStamp):
3427
+ c_sampling_type = _nvmlSamplingType_t(sampling_type)
3428
+ c_time_stamp = c_ulonglong(timeStamp)
3429
+ c_sample_count = c_uint(0)
3430
+ c_sample_value_type = _nvmlValueType_t()
3431
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetSamples")
3432
+
3433
+ ## First Call gets the size
3434
+ ret = fn(
3435
+ device,
3436
+ c_sampling_type,
3437
+ c_time_stamp,
3438
+ byref(c_sample_value_type),
3439
+ byref(c_sample_count),
3440
+ None,
3441
+ )
3442
+
3443
+ # Stop if this fails
3444
+ if ret != NVML_SUCCESS:
3445
+ raise NVMLError(ret)
3446
+
3447
+ sampleArray = c_sample_count.value * c_nvmlSample_t
3448
+ c_samples = sampleArray()
3449
+ ret = fn(
3450
+ device,
3451
+ c_sampling_type,
3452
+ c_time_stamp,
3453
+ byref(c_sample_value_type),
3454
+ byref(c_sample_count),
3455
+ c_samples,
3456
+ )
3457
+ _nvmlCheckReturn(ret)
3458
+ return (c_sample_value_type.value, c_samples[0 : c_sample_count.value])
3459
+
3460
+
3461
+ def nvmlDeviceGetViolationStatus(device, perfPolicyType):
3462
+ c_perfPolicy_type = _nvmlPerfPolicyType_t(perfPolicyType)
3463
+ c_violTime = c_nvmlViolationTime_t()
3464
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetViolationStatus")
3465
+
3466
+ ## Invoke the method to get violation time
3467
+ ret = fn(device, c_perfPolicy_type, byref(c_violTime))
3468
+ _nvmlCheckReturn(ret)
3469
+ return c_violTime
3470
+
3471
+
3472
+ def nvmlDeviceGetPcieThroughput(device, counter):
3473
+ c_util = c_uint()
3474
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetPcieThroughput")
3475
+ ret = fn(device, _nvmlPcieUtilCounter_t(counter), byref(c_util))
3476
+ _nvmlCheckReturn(ret)
3477
+ return c_util.value
3478
+
3479
+
3480
+ def nvmlSystemGetTopologyGpuSet(cpuNumber):
3481
+ c_count = c_uint(0)
3482
+ fn = _nvmlGetFunctionPointer("nvmlSystemGetTopologyGpuSet")
3483
+
3484
+ # First call will get the size
3485
+ ret = fn(cpuNumber, byref(c_count), None)
3486
+
3487
+ if ret != NVML_SUCCESS:
3488
+ raise NVMLError(ret)
3489
+ # call again with a buffer
3490
+ device_array = c_nvmlDevice_t * c_count.value
3491
+ c_devices = device_array()
3492
+ ret = fn(cpuNumber, byref(c_count), c_devices)
3493
+ _nvmlCheckReturn(ret)
3494
+ return list(c_devices[0 : c_count.value])
3495
+
3496
+
3497
+ def nvmlDeviceGetTopologyNearestGpus(device, level):
3498
+ c_count = c_uint(0)
3499
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetTopologyNearestGpus")
3500
+
3501
+ # First call will get the size
3502
+ ret = fn(device, level, byref(c_count), None)
3503
+
3504
+ if ret != NVML_SUCCESS:
3505
+ raise NVMLError(ret)
3506
+
3507
+ # call again with a buffer
3508
+ device_array = c_nvmlDevice_t * c_count.value
3509
+ c_devices = device_array()
3510
+ ret = fn(device, level, byref(c_count), c_devices)
3511
+ _nvmlCheckReturn(ret)
3512
+ return list(c_devices[0 : c_count.value])
3513
+
3514
+
3515
+ def nvmlDeviceGetTopologyCommonAncestor(device1, device2):
3516
+ c_level = _nvmlGpuTopologyLevel_t()
3517
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetTopologyCommonAncestor")
3518
+ ret = fn(device1, device2, byref(c_level))
3519
+ _nvmlCheckReturn(ret)
3520
+ return c_level.value
3521
+
3522
+
3523
+ def nvmlDeviceGetNvLinkUtilizationCounter(device, link, counter):
3524
+ c_rxcounter = c_ulonglong()
3525
+ c_txcounter = c_ulonglong()
3526
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetNvLinkUtilizationCounter")
3527
+ ret = fn(device, link, counter, byref(c_rxcounter), byref(c_txcounter))
3528
+ _nvmlCheckReturn(ret)
3529
+ return (c_rxcounter.value, c_txcounter.value)
3530
+
3531
+
3532
+ def nvmlDeviceFreezeNvLinkUtilizationCounter(device, link, counter, freeze):
3533
+ fn = _nvmlGetFunctionPointer("nvmlDeviceFreezeNvLinkUtilizationCounter")
3534
+ ret = fn(device, link, counter, freeze)
3535
+ _nvmlCheckReturn(ret)
3536
+ return None
3537
+
3538
+
3539
+ def nvmlDeviceResetNvLinkUtilizationCounter(device, link, counter):
3540
+ fn = _nvmlGetFunctionPointer("nvmlDeviceResetNvLinkUtilizationCounter")
3541
+ ret = fn(device, link, counter)
3542
+ _nvmlCheckReturn(ret)
3543
+ return None
3544
+
3545
+
3546
+ def nvmlDeviceSetNvLinkUtilizationControl(device, link, counter, control, reset):
3547
+ fn = _nvmlGetFunctionPointer("nvmlDeviceSetNvLinkUtilizationControl")
3548
+ ret = fn(device, link, counter, byref(control), reset)
3549
+ _nvmlCheckReturn(ret)
3550
+ return None
3551
+
3552
+
3553
+ def nvmlDeviceGetNvLinkUtilizationControl(device, link, counter):
3554
+ c_control = nvmlNvLinkUtilizationControl_t()
3555
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetNvLinkUtilizationControl")
3556
+ ret = fn(device, link, counter, byref(c_control))
3557
+ _nvmlCheckReturn(ret)
3558
+ return c_control
3559
+
3560
+
3561
+ def nvmlDeviceGetNvLinkCapability(device, link, capability):
3562
+ c_capResult = c_uint()
3563
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetNvLinkCapability")
3564
+ ret = fn(device, link, capability, byref(c_capResult))
3565
+ _nvmlCheckReturn(ret)
3566
+ return c_capResult.value
3567
+
3568
+
3569
+ def nvmlDeviceGetNvLinkErrorCounter(device, link, counter):
3570
+ c_result = c_ulonglong()
3571
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetNvLinkErrorCounter")
3572
+ ret = fn(device, link, counter, byref(c_result))
3573
+ _nvmlCheckReturn(ret)
3574
+ return c_result.value
3575
+
3576
+
3577
+ def nvmlDeviceResetNvLinkErrorCounters(device, link):
3578
+ fn = _nvmlGetFunctionPointer("nvmlDeviceResetNvLinkErrorCounters")
3579
+ ret = fn(device, link)
3580
+ _nvmlCheckReturn(ret)
3581
+ return None
3582
+
3583
+
3584
+ def nvmlDeviceGetNvLinkRemotePciInfo(device, link):
3585
+ c_pci = nvmlPciInfo_t()
3586
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetNvLinkRemotePciInfo_v2")
3587
+ ret = fn(device, link, byref(c_pci))
3588
+ _nvmlCheckReturn(ret)
3589
+ return c_pci
3590
+
3591
+
3592
+ def nvmlDeviceGetNvLinkRemoteDeviceType(handle, link):
3593
+ c_type = _nvmlNvLinkDeviceType_t()
3594
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetNvLinkRemoteDeviceType")
3595
+ ret = fn(handle, link, byref(c_type))
3596
+ _nvmlCheckReturn(ret)
3597
+ return c_type.value
3598
+
3599
+
3600
+ def nvmlDeviceGetNvLinkState(device, link):
3601
+ c_isActive = c_uint()
3602
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetNvLinkState")
3603
+ ret = fn(device, link, byref(c_isActive))
3604
+ _nvmlCheckReturn(ret)
3605
+ return c_isActive.value
3606
+
3607
+
3608
+ def nvmlDeviceGetNvLinkVersion(device, link):
3609
+ c_version = c_uint()
3610
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetNvLinkVersion")
3611
+ ret = fn(device, link, byref(c_version))
3612
+ _nvmlCheckReturn(ret)
3613
+ return c_version.value
3614
+
3615
+
3616
+ def nvmlDeviceModifyDrainState(pciInfo, newState):
3617
+ fn = _nvmlGetFunctionPointer("nvmlDeviceModifyDrainState")
3618
+ ret = fn(pointer(pciInfo), newState)
3619
+ _nvmlCheckReturn(ret)
3620
+ return None
3621
+
3622
+
3623
+ def nvmlDeviceQueryDrainState(pciInfo):
3624
+ c_newState = c_uint()
3625
+ fn = _nvmlGetFunctionPointer("nvmlDeviceQueryDrainState")
3626
+ ret = fn(pointer(pciInfo), byref(c_newState))
3627
+ _nvmlCheckReturn(ret)
3628
+ return c_newState.value
3629
+
3630
+
3631
+ def nvmlDeviceRemoveGpu(pciInfo):
3632
+ fn = _nvmlGetFunctionPointer("nvmlDeviceRemoveGpu")
3633
+ ret = fn(pointer(pciInfo))
3634
+ _nvmlCheckReturn(ret)
3635
+ return None
3636
+
3637
+
3638
+ def nvmlDeviceDiscoverGpus(pciInfo):
3639
+ fn = _nvmlGetFunctionPointer("nvmlDeviceDiscoverGpus")
3640
+ ret = fn(pointer(pciInfo))
3641
+ _nvmlCheckReturn(ret)
3642
+ return None
3643
+
3644
+
3645
+ def nvmlDeviceGetFieldValues(handle, fieldIds):
3646
+ values_arr = c_nvmlFieldValue_t * len(fieldIds)
3647
+ values = values_arr()
3648
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetFieldValues")
3649
+
3650
+ for i, fieldId in enumerate(fieldIds):
3651
+ try:
3652
+ (values[i].fieldId, values[i].scopeId) = fieldId
3653
+ except TypeError:
3654
+ values[i].fieldId = fieldId
3655
+
3656
+ ret = fn(handle, c_int32(len(fieldIds)), byref(values))
3657
+ _nvmlCheckReturn(ret)
3658
+ return values
3659
+
3660
+
3661
+ def nvmlDeviceGetVirtualizationMode(handle):
3662
+ c_virtualization_mode = c_ulonglong()
3663
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetVirtualizationMode")
3664
+ ret = fn(handle, byref(c_virtualization_mode))
3665
+ _nvmlCheckReturn(ret)
3666
+ return c_virtualization_mode.value
3667
+
3668
+
3669
+ def nvmlDeviceSetVirtualizationMode(handle, virtualization_mode):
3670
+ fn = _nvmlGetFunctionPointer("nvmlDeviceSetVirtualizationMode")
3671
+ return fn(handle, virtualization_mode)
3672
+
3673
+
3674
+ def nvmlDeviceGetSupportedVgpus(handle):
3675
+ # first call to get the size
3676
+ c_vgpu_count = c_uint(0)
3677
+
3678
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetSupportedVgpus")
3679
+ ret = fn(handle, byref(c_vgpu_count), None)
3680
+
3681
+ if ret == NVML_SUCCESS:
3682
+ # special case, no supported vGPUs
3683
+ return []
3684
+ elif ret == NVML_ERROR_INSUFFICIENT_SIZE:
3685
+ # typical case
3686
+ vgpu_type_ids_array = _nvmlVgpuTypeId_t * c_vgpu_count.value
3687
+ c_vgpu_type_ids = vgpu_type_ids_array()
3688
+
3689
+ # make the call again
3690
+ ret = fn(handle, byref(c_vgpu_count), c_vgpu_type_ids)
3691
+ _nvmlCheckReturn(ret)
3692
+ vgpus = []
3693
+ for i in range(c_vgpu_count.value):
3694
+ vgpus.append(c_vgpu_type_ids[i])
3695
+ return vgpus
3696
+ else:
3697
+ # error case
3698
+ raise NVMLError(ret)
3699
+
3700
+
3701
+ def nvmlDeviceGetCreatableVgpus(handle):
3702
+ # first call to get the size
3703
+ c_vgpu_count = c_uint(0)
3704
+
3705
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetCreatableVgpus")
3706
+ ret = fn(handle, byref(c_vgpu_count), None)
3707
+
3708
+ if ret == NVML_SUCCESS:
3709
+ # special case, no supported vGPUs
3710
+ return []
3711
+ elif ret == NVML_ERROR_INSUFFICIENT_SIZE:
3712
+ # typical case
3713
+ vgpu_type_ids_array = _nvmlVgpuTypeId_t * c_vgpu_count.value
3714
+ c_vgpu_type_ids = vgpu_type_ids_array()
3715
+
3716
+ # make the call again
3717
+ ret = fn(handle, byref(c_vgpu_count), c_vgpu_type_ids)
3718
+ _nvmlCheckReturn(ret)
3719
+ vgpus = []
3720
+ for i in range(c_vgpu_count.value):
3721
+ vgpus.append(c_vgpu_type_ids[i])
3722
+ return vgpus
3723
+ else:
3724
+ # error case
3725
+ raise NVMLError(ret)
3726
+
3727
+
3728
+ def nvmlVgpuTypeGetGpuInstanceProfileId(vgpuTypeId):
3729
+ c_profile_id = c_uint(0)
3730
+ fn = _nvmlGetFunctionPointer("nvmlVgpuTypeGetGpuInstanceProfileId")
3731
+ ret = fn(vgpuTypeId, byref(c_profile_id))
3732
+ _nvmlCheckReturn(ret)
3733
+ return c_profile_id.value
3734
+
3735
+
3736
+ @convertStrBytes
3737
+ def nvmlVgpuTypeGetClass(vgpuTypeId):
3738
+ c_class = create_string_buffer(NVML_DEVICE_NAME_BUFFER_SIZE)
3739
+ c_buffer_size = c_uint(NVML_DEVICE_NAME_BUFFER_SIZE)
3740
+ fn = _nvmlGetFunctionPointer("nvmlVgpuTypeGetClass")
3741
+ ret = fn(vgpuTypeId, c_class, byref(c_buffer_size))
3742
+ _nvmlCheckReturn(ret)
3743
+ return c_class.value
3744
+
3745
+
3746
+ @convertStrBytes
3747
+ def nvmlVgpuTypeGetName(vgpuTypeId):
3748
+ c_name = create_string_buffer(NVML_DEVICE_NAME_BUFFER_SIZE)
3749
+ c_buffer_size = c_uint(NVML_DEVICE_NAME_BUFFER_SIZE)
3750
+ fn = _nvmlGetFunctionPointer("nvmlVgpuTypeGetName")
3751
+ ret = fn(vgpuTypeId, c_name, byref(c_buffer_size))
3752
+ _nvmlCheckReturn(ret)
3753
+ return c_name.value
3754
+
3755
+
3756
+ def nvmlVgpuTypeGetDeviceID(vgpuTypeId):
3757
+ c_device_id = c_ulonglong(0)
3758
+ c_subsystem_id = c_ulonglong(0)
3759
+ fn = _nvmlGetFunctionPointer("nvmlVgpuTypeGetDeviceID")
3760
+ ret = fn(vgpuTypeId, byref(c_device_id), byref(c_subsystem_id))
3761
+ _nvmlCheckReturn(ret)
3762
+ return (c_device_id.value, c_subsystem_id.value)
3763
+
3764
+
3765
+ def nvmlVgpuTypeGetFramebufferSize(vgpuTypeId):
3766
+ c_fb_size = c_ulonglong(0)
3767
+ fn = _nvmlGetFunctionPointer("nvmlVgpuTypeGetFramebufferSize")
3768
+ ret = fn(vgpuTypeId, byref(c_fb_size))
3769
+ _nvmlCheckReturn(ret)
3770
+ return c_fb_size.value
3771
+
3772
+
3773
+ def nvmlVgpuTypeGetNumDisplayHeads(vgpuTypeId):
3774
+ c_num_heads = c_uint(0)
3775
+ fn = _nvmlGetFunctionPointer("nvmlVgpuTypeGetNumDisplayHeads")
3776
+ ret = fn(vgpuTypeId, byref(c_num_heads))
3777
+ _nvmlCheckReturn(ret)
3778
+ return c_num_heads.value
3779
+
3780
+
3781
+ def nvmlVgpuTypeGetResolution(vgpuTypeId):
3782
+ c_xdim = c_uint(0)
3783
+ c_ydim = c_uint(0)
3784
+ fn = _nvmlGetFunctionPointer("nvmlVgpuTypeGetResolution")
3785
+ ret = fn(vgpuTypeId, 0, byref(c_xdim), byref(c_ydim))
3786
+ _nvmlCheckReturn(ret)
3787
+ return (c_xdim.value, c_ydim.value)
3788
+
3789
+
3790
+ @convertStrBytes
3791
+ def nvmlVgpuTypeGetLicense(vgpuTypeId):
3792
+ c_license = create_string_buffer(NVML_GRID_LICENSE_BUFFER_SIZE)
3793
+ c_buffer_size = c_uint(NVML_GRID_LICENSE_BUFFER_SIZE)
3794
+ fn = _nvmlGetFunctionPointer("nvmlVgpuTypeGetLicense")
3795
+ ret = fn(vgpuTypeId, c_license, c_buffer_size)
3796
+ _nvmlCheckReturn(ret)
3797
+ return c_license.value
3798
+
3799
+
3800
+ def nvmlVgpuTypeGetFrameRateLimit(vgpuTypeId):
3801
+ c_frl_config = c_uint(0)
3802
+ fn = _nvmlGetFunctionPointer("nvmlVgpuTypeGetFrameRateLimit")
3803
+ ret = fn(vgpuTypeId, byref(c_frl_config))
3804
+ _nvmlCheckReturn(ret)
3805
+ return c_frl_config.value
3806
+
3807
+
3808
+ def nvmlVgpuTypeGetMaxInstances(handle, vgpuTypeId):
3809
+ c_max_instances = c_uint(0)
3810
+ fn = _nvmlGetFunctionPointer("nvmlVgpuTypeGetMaxInstances")
3811
+ ret = fn(handle, vgpuTypeId, byref(c_max_instances))
3812
+ _nvmlCheckReturn(ret)
3813
+ return c_max_instances.value
3814
+
3815
+
3816
+ def nvmlVgpuTypeGetMaxInstancesPerVm(vgpuTypeId):
3817
+ c_max_instances_per_vm = c_uint(0)
3818
+ fn = _nvmlGetFunctionPointer("nvmlVgpuTypeGetMaxInstancesPerVm")
3819
+ ret = fn(vgpuTypeId, byref(c_max_instances_per_vm))
3820
+ _nvmlCheckReturn(ret)
3821
+ return c_max_instances_per_vm.value
3822
+
3823
+
3824
+ def nvmlDeviceGetActiveVgpus(handle):
3825
+ # first call to get the size
3826
+ c_vgpu_count = c_uint(0)
3827
+
3828
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetActiveVgpus")
3829
+ ret = fn(handle, byref(c_vgpu_count), None)
3830
+
3831
+ if ret == NVML_SUCCESS:
3832
+ # special case, no active vGPUs
3833
+ return []
3834
+ elif ret == NVML_ERROR_INSUFFICIENT_SIZE:
3835
+ # typical case
3836
+ vgpu_instance_array = _nvmlVgpuInstance_t * c_vgpu_count.value
3837
+ c_vgpu_instances = vgpu_instance_array()
3838
+
3839
+ # make the call again
3840
+ ret = fn(handle, byref(c_vgpu_count), c_vgpu_instances)
3841
+ _nvmlCheckReturn(ret)
3842
+ vgpus = []
3843
+ for i in range(c_vgpu_count.value):
3844
+ vgpus.append(c_vgpu_instances[i])
3845
+ return vgpus
3846
+ else:
3847
+ # error case
3848
+ raise NVMLError(ret)
3849
+
3850
+
3851
+ @convertStrBytes
3852
+ def nvmlVgpuInstanceGetVmID(vgpuInstance):
3853
+ c_vm_id = create_string_buffer(NVML_DEVICE_UUID_BUFFER_SIZE)
3854
+ c_buffer_size = c_uint(NVML_GRID_LICENSE_BUFFER_SIZE)
3855
+ c_vm_id_type = c_uint(0)
3856
+ fn = _nvmlGetFunctionPointer("nvmlVgpuInstanceGetVmID")
3857
+ ret = fn(vgpuInstance, byref(c_vm_id), c_buffer_size, byref(c_vm_id_type))
3858
+ _nvmlCheckReturn(ret)
3859
+ return (c_vm_id.value, c_vm_id_type.value)
3860
+
3861
+
3862
+ @convertStrBytes
3863
+ def nvmlVgpuInstanceGetUUID(vgpuInstance):
3864
+ c_uuid = create_string_buffer(NVML_DEVICE_UUID_BUFFER_SIZE)
3865
+ c_buffer_size = c_uint(NVML_DEVICE_UUID_BUFFER_SIZE)
3866
+ fn = _nvmlGetFunctionPointer("nvmlVgpuInstanceGetUUID")
3867
+ ret = fn(vgpuInstance, byref(c_uuid), c_buffer_size)
3868
+ _nvmlCheckReturn(ret)
3869
+ return c_uuid.value
3870
+
3871
+
3872
+ @convertStrBytes
3873
+ def nvmlVgpuInstanceGetMdevUUID(vgpuInstance):
3874
+ c_uuid = create_string_buffer(NVML_DEVICE_UUID_BUFFER_SIZE)
3875
+ c_buffer_size = c_uint(NVML_DEVICE_UUID_BUFFER_SIZE)
3876
+ fn = _nvmlGetFunctionPointer("nvmlVgpuInstanceGetMdevUUID")
3877
+ ret = fn(vgpuInstance, byref(c_uuid), c_buffer_size)
3878
+ _nvmlCheckReturn(ret)
3879
+ return c_uuid.value
3880
+
3881
+
3882
+ @convertStrBytes
3883
+ def nvmlVgpuInstanceGetVmDriverVersion(vgpuInstance):
3884
+ c_driver_version = create_string_buffer(NVML_SYSTEM_DRIVER_VERSION_BUFFER_SIZE)
3885
+ c_buffer_size = c_uint(NVML_SYSTEM_DRIVER_VERSION_BUFFER_SIZE)
3886
+ fn = _nvmlGetFunctionPointer("nvmlVgpuInstanceGetVmDriverVersion")
3887
+ ret = fn(vgpuInstance, byref(c_driver_version), c_buffer_size)
3888
+ _nvmlCheckReturn(ret)
3889
+ return c_driver_version.value
3890
+
3891
+
3892
+ def nvmlVgpuInstanceGetLicenseStatus(vgpuInstance):
3893
+ c_license_status = c_uint(0)
3894
+ fn = _nvmlGetFunctionPointer("nvmlVgpuInstanceGetLicenseStatus")
3895
+ ret = fn(vgpuInstance, byref(c_license_status))
3896
+ _nvmlCheckReturn(ret)
3897
+ return c_license_status.value
3898
+
3899
+
3900
+ def nvmlVgpuInstanceGetLicenseInfo_v2(vgpuInstance):
3901
+ fn = _nvmlGetFunctionPointer("nvmlVgpuInstanceGetLicenseInfo_v2")
3902
+ c_license_info = c_nvmlVgpuLicenseInfo_t()
3903
+ ret = fn(vgpuInstance, byref(c_license_info))
3904
+ _nvmlCheckReturn(ret)
3905
+ return c_license_info
3906
+
3907
+
3908
+ def nvmlVgpuInstanceGetLicenseInfo(vgpuInstance):
3909
+ return nvmlVgpuInstanceGetLicenseInfo_v2(vgpuInstance)
3910
+
3911
+
3912
+ def nvmlVgpuInstanceGetFrameRateLimit(vgpuInstance):
3913
+ c_frl = c_uint(0)
3914
+ fn = _nvmlGetFunctionPointer("nvmlVgpuInstanceGetFrameRateLimit")
3915
+ ret = fn(vgpuInstance, byref(c_frl))
3916
+ _nvmlCheckReturn(ret)
3917
+ return c_frl.value
3918
+
3919
+
3920
+ def nvmlVgpuInstanceGetEccMode(vgpuInstance):
3921
+ c_mode = _nvmlEnableState_t()
3922
+ fn = _nvmlGetFunctionPointer("nvmlVgpuInstanceGetEccMode")
3923
+ ret = fn(vgpuInstance, byref(c_mode))
3924
+ _nvmlCheckReturn(ret)
3925
+ return c_mode.value
3926
+
3927
+
3928
+ def nvmlVgpuInstanceGetType(vgpuInstance):
3929
+ c_vgpu_type = c_uint(0)
3930
+ fn = _nvmlGetFunctionPointer("nvmlVgpuInstanceGetType")
3931
+ ret = fn(vgpuInstance, byref(c_vgpu_type))
3932
+ _nvmlCheckReturn(ret)
3933
+ return c_vgpu_type.value
3934
+
3935
+
3936
+ def nvmlVgpuInstanceGetEncoderCapacity(vgpuInstance):
3937
+ c_encoder_capacity = c_ulonglong(0)
3938
+ fn = _nvmlGetFunctionPointer("nvmlVgpuInstanceGetEncoderCapacity")
3939
+ ret = fn(vgpuInstance, byref(c_encoder_capacity))
3940
+ _nvmlCheckReturn(ret)
3941
+ return c_encoder_capacity.value
3942
+
3943
+
3944
+ def nvmlVgpuInstanceSetEncoderCapacity(vgpuInstance, encoder_capacity):
3945
+ fn = _nvmlGetFunctionPointer("nvmlVgpuInstanceSetEncoderCapacity")
3946
+ return fn(vgpuInstance, encoder_capacity)
3947
+
3948
+
3949
+ def nvmlVgpuInstanceGetFbUsage(vgpuInstance):
3950
+ c_fb_usage = c_uint(0)
3951
+ fn = _nvmlGetFunctionPointer("nvmlVgpuInstanceGetFbUsage")
3952
+ ret = fn(vgpuInstance, byref(c_fb_usage))
3953
+ _nvmlCheckReturn(ret)
3954
+ return c_fb_usage.value
3955
+
3956
+
3957
+ def nvmlVgpuTypeGetCapabilities(vgpuTypeId, capability):
3958
+ c_cap_result = c_uint(0)
3959
+ fn = _nvmlGetFunctionPointer("nvmlVgpuTypeGetCapabilities")
3960
+ ret = fn(vgpuTypeId, _nvmlVgpuCapability_t(capability), byref(c_cap_result))
3961
+ _nvmlCheckReturn(ret)
3962
+ return c_cap_result.value
3963
+
3964
+
3965
+ def nvmlVgpuInstanceGetGpuInstanceId(vgpuInstance):
3966
+ c_id = c_uint(0)
3967
+ fn = _nvmlGetFunctionPointer("nvmlVgpuInstanceGetGpuInstanceId")
3968
+ ret = fn(vgpuInstance, byref(c_id))
3969
+ _nvmlCheckReturn(ret)
3970
+ return c_id.value
3971
+
3972
+
3973
+ def nvmlVgpuInstanceGetGpuPciId(vgpuInstance):
3974
+ c_vgpuPciId = create_string_buffer(NVML_DEVICE_PCI_BUS_ID_BUFFER_SIZE)
3975
+ fn = _nvmlGetFunctionPointer("nvmlVgpuInstanceGetGpuPciId")
3976
+ ret = fn(
3977
+ vgpuInstance, c_vgpuPciId, byref(c_uint(NVML_DEVICE_PCI_BUS_ID_BUFFER_SIZE))
3978
+ )
3979
+ _nvmlCheckReturn(ret)
3980
+ return c_vgpuPciId.value
3981
+
3982
+
3983
+ def nvmlDeviceGetVgpuUtilization(handle, timeStamp):
3984
+ # first call to get the size
3985
+ c_vgpu_count = c_uint(0)
3986
+ c_time_stamp = c_ulonglong(timeStamp)
3987
+ c_sample_value_type = _nvmlValueType_t()
3988
+
3989
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetVgpuUtilization")
3990
+ ret = fn(
3991
+ handle, c_time_stamp, byref(c_sample_value_type), byref(c_vgpu_count), None
3992
+ )
3993
+
3994
+ if ret == NVML_SUCCESS:
3995
+ # special case, no active vGPUs
3996
+ return []
3997
+ elif ret == NVML_ERROR_INSUFFICIENT_SIZE:
3998
+ # typical case
3999
+ sampleArray = c_vgpu_count.value * c_nvmlVgpuInstanceUtilizationSample_t
4000
+ c_samples = sampleArray()
4001
+
4002
+ # make the call again
4003
+ ret = fn(
4004
+ handle,
4005
+ c_time_stamp,
4006
+ byref(c_sample_value_type),
4007
+ byref(c_vgpu_count),
4008
+ c_samples,
4009
+ )
4010
+ _nvmlCheckReturn(ret)
4011
+
4012
+ return c_samples[0 : c_vgpu_count.value]
4013
+ else:
4014
+ # error case
4015
+ raise NVMLError(ret)
4016
+
4017
+
4018
+ def nvmlDeviceGetP2PStatus(device1, device2, p2pIndex):
4019
+ c_p2pstatus = _nvmlGpuP2PStatus_t()
4020
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetP2PStatus")
4021
+ ret = fn(device1, device2, p2pIndex, byref(c_p2pstatus))
4022
+ _nvmlCheckReturn(ret)
4023
+ return c_p2pstatus.value
4024
+
4025
+
4026
+ def nvmlDeviceGetGridLicensableFeatures_v4(handle):
4027
+ c_get_grid_licensable_features = c_nvmlGridLicensableFeatures_v4_t()
4028
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetGridLicensableFeatures_v4")
4029
+ ret = fn(handle, byref(c_get_grid_licensable_features))
4030
+ _nvmlCheckReturn(ret)
4031
+
4032
+ return c_get_grid_licensable_features
4033
+
4034
+
4035
+ def nvmlDeviceGetGridLicensableFeatures(handle):
4036
+ return nvmlDeviceGetGridLicensableFeatures_v4(handle)
4037
+
4038
+
4039
+ def nvmlDeviceGetGspFirmwareVersion(handle, version):
4040
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetGspFirmwareVersion")
4041
+ ret = fn(handle, version)
4042
+ _nvmlCheckReturn(ret)
4043
+ return ret
4044
+
4045
+
4046
+ def nvmlDeviceGetGspFirmwareMode(handle, isEnabled, defaultMode):
4047
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetGspFirmwareMode")
4048
+ ret = fn(handle, isEnabled, defaultMode)
4049
+ _nvmlCheckReturn(ret)
4050
+ return ret
4051
+
4052
+
4053
+ def nvmlDeviceGetEncoderCapacity(handle, encoderQueryType):
4054
+ c_encoder_capacity = c_ulonglong(0)
4055
+ c_encoderQuery_type = _nvmlEncoderQueryType_t(encoderQueryType)
4056
+
4057
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetEncoderCapacity")
4058
+ ret = fn(handle, c_encoderQuery_type, byref(c_encoder_capacity))
4059
+ _nvmlCheckReturn(ret)
4060
+ return c_encoder_capacity.value
4061
+
4062
+
4063
+ def nvmlDeviceGetVgpuProcessUtilization(handle, timeStamp):
4064
+ # first call to get the size
4065
+ c_vgpu_count = c_uint(0)
4066
+ c_time_stamp = c_ulonglong(timeStamp)
4067
+
4068
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetVgpuProcessUtilization")
4069
+ ret = fn(handle, c_time_stamp, byref(c_vgpu_count), None)
4070
+
4071
+ if ret == NVML_SUCCESS:
4072
+ # special case, no active vGPUs
4073
+ return []
4074
+ elif ret == NVML_ERROR_INSUFFICIENT_SIZE:
4075
+ # typical case
4076
+ sampleArray = c_vgpu_count.value * c_nvmlVgpuProcessUtilizationSample_t
4077
+ c_samples = sampleArray()
4078
+
4079
+ # make the call again
4080
+ ret = fn(handle, c_time_stamp, byref(c_vgpu_count), c_samples)
4081
+ _nvmlCheckReturn(ret)
4082
+
4083
+ return c_samples[0 : c_vgpu_count.value]
4084
+ else:
4085
+ # error case
4086
+ raise NVMLError(ret)
4087
+
4088
+
4089
+ def nvmlDeviceGetEncoderStats(handle):
4090
+ c_encoderCount = c_ulonglong(0)
4091
+ c_encodeFps = c_ulonglong(0)
4092
+ c_encoderLatency = c_ulonglong(0)
4093
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetEncoderStats")
4094
+ ret = fn(handle, byref(c_encoderCount), byref(c_encodeFps), byref(c_encoderLatency))
4095
+ _nvmlCheckReturn(ret)
4096
+ return (c_encoderCount.value, c_encodeFps.value, c_encoderLatency.value)
4097
+
4098
+
4099
+ def nvmlDeviceGetEncoderSessions(handle):
4100
+ # first call to get the size
4101
+ c_session_count = c_uint(0)
4102
+
4103
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetEncoderSessions")
4104
+ ret = fn(handle, byref(c_session_count), None)
4105
+
4106
+ if ret == NVML_SUCCESS:
4107
+ if c_session_count.value != 0:
4108
+ # typical case
4109
+ session_array = c_nvmlEncoderSession_t * c_session_count.value
4110
+ c_sessions = session_array()
4111
+
4112
+ # make the call again
4113
+ ret = fn(handle, byref(c_session_count), c_sessions)
4114
+ _nvmlCheckReturn(ret)
4115
+ sessions = []
4116
+ for i in range(c_session_count.value):
4117
+ sessions.append(c_sessions[i])
4118
+ return sessions
4119
+ else:
4120
+ return [] # no active sessions
4121
+ else:
4122
+ # error case
4123
+ raise NVMLError(ret)
4124
+
4125
+
4126
+ def nvmlDeviceGetFBCStats(handle):
4127
+ c_fbcStats = c_nvmlFBCStats_t()
4128
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetFBCStats")
4129
+ ret = fn(handle, byref(c_fbcStats))
4130
+ _nvmlCheckReturn(ret)
4131
+ return c_fbcStats
4132
+
4133
+
4134
+ def nvmlDeviceGetFBCSessions(handle):
4135
+ # first call to get the size
4136
+ c_session_count = c_uint(0)
4137
+
4138
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetFBCSessions")
4139
+ ret = fn(handle, byref(c_session_count), None)
4140
+
4141
+ if ret == NVML_SUCCESS:
4142
+ if c_session_count.value != 0:
4143
+ # typical case
4144
+ session_array = c_nvmlFBCSession_t * c_session_count.value
4145
+ c_sessions = session_array()
4146
+
4147
+ # make the call again
4148
+ ret = fn(handle, byref(c_session_count), c_sessions)
4149
+ _nvmlCheckReturn(ret)
4150
+ sessions = []
4151
+ for i in range(c_session_count.value):
4152
+ sessions.append(c_sessions[i])
4153
+ return sessions
4154
+ else:
4155
+ return [] # no active sessions
4156
+ else:
4157
+ # error case
4158
+ raise NVMLError(ret)
4159
+
4160
+
4161
+ def nvmlVgpuInstanceGetEncoderStats(vgpuInstance):
4162
+ c_encoderCount = c_ulonglong(0)
4163
+ c_encodeFps = c_ulonglong(0)
4164
+ c_encoderLatency = c_ulonglong(0)
4165
+ fn = _nvmlGetFunctionPointer("nvmlVgpuInstanceGetEncoderStats")
4166
+ ret = fn(
4167
+ vgpuInstance, byref(c_encoderCount), byref(c_encodeFps), byref(c_encoderLatency)
4168
+ )
4169
+ _nvmlCheckReturn(ret)
4170
+ return (c_encoderCount.value, c_encodeFps.value, c_encoderLatency.value)
4171
+
4172
+
4173
+ def nvmlVgpuInstanceGetEncoderSessions(vgpuInstance):
4174
+ # first call to get the size
4175
+ c_session_count = c_uint(0)
4176
+
4177
+ fn = _nvmlGetFunctionPointer("nvmlVgpuInstanceGetEncoderSessions")
4178
+ ret = fn(vgpuInstance, byref(c_session_count), None)
4179
+
4180
+ if ret == NVML_SUCCESS:
4181
+ if c_session_count.value != 0:
4182
+ # typical case
4183
+ session_array = c_nvmlEncoderSession_t * c_session_count.value
4184
+ c_sessions = session_array()
4185
+
4186
+ # make the call again
4187
+ ret = fn(vgpuInstance, byref(c_session_count), c_sessions)
4188
+ _nvmlCheckReturn(ret)
4189
+ sessions = []
4190
+ for i in range(c_session_count.value):
4191
+ sessions.append(c_sessions[i])
4192
+ return sessions
4193
+ else:
4194
+ return [] # no active sessions
4195
+ else:
4196
+ # error case
4197
+ raise NVMLError(ret)
4198
+
4199
+
4200
+ def nvmlVgpuInstanceGetFBCStats(vgpuInstance):
4201
+ c_fbcStats = c_nvmlFBCStats_t()
4202
+ fn = _nvmlGetFunctionPointer("nvmlVgpuInstanceGetFBCStats")
4203
+ ret = fn(vgpuInstance, byref(c_fbcStats))
4204
+ _nvmlCheckReturn(ret)
4205
+ return c_fbcStats
4206
+
4207
+
4208
+ def nvmlVgpuInstanceGetFBCSessions(vgpuInstance):
4209
+ # first call to get the size
4210
+ c_session_count = c_uint(0)
4211
+
4212
+ fn = _nvmlGetFunctionPointer("nvmlVgpuInstanceGetFBCSessions")
4213
+ ret = fn(vgpuInstance, byref(c_session_count), None)
4214
+
4215
+ if ret == NVML_SUCCESS:
4216
+ if c_session_count.value != 0:
4217
+ # typical case
4218
+ session_array = c_nvmlFBCSession_t * c_session_count.value
4219
+ c_sessions = session_array()
4220
+
4221
+ # make the call again
4222
+ ret = fn(vgpuInstance, byref(c_session_count), c_sessions)
4223
+ _nvmlCheckReturn(ret)
4224
+ sessions = []
4225
+ for i in range(c_session_count.value):
4226
+ sessions.append(c_sessions[i])
4227
+ return sessions
4228
+ else:
4229
+ return [] # no active sessions
4230
+ else:
4231
+ # error case
4232
+ raise NVMLError(ret)
4233
+
4234
+
4235
+ def nvmlDeviceGetProcessUtilization(handle, timeStamp):
4236
+ # first call to get the size
4237
+ c_count = c_uint(0)
4238
+ c_time_stamp = c_ulonglong(timeStamp)
4239
+
4240
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetProcessUtilization")
4241
+ ret = fn(handle, None, byref(c_count), c_time_stamp)
4242
+
4243
+ if ret == NVML_ERROR_INSUFFICIENT_SIZE:
4244
+ # typical case
4245
+ sampleArray = c_count.value * c_nvmlProcessUtilizationSample_t
4246
+ c_samples = sampleArray()
4247
+
4248
+ # make the call again
4249
+ ret = fn(handle, c_samples, byref(c_count), c_time_stamp)
4250
+ _nvmlCheckReturn(ret)
4251
+
4252
+ return c_samples[0 : c_count.value]
4253
+ else:
4254
+ # error case
4255
+ raise NVMLError(ret)
4256
+
4257
+
4258
+ def nvmlVgpuInstanceGetMetadata(vgpuInstance):
4259
+ fn = _nvmlGetFunctionPointer("nvmlVgpuInstanceGetMetadata")
4260
+ c_vgpuMetadata = c_nvmlVgpuMetadata_t()
4261
+ c_bufferSize = c_uint(0)
4262
+ # Make the first NVML API call to get the c_bufferSize value.
4263
+ # We have already allocated required buffer above.
4264
+ ret = fn(vgpuInstance, byref(c_vgpuMetadata), byref(c_bufferSize))
4265
+ if ret == NVML_ERROR_INSUFFICIENT_SIZE:
4266
+ ret = fn(vgpuInstance, byref(c_vgpuMetadata), byref(c_bufferSize))
4267
+ _nvmlCheckReturn(ret)
4268
+ else:
4269
+ raise NVMLError(ret)
4270
+ return c_vgpuMetadata
4271
+
4272
+
4273
+ def nvmlDeviceGetVgpuMetadata(handle):
4274
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetVgpuMetadata")
4275
+ c_vgpuPgpuMetadata = c_nvmlVgpuPgpuMetadata_t()
4276
+ c_bufferSize = c_uint(0)
4277
+ # Make the first NVML API call to get the c_bufferSize value.
4278
+ # We have already allocated required buffer above.
4279
+ ret = fn(handle, byref(c_vgpuPgpuMetadata), byref(c_bufferSize))
4280
+ if ret == NVML_ERROR_INSUFFICIENT_SIZE:
4281
+ ret = fn(handle, byref(c_vgpuPgpuMetadata), byref(c_bufferSize))
4282
+ _nvmlCheckReturn(ret)
4283
+ else:
4284
+ raise NVMLError(ret)
4285
+ return c_vgpuPgpuMetadata
4286
+
4287
+
4288
+ def nvmlGetVgpuCompatibility(vgpuMetadata, pgpuMetadata):
4289
+ fn = _nvmlGetFunctionPointer("nvmlGetVgpuCompatibility")
4290
+ c_vgpuPgpuCompatibility = c_nvmlVgpuPgpuCompatibility_t()
4291
+ ret = fn(byref(vgpuMetadata), byref(pgpuMetadata), byref(c_vgpuPgpuCompatibility))
4292
+ _nvmlCheckReturn(ret)
4293
+ return c_vgpuPgpuCompatibility
4294
+
4295
+
4296
+ @convertStrBytes
4297
+ def nvmlDeviceGetPgpuMetadataString(handle):
4298
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetPgpuMetadataString")
4299
+ c_pgpuMetadata = create_string_buffer(NVML_VGPU_PGPU_METADATA_OPAQUE_DATA_SIZE)
4300
+ c_bufferSize = c_uint(0)
4301
+ # Make the first NVML API call to get the c_bufferSize value.
4302
+ # We have already allocated required buffer above.
4303
+ ret = fn(handle, byref(c_pgpuMetadata), byref(c_bufferSize))
4304
+ if ret == NVML_ERROR_INSUFFICIENT_SIZE:
4305
+ ret = fn(handle, byref(c_pgpuMetadata), byref(c_bufferSize))
4306
+ _nvmlCheckReturn(ret)
4307
+ else:
4308
+ raise NVMLError(ret)
4309
+ return (c_pgpuMetadata.value, c_bufferSize.value)
4310
+
4311
+
4312
+ def nvmlSetVgpuVersion(vgpuVersion):
4313
+ fn = _nvmlGetFunctionPointer("nvmlSetVgpuVersion")
4314
+ ret = fn(byref(vgpuVersion))
4315
+ _nvmlCheckReturn(ret)
4316
+ return ret
4317
+
4318
+
4319
+ def nvmlGetVgpuVersion(supported, current):
4320
+ fn = _nvmlGetFunctionPointer("nvmlGetVgpuVersion")
4321
+ ret = fn(byref(supported), byref(current))
4322
+ _nvmlCheckReturn(ret)
4323
+ return ret
4324
+
4325
+
4326
+ def nvmlVgpuInstanceGetAccountingMode(vgpuInstance):
4327
+ c_mode = _nvmlEnableState_t()
4328
+ fn = _nvmlGetFunctionPointer("nvmlVgpuInstanceGetAccountingMode")
4329
+ ret = fn(vgpuInstance, byref(c_mode))
4330
+ _nvmlCheckReturn(ret)
4331
+ return c_mode.value
4332
+
4333
+
4334
+ def nvmlVgpuInstanceGetAccountingPids(vgpuInstance):
4335
+ c_pidCount = c_uint()
4336
+ fn = _nvmlGetFunctionPointer("nvmlVgpuInstanceGetAccountingPids")
4337
+ ret = fn(vgpuInstance, byref(c_pidCount), None)
4338
+ if ret == NVML_ERROR_INSUFFICIENT_SIZE:
4339
+ sampleArray = c_pidCount.value * c_uint
4340
+ c_pidArray = sampleArray()
4341
+ ret = fn(vgpuInstance, byref(c_pidCount), byref(c_pidArray))
4342
+ _nvmlCheckReturn(ret)
4343
+ else:
4344
+ raise NVMLError(ret)
4345
+ return (c_pidCount, c_pidArray)
4346
+
4347
+
4348
+ def nvmlVgpuInstanceGetAccountingStats(vgpuInstance, pid):
4349
+ c_accountingStats = c_nvmlAccountingStats_t()
4350
+ fn = _nvmlGetFunctionPointer("nvmlVgpuInstanceGetAccountingStats")
4351
+ ret = fn(vgpuInstance, pid, byref(c_accountingStats))
4352
+ _nvmlCheckReturn(ret)
4353
+ return c_accountingStats
4354
+
4355
+
4356
+ def nvmlVgpuInstanceClearAccountingPids(vgpuInstance):
4357
+ fn = _nvmlGetFunctionPointer("nvmlVgpuInstanceClearAccountingPids")
4358
+ ret = fn(vgpuInstance)
4359
+ _nvmlCheckReturn(ret)
4360
+ return ret
4361
+
4362
+
4363
+ def nvmlGetExcludedDeviceCount():
4364
+ c_count = c_uint()
4365
+ fn = _nvmlGetFunctionPointer("nvmlGetExcludedDeviceCount")
4366
+ ret = fn(byref(c_count))
4367
+ _nvmlCheckReturn(ret)
4368
+ return c_count.value
4369
+
4370
+
4371
+ def nvmlGetExcludedDeviceInfoByIndex(index):
4372
+ c_index = c_uint(index)
4373
+ info = c_nvmlExcludedDeviceInfo_t()
4374
+ fn = _nvmlGetFunctionPointer("nvmlGetExcludedDeviceInfoByIndex")
4375
+ ret = fn(c_index, byref(info))
4376
+ _nvmlCheckReturn(ret)
4377
+ return info
4378
+
4379
+
4380
+ def nvmlDeviceGetHostVgpuMode(handle):
4381
+ c_host_vgpu_mode = _nvmlHostVgpuMode_t()
4382
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetHostVgpuMode")
4383
+ ret = fn(handle, byref(c_host_vgpu_mode))
4384
+ _nvmlCheckReturn(ret)
4385
+ return c_host_vgpu_mode.value
4386
+
4387
+
4388
+ def nvmlDeviceSetMigMode(device, mode):
4389
+ c_activationStatus = c_uint()
4390
+ fn = _nvmlGetFunctionPointer("nvmlDeviceSetMigMode")
4391
+ ret = fn(device, mode, byref(c_activationStatus))
4392
+ _nvmlCheckReturn(ret)
4393
+ return c_activationStatus.value
4394
+
4395
+
4396
+ def nvmlDeviceGetMigMode(device):
4397
+ c_currentMode = c_uint()
4398
+ c_pendingMode = c_uint()
4399
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetMigMode")
4400
+ ret = fn(device, byref(c_currentMode), byref(c_pendingMode))
4401
+ _nvmlCheckReturn(ret)
4402
+ return [c_currentMode.value, c_pendingMode.value]
4403
+
4404
+
4405
+ def nvmlDeviceGetGpuInstanceProfileInfo(device, profile, version=2):
4406
+ if version == 2:
4407
+ c_info = c_nvmlGpuInstanceProfileInfo_v2_t()
4408
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetGpuInstanceProfileInfoV")
4409
+ elif version == 1:
4410
+ c_info = c_nvmlGpuInstanceProfileInfo_t()
4411
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetGpuInstanceProfileInfo")
4412
+ else:
4413
+ raise NVMLError(NVML_ERROR_FUNCTION_NOT_FOUND)
4414
+ ret = fn(device, profile, byref(c_info))
4415
+ _nvmlCheckReturn(ret)
4416
+ return c_info
4417
+
4418
+
4419
+ # Define function alias for the API exposed by NVML
4420
+ nvmlDeviceGetGpuInstanceProfileInfoV = nvmlDeviceGetGpuInstanceProfileInfo
4421
+
4422
+
4423
+ def nvmlDeviceGetGpuInstanceRemainingCapacity(device, profileId):
4424
+ c_count = c_uint()
4425
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetGpuInstanceRemainingCapacity")
4426
+ ret = fn(device, profileId, byref(c_count))
4427
+ _nvmlCheckReturn(ret)
4428
+ return c_count.value
4429
+
4430
+
4431
+ def nvmlDeviceGetGpuInstancePossiblePlacements(
4432
+ device, profileId, placementsRef, countRef
4433
+ ):
4434
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetGpuInstancePossiblePlacements_v2")
4435
+ ret = fn(device, profileId, placementsRef, countRef)
4436
+ _nvmlCheckReturn(ret)
4437
+ return ret
4438
+
4439
+
4440
+ def nvmlDeviceCreateGpuInstance(device, profileId):
4441
+ c_instance = c_nvmlGpuInstance_t()
4442
+ fn = _nvmlGetFunctionPointer("nvmlDeviceCreateGpuInstance")
4443
+ ret = fn(device, profileId, byref(c_instance))
4444
+ _nvmlCheckReturn(ret)
4445
+ return c_instance
4446
+
4447
+
4448
+ def nvmlDeviceCreateGpuInstanceWithPlacement(device, profileId, placement):
4449
+ c_instance = c_nvmlGpuInstance_t()
4450
+ fn = _nvmlGetFunctionPointer("nvmlDeviceCreateGpuInstanceWithPlacement")
4451
+ ret = fn(device, profileId, placement, byref(c_instance))
4452
+ _nvmlCheckReturn(ret)
4453
+ return c_instance
4454
+
4455
+
4456
+ def nvmlGpuInstanceDestroy(gpuInstance):
4457
+ fn = _nvmlGetFunctionPointer("nvmlGpuInstanceDestroy")
4458
+ ret = fn(gpuInstance)
4459
+ _nvmlCheckReturn(ret)
4460
+ return ret
4461
+
4462
+
4463
+ def nvmlDeviceGetGpuInstances(device, profileId, gpuInstancesRef, countRef):
4464
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetGpuInstances")
4465
+ ret = fn(device, profileId, gpuInstancesRef, countRef)
4466
+ _nvmlCheckReturn(ret)
4467
+ return ret
4468
+
4469
+
4470
+ def nvmlDeviceGetGpuInstanceById(device, gpuInstanceId):
4471
+ c_instance = c_nvmlGpuInstance_t()
4472
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetGpuInstanceById")
4473
+ ret = fn(device, gpuInstanceId, byref(c_instance))
4474
+ _nvmlCheckReturn(ret)
4475
+ return c_instance
4476
+
4477
+
4478
+ def nvmlGpuInstanceGetInfo(gpuInstance):
4479
+ c_info = c_nvmlGpuInstanceInfo_t()
4480
+ fn = _nvmlGetFunctionPointer("nvmlGpuInstanceGetInfo")
4481
+ ret = fn(gpuInstance, byref(c_info))
4482
+ _nvmlCheckReturn(ret)
4483
+ return c_info
4484
+
4485
+
4486
+ def nvmlGpuInstanceGetComputeInstanceProfileInfo(
4487
+ device, profile, engProfile, version=2
4488
+ ):
4489
+ if version == 2:
4490
+ c_info = c_nvmlComputeInstanceProfileInfo_v2_t()
4491
+ fn = _nvmlGetFunctionPointer("nvmlGpuInstanceGetComputeInstanceProfileInfoV")
4492
+ elif version == 1:
4493
+ c_info = c_nvmlComputeInstanceProfileInfo_t()
4494
+ fn = _nvmlGetFunctionPointer("nvmlGpuInstanceGetComputeInstanceProfileInfo")
4495
+ else:
4496
+ raise NVMLError(NVML_ERROR_FUNCTION_NOT_FOUND)
4497
+ ret = fn(device, profile, engProfile, byref(c_info))
4498
+ _nvmlCheckReturn(ret)
4499
+ return c_info
4500
+
4501
+
4502
+ # Define function alias for the API exposed by NVML
4503
+ nvmlGpuInstanceGetComputeInstanceProfileInfoV = (
4504
+ nvmlGpuInstanceGetComputeInstanceProfileInfo
4505
+ )
4506
+
4507
+
4508
+ def nvmlGpuInstanceGetComputeInstanceRemainingCapacity(gpuInstance, profileId):
4509
+ c_count = c_uint()
4510
+ fn = _nvmlGetFunctionPointer("nvmlGpuInstanceGetComputeInstanceRemainingCapacity")
4511
+ ret = fn(gpuInstance, profileId, byref(c_count))
4512
+ _nvmlCheckReturn(ret)
4513
+ return c_count.value
4514
+
4515
+
4516
+ def nvmlGpuInstanceCreateComputeInstance(gpuInstance, profileId):
4517
+ c_instance = c_nvmlComputeInstance_t()
4518
+ fn = _nvmlGetFunctionPointer("nvmlGpuInstanceCreateComputeInstance")
4519
+ ret = fn(gpuInstance, profileId, byref(c_instance))
4520
+ _nvmlCheckReturn(ret)
4521
+ return c_instance
4522
+
4523
+
4524
+ def nvmlComputeInstanceDestroy(computeInstance):
4525
+ fn = _nvmlGetFunctionPointer("nvmlComputeInstanceDestroy")
4526
+ ret = fn(computeInstance)
4527
+ _nvmlCheckReturn(ret)
4528
+ return ret
4529
+
4530
+
4531
+ def nvmlGpuInstanceGetComputeInstances(
4532
+ gpuInstance, profileId, computeInstancesRef, countRef
4533
+ ):
4534
+ fn = _nvmlGetFunctionPointer("nvmlGpuInstanceGetComputeInstances")
4535
+ ret = fn(gpuInstance, profileId, computeInstancesRef, countRef)
4536
+ _nvmlCheckReturn(ret)
4537
+ return ret
4538
+
4539
+
4540
+ def nvmlGpuInstanceGetComputeInstanceById(gpuInstance, computeInstanceId):
4541
+ c_instance = c_nvmlComputeInstance_t()
4542
+ fn = _nvmlGetFunctionPointer("nvmlGpuInstanceGetComputeInstanceById")
4543
+ ret = fn(gpuInstance, computeInstanceId, byref(c_instance))
4544
+ _nvmlCheckReturn(ret)
4545
+ return c_instance
4546
+
4547
+
4548
+ def nvmlComputeInstanceGetInfo_v2(computeInstance):
4549
+ c_info = c_nvmlComputeInstanceInfo_t()
4550
+ fn = _nvmlGetFunctionPointer("nvmlComputeInstanceGetInfo_v2")
4551
+ ret = fn(computeInstance, byref(c_info))
4552
+ _nvmlCheckReturn(ret)
4553
+ return c_info
4554
+
4555
+
4556
+ def nvmlComputeInstanceGetInfo(computeInstance):
4557
+ return nvmlComputeInstanceGetInfo_v2(computeInstance)
4558
+
4559
+
4560
+ def nvmlDeviceIsMigDeviceHandle(device):
4561
+ c_isMigDevice = c_uint()
4562
+ fn = _nvmlGetFunctionPointer("nvmlDeviceIsMigDeviceHandle")
4563
+ ret = fn(device, byref(c_isMigDevice))
4564
+ _nvmlCheckReturn(ret)
4565
+ return c_isMigDevice
4566
+
4567
+
4568
+ def nvmlDeviceGetGpuInstanceId(device):
4569
+ c_gpuInstanceId = c_uint()
4570
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetGpuInstanceId")
4571
+ ret = fn(device, byref(c_gpuInstanceId))
4572
+ _nvmlCheckReturn(ret)
4573
+ return c_gpuInstanceId.value
4574
+
4575
+
4576
+ def nvmlDeviceGetComputeInstanceId(device):
4577
+ c_computeInstanceId = c_uint()
4578
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetComputeInstanceId")
4579
+ ret = fn(device, byref(c_computeInstanceId))
4580
+ _nvmlCheckReturn(ret)
4581
+ return c_computeInstanceId.value
4582
+
4583
+
4584
+ def nvmlDeviceGetMaxMigDeviceCount(device):
4585
+ c_count = c_uint()
4586
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetMaxMigDeviceCount")
4587
+ ret = fn(device, byref(c_count))
4588
+ _nvmlCheckReturn(ret)
4589
+ return c_count.value
4590
+
4591
+
4592
+ def nvmlDeviceGetMigDeviceHandleByIndex(device, index):
4593
+ c_index = c_uint(index)
4594
+ migDevice = c_nvmlDevice_t()
4595
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetMigDeviceHandleByIndex")
4596
+ ret = fn(device, c_index, byref(migDevice))
4597
+ _nvmlCheckReturn(ret)
4598
+ return migDevice
4599
+
4600
+
4601
+ def nvmlDeviceGetDeviceHandleFromMigDeviceHandle(migDevice):
4602
+ device = c_nvmlDevice_t()
4603
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetDeviceHandleFromMigDeviceHandle")
4604
+ ret = fn(migDevice, byref(device))
4605
+ _nvmlCheckReturn(ret)
4606
+ return device
4607
+
4608
+
4609
+ def nvmlDeviceGetAttributes_v2(device):
4610
+ c_attrs = c_nvmlDeviceAttributes()
4611
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetAttributes_v2")
4612
+ ret = fn(device, byref(c_attrs))
4613
+ _nvmlCheckReturn(ret)
4614
+ return c_attrs
4615
+
4616
+
4617
+ def nvmlDeviceGetAttributes(device):
4618
+ return nvmlDeviceGetAttributes_v2(device)
4619
+
4620
+
4621
+ def nvmlDeviceGetRemappedRows(device):
4622
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetRemappedRows")
4623
+ c_corr = c_uint()
4624
+ c_unc = c_uint()
4625
+ c_bpending = c_uint()
4626
+ c_bfailure = c_uint()
4627
+ ret = fn(device, byref(c_corr), byref(c_unc), byref(c_bpending), byref(c_bfailure))
4628
+ _nvmlCheckReturn(ret)
4629
+ return (c_corr.value, c_unc.value, c_bpending.value, c_bfailure.value)
4630
+
4631
+
4632
+ def nvmlDeviceGetRowRemapperHistogram(device):
4633
+ c_vals = c_nvmlRowRemapperHistogramValues()
4634
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetRowRemapperHistogram")
4635
+ ret = fn(device, byref(c_vals))
4636
+ _nvmlCheckReturn(ret)
4637
+ return c_vals
4638
+
4639
+
4640
+ def nvmlDeviceGetArchitecture(device):
4641
+ arch = _nvmlDeviceArchitecture_t()
4642
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetArchitecture")
4643
+ ret = fn(device, byref(arch))
4644
+ _nvmlCheckReturn(ret)
4645
+ return arch.value
4646
+
4647
+
4648
+ def nvmlDeviceGetBusType(device):
4649
+ c_busType = _nvmlBusType_t()
4650
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetBusType")
4651
+ ret = fn(device, byref(c_busType))
4652
+ _nvmlCheckReturn(ret)
4653
+ return c_busType.value
4654
+
4655
+
4656
+ def nvmlDeviceGetIrqNum(device):
4657
+ c_irqNum = c_uint()
4658
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetIrqNum")
4659
+ ret = fn(device, byref(c_irqNum))
4660
+ _nvmlCheckReturn(ret)
4661
+ return c_irqNum.value
4662
+
4663
+
4664
+ def nvmlDeviceGetNumGpuCores(device):
4665
+ c_numCores = c_uint()
4666
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetNumGpuCores")
4667
+ ret = fn(device, byref(c_numCores))
4668
+ _nvmlCheckReturn(ret)
4669
+ return c_numCores.value
4670
+
4671
+
4672
+ def nvmlDeviceGetPowerSource(device):
4673
+ c_powerSource = _nvmlPowerSource_t()
4674
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetPowerSource")
4675
+ ret = fn(device, byref(c_powerSource))
4676
+ _nvmlCheckReturn(ret)
4677
+ return c_powerSource.value
4678
+
4679
+
4680
+ def nvmlDeviceGetMemoryBusWidth(device):
4681
+ c_memBusWidth = c_uint()
4682
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetMemoryBusWidth")
4683
+ ret = fn(device, byref(c_memBusWidth))
4684
+ _nvmlCheckReturn(ret)
4685
+ return c_memBusWidth.value
4686
+
4687
+
4688
+ def nvmlDeviceGetPcieLinkMaxSpeed(device):
4689
+ c_speed = _nvmlPcieLinkMaxSpeed_t()
4690
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetPcieLinkMaxSpeed")
4691
+ ret = fn(device, byref(c_speed))
4692
+ _nvmlCheckReturn(ret)
4693
+ return c_speed.value
4694
+
4695
+
4696
+ def nvmlDeviceGetAdaptiveClockInfoStatus(device):
4697
+ c_adaptiveClockInfoStatus = _nvmlAdaptiveClockInfoStatus_t()
4698
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetAdaptiveClockInfoStatus")
4699
+ ret = fn(device, byref(c_adaptiveClockInfoStatus))
4700
+ _nvmlCheckReturn(ret)
4701
+ return c_adaptiveClockInfoStatus.value
4702
+
4703
+
4704
+ def nvmlDeviceGetPcieSpeed(device):
4705
+ c_speed = c_uint()
4706
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetPcieSpeed")
4707
+ ret = fn(device, byref(c_speed))
4708
+ _nvmlCheckReturn(ret)
4709
+ return c_speed.value
4710
+
4711
+
4712
+ def nvmlDeviceGetDynamicPstatesInfo(device, c_dynamicpstatesinfo):
4713
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetDynamicPstatesInfo")
4714
+ ret = fn(device, c_dynamicpstatesinfo)
4715
+ _nvmlCheckReturn(ret)
4716
+ return ret
4717
+
4718
+
4719
+ def nvmlDeviceSetFanSpeed_v2(handle, index, speed):
4720
+ fn = _nvmlGetFunctionPointer("nvmlDeviceSetFanSpeed_v2")
4721
+ ret = fn(handle, index, speed)
4722
+ _nvmlCheckReturn(ret)
4723
+ return ret
4724
+
4725
+
4726
+ def nvmlDeviceGetThermalSettings(device, sensorindex, c_thermalsettings):
4727
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetThermalSettings")
4728
+ ret = fn(device, sensorindex, c_thermalsettings)
4729
+ _nvmlCheckReturn(ret)
4730
+ return ret
4731
+
4732
+
4733
+ def nvmlDeviceGetMinMaxClockOfPState(device, type, pstate, minClockMHz, maxClockMHz):
4734
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetMinMaxClockOfPState")
4735
+ ret = fn(
4736
+ device,
4737
+ _nvmlClockType_t(type),
4738
+ _nvmlClockType_t(pstate),
4739
+ minClockMHz,
4740
+ maxClockMHz,
4741
+ )
4742
+ _nvmlCheckReturn(ret)
4743
+ return ret
4744
+
4745
+
4746
+ def nvmlDeviceGetSupportedPerformanceStates(device):
4747
+ pstates = []
4748
+ c_count = c_uint(NVML_MAX_GPU_PERF_PSTATES)
4749
+ c_size = sizeof(c_uint) * c_count.value
4750
+
4751
+ # NOTE: use 'c_uint' to represent the size of the nvmlPstate_t enumeration.
4752
+ pstates_array = _nvmlPstates_t * c_count.value
4753
+ c_pstates = pstates_array()
4754
+
4755
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetSupportedPerformanceStates")
4756
+ ret = fn(device, c_pstates, c_size)
4757
+ _nvmlCheckReturn(ret)
4758
+
4759
+ for value in c_pstates:
4760
+ if value != NVML_PSTATE_UNKNOWN:
4761
+ pstates.append(value)
4762
+
4763
+ return pstates
4764
+
4765
+
4766
+ def nvmlDeviceGetGpcClkVfOffset(device):
4767
+ offset = c_int32()
4768
+ fn = _nvmlGetFunctionPointer("nvmlDeviceGetGpcClkVfOffset")
4769
+ ret = fn(device, byref(offset))
4770
+ _nvmlCheckReturn(ret)
4771
+ return offset.value
4772
+
4773
+
4774
+ def nvmlDeviceSetGpcClkVfOffset(device, offset):
4775
+ c_offset = c_int32(offset)
4776
+ fn = _nvmlGetFunctionPointer("nvmlDeviceSetGpcClkVfOffset")
4777
+ ret = fn(device, c_offset)
4778
+ _nvmlCheckReturn(ret)
4779
+ return ret