Skip to content

Commit 994a8b4

Browse files
committed
GPU (Nvidia): fall back to nvmlDeviceGetMemoryInfo if nvmlDeviceGetMemoryInfo_v2 isn't supported
1 parent 76710c8 commit 994a8b4

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

src/detection/gpu/gpu_nvidia.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ struct FFNvmlData {
1010
FF_LIBRARY_SYMBOL(nvmlDeviceGetPciInfo_v3)
1111
FF_LIBRARY_SYMBOL(nvmlDeviceGetTemperature)
1212
FF_LIBRARY_SYMBOL(nvmlDeviceGetMemoryInfo_v2)
13+
FF_LIBRARY_SYMBOL(nvmlDeviceGetMemoryInfo)
1314
FF_LIBRARY_SYMBOL(nvmlDeviceGetNumGpuCores)
1415
FF_LIBRARY_SYMBOL(nvmlDeviceGetMaxClockInfo)
1516
FF_LIBRARY_SYMBOL(nvmlDeviceGetUtilizationRates)
@@ -36,6 +37,7 @@ const char* ffDetectNvidiaGpuInfo(const FFGpuDriverCondition* cond, FFGpuDriverR
3637
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(libnvml, nvmlData, nvmlDeviceGetPciInfo_v3)
3738
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(libnvml, nvmlData, nvmlDeviceGetTemperature)
3839
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(libnvml, nvmlData, nvmlDeviceGetMemoryInfo_v2)
40+
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(libnvml, nvmlData, nvmlDeviceGetMemoryInfo)
3941
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(libnvml, nvmlData, nvmlDeviceGetNumGpuCores)
4042
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(libnvml, nvmlData, nvmlDeviceGetMaxClockInfo)
4143
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(libnvml, nvmlData, nvmlDeviceGetUtilizationRates)
@@ -130,6 +132,15 @@ const char* ffDetectNvidiaGpuInfo(const FFGpuDriverCondition* cond, FFGpuDriverR
130132
result.memory->total = memory.used + memory.free;
131133
result.memory->used = memory.used;
132134
}
135+
else
136+
{
137+
nvmlMemory_t memory_v1;
138+
if (nvmlData.ffnvmlDeviceGetMemoryInfo(device, &memory_v1) == NVML_SUCCESS)
139+
{
140+
result.memory->total = memory_v1.total;
141+
result.memory->used = memory_v1.used;
142+
}
143+
}
133144
}
134145

135146
if (result.coreCount)

src/detection/gpu/nvml.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,18 @@ typedef struct {
5656
// https://github.com/NVIDIA/nvidia-settings/issues/78#issuecomment-1012837988
5757
enum { nvmlMemory_v2 = (unsigned int)(sizeof(nvmlMemory_v2_t) | (2 << 24U)) };
5858

59+
// https://docs.nvidia.com/deploy/nvml-api/structnvmlMemory__t.html#structnvmlMemory__t
60+
// Memory allocation information for a device (v1)
61+
typedef struct
62+
{
63+
// Total physical device memory (in bytes)
64+
unsigned long long total;
65+
// Unallocated device memory (in bytes)
66+
unsigned long long free;
67+
// Sum of Reserved and Allocated device memory (in bytes)
68+
unsigned long long used;
69+
} nvmlMemory_t;
70+
5971
// https://docs.nvidia.com/deploy/nvml-api/group__nvmlDeviceEnumvs.html#group__nvmlDeviceEnumvs_1g805c0647be9996589fc5e3f6ff680c64
6072
// Clock types
6173
typedef enum {
@@ -124,6 +136,8 @@ extern nvmlReturn_t nvmlDeviceGetPciInfo_v3(nvmlDevice_t device, nvmlPciInfo_t*
124136
extern nvmlReturn_t nvmlDeviceGetTemperature(nvmlDevice_t device, nvmlTemperatureSensors_t sensorType, unsigned int* temp);
125137
// Retrieves the amount of used, free, reserved and total memory available on the device, in bytes. The reserved amount is supported on version 2 only
126138
extern nvmlReturn_t nvmlDeviceGetMemoryInfo_v2(nvmlDevice_t device, nvmlMemory_v2_t* memory);
139+
// Retrieves the amount of used, free, total memory available on the device, in bytes.
140+
extern nvmlReturn_t nvmlDeviceGetMemoryInfo(nvmlDevice_t device, nvmlMemory_t *memory);
127141
// Gets the device's core count
128142
extern nvmlReturn_t nvmlDeviceGetNumGpuCores(nvmlDevice_t device, unsigned int* numCores);
129143
// Retrieves the maximum clock speeds for the device

0 commit comments

Comments
 (0)