nvidia-ml-py


Namenvidia-ml-py JSON
Version 12.535.133 PyPI version JSON
download
home_pagehttps://forums.developer.nvidia.com
SummaryPython Bindings for the NVIDIA Management Library
upload_time2023-11-02 14:47:22
maintainer
docs_urlhttps://pythonhosted.org/nvidia-ml-py/
authorNVIDIA Corporation
requires_python
licenseBSD
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            pyNVML
======

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

```
// C Function and typedef struct
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;


# Python call to function and accessing members of ctype struct
>>> info = nvmlDeviceGetMemoryInfo(handle)
>>> print(f"Total memory: {info.total}")
Total memory: 5636292608
>>> print(f"Free memory:, {info.free}")
Free memory: 5578420224
>>> print(f"Used memory: {info.used}")
Used memory: 57872384
```

- Python handles string buffer creation.

```
// C Function that needs character array and length
nvmlReturn_t nvmlSystemGetDriverVersion(char* version,
                                        unsigned int length);

# Python function handles memory
>>> version = nvmlSystemGetDriverVersion()
>>> print(version)
... 11.520.75
>>> 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.

EXCEPTIONS
----------
Since the C library uses return codes and python prefers exception handling, the
library converts all return codes to various exceptions. The exceptions are generated
automatically via a function at run time instead of being defined manually.

The list of exceptions can be found in NVMLError base class.

The example seen above in the FUNCTIONS section:

```
>>> try:
...     nvmlDeviceGetCount()
... except NVMLError as error:
...     print(error)
...
Uninitialized
```

Can be more accurately caught like this:

```
>>> try:
...     nvmlDeviceGetCount()
... except NVMLError_Uninitialized as error:
...     print(error)
...
Uninitialized
```

The conversion from name to exception is like this for all exceptions:
* `NVML_ERROR_UNINITIALIZED` => `NVMLError_Uninitialized`
* `NVML_ERROR_LIBRARY_NOT_FOUND` => `NVMLError_LibraryNotFound`
* `NVML_ERROR_ALREADY_INITIALIZED` => `NVMLError_AlreadyInitialized`

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 10.418
- Added new functions for NVML 10.418.  See NVML documentation for more information.
- Fixed issues with using the bindings with Python 3.x
- Replaced sample app nvidia_smi.py with example.py

Version 11.515.48
- Python3 support added
- Updated API to add function new to NVML, bringing pynvml up to date with NVML
- Added auto-version to handle byte and string conversion automatically for both structs and functions
- Minor bug fixes
- Added README.txt correctly in long_description for pypi.org

Version 11.520
- Updated Long Description to be actual markdown
- Added new functions for NVML 11.520

Version 11.525
- Added new functions for NVML 11.525

COPYRIGHT
---------
Copyright (c) 2011-2023, 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.


            

Raw data

            {
    "_id": null,
    "home_page": "https://forums.developer.nvidia.com",
    "name": "nvidia-ml-py",
    "maintainer": "",
    "docs_url": "https://pythonhosted.org/nvidia-ml-py/",
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "",
    "author": "NVIDIA Corporation",
    "author_email": "nvml-bindings@nvidia.com",
    "download_url": "https://files.pythonhosted.org/packages/c9/f5/35d8002a4a9532c58fa304046de2d9b8be18183c341c517ac48f2bce907a/nvidia-ml-py-12.535.133.tar.gz",
    "platform": null,
    "description": "pyNVML\n======\n\nPython bindings to the NVIDIA Management Library\n------------------------------------------------\n\nProvides a Python interface to GPU management and monitoring functions.\n\nThis is a wrapper around the NVML library.\nFor information about the NVML library, see the NVML developer page\nhttp://developer.nvidia.com/nvidia-management-library-nvml\n\nDownload the latest package from:\nhttp://pypi.python.org/pypi/nvidia-ml-py/\n\nNote this file can be run with 'python -m doctest -v README.txt'\nalthough the results are system dependent\n\nThe nvml header file contains function documentation that is relevant\nto this wrapper. The header file is distributed with.\nhttps://developer.nvidia.com/gpu-deployment-kit\n\nThe main difference is this library handles allocating structs and\npassing pointers to the functions, before returning the desired value.\nNon-success return codes are raised as exceptions as described in the\nsection below.\n\nREQUIRES\n--------\nPython 2.5, or an earlier version with the ctypes module.\n\nINSTALLATION\n------------\n\nPip Installation with python3:\n- `python3 -m pip install nvidia-ml-py`\n\nManual Installation:\n```\n$ tar -xzf nvidia-ml-py-$major-$minor-$patch.tar.gz`\n$ cd nvidia-ml-py-$major-$minor-$patch\n$ sudo python setup.py install\n```\n\nUSAGE\n-----\n```\n>>> from pynvml import *\n>>> nvmlInit()\n>>> print(f\"Driver Version: {nvmlSystemGetDriverVersion()}\")\nDriver Version: 11.515.48\n>>> deviceCount = nvmlDeviceGetCount()\n>>> for i in range(deviceCount):\n...     handle = nvmlDeviceGetHandleByIndex(i)\n...     print(f\"Device {i} : {nvmlDeviceGetName(handle)}\")\n...\nDevice 0 : Tesla K40c\n\n>>> nvmlShutdown()\n```\n\nFUNCTIONS\n---------\nPython methods wrap NVML functions, implemented in a C shared library.\nEach function's use is the same with the following exceptions:\n\n- Instead of returning error codes, failing error codes are raised as Python exceptions.\n\n```\n>>> try:\n...     nvmlDeviceGetCount()\n... except NVMLError as error:\n...     print(error)\n...\nUninitialized\n```\n\n- C function output parameters are returned from the corresponding Python function left to right.\n```\nnvmlReturn_t nvmlDeviceGetEccMode(nvmlDevice_t device,\n                                  nvmlEnableState_t *current,\n                                  nvmlEnableState_t *pending);\n\n>>> nvmlInit()\n>>> handle = nvmlDeviceGetHandleByIndex(0)\n>>> (current, pending) = nvmlDeviceGetEccMode(handle)\n```\n- C structs are converted into Python classes.\n\n```\n// C Function and typedef struct\nnvmlReturn_t DECLDIR nvmlDeviceGetMemoryInfo(nvmlDevice_t device,\n                                             nvmlMemory_t *memory);\ntypedef struct nvmlMemory_st {\n    unsigned long long total;\n    unsigned long long free;\n    unsigned long long used;\n} nvmlMemory_t;\n\n\n# Python call to function and accessing members of ctype struct\n>>> info = nvmlDeviceGetMemoryInfo(handle)\n>>> print(f\"Total memory: {info.total}\")\nTotal memory: 5636292608\n>>> print(f\"Free memory:, {info.free}\")\nFree memory: 5578420224\n>>> print(f\"Used memory: {info.used}\")\nUsed memory: 57872384\n```\n\n- Python handles string buffer creation.\n\n```\n// C Function that needs character array and length\nnvmlReturn_t nvmlSystemGetDriverVersion(char* version,\n                                        unsigned int length);\n\n# Python function handles memory\n>>> version = nvmlSystemGetDriverVersion()\n>>> print(version)\n... 11.520.75\n>>> nvmlShutdown()\n```\n\nFor usage information see the NVML documentation.\n\nVARIABLES\n---------\nAll meaningful NVML constants and enums are exposed in Python.\n\nThe NVML_VALUE_NOT_AVAILABLE constant is not used.  Instead None is mapped to the field.\n\nEXCEPTIONS\n----------\nSince the C library uses return codes and python prefers exception handling, the\nlibrary converts all return codes to various exceptions. The exceptions are generated\nautomatically via a function at run time instead of being defined manually.\n\nThe list of exceptions can be found in NVMLError base class.\n\nThe example seen above in the FUNCTIONS section:\n\n```\n>>> try:\n...     nvmlDeviceGetCount()\n... except NVMLError as error:\n...     print(error)\n...\nUninitialized\n```\n\nCan be more accurately caught like this:\n\n```\n>>> try:\n...     nvmlDeviceGetCount()\n... except NVMLError_Uninitialized as error:\n...     print(error)\n...\nUninitialized\n```\n\nThe conversion from name to exception is like this for all exceptions:\n* `NVML_ERROR_UNINITIALIZED` => `NVMLError_Uninitialized`\n* `NVML_ERROR_LIBRARY_NOT_FOUND` => `NVMLError_LibraryNotFound`\n* `NVML_ERROR_ALREADY_INITIALIZED` => `NVMLError_AlreadyInitialized`\n\nRELEASE NOTES\n-------------\nVersion 2.285.0\n- Added new functions for NVML 2.285.  See NVML documentation for more information.\n- Ported to support Python 3.0 and Python 2.0 syntax.\n- Added nvidia_smi.py tool as a sample app.\n\nVersion 3.295.0\n- Added new functions for NVML 3.295.  See NVML documentation for more information.\n- Updated nvidia_smi.py tool\n- Includes additional error handling\n\nVersion 4.304.0\n- Added new functions for NVML 4.304.  See NVML documentation for more information.\n- Updated nvidia_smi.py tool\n\nVersion 4.304.3\n- Fixing nvmlUnitGetDeviceCount bug\n\nVersion 5.319.0\n- Added new functions for NVML 5.319.  See NVML documentation for more information.\n\nVersion 6.340.0\n- Added new functions for NVML 6.340.  See NVML documentation for more information.\n\nVersion 7.346.0\n- Added new functions for NVML 7.346.  See NVML documentation for more information.\n\nVersion 7.352.0\n- Added new functions for NVML 7.352.  See NVML documentation for more information.\n\nVersion 10.418\n- Added new functions for NVML 10.418.  See NVML documentation for more information.\n- Fixed issues with using the bindings with Python 3.x\n- Replaced sample app nvidia_smi.py with example.py\n\nVersion 11.515.48\n- Python3 support added\n- Updated API to add function new to NVML, bringing pynvml up to date with NVML\n- Added auto-version to handle byte and string conversion automatically for both structs and functions\n- Minor bug fixes\n- Added README.txt correctly in long_description for pypi.org\n\nVersion 11.520\n- Updated Long Description to be actual markdown\n- Added new functions for NVML 11.520\n\nVersion 11.525\n- Added new functions for NVML 11.525\n\nCOPYRIGHT\n---------\nCopyright (c) 2011-2023, NVIDIA Corporation.  All rights reserved.\n\nLICENSE\n-------\nRedistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:\n\n- Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.\n\n- 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.\n\n- 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.\n\nTHIS 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.\n\n",
    "bugtrack_url": null,
    "license": "BSD",
    "summary": "Python Bindings for the NVIDIA Management Library",
    "version": "12.535.133",
    "project_urls": {
        "Homepage": "https://forums.developer.nvidia.com"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a81035b88b64d76aac88ae6b39208827ac0e2a4a2d78f3f2159882efefcad7fd",
                "md5": "98910bed156b3367f1203acb9827f12d",
                "sha256": "91d808d3f246d30bead2a0a2540b74b9e9fc584a9c3f1f55abfc2940c4e44fd2"
            },
            "downloads": -1,
            "filename": "nvidia_ml_py-12.535.133-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "98910bed156b3367f1203acb9827f12d",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 37087,
            "upload_time": "2023-11-02T14:47:20",
            "upload_time_iso_8601": "2023-11-02T14:47:20.746304Z",
            "url": "https://files.pythonhosted.org/packages/a8/10/35b88b64d76aac88ae6b39208827ac0e2a4a2d78f3f2159882efefcad7fd/nvidia_ml_py-12.535.133-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c9f535d8002a4a9532c58fa304046de2d9b8be18183c341c517ac48f2bce907a",
                "md5": "64e3bc3b8718767771d5d366a3109cba",
                "sha256": "b1559af0d57dd20955bf58d05afff7b166ddd44947eb3051c9905638799eb1dc"
            },
            "downloads": -1,
            "filename": "nvidia-ml-py-12.535.133.tar.gz",
            "has_sig": false,
            "md5_digest": "64e3bc3b8718767771d5d366a3109cba",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 35808,
            "upload_time": "2023-11-02T14:47:22",
            "upload_time_iso_8601": "2023-11-02T14:47:22.425720Z",
            "url": "https://files.pythonhosted.org/packages/c9/f5/35d8002a4a9532c58fa304046de2d9b8be18183c341c517ac48f2bce907a/nvidia-ml-py-12.535.133.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-11-02 14:47:22",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "nvidia-ml-py"
}
        
Elapsed time: 0.14427s