-
Notifications
You must be signed in to change notification settings - Fork 32
/
misc.cpp
74 lines (60 loc) · 1.66 KB
/
misc.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include "misc.h"
volatile int gpu_temp[MAX_GPU_NUM];
void update_temperature(void)
{
#if (ENABLE_NVML==1)
unsigned int deviceCount;
NVML_CHECK(nvmlDeviceGetCount( &deviceCount ));
for( unsigned int devIdx = 0; devIdx < deviceCount; ++devIdx )
{
nvmlDevice_t devHandle;
NVML_CHECK(nvmlDeviceGetHandleByIndex( devIdx, &devHandle ));
unsigned int devTemperature;
NVML_CHECK(nvmlDeviceGetTemperature( devHandle, NVML_TEMPERATURE_GPU, &devTemperature ));
gpu_temp[devIdx] = devTemperature;
DEBUG_PRINTF("temperature updated: (gpu %d) %d \n", devIdx, devTemperature);
}
#endif
}
void get_serial_number(unsigned int devIdx, char* serial)
{
#if (ENABLE_NVML==1)
try
{
nvmlDevice_t devHandle;
NVML_CHECK(nvmlDeviceGetHandleByIndex( devIdx, &devHandle ));
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);
#endif
}
void
get_driver_info(char* info, unsigned int len)
{
FILE* file = fopen(NV_DRIVER_VER_FILE, "r");
if (file == NULL){
PRINTF("Warning: Opening %s failed\n", NV_DRIVER_VER_FILE);
info[0] = 0;
return;
}
if ( fgets(info, len, file) == NULL){
PRINTF("Warning: reading file failed\n");
info[0] = 0;
fclose(file);
return;
}
fclose(file);
PRINTF("%s", info);
return;
}