Skip to content

Commit a2f576f

Browse files
committed
GPU (WSL): support nvml too
1 parent 3b9b03a commit a2f576f

File tree

5 files changed

+22
-15
lines changed

5 files changed

+22
-15
lines changed

src/detection/gpu/gpu_linux.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ static void pciHandleDevice(FF_MAYBE_UNUSED const FFGPUOptions* options, FFlist*
251251
.temp = options->temp ? &gpu->temperature : NULL,
252252
.memory = options->useNvml ? &gpu->dedicated : NULL,
253253
.coreCount = options->useNvml ? (uint32_t*) &gpu->coreCount : NULL,
254-
});
254+
}, "libnvidia-ml.so");
255255

256256
if (gpu->dedicated.total != FF_GPU_VMEM_SIZE_UNSET)
257257
gpu->type = gpu->dedicated.total > 1024 * 1024 * 1024 ? FF_GPU_TYPE_DISCRETE : FF_GPU_TYPE_INTEGRATED;

src/detection/gpu/gpu_nvidia.c

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,12 @@ struct FFNvmlData {
1515
bool inited;
1616
} nvmlData;
1717

18-
const char* ffDetectNvidiaGpuInfo(FFGpuNvidiaCondition cond, FFGpuNvidiaResult result)
18+
const char* ffDetectNvidiaGpuInfo(FFGpuNvidiaCondition cond, FFGpuNvidiaResult result, const char* soName)
1919
{
2020
if (!nvmlData.inited)
2121
{
2222
nvmlData.inited = true;
23-
FF_LIBRARY_LOAD(libnvml, NULL, "dlopen nvml failed",
24-
#ifdef _WIN32
25-
"nvml"
26-
#else
27-
"libnvidia-ml"
28-
#endif
29-
FF_LIBRARY_EXTENSION, -1
30-
);
23+
FF_LIBRARY_LOAD(libnvml, NULL, "dlopen nvml failed", soName , 1);
3124
FF_LIBRARY_LOAD_SYMBOL_MESSAGE(libnvml, nvmlInit_v2)
3225
FF_LIBRARY_LOAD_SYMBOL_MESSAGE(libnvml, nvmlShutdown)
3326
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(libnvml, nvmlData, nvmlDeviceGetCount_v2)

src/detection/gpu/gpu_nvidia.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
#include "gpu.h"
44

55
// Use pciBusId if not NULL; use pciDeviceId and pciSubSystemId otherwise
6-
// pciBusId = "domain:bus:device.function"
7-
// pciDeviceId = (deviceId << 16) | vendorId
86
typedef struct FFGpuNvidiaCondition
97
{
8+
// "domain:bus:device.function"
109
const char* pciBusId;
10+
// (deviceId << 16) | vendorId
1111
uint32_t pciDeviceId;
1212
uint32_t pciSubSystemId;
1313
} FFGpuNvidiaCondition;
@@ -20,4 +20,4 @@ typedef struct FFGpuNvidiaResult
2020
uint32_t* coreCount;
2121
} FFGpuNvidiaResult;
2222

23-
const char* ffDetectNvidiaGpuInfo(FFGpuNvidiaCondition cond, FFGpuNvidiaResult result);
23+
const char* ffDetectNvidiaGpuInfo(FFGpuNvidiaCondition cond, FFGpuNvidiaResult result, const char* soName);

src/detection/gpu/gpu_windows.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ const char* ffDetectGPUImpl(FF_MAYBE_UNUSED const FFGPUOptions* options, FFlist*
9999
.temp = options->temp ? &gpu->temperature : NULL,
100100
.memory = options->useNvml ? &gpu->dedicated : NULL,
101101
.coreCount = options->useNvml ? (uint32_t*) &gpu->coreCount : NULL,
102-
});
102+
}, "nvml.dll");
103103
}
104104
}
105105
}

src/detection/gpu/gpu_wsl.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
extern "C" {
55
#include "common/library.h"
66
#include "detection/gpu/gpu.h"
7+
#include "detection/gpu/gpu_nvidia.h"
78
}
89

910
#include <wsl/winadapter.h>
@@ -92,7 +93,20 @@ const char* ffGPUDetectByDirectX(FF_MAYBE_UNUSED const FFGPUOptions* options, FF
9293
if (SUCCEEDED(adapter->GetProperty(DXCoreAdapterProperty::HardwareID, sizeof(hardwareId), &hardwareId)))
9394
{
9495
const char* vendorStr = ffGetGPUVendorString((unsigned) hardwareId.vendorID);
95-
ffStrbufAppendS(&gpu->vendor, vendorStr);
96+
ffStrbufSetStatic(&gpu->vendor, vendorStr);
97+
98+
if (vendorStr == FF_GPU_VENDOR_NAME_NVIDIA && options->useNvml)
99+
{
100+
ffDetectNvidiaGpuInfo((FFGpuNvidiaCondition) {
101+
.pciBusId = nullptr,
102+
.pciDeviceId = (hardwareId.deviceID << 16) | hardwareId.vendorID,
103+
.pciSubSystemId = hardwareId.subSysID
104+
}, (FFGpuNvidiaResult) {
105+
.temp = options->temp ? &gpu->temperature : NULL,
106+
.memory = options->useNvml ? &gpu->dedicated : NULL,
107+
.coreCount = options->useNvml ? (uint32_t*) &gpu->coreCount : NULL,
108+
}, "/usr/lib/wsl/lib/libnvidia-ml.so");
109+
}
96110
}
97111
}
98112

0 commit comments

Comments
 (0)