-
Notifications
You must be signed in to change notification settings - Fork 56
/
main.cc
157 lines (129 loc) · 5.05 KB
/
main.cc
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#include <iomanip>
#include <iostream>
#include <vector>
#ifdef __linux__
#include <unistd.h>
#include <sys/types.h>
#endif
#include <level_zero/ze_api.h>
#include <level_zero/zes_api.h>
#include "pti_assert.h"
#include "utils.h"
#include "ze_utils.h"
#define BYTES_IN_MB (1024 * 1024)
int main() {
utils::SetEnv("ZES_ENABLE_SYSMAN", "1");
ze_result_t status = ZE_RESULT_SUCCESS;
status = zeInit(ZE_INIT_FLAG_GPU_ONLY);
PTI_ASSERT(status == ZE_RESULT_SUCCESS);
ze_device_handle_t device = utils::ze::GetGpuDevice();
if (device == nullptr) {
std::cout << "[WARNING] GPU device was not found" << std::endl;
return 0;
}
// Sysman Device Properties
{
zes_device_properties_t device_props{
ZES_STRUCTURE_TYPE_DEVICE_PROPERTIES, };
status = zesDeviceGetProperties(device, &device_props);
PTI_ASSERT(status == ZE_RESULT_SUCCESS);
std::cout << "Device: " << device_props.core.name << std::endl;
std::cout << "-- Subdevice Count: " <<
device_props.numSubdevices << std::endl;
std::cout << "-- Driver Version: " <<
device_props.driverVersion << std::endl;
}
// Sysman PCI Properties
{
zes_pci_properties_t pci_props{ZES_STRUCTURE_TYPE_PCI_PROPERTIES, };
status = zesDevicePciGetProperties(device, &pci_props);
PTI_ASSERT(status == ZE_RESULT_SUCCESS);
std::cout << "-- PCI Bus: " << std::hex << std::setfill('0') <<
std::setw(4) << pci_props.address.domain << ":" <<
std::setw(2) << pci_props.address.bus << ":" <<
std::setw(2) << pci_props.address.device << "." <<
std::setw(1) << pci_props.address.function <<
std::dec << std::setfill(' ') << std::endl;
}
// Sysman Memory Properties
{
uint32_t module_count = 0;
status = zesDeviceEnumMemoryModules(device, &module_count, nullptr);
PTI_ASSERT(status == ZE_RESULT_SUCCESS);
if (module_count > 0) {
std::cout << "-- Memory Modules: " << module_count << std::endl;
std::vector<zes_mem_handle_t> module_list(module_count);
status = zesDeviceEnumMemoryModules(
device, &module_count, module_list.data());
PTI_ASSERT(status == ZE_RESULT_SUCCESS);
for (uint32_t i = 0; i < module_count; ++i) {
zes_mem_properties_t memory_props{ZES_STRUCTURE_TYPE_MEM_PROPERTIES, };
status = zesMemoryGetProperties(module_list[i], &memory_props);
PTI_ASSERT(status == ZE_RESULT_SUCCESS);
std::cout << "---- [" << i << "] Module Capacity (MB): " <<
memory_props.physicalSize / BYTES_IN_MB << std::endl;
}
}
}
// Core Frequency
{
uint32_t domain_count = 0;
status = zesDeviceEnumFrequencyDomains(device, &domain_count, nullptr);
PTI_ASSERT(status == ZE_RESULT_SUCCESS);
if (domain_count > 0) {
std::cout << "-- Frequency Domains: " << domain_count << std::endl;
std::vector<zes_freq_handle_t> domain_list(domain_count);
status = zesDeviceEnumFrequencyDomains(
device, &domain_count, domain_list.data());
PTI_ASSERT(status == ZE_RESULT_SUCCESS);
for (uint32_t i = 0; i < domain_count; ++i) {
zes_freq_properties_t domain_props{
ZES_STRUCTURE_TYPE_FREQ_PROPERTIES, };
status = zesFrequencyGetProperties(domain_list[i], &domain_props);
PTI_ASSERT(status == ZE_RESULT_SUCCESS);
std::cout << "---- [" << i << "] Clock EU Freq Range (MHz): " <<
domain_props.min << " - " << domain_props.max <<
(domain_props.canControl ? " (changeable)" : " (unchangeable)") <<
std::endl;
zes_freq_state_t state{ZES_STRUCTURE_TYPE_FREQ_STATE, };
status = zesFrequencyGetState(domain_list[i], &state);
PTI_ASSERT(status == ZE_RESULT_SUCCESS);
std::cout << "---- [" << i << "] Current Clock EU Freq (MHz): " <<
state.actual << std::endl;
}
}
}
// Core Temperature
{
uint32_t sensor_count = 0;
status = zesDeviceEnumTemperatureSensors(
device, &sensor_count, nullptr);
if (status == ZE_RESULT_SUCCESS && sensor_count > 0) {
#ifdef __linux__
if (geteuid() != 0) {
std::cout << "Need to be root to see temperature" << std::endl;
return 0;
}
#endif
std::cout << "-- Temperature Sensors: " << sensor_count << std::endl;
std::vector<zes_temp_handle_t> sensor_list(sensor_count);
status = zesDeviceEnumTemperatureSensors(
device, &sensor_count, sensor_list.data());
PTI_ASSERT(status == ZE_RESULT_SUCCESS);
for (uint32_t i = 0; i < sensor_count; ++i) {
zes_temp_properties_t temp_props{
ZES_STRUCTURE_TYPE_TEMP_PROPERTIES, };
status = zesTemperatureGetProperties(sensor_list[i], &temp_props);
PTI_ASSERT(status == ZE_RESULT_SUCCESS);
if (temp_props.type == ZES_TEMP_SENSORS_GPU) {
double temperature = 0.0f;
status = zesTemperatureGetState(sensor_list[i], &temperature);
PTI_ASSERT(status == ZE_RESULT_SUCCESS);
std::cout << "---- [" << i << "] Core Temperature (C): " <<
temperature << std::endl;
}
}
}
}
return 0;
}