Skip to content

Commit

Permalink
Remove pynvml module and convert to a "meta package" (#57)
Browse files Browse the repository at this point in the history
  • Loading branch information
rjzamora authored Nov 27, 2024
1 parent 82cb5e0 commit 3ab8776
Show file tree
Hide file tree
Showing 18 changed files with 93 additions and 7,753 deletions.
1 change: 0 additions & 1 deletion .gitattributes

This file was deleted.

3 changes: 1 addition & 2 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
include versioneer.py
include pynvml/_version.py
include help_query_gpu.txt
20 changes: 0 additions & 20 deletions PKG-INFO

This file was deleted.

160 changes: 26 additions & 134 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,39 +1,31 @@
> [!WARNING]
> This package includes unofficial NVML bindings and utilities.
> This package is intended for demonstration purposes only. There
> is no guarantee for long-term maintenence or support.
>
> **The `pynvml` module is NOT developed or maintained in this project!**
>
> This project provides unofficial NVML Python utilities (i.e. the `pynvml_utils` module).
> The `pynvml_utils` module is intended for demonstration purposes only.
> There is no guarantee for long-term maintenence or support.
>
> The official NVML bindings are published by NVIDIA under a different
> `nvidia-ml-py` project (see: https://pypi.org/project/nvidia-ml-py/).
> The `pynvml_utils` module depends on the official NVML bindings
> published by NVIDIA under a different `nvidia-ml-py` project
> (see: https://pypi.org/project/nvidia-ml-py/).
>
> Future releases of this project will not include NVML bindings
> directly, but will instead depend on `nvidia-ml-py`.
>
> Please migrate to the official package for long-term support.
> You can still import and use a familar `pynvml` module after
> migrating to the official package.
Python bindings and utilities for the NVIDIA Management Library
===============================================================

> [!IMPORTANT]
> As of version 11.0.0, the NVML-wrappers used in pynvml are directly
> copied from [nvidia-ml-py](https://pypi.org/project/nvidia-ml-py/).
> In a future release, the local bindings will be removed, and
> `nvidia-ml-py` will become a required dependency.
Python utilities for the NVIDIA Management Library
===============================================================

This project provides Python utilities and bindings for the
This project provides unofficial Python utilities for the
NVIDIA Management Library (NVML).

For information about the NVML library, see the NVML developer page
http://developer.nvidia.com/nvidia-management-library-nvml

Note that 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.
`nvidia-ml-py`.


Installation
------------
Expand All @@ -43,24 +35,12 @@ Installation
Usage
-----

You can use the lower level nvml bindings provided by `nvidia-ml-py`

```python
>>> 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()
```
Bindings for the high-level `nvidia-smi` API are available
in `pynvml_utils.nvidia_smi`:

Or the higher level `nvidia_smi` API
> [!WARNING]
> The `nvidia_smi` module is intended for demonstration purposes only.
> There is no guarantee for long-term maintenence or support.
```python
from pynvml_utils import nvidia_smi
Expand All @@ -74,104 +54,16 @@ nvsmi = nvidia_smi.getInstance()
print(nvsmi.DeviceQuery('--help-query-gpu'), end='\n')
```

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.

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

- C function output parameters are returned from the corresponding
Python function left to right.

```c
nvmlReturn_t nvmlDeviceGetEccMode(nvmlDevice_t device,
nvmlEnableState_t *current,
nvmlEnableState_t *pending);
```

```python
>>> nvmlInit()
>>> handle = nvmlDeviceGetHandleByIndex(0)
>>> (current, pending) = nvmlDeviceGetEccMode(handle)
```

- C structs are converted into Python classes.

```c
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
>>> 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.

```c
nvmlReturn_t nvmlSystemGetDriverVersion(char* version,
unsigned int length);
```

```python
>>> 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.

NVML Permissions
----------------

Many of the `pynvml` wrappers assume that the underlying NVIDIA Management Library (NVML) API can be used without admin/root privileges. However, it is certainly possible for the system permissions to prevent pynvml from querying GPU performance counters. For example:

```
$ nvidia-smi nvlink -g 0
GPU 0: Tesla V100-SXM2-32GB (UUID: GPU-96ab329d-7a1f-73a8-a9b7-18b4b2855f92)
NVML: Unable to get the NvLink link utilization counter control for link 0: Insufficient Permissions
```

A simple way to check the permissions status is to look for `RmProfilingAdminOnly` in the driver `params` file (Note that `RmProfilingAdminOnly == 1` means that admin/sudo access is required):

```
$ cat /proc/driver/nvidia/params | grep RmProfilingAdminOnly
RmProfilingAdminOnly: 1
```
Release Notes
-------------

For more information on setting/unsetting the relevant admin privileges, see [these notes](https://developer.nvidia.com/nvidia-development-tools-solutions-ERR_NVGPUCTRPERM-permission-issue-performance-counters) on resolving `ERR_NVGPUCTRPERM` errors.
- Version 12.0.0
- Remove pynvml module and depend on nvidia-ml-py
- Pin to nvidia-ml-py>=12.0.0,<13.0.0a0


Release Notes
-------------
Old Releases
------------

- Version 2.285.0
- Added new functions for NVML 2.285. See NVML documentation for more information.
Expand Down
27 changes: 10 additions & 17 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,20 @@
# BUILD: docker build --network=host --file docker/Dockerfile --tag pynvml .
# RUN: docker run --gpus all --rm -it pynvml
##############################################################
FROM python:3.6
FROM python:3.9

ENV DEBIAN_FRONTEND noninteractive

ADD ./requirements.txt /app/requirements.txt
ADD . /app/.
RUN <<EOF
cd /app
pip install --no-cache-dir --upgrade pip
pip install --no-cache-dir -e .

RUN pip install --no-cache-dir --upgrade pip && \
pip install --no-cache-dir -r /app/requirements.txt && \
rm -rf ~/.cache/pip

ADD ./pynvml /app/pynvml
ADD ./setup.py /app/
ADD ./setup.cfg /app/
ADD ./README.md /app/
ADD ./PKG-INFO /app/
ADD ./MANIFEST.in /app/
ADD ./help_query_gpu.txt /app/
ADD docker/entrypoint.sh /docker-entrypoint.sh

RUN chmod +x /docker-entrypoint.sh
find /app -type f -name '*.pyc' -delete
find /app -type d -name '__pycache__' -delete
rm -rf ~/.cache/pip
EOF

## Create App user
# Set the home directory to our app user's home.
Expand All @@ -35,5 +29,4 @@ ENV APP_HOME=/app
WORKDIR /app

EXPOSE 8888
ENTRYPOINT ["/docker-entrypoint.sh"]
CMD ["bash"]
8 changes: 0 additions & 8 deletions docker/entrypoint.sh

This file was deleted.

5 changes: 0 additions & 5 deletions pynvml/__init__.py

This file was deleted.

Loading

0 comments on commit 3ab8776

Please sign in to comment.