-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdevice.h
32 lines (26 loc) · 926 Bytes
/
device.h
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
#ifndef _DEVICE_H_
#define _DEVICE_H_
#include <chrono>
#include <ctime>
#include <iostream>
#include <thread>
#include <vector>
#include <nvml.h>
#include "common.h"
int constexpr device_name_length = 64;
class GPUDevice {
private:
nvmlDevice_t device; // device hanlder
char name[device_name_length]; // device name
std::vector<nvmlUtilization_t> utilizations; // contains samplings of utilizations (Cores and Memory)
public:
GPUDevice(int device_id) {
NVML_RT_CALL(nvmlDeviceGetHandleByIndex_v2(device_id, &device));
NVML_RT_CALL(nvmlDeviceGetName(device, name, device_name_length));
std::cout << "Device " << device_id << "(" << device << ") : " << name << "\n";
}
void query();
nvmlUtilization_t get_utilization(int i); // get both gpu and memory utilization
nvmlUtilization_t get_utilization(); // get both gpu and memory utilization
};
#endif // _DEVICE_H_