Migrate to use libnvml to check nvlink status directly (BugFix)#2634
Migrate to use libnvml to check nvlink status directly (BugFix)#2634hanhsuan wants to merge 1 commit into
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2634 +/- ##
==========================================
+ Coverage 59.84% 59.88% +0.03%
==========================================
Files 485 485
Lines 48752 48801 +49
Branches 8732 8739 +7
==========================================
+ Hits 29177 29223 +46
- Misses 18658 18659 +1
- Partials 917 919 +2
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
fb39fca to
91aae37
Compare
2. set __GLX_VENDOR_LIBRARY_NAME=mesa for non NV card
91aae37 to
48908f0
Compare
There was a problem hiding this comment.
Pull request overview
This PR updates the providers/base prime offload helper to stop relying on nvidia-smi nvlink --status output and instead query NVLink status directly via NVML (loaded with ctypes). It also adjusts the GLX vendor selection for non-NVIDIA offload runs to ensure Mesa is used by default, aligning with the reported offload failure scenario.
Changes:
- Add
PrimeOffloader.check_nv_link_status()usingctypes.CDLL("libnvidia-ml.so.1")to detect active NVLink via NVML APIs. - Update
check_nv_offload_env()to use NVML-based NVLink detection rather than parsingnvidia-smioutput. - Set
__GLX_VENDOR_LIBRARY_NAME=mesafor non-NVIDIA offload environments and add unit tests covering NVML/NVLink detection and updated behavior.
Reviewed changes
Copilot reviewed 1 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| providers/base/bin/prime_offload_tester.py | Adds NVML/ctypes NVLink detection, switches NVLink gating logic to use it, and sets Mesa GLX vendor for non-NVIDIA offload. |
| providers/base/tests/test_prime_offload_tester.py | Adds unit tests for NVML-based NVLink detection and updates NVLink-related environment checks. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
tomli380576
left a comment
There was a problem hiding this comment.
lgtm the test results look ok
| # Define NVML return codes | ||
| NVML_SUCCESS = 0 | ||
| NVML_ERROR_NOT_SUPPORTED = 3 |
There was a problem hiding this comment.
source for future reviewers: https://github.com/NVIDIA/nvidia-settings/blob/5b341a9e54f08ac324e148e1e7e102030e42b1c4/src/nvml.h#L1293
| ret = nvmlInit() | ||
| if ret != NVML_SUCCESS: | ||
| self.logger.info("NVML initialization failed") | ||
| return False |
There was a problem hiding this comment.
source for future reviewers: https://github.com/NVIDIA/nvidia-settings/blob/5b341a9e54f08ac324e148e1e7e102030e42b1c4/src/nvml.h#L3974-L4000
| nvmlDeviceGetHandleByIndex = nvml.nvmlDeviceGetHandleByIndex_v2 | ||
| nvmlDeviceGetHandleByIndex.argtypes = [ | ||
| ctypes.c_uint, | ||
| ctypes.POINTER(ctypes.c_void_p), | ||
| ] | ||
| nvmlDeviceGetHandleByIndex.restype = ctypes.c_int |
There was a problem hiding this comment.
source for future reviewers: https://github.com/NVIDIA/nvidia-settings/blob/5b341a9e54f08ac324e148e1e7e102030e42b1c4/src/nvml.h#L4593-L4639
| nvmlDeviceGetNvLinkState = nvml.nvmlDeviceGetNvLinkState | ||
| nvmlDeviceGetNvLinkState.argtypes = [ | ||
| ctypes.c_void_p, | ||
| ctypes.c_uint, | ||
| ctypes.POINTER(ctypes.c_uint), | ||
| ] | ||
| nvmlDeviceGetNvLinkState.restype = ctypes.c_int |
There was a problem hiding this comment.
source for future reviewers: https://github.com/NVIDIA/nvidia-settings/blob/5b341a9e54f08ac324e148e1e7e102030e42b1c4/src/nvml.h#L9486-L9504
There was a problem hiding this comment.
the 1st arg is a void pointer because otherwise we need to bring in the entire nvmlDevice_st struct
|
the pseudocode is basically |
Description
With nvidia-driver-580, the output of nvidia-smi nvlink --status was empty. However, with nvidia-driver-595, nvidia-smi nvlink --status now returns something, which broke the
prime_offload_test.pyand we don't want to depend on the output fromnvidia-smi nvlink -sanymore. Therefore, migrating to usectypewould be a easier way to skip to add more dependencies into checkbox.At the same time, add
__GLX_VENDOR_LIBRARY_NAME=mesafor all non-nvidia to make sure the default is set to the right one.Resolved issues
#2560
Documentation
Tests
26.04 (I+N): https://certification.canonical.com/hardware/202001-27667/submission/498212/
24.04 (I+N): https://certification.canonical.com/hardware/202001-27667/submission/498219/
22.04 run 24.04 test plan (I+N) : https://certification.canonical.com/hardware/202001-27667/submission/498211/
22.04 with NVLINK: https://certification.canonical.com/hardware/202303-31329/submission/498220/
24.04 (A+N): https://certification.canonical.com/hardware/202603-38521/submission/498366/