2022-01-14 21:41:38 +00:00
|
|
|
#include "amdgpu.h"
|
2022-02-18 15:31:36 +00:00
|
|
|
#include "gpu.h"
|
2022-02-04 20:01:44 +00:00
|
|
|
#include "cpu.h"
|
2022-01-14 21:41:38 +00:00
|
|
|
|
2022-02-04 18:52:54 +00:00
|
|
|
std::string metrics_path = "";
|
2022-01-14 21:41:38 +00:00
|
|
|
|
|
|
|
void amdgpu_get_metrics()
|
|
|
|
{
|
2022-02-04 18:52:54 +00:00
|
|
|
if (!metrics_path.empty()){
|
|
|
|
struct metrics_table_header header;
|
|
|
|
std::ifstream in(metrics_path, std::ios_base::in | std::ios_base::binary);
|
|
|
|
in.read((char*)&header, sizeof(header));
|
|
|
|
if (header.format_revision == 1){
|
2022-03-13 14:51:41 +00:00
|
|
|
cpuStats.cpu_type = "CPU";
|
2022-02-04 18:52:54 +00:00
|
|
|
// Desktop GPUs
|
|
|
|
struct gpu_metrics_v1_3 amdgpu_metrics;
|
|
|
|
in.clear();
|
|
|
|
in.seekg(0);
|
|
|
|
in.read((char*)&amdgpu_metrics, sizeof(amdgpu_metrics));
|
|
|
|
gpu_info.load = amdgpu_metrics.average_gfx_activity;
|
|
|
|
gpu_info.CoreClock = amdgpu_metrics.average_gfxclk_frequency;
|
|
|
|
gpu_info.powerUsage = amdgpu_metrics.average_socket_power;
|
|
|
|
gpu_info.temp = amdgpu_metrics.temperature_edge;
|
|
|
|
gpu_info.MemClock = amdgpu_metrics.current_uclk;
|
|
|
|
} else if (header.format_revision == 2){
|
|
|
|
// APUs
|
2022-03-13 14:51:41 +00:00
|
|
|
cpuStats.cpu_type = "APU";
|
2022-02-04 18:52:54 +00:00
|
|
|
struct gpu_metrics_v2_2 amdgpu_metrics;
|
|
|
|
in.clear();
|
|
|
|
in.seekg(0);
|
|
|
|
in.read((char*)&amdgpu_metrics, sizeof(amdgpu_metrics));
|
|
|
|
gpu_info.load = amdgpu_metrics.average_gfx_activity;
|
2022-02-06 20:56:33 +00:00
|
|
|
gpu_info.CoreClock = amdgpu_metrics.current_gfxclk;
|
2022-02-07 03:34:17 +00:00
|
|
|
gpu_info.powerUsage = amdgpu_metrics.average_gfx_power / 1000.f;
|
2022-02-04 18:52:54 +00:00
|
|
|
gpu_info.temp = amdgpu_metrics.temperature_gfx / 100;
|
|
|
|
gpu_info.MemClock = amdgpu_metrics.current_uclk;
|
2022-02-07 03:34:17 +00:00
|
|
|
gpu_info.apu_cpu_power = amdgpu_metrics.average_cpu_power / 1000.f;
|
2022-02-04 20:01:44 +00:00
|
|
|
int cpu_temp = 0;
|
2022-03-06 13:39:14 +00:00
|
|
|
for (unsigned i = 0; i < cpuStats.GetCPUData().size() / 2; i++)
|
2022-02-04 20:01:44 +00:00
|
|
|
if (amdgpu_metrics.temperature_core[i] > cpu_temp)
|
|
|
|
cpu_temp = amdgpu_metrics.temperature_core[i];
|
|
|
|
|
|
|
|
gpu_info.apu_cpu_temp = cpu_temp / 100;
|
2022-02-04 18:52:54 +00:00
|
|
|
}
|
|
|
|
}
|
2022-03-05 20:12:30 +00:00
|
|
|
}
|