Fix device info

This commit is contained in:
Nicolas Mowen 2024-10-07 19:01:52 -06:00
parent f1097539b0
commit 75ba023b5d

View File

@ -339,7 +339,10 @@ def get_intel_gpu_stats() -> dict[str, str]:
def try_get_info(f, h, default="N/A"): def try_get_info(f, h, default="N/A"):
try: try:
if h:
v = f(h) v = f(h)
else:
v = f()
except nvml.NVMLError_NotSupported: except nvml.NVMLError_NotSupported:
v = default v = default
return v return v
@ -443,14 +446,16 @@ def get_nvidia_driver_info() -> dict[str, any]:
deviceCount = nvml.nvmlDeviceGetCount() deviceCount = nvml.nvmlDeviceGetCount()
for i in range(deviceCount): for i in range(deviceCount):
handle = nvml.nvmlDeviceGetHandleByIndex(i) handle = nvml.nvmlDeviceGetHandleByIndex(i)
driver = try_get_info(nvml.nvmlSystemGetDriverVersion, handle, default=None) driver = try_get_info(nvml.nvmlSystemGetDriverVersion, None, default=None)
cuda = try_get_info( cuda_compute = try_get_info(
nvml.nvmlDeviceGetCudaComputeCapability, handle, default=None nvml.nvmlDeviceGetCudaComputeCapability, handle, default=None
) )
vbios = try_get_info(nvml.nvmlDeviceGetVbiosVersion, handle, default=None)
results[i] = { results[i] = {
"name": nvml.nvmlDeviceGetName(handle), "name": nvml.nvmlDeviceGetName(handle),
"driver": driver or "unknown", "driver": driver or "unknown",
"cuda": cuda or "unknown", "cuda_compute": cuda_compute or "unknown",
"vbios": vbios or "unknown",
} }
except Exception: except Exception:
pass pass