Repository navigation
[AI generated] fix: try next NVML library candidate when nvmlInit fails - #1869
Open
raylei50653 wants to merge 3 commits into
Open
raylei50653 wants to merge 3 commits into
raylei50653 wants to merge 3 commits into
Conversation
Gpu::Nvml::init() stopped at the first libnvidia-ml candidate that dlopen() could load, even if nvmlInit() then failed. On WSL2 with the native nvidia-utils package installed, libnvidia-ml.so resolves to the native Linux driver library, which fails with "Driver Not Loaded", while libnvidia-ml.so.1 resolves to the working WSL library in /usr/lib/wsl/lib. The GPU box was therefore never shown. Unload the library and move on to the next candidate when symbol loading or nvmlInit() fails. Behaviour is unchanged when the first candidate initializes successfully. Closes: aristocratos#1868 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Try libnvidia-ml.so.1 before the unversioned libnvidia-ml.so, which is usually only a development symlink. On WSL2 this finds the working WSL library on the first attempt. Set all NVML function pointers back to nullptr before unloading a library that failed to load its symbols or to initialize, so none of them point into an unloaded library. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Author
|
Both points have been addressed. I’ve submitted the latest fixes and updated the PR body. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #1868
[AI generated] This change was developed with Claude Code (Claude Opus 5.5). I reviewed the implementation and tested the affected WSL2 setup.
Problem
On WSL2 with the distro's native
nvidia-utilsinstalled, btop may load the native Linux NVML library instead of the working WSL library.Previously,
Gpu::Nvml::init()stopped at the first library thatdlopen()could load, even ifnvmlInit()failed withDriver Not Loaded. As a result, btop did not detect the NVIDIA GPU despitenvidia-smiworking correctly.Changes
nvmlInit()for each candidate. If initialization fails, unload the library and continue to the next candidate.libnvidia-ml.so.1before the unversionedlibnvidia-ml.so, which is typically a development symlink. This allows the working WSL library to be selected on the first attempt in the reported setup.The candidate ordering and function-pointer cleanup also address both hardening suggestions from the review.
Testing
Environment: Arch Linux on WSL2, NVIDIA RTX 5070 Ti Laptop GPU,
LD_LIBRARY_PATHunset.Additional validation:
btop_testpasses.Scope
This change is limited to Linux NVML library selection and initialization. It does not alter GPU metric collection after successful initialization.