From 86303be746a00e0dc33ddea72df0e1784eb169f4 Mon Sep 17 00:00:00 2001 From: Axel Huebl Date: Thu, 11 Oct 2018 12:50:22 +0200 Subject: [PATCH] NVML: Handle Unsupported GPU Catch errors if NVML can not query the device serial number, e.g. on Quadro, Mobile or other product lines. --- misc.cpp | 19 +++++++++++++++---- misc.h | 1 + 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/misc.cpp b/misc.cpp index 0ff94af..6ff5c89 100644 --- a/misc.cpp +++ b/misc.cpp @@ -26,11 +26,22 @@ void update_temperature(void) void get_serial_number(unsigned int devIdx, char* serial) { #if (ENABLE_NVML==1) - nvmlDevice_t devHandle; - NVML_CHECK(nvmlDeviceGetHandleByIndex( devIdx, &devHandle )); + try + { + nvmlDevice_t devHandle; + NVML_CHECK(nvmlDeviceGetHandleByIndex( devIdx, &devHandle )); - unsigned int serialLength = NVML_DEVICE_SERIAL_BUFFER_SIZE; - NVML_CHECK(nvmlDeviceGetSerial( devHandle, serial, serialLength )); + unsigned int serialLength = NVML_DEVICE_SERIAL_BUFFER_SIZE; + NVML_CHECK(nvmlDeviceGetSerial( devHandle, serial, serialLength )); + } + catch(const std::runtime_error& e) + { + std::strncpy( + serial, + "unknown (NVML runtime error)", + NVML_DEVICE_SERIAL_BUFFER_SIZE); + serial[NVML_DEVICE_SERIAL_BUFFER_SIZE-1] = '\0'; + } #else (void)(devIdx); (void)(serial); diff --git a/misc.h b/misc.h index 453a060..7ccc611 100644 --- a/misc.h +++ b/misc.h @@ -2,6 +2,7 @@ #include #include +#include #include "cuda_memtest.h" void update_temperature(void);