[BUG] NVIDIA GPU not detected on WSL2 when native nvidia-utils is installed (NVML Driver Not Loaded)
Describe the bug
On WSL2 with the native nvidia-utils package installed, btop doesn't show the NVIDIA GPU, even though nvidia-smi works. The debug log says:
DEBUG: Failed to initialize NVML, NVIDIA GPUs will not be detected: Driver Not LoadedIn this setup there are two NVML libraries, and both have the SONAME libnvidia-ml.so.1:
/usr/lib/libnvidia-ml.so->libnvidia-ml.so.615.71.09(native Linux driver, fromnvidia-utils)/usr/lib/wsl/lib/libnvidia-ml.so.1(WSL library, listed first in the ld.so cache forlibnvidia-ml.so.1)
Gpu::Nvml::init() tries libnvidia-ml.so first. That resolves to the native library, so dlopen() succeeds and the search stops. Then nvmlInit() fails with NVML_ERROR_DRIVER_NOT_LOADED, and libnvidia-ml.so.1 (which would work) is never tried.
If you set LD_LIBRARY_PATH to point at the WSL library, the problem goes away for an unprivileged binary. It doesn't help when btop has file capabilities (cap_perfmon, etc.), because secure execution makes the loader ignore LD_LIBRARY_PATH.
To Reproduce
- Use WSL2 with the Windows NVIDIA driver, and install the distro's
nvidia-utils(Arch in my case). - Run btop, built with GPU support, with
gpu0inshown_boxes. - The GPU box is missing, and
/proc/<pid>/mapsshows/usr/lib/libnvidia-ml.so.615.71.09loaded.
Expected behavior
If nvmlInit() fails for one library candidate, btop should try the next one.
Info
- btop++ version: 1.4.7 (also reproduced on current
main) - Platform: Arch Linux on WSL2
- GPU: NVIDIA RTX 5070 Ti Laptop GPU
Source: aristocratos/btop