From e25af9441361aa420a459318b58caa84b36fcaa2 Mon Sep 17 00:00:00 2001 From: Dhanesh Date: Fri, 26 Jun 2026 20:43:09 +0530 Subject: [PATCH] fix: add fallback methods for NVIDIA driver queries Introduce additional fallback mechanisms to collect the NVIDIA driver version when primary querying methods fail. Signed-off-by: Dhanesh --- lib/rendering/rt/gpu/optix/OptixGPUUtils.cc | 38 ++++++++++++++++++--- 1 file changed, 34 insertions(+), 4 deletions(-) diff --git a/lib/rendering/rt/gpu/optix/OptixGPUUtils.cc b/lib/rendering/rt/gpu/optix/OptixGPUUtils.cc index 01d5ef85..cf62cab4 100644 --- a/lib/rendering/rt/gpu/optix/OptixGPUUtils.cc +++ b/lib/rendering/rt/gpu/optix/OptixGPUUtils.cc @@ -30,15 +30,45 @@ getNVIDIADriverVersion(int* major, int* minor) { *major = 0; *minor = 0; - bool success = false; - FILE *fp = fopen("/sys/module/nvidia/version", "r"); + + // 1. query Nvidia smi + FILE* pipe = popen("nvidia-smi --query-gpu=driver_version --format=csv,noheader 2>/dev/null", "r"); + if (pipe) { + char buffer[128]; + if (fgets(buffer, sizeof(buffer), pipe) != NULL) { + if (sscanf(buffer, "%d.%d", major, minor) == 2) { + pclose(pipe); + return true; + } + } + pclose(pipe); + } + + // 2. Fallback: Check the sysfs path used previously + FILE* fp = fopen("/sys/module/nvidia/version", "r"); if (fp != NULL) { if (fscanf(fp, "%d.%d", major, minor) == 2) { - success = true; + fclose(fp); + return true; } fclose(fp); } - return success; + + // 3. if previous steps didnt work, Check the /proc path (legacy) + fp = fopen("/proc/driver/nvidia/version", "r"); + if (fp != NULL) { + // Format is typically "NVRM version: NVIDIA UNIX x86_64 Kernel Module 5xx.xx.xx ..." + char line[256]; + while (fgets(line, sizeof(line), fp)) { + if (sscanf(line, "NVRM version: NVIDIA UNIX x86_64 Kernel Module %d.%d", major, minor) == 2) { + fclose(fp); + return true; + } + } + fclose(fp); + } + + return false; } bool