6#ifndef LEVELZEROIMP_HPP_INCLUDE
7#define LEVELZEROIMP_HPP_INCLUDE
16#include <level_zero/ze_api.h>
17#include <level_zero/zes_api.h>
18#include <level_zero/zet_api.h>
31 int num_gpu(
void)
const override;
32 int num_gpu(
int domain)
const override;
34 int domain)
const override;
36 int l0_domain,
int l0_domain_idx)
const override;
38 int l0_domain,
int l0_domain_idx)
const override;
39 double frequency_min(
unsigned int l0_device_idx,
int l0_domain,
40 int l0_domain_idx)
const override;
41 double frequency_max(
unsigned int l0_device_idx,
int l0_domain,
42 int l0_domain_idx)
const override;
45 int l0_domain_idx)
const override;
47 int l0_domain_idx)
const override;
50 int l0_domain_idx)
const override;
52 int l0_domain)
const override;
54 int l0_domain_idx)
const override;
57 int l0_domain,
int l0_domain_idx)
const override;
58 uint64_t
active_time(
unsigned int l0_device_idx,
int l0_domain,
59 int l0_domain_idx)
const override;
61 int l0_domain,
int l0_domain_idx)
const override;
63 int l0_domain)
const override;
64 std::pair<uint64_t, uint64_t>
energy_pair(
int geopm_domain,
unsigned int l0_device_idx,
65 int l0_domain_idx)
const override;
66 uint64_t
energy(
int geopm_domain,
unsigned int l0_device_idx,
67 int l0_domain,
int l0_domain_idx)
const override;
69 unsigned int l0_device_idx,
71 int l0_domain_idx)
const override;
73 int l0_domain)
const override;
75 int l0_domain,
int l0_domain_idx)
const override;
85 double range_max)
const override;
90 double setting)
const override;
92 int ras_domain_count(
unsigned int l0_device_idx,
int l0_domain)
const override;
95 int l0_domain_idx)
const override;
98 int l0_domain_idx)
const override;
101 int l0_domain_idx)
const override;
104 int l0_domain_idx)
const override;
107 int l0_domain_idx)
const override;
110 int l0_domain_idx)
const override;
113 int l0_domain_idx)
const override;
116 int l0_domain_idx)
const override;
119 int l0_domain_idx)
const override;
122 int l0_domain_idx)
const override;
125 int l0_domain_idx)
const override;
128 int l0_domain_idx)
const override;
131 int l0_domain_idx)
const override;
134 int l0_domain_idx)
const override;
135 std::vector<double>
metric_sample(
unsigned int l0_device_idx,
136 unsigned int l0_domain_idx,
137 std::string metric_name)
const override;
142 unsigned int l0_domain_idx)
override;
146 M_ERROR_TYPE_CORRECTABLE,
147 M_ERROR_TYPE_UNCORRECTABLE,
151 struct m_frequency_s {
155 double efficient = 0;
157 uint32_t throttle_reasons = 0;
159 struct m_power_limit_s {
165 struct m_subdevice_s {
167 std::vector<std::vector<zes_freq_handle_t> > freq_domain;
168 std::vector<std::vector<zes_temp_handle_t> > temp_domain_max;
169 std::vector<std::vector<zes_engine_handle_t> > engine_domain;
170 mutable std::vector<std::vector<uint64_t> > cached_timestamp;
173 std::vector<std::vector<zes_perf_handle_t>> perf_domain;
175 uint32_t num_subdevice_power_domain;
176 std::vector<zes_pwr_handle_t> power_domain;
177 mutable std::vector<uint64_t> cached_energy_timestamp;
185 std::vector<zes_ras_handle_t> ras_domain;
188 std::vector<ze_context_handle_t> context;
191 std::vector<uint32_t> num_metric;
192 std::vector<uint32_t> num_reports;
193 std::vector<bool> metric_domain_cached;
194 std::vector<zet_metric_streamer_handle_t> metric_streamer;
195 std::vector<zet_metric_group_handle_t> metric_group_handle;
196 std::vector<size_t> zet_data_size;
197 std::vector<std::vector<uint8_t>> zet_data;
198 std::vector<size_t> report_byte_size;
203 std::vector<std::map<std::string, size_t>> metric_name_idx;
206 mutable std::vector<std::map<std::string, std::vector<double>>> metric_data;
216 mutable std::vector<std::map<std::string, m_metric_aggregate>> metric_data_accum;
220 std::vector<bool> metric_active;
225 std::vector<std::chrono::steady_clock::time_point> metric_last_drain;
226 mutable std::vector<bool> metrics_initialized;
229 struct m_device_info_s {
230 ze_driver_handle_t driver;
231 zes_device_handle_t device_handle;
232 ze_device_properties_t property;
233 uint32_t num_subdevice;
234 std::vector<zes_device_handle_t> subdevice_handle;
240 m_subdevice_s subdevice;
243 zes_pwr_handle_t power_domain;
245 uint32_t num_device_power_domain;
246 mutable uint64_t cached_energy_timestamp;
248 uint32_t metric_sampling_period_ns;
251 void ras_domain_cache(
unsigned int l0_device_idx);
253 void frequency_domain_cache(
unsigned int l0_device_idx);
254 void power_domain_cache(
unsigned int l0_device_idx);
255 void perf_domain_cache(
unsigned int l0_device_idx);
256 void engine_domain_cache(
unsigned int l0_device_idx);
257 void temperature_domain_cache(
unsigned int l0_device_idx);
258 void check_ze_result(ze_result_t ze_result,
int error, std::string message,
261 std::pair<double, double> frequency_min_max(
unsigned int l0_device_idx,
262 int l0_domain,
int l0_domain_idx)
const;
264 m_power_limit_s power_limit_default(
unsigned int l0_device_idx)
const;
265 uint64_t ras_status_helper(
unsigned int l0_device_idx,
268 zes_ras_error_cat_t errorcat,
269 int errortype)
const;
271 m_frequency_s frequency_status_helper(
unsigned int l0_device_idx,
272 int l0_domain,
int l0_domain_idx)
const;
275 uint32_t m_num_gpu_subdevice;
277 std::vector<ze_driver_handle_t> m_levelzero_driver;
278 std::vector<m_device_info_s> m_devices;
280 static constexpr uint32_t SAMPLING_PERIOD_NS = 500000;
281 static constexpr size_t DEFAULT_REPORT_BUFFER_SIZE = 16 * 1024 * 1024;
282 static constexpr uint32_t DEFAULT_MAX_REPORTS_PER_READ = 30;
287 static constexpr uint64_t METRIC_DRAIN_PERIOD_US = 20000;
293 std::thread m_metric_thread;
294 std::mutex m_metric_mutex;
295 std::atomic<bool> m_metric_thread_active;
296 bool m_metric_thread_started;
300 std::exception_ptr m_metric_thread_error;
302 void metric_group_init(
unsigned int l0_device_idx);
303 void metric_calc(
unsigned int l0_device_idx,
unsigned int l0_domain_idx,
304 size_t data_size,
const uint8_t *data);
306 void metric_execute(
unsigned int l0_device_idx,
307 unsigned int l0_domain_idx);
308 void metric_destroy(
unsigned int l0_device_idx,
309 unsigned int l0_domain_idx);
313 void metric_sample_thread(
void);
315 void metric_drain(
unsigned int l0_device_idx,
unsigned int l0_domain_idx);
316 void metric_thread_start(
void);
317 void metric_thread_stop(
void);
319 double metric_data_convert(zet_typed_value_t data)
const;
Definition LevelZero.hpp:18
Definition LevelZeroImp.hpp:27
int frequency_domain_count(unsigned int l0_device_idx, int domain) const override
Get the number of LevelZero frequency domains of a certain type.
Definition LevelZero.cpp:1254
double ras_programming_errcount_correctable(unsigned int l0_device_idx, int l0_domain, int l0_domain_idx) const override
Get the LevelZero count of number of correctable hardware exceptions generated by the way workloads h...
Definition LevelZero.cpp:1311
uint64_t active_time(unsigned int l0_device_idx, int l0_domain, int l0_domain_idx) const override
Get the LevelZero device active time in microseconds.
Definition LevelZero.cpp:1545
LevelZeroImp()
Definition LevelZero.cpp:39
double ras_reset_count_uncorrectable(unsigned int l0_device_idx, int l0_domain, int l0_domain_idx) const override
Get the LevelZero count of number of uncorrectable accelerator engine resets attempted by the driver.
Definition LevelZero.cpp:1359
double frequency_efficient(unsigned int l0_device_idx, int l0_domain, int l0_domain_idx) const override
Get the LevelZero device efficient frequency in MHz.
Definition LevelZero.cpp:1441
std::pair< uint64_t, uint64_t > energy_pair(int geopm_domain, unsigned int l0_device_idx, int l0_domain_idx) const override
Get the LevelZero device energy and timestamp in microjoules and microseconds.
Definition LevelZero.cpp:1590
int num_gpu(void) const override
Number of GPUs on the platform.
Definition LevelZero.cpp:1211
void metric_read(unsigned int l0_device_idx, unsigned int l0_domain_idx) override
Definition LevelZero.cpp:915
double ras_compute_errcount_uncorrectable(unsigned int l0_device_idx, int l0_domain, int l0_domain_idx) const override
Get the LevelZero count of number of uncorrectable errors that have occurred in the compute accelerat...
Definition LevelZero.cpp:1383
double frequency_status(unsigned int l0_device_idx, int l0_domain, int l0_domain_idx) const override
Get the LevelZero device actual frequency in MHz.
Definition LevelZero.cpp:1435
double temperature_max(unsigned int l0_device_idx, int l0_domain, int l0_domain_idx) const override
Get the LevelZero device maximum temperature in Celsius.
Definition LevelZero.cpp:1527
int ras_domain_count(unsigned int l0_device_idx, int l0_domain) const override
Get the number of LevelZero RAS domains of a certain type.
Definition LevelZero.cpp:1287
std::pair< uint64_t, uint64_t > active_time_pair(unsigned int l0_device_idx, int l0_domain, int l0_domain_idx) const override
Get the LevelZero device active time and timestamp in microseconds.
Definition LevelZero.cpp:1551
double ras_noncompute_errcount_correctable(unsigned int l0_device_idx, int l0_domain, int l0_domain_idx) const override
Get the LevelZero count of number of correctable errors that have occurred in the fixed-function acce...
Definition LevelZero.cpp:1335
int power_domain_count(int geopm_domain, unsigned int l0_device_idx, int l0_domain) const override
Get the number of LevelZero power domains of a certain type.
Definition LevelZero.cpp:1238
double ras_noncompute_errcount_uncorrectable(unsigned int l0_device_idx, int l0_domain, int l0_domain_idx) const override
Get the LevelZero count of number of uncorrectable errors that have occurred in the fixed-function ac...
Definition LevelZero.cpp:1391
double ras_display_errcount_correctable(unsigned int l0_device_idx, int l0_domain, int l0_domain_idx) const override
Get the LevelZero count of number of correctable errors that have occurred in the display.
Definition LevelZero.cpp:1351
double ras_display_errcount_uncorrectable(unsigned int l0_device_idx, int l0_domain, int l0_domain_idx) const override
Get the LevelZero count of number of uncorrectable errors that have occurred in the display.
Definition LevelZero.cpp:1407
int temperature_domain_count(unsigned int l0_device_idx, int l0_domain) const override
Get the number of LevelZero temperature domains.
Definition LevelZero.cpp:1269
void metric_update_rate_control(unsigned int l0_device_idx, uint32_t setting) override
Definition LevelZero.cpp:1706
int engine_domain_count(unsigned int l0_device_idx, int domain) const override
Get the number of LevelZero engine domains.
Definition LevelZero.cpp:1259
void performance_factor_control(unsigned int l0_device_idx, int l0_domain, int l0_domain_idx, double setting) const override
Set the performance factor for the LevelZero device.
Definition LevelZero.cpp:1691
int32_t power_limit_max(unsigned int l0_device_idx) const override
Get the LevelZero device maximum power limit in milliwatts.
Definition LevelZero.cpp:1642
int32_t power_limit_tdp(unsigned int l0_device_idx) const override
Get the LevelZero device default power limit in milliwatts.
Definition LevelZero.cpp:1624
uint64_t active_time_timestamp(unsigned int l0_device_idx, int l0_domain, int l0_domain_idx) const override
Get the cachced LevelZero device timestamp for the active time value in microseconds.
Definition LevelZero.cpp:1539
uint64_t energy_timestamp(int geopm_domain, unsigned int l0_device_idx, int l0_domain, int l0_domain_idx) const override
Get the LevelZero device energy cached timestamp in microseconds.
Definition LevelZero.cpp:1569
double ras_cache_errcount_correctable(unsigned int l0_device_idx, int l0_domain, int l0_domain_idx) const override
Get the LevelZero count of number of correctable errors that have occurred in caches (L1/L3/register ...
Definition LevelZero.cpp:1343
std::pair< double, double > frequency_range(unsigned int l0_device_idx, int l0_domain, int l0_domain_idx) const override
Get the LevelZero device minimum and maximum frequency control range in MHz.
Definition LevelZero.cpp:1515
double performance_factor(unsigned int l0_device_idx, int l0_domain, int l0_domain_idx) const override
Get the performance factor value of various LevelZero domains.
Definition LevelZero.cpp:1274
virtual ~LevelZeroImp()
Definition LevelZero.cpp:236
uint32_t frequency_throttle_reasons(unsigned int l0_device_idx, int l0_domain, int l0_domain_idx) const override
Get the LevelZero device frequency throttle reasons.
Definition LevelZero.cpp:1447
double ras_cache_errcount_uncorrectable(unsigned int l0_device_idx, int l0_domain, int l0_domain_idx) const override
Get the LevelZero count of number of uncorrectable errors that have occurred in caches (L1/L3/registe...
Definition LevelZero.cpp:1399
double frequency_min(unsigned int l0_device_idx, int l0_domain, int l0_domain_idx) const override
Get the LevelZero device mininmum frequency in MHz.
Definition LevelZero.cpp:1473
std::vector< double > frequency_supported(unsigned int l0_device_idx, int l0_domain, int l0_domain_idx) const override
Get the LevelZero device supported frequencies in MHz.
Definition LevelZero.cpp:1497
double ras_reset_count_correctable(unsigned int l0_device_idx, int l0_domain, int l0_domain_idx) const override
Get the LevelZero count of number of correctable accelerator engine resets attempted by the driver.
Definition LevelZero.cpp:1303
int32_t power_limit_min(unsigned int l0_device_idx) const override
Get the LevelZero device minimum power limit in milliwatts.
Definition LevelZero.cpp:1633
double frequency_max(unsigned int l0_device_idx, int l0_domain, int l0_domain_idx) const override
Get the LevelZero device maximum frequency in MHz.
Definition LevelZero.cpp:1479
double ras_compute_errcount_correctable(unsigned int l0_device_idx, int l0_domain, int l0_domain_idx) const override
Get the LevelZero count of number of correctable errors that have occurred in the compute accelerator...
Definition LevelZero.cpp:1327
std::vector< double > metric_sample(unsigned int l0_device_idx, unsigned int l0_domain_idx, std::string metric_name) const override
Definition LevelZero.cpp:1112
void frequency_control(unsigned int l0_device_idx, int l0_domain, int l0_domain_idx, double range_min, double range_max) const override
Set min and max frequency for LevelZero device.
Definition LevelZero.cpp:1667
double ras_driver_errcount_correctable(unsigned int l0_device_idx, int l0_domain, int l0_domain_idx) const override
Get the LevelZero count of number of low level driver communication correctable errors have occurred.
Definition LevelZero.cpp:1319
int performance_domain_count(unsigned int l0_device_idx, int l0_domain) const override
Get the number of LevelZero perf domains of a certain type.
Definition LevelZero.cpp:1264
double ras_programming_errcount_uncorrectable(unsigned int l0_device_idx, int l0_domain, int l0_domain_idx) const override
Get the LevelZero count of number of uncorrectable hardware exceptions generated by the way workloads...
Definition LevelZero.cpp:1367
double ras_driver_errcount_uncorrectable(unsigned int l0_device_idx, int l0_domain, int l0_domain_idx) const override
Get the LevelZero count of number of low level driver communication uncorrectable errors have occurre...
Definition LevelZero.cpp:1375
uint32_t metric_update_rate(unsigned int l0_device_idx) const override
Definition LevelZero.cpp:1701
uint64_t energy(int geopm_domain, unsigned int l0_device_idx, int l0_domain, int l0_domain_idx) const override
Get the LevelZero device energy in microjoules.
Definition LevelZero.cpp:1584
Definition LevelZeroImp.hpp:212
double sum
Definition LevelZeroImp.hpp:213
uint64_t count
Definition LevelZeroImp.hpp:214