-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgpu.cpp
47 lines (38 loc) · 763 Bytes
/
gpu.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
#include <stdio.h>
#include <vector>
#include <string>
#include "command.cpp"
#include "cpu.cpp"
using namespace std;
string probeGpu() {
return execCommand("nvidia-smi --id=0 --query-gpu=temperature.gpu --format=csv");
}
vector<double> parseGpuTemp(const string &gpu_temp) {
vector<string> lines = split(gpu_temp.c_str(), '\n');
vector<double> temps;
if (lines.size() == 2) {
double temp = stod(lines.at(1));
temps.push_back(temp);
}
return temps;
}
vector<double> getGpuTemp() {
string gpu_temp = probeGpu();
return parseGpuTemp(gpu_temp);
}
class GPU
{
private:
vector<double> temps;
public:
GPU()
{
}
void update()
{
temps = parseGpuTemp(probeGpu());
}
vector<double> getTemps() {
return temps;
}
};