Note: I'm no longer maintaining this code, so please fork it and improve it even more!
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.md
although the results are system dependent
Python 2.5+, or an earlier version with the ctypes
module.
sudo python setup.py install
Or locally:
python setup.py install --user
>>> from pynvml import *
>>> nvmlInit()
>>> print "Driver Version:", nvmlSystemGetDriverVersion()
Driver Version: 352.00
>>> deviceCount = nvmlDeviceGetCount()
>>> for i in range(deviceCount):
... handle = nvmlDeviceGetHandleByIndex(i)
... print "Device", i, ":", nvmlDeviceGetName(handle)
...
Device 0 : Tesla K40c
>>> nvmlShutdown()
Additionally, see nvidia_smi.py
. A sample application.
Python methods wrap NVML functions, implemented in a C shared library. Each function's use is the same with the following exceptions:
>>> try:
... nvmlDeviceGetCount()
... except NVMLError as error:
... print(error)
...
Uninitialized
nvmlReturn_t nvmlDeviceGetEccMode(nvmlDevice_t device,
nvmlEnableState_t *current,
nvmlEnableState_t *pending);
>>> nvmlInit()
>>> handle = nvmlDeviceGetHandleByIndex(0)
>>> (current, pending) = nvmlDeviceGetEccMode(handle)
nvmlReturn_t DECLDIR nvmlDeviceGetMemoryInfo(nvmlDevice_t device,
nvmlMemory_t *memory);
typedef struct nvmlMemory_st {
unsigned long long total;
unsigned long long free;
unsigned long long used;
} nvmlMemory_t;
>>> info = nvmlDeviceGetMemoryInfo(handle)
>>> print "Total memory:", info.total
Total memory: 5636292608
>>> print "Free memory:", info.free
Free memory: 5578420224
>>> print "Used memory:", info.used
Used memory: 57872384
nvmlReturn_t nvmlSystemGetDriverVersion(char* version,
unsigned int length);
>>> version = nvmlSystemGetDriverVersion();
>>> nvmlShutdown()
For usage information see the NVML documentation.
All meaningful NVML constants and enums are exposed in Python.
The NVML_VALUE_NOT_AVAILABLE
constant is not used. Instead None
is mapped to the field.
Version 2.285.0