-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathVII-smi.c
63 lines (57 loc) · 1.65 KB
/
VII-smi.c
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
#include <stdio.h>
#include <nvml.h>
int main()
{
nvmlReturn_t result;
unsigned int device_count, i;
// First initialize NVML library
result = nvmlInit();
if (NVML_SUCCESS == result)
{
result = nvmlDeviceGetCount(&device_count);
if (NVML_SUCCESS == result)
{
for (i = 0; i < device_count; i++)
{
nvmlDevice_t device;
nvmlReturn_t result1;
nvmlReturn_t result2;
nvmlReturn_t result3;
unsigned int fanspeed=0;
unsigned int temperature=0;
unsigned int power=0;
nvmlComputeMode_t sensor = 0;
result = nvmlDeviceGetHandleByIndex(i, &device);
if (NVML_SUCCESS == result)
{
result1 = nvmlDeviceGetFanSpeed(device, &fanspeed);
result2 = nvmlDeviceGetTemperature ( device, sensor, &temperature );
result3 = nvmlDeviceGetPowerUsage ( device, &power );
if(NVML_SUCCESS == result1)
{
printf("GPU %i fan speed=%d\n", i, fanspeed);
}
else printf("GPU %i fan speed=failed to get\n", i);
if (NVML_SUCCESS == result2)
{
printf("GPU %i temperature=%d\n", i, temperature);
}
else printf("GPU %i temperature=failed to get\n", i);
if(NVML_SUCCESS == result3)
{
printf("GPU %i power=%d\n", i, power/1000);
}
else printf("GPU %i power=failed to get\n", i);
}
else printf("Failed to get handle for device %i\n", i);
}
}
else printf("API failed\n");
result = nvmlShutdown();
if (NVML_SUCCESS != result)
{
printf("Warning: Failed to shutdown NVML\n");
}
}
return 0;
}