Python Bindings for the NVIDIA Management Library
Actively maintained. Last release 2 months ago. A safe choice.
pip install nvidia-ml-pypyNVML
Python bindings to the NVIDIA Management Library
Provides a Python interface to GPU management and monitoring functions.
This is a wrapper around the NVML library. For information about the NVML library, see the NVML developer page http://developer.nvidia.com/nvidia-management-library-nvml
Download the latest package from: http://pypi.python.org/pypi/nvidia-ml-py/
Note this file can be run with 'python -m doctest -v README.txt' although the results are system dependent
The nvml header file contains function documentation that is relevant to this wrapper. The header file is distributed with. https://developer.nvidia.com/gpu-deployment-kit
The main difference is this library handles allocating structs and passing pointers to the functions, before returning the desired value. Non-success return codes are raised as exceptions as described in the section below.
REQUIRES
Python 2.5, or an earlier version with the ctypes module.
INSTALLATION
Pip Installation with python3:
python3 -m pip install nvidia-ml-py
Manual Installation:
$ tar -xzf nvidia-ml-py-$major-$minor-$patch.tar.gz`
$ cd nvidia-ml-py-$major-$minor-$patch
$ sudo python setup.py install
USAGE
>>> from pynvml import *
>>> nvmlInit()
>>> print(f"Driver Version: {nvmlSystemGetDriverVersion()}")
Driver Version: 11.515.48
>>> deviceCount = nvmlDeviceGetCount()
>>> for i in range(deviceCount):
... handle = nvmlDeviceGetHandleByIndex(i)
... print(f"Device {i} : {nvmlDeviceGetName(handle)}")
...
Device 0 : Tesla K40c
>>> nvmlShutdown()
FUNCTIONS
Python methods wrap NVML functions, implemented in a C shared library. Each function's use is the same with the following exceptions:
- Instead of returning error codes, failing error codes are raised as Python exceptions.
>>> try:
... nvmlDeviceGetCount()
... except NVMLError as error:
... print(error)
...
Uninitialized
- C function output parameters are returned from the corresponding Python function left to right.
nvmlReturn_t nvmlDeviceGetEccMode(nvmlDevice_t device,
nvmlEnableState_t *current,
nvmlEnableState_t *pending);
>>> nvmlInit()
>>> handle = nvmlDeviceGetHandleByIndex(0)
>>> (current, pending) = nvmlDeviceGetEccMode(handle)