Skip to content

Commit 9499b0a

Browse files
committed
NVML: Handle Unsupported GPU
Catch errors if NVML can not query the device serial number, e.g. on Quadro, Mobile or other product lines.
1 parent 7a585d5 commit 9499b0a

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

misc.cpp

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,22 @@ void update_temperature(void)
2626
void get_serial_number(unsigned int devIdx, char* serial)
2727
{
2828
#if (ENABLE_NVML==1)
29-
nvmlDevice_t devHandle;
30-
NVML_CHECK(nvmlDeviceGetHandleByIndex( devIdx, &devHandle ));
29+
try
30+
{
31+
nvmlDevice_t devHandle;
32+
NVML_CHECK(nvmlDeviceGetHandleByIndex( devIdx, &devHandle ));
3133

32-
unsigned int serialLength = NVML_DEVICE_SERIAL_BUFFER_SIZE;
33-
NVML_CHECK(nvmlDeviceGetSerial( devHandle, serial, serialLength ));
34+
unsigned int serialLength = NVML_DEVICE_SERIAL_BUFFER_SIZE;
35+
NVML_CHECK(nvmlDeviceGetSerial( devHandle, serial, serialLength ));
36+
}
37+
catch(const std::runtime_error& e)
38+
{
39+
strncpy(
40+
serial,
41+
"unknown (NVML runtime error)",
42+
NVML_DEVICE_SERIAL_BUFFER_SIZE);
43+
serial[NVML_DEVICE_SERIAL_BUFFER_SIZE-1] = '\0';
44+
}
3445
#else
3546
(void)(devIdx);
3647
(void)(serial);

misc.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#include <cstdlib>
44
#include <cassert>
5+
#include <cstring>
56
#include "cuda_memtest.h"
67

78
void update_temperature(void);

0 commit comments

Comments
 (0)