Skip to content

Commit 4d12dd5

Browse files
committed
Initial Commit
Ran 2to3 on the nvidia-ml-py package from PyPi. Packaged it with setuptools.
0 parents  commit 4d12dd5

File tree

6 files changed

+2820
-0
lines changed

6 files changed

+2820
-0
lines changed

LICENSE

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
LICENSE
2+
-------
3+
Redistribution and use in source and binary forms, with or without
4+
modification, are permitted provided that the following conditions are met:
5+
6+
- Redistributions of source code must retain the above copyright notice, this
7+
list of conditions and the following disclaimer.
8+
9+
- Redistributions in binary form must reproduce the above copyright notice,
10+
this list of conditions and the following disclaimer in the documentation
11+
and/or other materials provided with the distribution.
12+
13+
- Neither the name of the NVIDIA Corporation nor the names of its contributors
14+
may be used to endorse or promote products derived from this software without
15+
specific prior written permission.
16+
17+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
21+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
24+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27+
28+

README.md

Lines changed: 186 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,186 @@
1+
# fbcotter/py3nvml
2+
3+
Python 3 compatible bindings to the NVIDIA Management Library
4+
5+
Origin python library can be found here
6+
[nvidia-ml-py](https://pypi.python.org/pypi/nvidia-ml-py/7.352.0). I have
7+
forked from version 7.352.0.
8+
9+
This is an NVIDIA sponsored library, but it only works for python <= 2.5. This
10+
package was created from the NVIDIA library by running **2to3** on it, and
11+
making it pip importable. (Also changed the README from a .txt to a .md).
12+
13+
## Info on NVIDIA Management Library
14+
15+
Provides a Python interface to GPU management and monitoring functions.
16+
17+
It is a wrapper around the NVML library.
18+
19+
For information about the NVML library, see the NVML developer page
20+
http://developer.nvidia.com/nvidia-management-library-nvml
21+
22+
23+
## Requires
24+
--------
25+
Python 3.5 or earlier
26+
27+
## Installation
28+
Download and pip install from Git:
29+
30+
$ git clone [email protected]:fbcotter/nvml.git
31+
$ cd py3nvml
32+
$ pip install .
33+
34+
35+
## Usage
36+
37+
>>> from py3nvml.pynvml import *
38+
>>> nvmlInit()
39+
>>> print "Driver Version:", nvmlSystemGetDriverVersion()
40+
Driver Version: 352.00
41+
>>> deviceCount = nvmlDeviceGetCount()
42+
>>> for i in range(deviceCount):
43+
... handle = nvmlDeviceGetHandleByIndex(i)
44+
... print("Device {}: {}".format(i, nvmlDeviceGetName(handle)))
45+
...
46+
Device 0 : Tesla K40c
47+
48+
>>> nvmlShutdown()
49+
50+
Additionally, see py3nvml.nvidia_smi.py. A sample application that prints out
51+
the same as the command line:
52+
53+
nvidia-smi -q -x
54+
55+
## Functions
56+
Python methods wrap NVML functions, implemented in a C shared library.
57+
Each function's use is the same with the following exceptions:
58+
59+
- Instead of returning error codes, failing error codes are raised as
60+
Python exceptions.
61+
62+
```python
63+
try:
64+
nvmlDeviceGetCount()
65+
except NVMLError as error:
66+
print error
67+
```
68+
Prints:
69+
```
70+
Uninitialized
71+
```
72+
73+
- C function output parameters are returned from the corresponding
74+
Python function left to right. Eg the C function:
75+
76+
```C
77+
nvmlReturn_t nvmlDeviceGetEccMode(nvmlDevice_t device,
78+
nvmlEnableState_t *current,
79+
nvmlEnableState_t *pending);
80+
```
81+
Can be called like so:
82+
```python
83+
>>> nvmlInit()
84+
>>> handle = nvmlDeviceGetHandleByIndex(0)
85+
>>> (current, pending) = nvmlDeviceGetEccMode(handle)
86+
```
87+
88+
- C structs are converted into Python classes.
89+
90+
E.g. the C struct:
91+
```C
92+
nvmlReturn_t DECLDIR nvmlDeviceGetMemoryInfo(nvmlDevice_t device,
93+
nvmlMemory_t *memory);
94+
typedef struct nvmlMemory_st {
95+
unsigned long long total;
96+
unsigned long long free;
97+
unsigned long long used;
98+
} nvmlMemory_t;
99+
```
100+
101+
Becomes:
102+
```python
103+
>>> info = nvmlDeviceGetMemoryInfo(handle)
104+
>>> print "Total memory:", info.total
105+
Total memory: 5636292608
106+
>>> print "Free memory:", info.free
107+
Free memory: 5578420224
108+
>>> print "Used memory:", info.used
109+
Used memory: 57872384
110+
111+
- Python handles string buffer creation.
112+
E.g. the C function:
113+
```C
114+
nvmlReturn_t nvmlSystemGetDriverVersion(char* version,
115+
unsigned int length);
116+
```
117+
Can be called like so:
118+
```python
119+
>>> version = nvmlSystemGetDriverVersion();
120+
>>> nvmlShutdown()
121+
```
122+
123+
For usage information see the NVML documentation.
124+
125+
## Variables
126+
---------
127+
All meaningful NVML constants and enums are exposed in Python.
128+
129+
The NVML_VALUE_NOT_AVAILABLE constant is not used. Instead None is mapped to the field.
130+
131+
## Release Notes
132+
-------------
133+
Version 2.285.0
134+
- Added new functions for NVML 2.285. See NVML documentation for more information.
135+
- Ported to support Python 3.0 and Python 2.0 syntax.
136+
- Added nvidia_smi.py tool as a sample app.
137+
Version 3.295.0
138+
- Added new functions for NVML 3.295. See NVML documentation for more information.
139+
- Updated nvidia_smi.py tool
140+
- Includes additional error handling
141+
Version 4.304.0
142+
- Added new functions for NVML 4.304. See NVML documentation for more information.
143+
- Updated nvidia_smi.py tool
144+
Version 4.304.3
145+
- Fixing nvmlUnitGetDeviceCount bug
146+
Version 5.319.0
147+
- Added new functions for NVML 5.319. See NVML documentation for more information.
148+
Version 6.340.0
149+
- Added new functions for NVML 6.340. See NVML documentation for more information.
150+
Version 7.346.0
151+
- Added new functions for NVML 7.346. See NVML documentation for more information.
152+
Version 7.352.0
153+
- Added new functions for NVML 7.352. See NVML documentation for more information.
154+
155+
COPYRIGHT
156+
---------
157+
Copyright (c) 2011-2015, NVIDIA Corporation. All rights reserved.
158+
159+
LICENSE
160+
-------
161+
Redistribution and use in source and binary forms, with or without
162+
modification, are permitted provided that the following conditions are met:
163+
164+
- Redistributions of source code must retain the above copyright notice, this
165+
list of conditions and the following disclaimer.
166+
167+
- Redistributions in binary form must reproduce the above copyright notice,
168+
this list of conditions and the following disclaimer in the documentation
169+
and/or other materials provided with the distribution.
170+
171+
- Neither the name of the NVIDIA Corporation nor the names of its contributors
172+
may be used to endorse or promote products derived from this software without
173+
specific prior written permission.
174+
175+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
176+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
177+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
178+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
179+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
180+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
181+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
182+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
183+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
184+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
185+
186+

py3nvml/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from . import py3nvml
2+
from . import nvidia_smi
3+

0 commit comments

Comments
 (0)