Skip to main content

Python Bindings for the NVIDIA Management Library

Project description

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

Note this file can be run with 'python -m doctest -v README.txt' although the results are system dependent

Requires

Python 3, or an earlier version with the ctypes module.

Installation

pip install .

Usage

You can use the lower level nvml bindings

>>> from pynvml import *
>>> nvmlInit()
>>> print "Driver Version:", nvmlSystemGetDriverVersion()
Driver Version: 410.00
>>> deviceCount = nvmlDeviceGetCount()
>>> for i in range(deviceCount):
...     handle = nvmlDeviceGetHandleByIndex(i)
...     print "Device", i, ":", nvmlDeviceGetName(handle)
...
Device 0 : Tesla V100

>>> nvmlShutdown()

Or the higher level nvidia_smi API

from pynvml.smi import nvidia_smi
nvsmi = nvidia_smi.getInstance()
nvsmi.DeviceQuery('memory.free, memory.total')

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)
    
  • C structs are converted into Python classes.

    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
    
  • Python handles string buffer creation.

    nvmlReturn_t nvmlSystemGetDriverVersion(char* version,
                                            unsigned int length);
    
    >>> version = nvmlSystemGetDriverVersion();
    >>> nvmlShutdown()
    

For usage information see the NVML documentation.

Variables

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.

Release Notes

  • Version 2.285.0
    • Added new functions for NVML 2.285. See NVML documentation for more information.
    • Ported to support Python 3.0 and Python 2.0 syntax.
    • Added nvidia_smi.py tool as a sample app.
  • Version 3.295.0
    • Added new functions for NVML 3.295. See NVML documentation for more information.
    • Updated nvidia_smi.py tool
      • Includes additional error handling
  • Version 4.304.0
    • Added new functions for NVML 4.304. See NVML documentation for more information.
    • Updated nvidia_smi.py tool
  • Version 4.304.3
    • Fixing nvmlUnitGetDeviceCount bug
  • Version 5.319.0
    • Added new functions for NVML 5.319. See NVML documentation for more information.
  • Version 6.340.0
    • Added new functions for NVML 6.340. See NVML documentation for more information.
  • Version 7.346.0
    • Added new functions for NVML 7.346. See NVML documentation for more information.
  • Version 7.352.0
    • Added new functions for NVML 7.352. See NVML documentation for more information.
  • Version 8.0.0
    • Refactor code to a nvidia_smi singleton class
    • Added DeviceQuery that returns a dictionary of (name, value).
    • Added filter parameters on DeviceQuery to match query api in nvidia-smi
    • Added filter parameters on XmlDeviceQuery to match query api in nvidia-smi
    • Added integer enumeration for filter strings to reduce overhead for performance monitoring.
    • Added loop(filter) method with async and callback support
  • Version 8.0.1
    • Restructuring directories into two packages (pynvml and nvidia_smi)
    • Adding initial tests for both packages
    • Some name-convention cleanup in pynvml
  • Version 8.0.2
    • Added NVLink function wrappers for pynvml module

Copyright

Copyright (c) 2011-2019, NVIDIA Corporation. All rights reserved.

License

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  • Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

  • Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

  • Neither the name of the NVIDIA Corporation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pynvml-8.0.2.tar.gz (37.4 kB view details)

Uploaded Source

Built Distribution

pynvml-8.0.2-py3-none-any.whl (35.6 kB view details)

Uploaded Python 3

File details

Details for the file pynvml-8.0.2.tar.gz.

File metadata

  • Download URL: pynvml-8.0.2.tar.gz
  • Upload date:
  • Size: 37.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.33.0 CPython/3.7.4

File hashes

Hashes for pynvml-8.0.2.tar.gz
Algorithm Hash digest
SHA256 465db2da0471b0ee9fe04bbeca6545d9fb5627181b0abac272ca0767b1579d00
MD5 69c4b33518409de9584870fee4397428
BLAKE2b-256 4594b9434439a20ceb6b0ee85506d48d7f4f5ceea0f15f2225c887b06d47444c

See more details on using hashes here.

File details

Details for the file pynvml-8.0.2-py3-none-any.whl.

File metadata

  • Download URL: pynvml-8.0.2-py3-none-any.whl
  • Upload date:
  • Size: 35.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.33.0 CPython/3.7.4

File hashes

Hashes for pynvml-8.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 95fe05b141c5f63dbb97cb35dd0f1c8a17d9240d5e4d1a68183b325b5168c4a4
MD5 0c0fd0351ef60ea81b3bb5140e365b64
BLAKE2b-256 97897a56c14117167a41efa3838b0d9f7960f05269fd23db396bbf19cceb4399

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page