Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions misc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Copy link
Member Author

@ax3l ax3l Oct 11, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

constant is 30

Safe std::strncpy used below with a string that is 28 chars and is therefore usually not cropped. Null-added manuall in case it gets cropped.

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);
Expand Down
1 change: 1 addition & 0 deletions misc.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <cstdlib>
#include <cassert>
#include <cstring>
#include "cuda_memtest.h"

void update_temperature(void);
Expand Down