[PR #30] [MERGED] feat(core/libnvml): add compatibility layers for NVML Python bindings #129

Closed
opened 2026-05-05 03:26:23 -06:00 by gitea-mirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/XuehaiPan/nvitop/pull/30
Author: @XuehaiPan
Created: 7/24/2022
Status: Merged
Merged: 10/17/2022
Merged by: @XuehaiPan

Base: mainHead: backward-compatibility


📝 Commits (8)

  • b88ecfe feat(core/libnvml): add compatibility layers for process info
  • 9c9b028 chore(core/libnvml): update supported nvidia-ml-py version list
  • abd98d8 feat(core/libnvml): add compatibility layers for memory info
  • 5054849 docs: add notes for environment variable LOGLEVEL
  • 6c343a2 fix(core/libnvml): fix memory version 2 API arguments
  • 34253e5 chore(core/libnvml): update supported nvidia-ml-py version list
  • c103922 chore(core/libnvml): add notes for incompatible nvidia-ml-py package for memory info version 2 APIs
  • 5bce06d style(core/libnvml): rename functions

📊 Changes

7 files changed (+286 additions, -23 deletions)

View changed files

📝 .github/ISSUE_TEMPLATE.md (+2 -1)
📝 README.md (+1 -14)
📝 nvitop/cli.py (+22 -3)
📝 nvitop/core/libnvml.py (+256 -3)
📝 nvitop/version.py (+3 -0)
📝 pyproject.toml (+1 -1)
📝 requirements.txt (+1 -1)

📄 Description

Issue Type

  • Improvement/feature implementation

Runtime Environment

  • Operating system and version: Ubuntu 20.04 LTS
  • Terminal emulator and version: GNOME Terminal 3.36.2
  • Python version: 3.9.13
  • NVML version (driver version): 470.129.06
  • nvitop version or commit: v0.7.1
  • python-ml-py version: 11.450.51
  • Locale: en_US.UTF-8

Description

Automatically patch the pynvml module when the first call fails when calling the versioned APIs. Now we support a more broad range of the PyPI package nvidia-ml-py dependency versions.

Motivation and Context

See #29 for more details.

Resolves #29
Closes #13

Testing

Using nvidia-ml-py == 11.515.48 with the NVIDIA R430 driver (CUDA 10.x):

$ pip3 install --ignore-installed .
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Processing /home/panxuehai/Projects/nvitop
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Installing backend dependencies ... done
  Preparing metadata (pyproject.toml) ... done
Collecting psutil>=5.6.6
  Using cached https://pypi.tuna.tsinghua.edu.cn/packages/62/1f/f14225bda76417ab9bd808ff21d5cd59d5435a9796ca09b34d4cb0edcd88/psutil-5.9.1-cp39-cp39-manylinux_2_12_x86_64.manylinux2010_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (281 kB)
Collecting cachetools>=1.0.1
  Using cached https://pypi.tuna.tsinghua.edu.cn/packages/68/aa/5fc646cae6e997c3adf3b0a7e257cda75cff21fcba15354dffd67789b7bb/cachetools-5.2.0-py3-none-any.whl (9.3 kB)
Collecting nvidia-ml-py<11.516.0a0,>=11.450.51
  Using cached https://pypi.tuna.tsinghua.edu.cn/packages/7c/b6/738d9c68f8abcdedf8901c4abf00df74e8f281626de67b5185dcc443e693/nvidia_ml_py-11.515.48-py3-none-any.whl (28 kB)
Collecting termcolor>=1.0.0
  Using cached termcolor-1.1.0-py3-none-any.whl
Building wheels for collected packages: nvitop
  Building wheel for nvitop (pyproject.toml) ... done
  Created wheel for nvitop: filename=nvitop-0.7.1+6.g0feed99-py3-none-any.whl size=154871 sha256=da07a27d8579e1cc38a3bd3d537f0d885d592df0c3293ba585b831fa236f100e
  Stored in directory: /tmp/pip-ephem-wheel-cache-3qzopv_e/wheels/9a/17/84/86d7a108dc1c0d7a25e96628d476e19df73a27353725b35779
Successfully built nvitop
Installing collected packages: termcolor, nvidia-ml-py, psutil, cachetools, nvitop
Successfully installed cachetools-5.2.0 nvidia-ml-py-11.515.48 nvitop-0.7.1+6.g84f43f5 psutil-5.9.1 termcolor-1.1.0

Result:

The v3 API nvmlDeviceGetComputeRunningProcesses_v3 fails-back to v2 API nvmlDeviceGetComputeRunningProcesses_v2 (which could not found either), then fails-back to v1 API nvmlDeviceGetComputeRunningProcesses.

$ LOGLEVEL=DEBUG ./nvitop.py -1
Patching NVML function pointer `nvmlDeviceGetComputeRunningProcesses_v3`
    Map NVML function `nvmlDeviceGetComputeRunningProcesses_v3` to `nvmlDeviceGetComputeRunningProcesses_v2`
    Map NVML function `nvmlDeviceGetGraphicsRunningProcesses_v3` to `nvmlDeviceGetGraphicsRunningProcesses_v2`
    Map NVML function `nvmlDeviceGetMPSComputeRunningProcesses_v3` to `nvmlDeviceGetMPSComputeRunningProcesses_v2`
    Patch NVML struct `c_nvmlProcessInfo_t` to `c_nvmlProcessInfo_v2_t`
Patching NVML function pointer `nvmlDeviceGetComputeRunningProcesses_v2`
    Map NVML function `nvmlDeviceGetComputeRunningProcesses_v2` to `nvmlDeviceGetComputeRunningProcesses`
    Map NVML function `nvmlDeviceGetGraphicsRunningProcesses_v2` to `nvmlDeviceGetGraphicsRunningProcesses`
    Map NVML function `nvmlDeviceGetMPSComputeRunningProcesses_v2` to `nvmlDeviceGetMPSComputeRunningProcesses`
    Map NVML function `nvmlDeviceGetComputeRunningProcesses_v3` to `nvmlDeviceGetComputeRunningProcesses`
    Map NVML function `nvmlDeviceGetGraphicsRunningProcesses_v3` to `nvmlDeviceGetGraphicsRunningProcesses`
    Map NVML function `nvmlDeviceGetMPSComputeRunningProcesses_v3` to `nvmlDeviceGetMPSComputeRunningProcesses`
    Patch NVML struct `c_nvmlProcessInfo_t` to `c_nvmlProcessInfo_v1_t`
Sun Jul 24 19:32:24 2022
╒═════════════════════════════════════════════════════════════════════════════╕
│ NVIDIA-SMI 430.64       Driver Version: 430.64       CUDA Version: 10.1     │
├───────────────────────────────┬──────────────────────┬──────────────────────┤
│ GPU  Name        Persistence-M│ Bus-Id        Disp.A │ Volatile Uncorr. ECC │
│ Fan  Temp  Perf  Pwr:Usage/Cap│         Memory-Usage │ GPU-Util  Compute M. │
╞═══════════════════════════════╪══════════════════════╪══════════════════════╪══════════════════════════════════════════════════════════════════════════════════╕
│   0  TITAN Xp            Off  │ 00000000:05:00.0 Off │                  N/A │ MEM: ▏ 0.2%                                                                      │
│ 24%   43C    P8    19W / 250W │     19MiB / 12194MiB │      0%      Default │ UTL: ▏ 0%                                                                        │
├───────────────────────────────┼──────────────────────┼──────────────────────┼──────────────────────────────────────────────────────────────────────────────────┤
│   1  TITAN Xp            Off  │ 00000000:06:00.0 Off │                  N/A │ MEM: ▏ 0.0%                                                                      │
│ 23%   36C    P8    10W / 250W │      2MiB / 12196MiB │      0%      Default │ UTL: ▏ 0%                                                                        │
├───────────────────────────────┼──────────────────────┼──────────────────────┼──────────────────────────────────────────────────────────────────────────────────┤
│   2  ..orce GTX TITAN X  Off  │ 00000000:09:00.0 Off │                  N/A │ MEM: ▏ 0.0%                                                                      │
│ 22%   34C    P8    17W / 250W │      2MiB / 12213MiB │      0%      Default │ UTL: ▏ 0%                                                                        │
╘═══════════════════════════════╧══════════════════════╧══════════════════════╧══════════════════════════════════════════════════════════════════════════════════╛
[ CPU: █████▉ 5.3%                                                                                                          ]  ( Load Average:  0.89  0.61  0.39 )
[ MEM: ███▋ 3.2%                                                                                                            ]  [ SWP: ▏ 0.0%                     ]

╒════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════╕
│ Processes:                                                                                                                                    panxuehai@ubuntu │
│ GPU     PID      USER  GPU-MEM %SM  %CPU  %MEM      TIME  COMMAND                                                                                              │
╞════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════╡
│   0    2122 G    root    17MiB   0   0.0   0.0  4.2 days  /usr/lib/xorg/Xorg -core :0 -seat seat0 -auth /var/run/lightdm/root/:0 -nolisten tcp vt7 -novtswitch │
╘════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════╛

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/XuehaiPan/nvitop/pull/30 **Author:** [@XuehaiPan](https://github.com/XuehaiPan) **Created:** 7/24/2022 **Status:** ✅ Merged **Merged:** 10/17/2022 **Merged by:** [@XuehaiPan](https://github.com/XuehaiPan) **Base:** `main` ← **Head:** `backward-compatibility` --- ### 📝 Commits (8) - [`b88ecfe`](https://github.com/XuehaiPan/nvitop/commit/b88ecfe2a56afdd2c8367b84a7f008ec58b4ee93) feat(core/libnvml): add compatibility layers for process info - [`9c9b028`](https://github.com/XuehaiPan/nvitop/commit/9c9b02809ab7f92bb924356ba8d39a7edb422e30) chore(core/libnvml): update supported `nvidia-ml-py` version list - [`abd98d8`](https://github.com/XuehaiPan/nvitop/commit/abd98d861d3048a1856a2e918f7f2757f9710cc3) feat(core/libnvml): add compatibility layers for memory info - [`5054849`](https://github.com/XuehaiPan/nvitop/commit/50548495b35ccb097ac577efbe48a98685c752e3) docs: add notes for environment variable `LOGLEVEL` - [`6c343a2`](https://github.com/XuehaiPan/nvitop/commit/6c343a24b6e6bca6ea2165a0ee774ecc7f66c8ea) fix(core/libnvml): fix memory version 2 API arguments - [`34253e5`](https://github.com/XuehaiPan/nvitop/commit/34253e521ed514d32539f98058085e61a93737b4) chore(core/libnvml): update supported `nvidia-ml-py` version list - [`c103922`](https://github.com/XuehaiPan/nvitop/commit/c1039222dfbf666fd74081257be5de3cdbe35d11) chore(core/libnvml): add notes for incompatible `nvidia-ml-py` package for memory info version 2 APIs - [`5bce06d`](https://github.com/XuehaiPan/nvitop/commit/5bce06d7a99c6be857c404657282dd0d180f809d) style(core/libnvml): rename functions ### 📊 Changes **7 files changed** (+286 additions, -23 deletions) <details> <summary>View changed files</summary> 📝 `.github/ISSUE_TEMPLATE.md` (+2 -1) 📝 `README.md` (+1 -14) 📝 `nvitop/cli.py` (+22 -3) 📝 `nvitop/core/libnvml.py` (+256 -3) 📝 `nvitop/version.py` (+3 -0) 📝 `pyproject.toml` (+1 -1) 📝 `requirements.txt` (+1 -1) </details> ### 📄 Description #### Issue Type <!-- Pick relevant types and delete the rest --> - Improvement/feature implementation #### Runtime Environment - Operating system and version: Ubuntu 20.04 LTS - Terminal emulator and version: GNOME Terminal 3.36.2 - Python version: `3.9.13` - NVML version (driver version): `470.129.06` - `nvitop` version or commit: `v0.7.1` - `python-ml-py` version: `11.450.51` - Locale: `en_US.UTF-8` #### Description <!-- Describe the changes in detail --> Automatically patch the `pynvml` module when the first call fails when calling the versioned APIs. Now we support a more broad range of the [PyPI package `nvidia-ml-py`](https://pypi.org/project/nvidia-ml-py/) dependency versions. #### Motivation and Context <!-- Why are these changes required? --> <!-- What problems do these changes solve? --> <!-- Link to relevant issues --> See #29 for more details. Resolves #29 Closes #13 #### Testing Using `nvidia-ml-py == 11.515.48` with the NVIDIA R430 driver (CUDA 10.x): ```console $ pip3 install --ignore-installed . Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple Processing /home/panxuehai/Projects/nvitop Installing build dependencies ... done Getting requirements to build wheel ... done Installing backend dependencies ... done Preparing metadata (pyproject.toml) ... done Collecting psutil>=5.6.6 Using cached https://pypi.tuna.tsinghua.edu.cn/packages/62/1f/f14225bda76417ab9bd808ff21d5cd59d5435a9796ca09b34d4cb0edcd88/psutil-5.9.1-cp39-cp39-manylinux_2_12_x86_64.manylinux2010_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (281 kB) Collecting cachetools>=1.0.1 Using cached https://pypi.tuna.tsinghua.edu.cn/packages/68/aa/5fc646cae6e997c3adf3b0a7e257cda75cff21fcba15354dffd67789b7bb/cachetools-5.2.0-py3-none-any.whl (9.3 kB) Collecting nvidia-ml-py<11.516.0a0,>=11.450.51 Using cached https://pypi.tuna.tsinghua.edu.cn/packages/7c/b6/738d9c68f8abcdedf8901c4abf00df74e8f281626de67b5185dcc443e693/nvidia_ml_py-11.515.48-py3-none-any.whl (28 kB) Collecting termcolor>=1.0.0 Using cached termcolor-1.1.0-py3-none-any.whl Building wheels for collected packages: nvitop Building wheel for nvitop (pyproject.toml) ... done Created wheel for nvitop: filename=nvitop-0.7.1+6.g0feed99-py3-none-any.whl size=154871 sha256=da07a27d8579e1cc38a3bd3d537f0d885d592df0c3293ba585b831fa236f100e Stored in directory: /tmp/pip-ephem-wheel-cache-3qzopv_e/wheels/9a/17/84/86d7a108dc1c0d7a25e96628d476e19df73a27353725b35779 Successfully built nvitop Installing collected packages: termcolor, nvidia-ml-py, psutil, cachetools, nvitop Successfully installed cachetools-5.2.0 nvidia-ml-py-11.515.48 nvitop-0.7.1+6.g84f43f5 psutil-5.9.1 termcolor-1.1.0 ``` Result: The v3 API `nvmlDeviceGetComputeRunningProcesses_v3` fails-back to v2 API `nvmlDeviceGetComputeRunningProcesses_v2` (which could not found either), then fails-back to v1 API `nvmlDeviceGetComputeRunningProcesses`. ```console $ LOGLEVEL=DEBUG ./nvitop.py -1 Patching NVML function pointer `nvmlDeviceGetComputeRunningProcesses_v3` Map NVML function `nvmlDeviceGetComputeRunningProcesses_v3` to `nvmlDeviceGetComputeRunningProcesses_v2` Map NVML function `nvmlDeviceGetGraphicsRunningProcesses_v3` to `nvmlDeviceGetGraphicsRunningProcesses_v2` Map NVML function `nvmlDeviceGetMPSComputeRunningProcesses_v3` to `nvmlDeviceGetMPSComputeRunningProcesses_v2` Patch NVML struct `c_nvmlProcessInfo_t` to `c_nvmlProcessInfo_v2_t` Patching NVML function pointer `nvmlDeviceGetComputeRunningProcesses_v2` Map NVML function `nvmlDeviceGetComputeRunningProcesses_v2` to `nvmlDeviceGetComputeRunningProcesses` Map NVML function `nvmlDeviceGetGraphicsRunningProcesses_v2` to `nvmlDeviceGetGraphicsRunningProcesses` Map NVML function `nvmlDeviceGetMPSComputeRunningProcesses_v2` to `nvmlDeviceGetMPSComputeRunningProcesses` Map NVML function `nvmlDeviceGetComputeRunningProcesses_v3` to `nvmlDeviceGetComputeRunningProcesses` Map NVML function `nvmlDeviceGetGraphicsRunningProcesses_v3` to `nvmlDeviceGetGraphicsRunningProcesses` Map NVML function `nvmlDeviceGetMPSComputeRunningProcesses_v3` to `nvmlDeviceGetMPSComputeRunningProcesses` Patch NVML struct `c_nvmlProcessInfo_t` to `c_nvmlProcessInfo_v1_t` Sun Jul 24 19:32:24 2022 ╒═════════════════════════════════════════════════════════════════════════════╕ │ NVIDIA-SMI 430.64 Driver Version: 430.64 CUDA Version: 10.1 │ ├───────────────────────────────┬──────────────────────┬──────────────────────┤ │ GPU Name Persistence-M│ Bus-Id Disp.A │ Volatile Uncorr. ECC │ │ Fan Temp Perf Pwr:Usage/Cap│ Memory-Usage │ GPU-Util Compute M. │ ╞═══════════════════════════════╪══════════════════════╪══════════════════════╪══════════════════════════════════════════════════════════════════════════════════╕ │ 0 TITAN Xp Off │ 00000000:05:00.0 Off │ N/A │ MEM: ▏ 0.2% │ │ 24% 43C P8 19W / 250W │ 19MiB / 12194MiB │ 0% Default │ UTL: ▏ 0% │ ├───────────────────────────────┼──────────────────────┼──────────────────────┼──────────────────────────────────────────────────────────────────────────────────┤ │ 1 TITAN Xp Off │ 00000000:06:00.0 Off │ N/A │ MEM: ▏ 0.0% │ │ 23% 36C P8 10W / 250W │ 2MiB / 12196MiB │ 0% Default │ UTL: ▏ 0% │ ├───────────────────────────────┼──────────────────────┼──────────────────────┼──────────────────────────────────────────────────────────────────────────────────┤ │ 2 ..orce GTX TITAN X Off │ 00000000:09:00.0 Off │ N/A │ MEM: ▏ 0.0% │ │ 22% 34C P8 17W / 250W │ 2MiB / 12213MiB │ 0% Default │ UTL: ▏ 0% │ ╘═══════════════════════════════╧══════════════════════╧══════════════════════╧══════════════════════════════════════════════════════════════════════════════════╛ [ CPU: █████▉ 5.3% ] ( Load Average: 0.89 0.61 0.39 ) [ MEM: ███▋ 3.2% ] [ SWP: ▏ 0.0% ] ╒════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════╕ │ Processes: panxuehai@ubuntu │ │ GPU PID USER GPU-MEM %SM %CPU %MEM TIME COMMAND │ ╞════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════╡ │ 0 2122 G root 17MiB 0 0.0 0.0 4.2 days /usr/lib/xorg/Xorg -core :0 -seat seat0 -auth /var/run/lightdm/root/:0 -nolisten tcp vt7 -novtswitch │ ╘════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════╛ ``` --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
gitea-mirror 2026-05-05 03:26:23 -06:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: github-starred/nvitop#129
No description provided.