Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 24 additions & 5 deletions src/extract_gpuinfo_nvidia.c
Original file line number Diff line number Diff line change
Expand Up @@ -310,11 +310,9 @@ __attribute__((constructor)) static void init_extract_gpuinfo_nvidia(void) { reg
* function gpuinfo_nvidia_last_error_string.
*
*/
static bool gpuinfo_nvidia_init(void) {
static bool gpuinfo_nvidia_init_with_lib(const char *libname) {

libnvidia_ml_handle = dlopen("libnvidia-ml.so", RTLD_LAZY);
if (!libnvidia_ml_handle)
libnvidia_ml_handle = dlopen("libnvidia-ml.so.1", RTLD_LAZY);
libnvidia_ml_handle = dlopen(libname, RTLD_LAZY);
if (!libnvidia_ml_handle) {
local_error_string = dlerror();
return false;
Expand Down Expand Up @@ -472,7 +470,8 @@ static bool gpuinfo_nvidia_init(void) {

last_nvml_return_status = nvmlInit();
if (last_nvml_return_status != NVML_SUCCESS) {
return false;
local_error_string = nvmlErrorString(last_nvml_return_status);
goto init_error_clean_exit;
}
local_error_string = NULL;

Expand All @@ -484,6 +483,26 @@ static bool gpuinfo_nvidia_init(void) {
return false;
}

/*
*
* Try the NVML libraries in turn. The SONAME (libnvidia-ml.so.1) comes first
* because it is the name the runtime driver always installs, while the
* unversioned libnvidia-ml.so is a development symlink that may point at a
* library unusable on this system (e.g. the native driver package installed
* inside WSL, where only the WSL-provided libnvidia-ml.so.1 can talk to the
* host GPU).
*
*/
static bool gpuinfo_nvidia_init(void) {
static const char *const nvml_libs[] = {"libnvidia-ml.so.1", "libnvidia-ml.so"};

for (size_t i = 0; i < sizeof(nvml_libs) / sizeof(*nvml_libs); ++i) {
if (gpuinfo_nvidia_init_with_lib(nvml_libs[i]))
return true;
}
return false;
}

static void gpuinfo_nvidia_shutdown(void) {
if (libnvidia_ml_handle) {
nvmlShutdown();
Expand Down
3 changes: 1 addition & 2 deletions src/extract_gpuinfo_v3d.c
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,7 @@ static void add_v3d_cards(struct nvtop_device *dev, const char *devname, struct
return;

const char *driver;
nvtop_device_get_driver(parent, &driver);
if (strcmp(driver, "v3d"))
if (nvtop_device_get_driver(parent, &driver) < 0 || strcmp(driver, "v3d"))
return;

struct gpu_info_v3d *thisGPU = &gpu_infos[v3d_gpu_count++];
Expand Down