-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHardData.h
More file actions
76 lines (65 loc) · 1.9 KB
/
Copy pathHardData.h
File metadata and controls
76 lines (65 loc) · 1.9 KB
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
75
76
#ifndef HARDDATA_H
#define HARDDATA_H
#include <nvml.h>
#include<QString>
class HardData{
nvmlDevice_t device;
nvmlMemory_t memory;
nvmlReturn_t result ;
unsigned int device_count;
unsigned int * fanSpeed;
unsigned int * cardTemp;
public:
~HardData(){
nvmlShutdown();
delete this;
}
void InitDisplayCard(){
// 初始化NVML库
result = nvmlInit();
//获得设备操作句柄
result = nvmlDeviceGetHandleByIndex(0,&device);
// 获取设备数量
if(NVML_SUCCESS != result){
}
}
int GetDisplayCardCount(){
device_count = -1;
result = nvmlDeviceGetCount(&device_count);
return device_count;
}
// 获取显卡名字函数
QString GetDisplayCardName(){
// 获得名字
char name[NVML_DEVICE_NAME_BUFFER_SIZE];
result = nvmlDeviceGetName(device, name, NVML_DEVICE_NAME_BUFFER_SIZE);
return QString::fromLocal8Bit(name,512);
}
// 获取显卡使用率函数
int GetDisplayCardUsage(){
nvmlUtilization_t nvmUtil;
// 获得显卡使用率
result = nvmlDeviceGetUtilizationRates(device, &nvmUtil);
return nvmUtil.gpu;
}
// 获取总显存
float GetDisplayCardMemoryTotal(){
result = nvmlDeviceGetMemoryInfo(device, &memory);
return ((float)(memory.total)/1024.0f/1024.0f/1024.0f);
}
// 获取已经用的显存
float GetDisplayCardMemoryUsed(){
result = nvmlDeviceGetMemoryInfo(device, &memory);
// return memory.used;
return (float)(memory.used)/1024.0f/1024.0f/1024.0f;
}
// 获取风扇转速
int GetFanSpeed(){
return nvmlDeviceGetFanSpeed(device,fanSpeed);
}
// 获取温度
// int GetCardTemp(){
// // return nvmlDeviceGetTemperature(device,tmpSensor,cardTemp);
// }
};
#endif // HARDDATA_H