Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose stats of all GPUs #532

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/gl/imgui_hud.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ void imgui_create(void *ctx)
} else {
vendorID = 0x10de;
}
init_gpu_stats(vendorID, params);
init_gpu_stats(vendorID, params,deviceID);
get_device_name(vendorID, deviceID, sw_stats);
// Setup Dear ImGui context
IMGUI_CHECKVERSION();
Expand Down Expand Up @@ -190,8 +190,8 @@ void imgui_render(unsigned int width, unsigned int height)
if (!state.imgui_ctx)
return;

check_keybinds(sw_stats, params, vendorID);
update_hud_info(sw_stats, params, vendorID);
check_keybinds(sw_stats, params, vendorID,deviceID);
update_hud_info(sw_stats, params, vendorID,deviceID);

ImGuiContext *saved_ctx = ImGui::GetCurrentContext();
ImGui::SetCurrentContext(state.imgui_ctx);
Expand Down
122 changes: 61 additions & 61 deletions src/gpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,30 +43,30 @@ bool checkNvidia(const char *pci_dev){
return nvSuccess;
}

void getNvidiaGpuInfo(){
void getNvidiaGpuInfo(int32_t deviceID){
#ifdef HAVE_NVML
if (nvmlSuccess){
getNVMLInfo();
gpu_info.load = nvidiaUtilization.gpu;
gpu_info.temp = nvidiaTemp;
gpu_info.memoryUsed = nvidiaMemory.used / (1024.f * 1024.f * 1024.f);
gpu_info.CoreClock = nvidiaCoreClock;
gpu_info.MemClock = nvidiaMemClock;
gpu_info.powerUsage = nvidiaPowerUsage / 1000;
gpu_info.memoryTotal = nvidiaMemory.total / (1024.f * 1024.f * 1024.f);
gpu_info[deviceID].load = nvidiaUtilization.gpu;
gpu_info[deviceID].temp = nvidiaTemp;
gpu_info[deviceID].memoryUsed = nvidiaMemory.used / (1024.f * 1024.f * 1024.f);
gpu_info[deviceID].CoreClock = nvidiaCoreClock;
gpu_info[deviceID].MemClock = nvidiaMemClock;
gpu_info[deviceID].powerUsage = nvidiaPowerUsage / 1000;
gpu_info[deviceID].memoryTotal = nvidiaMemory.total / (1024.f * 1024.f * 1024.f);
return;
}
#endif
#ifdef HAVE_XNVCTRL
if (nvctrlSuccess) {
getNvctrlInfo();
gpu_info.load = nvctrl_info.load;
gpu_info.temp = nvctrl_info.temp;
gpu_info.memoryUsed = nvctrl_info.memoryUsed / (1024.f);
gpu_info.CoreClock = nvctrl_info.CoreClock;
gpu_info.MemClock = nvctrl_info.MemClock;
gpu_info.powerUsage = 0;
gpu_info.memoryTotal = nvctrl_info.memoryTotal;
gpu_info[deviceID].load = nvctrl_info.load;
gpu_info[deviceID].temp = nvctrl_info.temp;
gpu_info[deviceID].memoryUsed = nvctrl_info.memoryUsed / (1024.f);
gpu_info[deviceID].CoreClock = nvctrl_info.CoreClock;
gpu_info[deviceID].MemClock = nvctrl_info.MemClock;
gpu_info[deviceID].powerUsage = 0;
gpu_info[deviceID].memoryTotal = nvctrl_info.memoryTotal;
return;
}
#endif
Expand All @@ -75,68 +75,68 @@ nvapi_util();
#endif
}

void getAmdGpuInfo(){
if (amdgpu.busy) {
rewind(amdgpu.busy);
fflush(amdgpu.busy);
int value = 0;
if (fscanf(amdgpu.busy, "%d", &value) != 1)
void getAmdGpuInfo(int32_t deviceID){
if (amdgpu[deviceID].busy) {
rewind(amdgpu[deviceID].busy);
fflush(amdgpu[deviceID].busy);
int value = 0;
if (fscanf(amdgpu[deviceID].busy, "%d", &value) != 1)
value = 0;
gpu_info[deviceID].load = value;
}

if (amdgpu[deviceID].temp) {
rewind(amdgpu[deviceID].temp);
fflush(amdgpu[deviceID].temp);
int value = 0;
if (fscanf(amdgpu[deviceID].temp, "%d", &value) != 1)
value = 0;
gpu_info[deviceID].temp = value / 1000;
}

int64_t value = 0;

if (amdgpu[deviceID].vram_total) {
rewind(amdgpu[deviceID].vram_total);
fflush(amdgpu[deviceID].vram_total);
if (fscanf(amdgpu[deviceID].vram_total, "%" PRId64, &value) != 1)
value = 0;
gpu_info.load = value;
gpu_info[deviceID].memoryTotal = float(value) / (1024 * 1024 * 1024);
}

if (amdgpu.temp) {
rewind(amdgpu.temp);
fflush(amdgpu.temp);
int value = 0;
if (fscanf(amdgpu.temp, "%d", &value) != 1)
if (amdgpu[deviceID].vram_used) {
rewind(amdgpu[deviceID].vram_used);
fflush(amdgpu[deviceID].vram_used);
if (fscanf(amdgpu[deviceID].vram_used, "%" PRId64, &value) != 1)
value = 0;
gpu_info.temp = value / 1000;
gpu_info[deviceID].memoryUsed = float(value) / (1024 * 1024 * 1024);
}

int64_t value = 0;

if (amdgpu.vram_total) {
rewind(amdgpu.vram_total);
fflush(amdgpu.vram_total);
if (fscanf(amdgpu.vram_total, "%" PRId64, &value) != 1)
value = 0;
gpu_info.memoryTotal = float(value) / (1024 * 1024 * 1024);
}

if (amdgpu.vram_used) {
rewind(amdgpu.vram_used);
fflush(amdgpu.vram_used);
if (fscanf(amdgpu.vram_used, "%" PRId64, &value) != 1)
value = 0;
gpu_info.memoryUsed = float(value) / (1024 * 1024 * 1024);
}

if (amdgpu.core_clock) {
rewind(amdgpu.core_clock);
fflush(amdgpu.core_clock);
if (fscanf(amdgpu.core_clock, "%" PRId64, &value) != 1)
if (amdgpu[deviceID].core_clock) {
rewind(amdgpu[deviceID].core_clock);
fflush(amdgpu[deviceID].core_clock);
if (fscanf(amdgpu[deviceID].core_clock, "%" PRId64, &value) != 1)
value = 0;

gpu_info.CoreClock = value / 1000000;
gpu_info[deviceID].CoreClock = value / 1000000;
}

if (amdgpu.memory_clock) {
rewind(amdgpu.memory_clock);
fflush(amdgpu.memory_clock);
if (fscanf(amdgpu.memory_clock, "%" PRId64, &value) != 1)
if (amdgpu[deviceID].memory_clock) {
rewind(amdgpu[deviceID].memory_clock);
fflush(amdgpu[deviceID].memory_clock);
if (fscanf(amdgpu[deviceID].memory_clock, "%" PRId64, &value) != 1)
value = 0;

gpu_info.MemClock = value / 1000000;
gpu_info[deviceID].MemClock = value / 1000000;
}

if (amdgpu.power_usage) {
rewind(amdgpu.power_usage);
fflush(amdgpu.power_usage);
if (fscanf(amdgpu.power_usage, "%" PRId64, &value) != 1)
if (amdgpu[deviceID].power_usage) {
rewind(amdgpu[deviceID].power_usage);
fflush(amdgpu[deviceID].power_usage);
if (fscanf(amdgpu[deviceID].power_usage, "%" PRId64, &value) != 1)
value = 0;

gpu_info.powerUsage = value / 1000000;
gpu_info[deviceID].powerUsage = value / 1000000;
}
}

Expand Down
5 changes: 3 additions & 2 deletions src/gpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ struct amdgpu_files
FILE *power_usage;
};

extern amdgpu_files amdgpu;
extern std::unordered_map<int32_t, amdgpu_files> amdgpu;

struct gpuInfo{
std::string deviceName;
int load;
int temp;
float memoryUsed;
Expand All @@ -28,7 +29,7 @@ struct gpuInfo{
int powerUsage;
};

extern struct gpuInfo gpu_info;
extern std::unordered_map<int32_t, struct gpuInfo> gpu_info;

void getNvidiaGpuInfo(void);
void getAmdGpuInfo(void);
Expand Down
50 changes: 35 additions & 15 deletions src/hud_elements.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,14 +131,20 @@ void HudElements::version(){
}

void HudElements::gpu_stats(){
if (HUDElements.params->enabled[OVERLAY_PARAM_ENABLED_gpu_stats]){
for(auto per_gpu_info: gpu_info){
if (HUDElements.params->enabled[OVERLAY_PARAM_ENABLED_gpu_stats]){
ImGui::TableNextRow(); ImGui::TableNextColumn();
const char* gpu_text;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason for turning it into std::string instead?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was concatenating the name of the GPU. I've since put that on a separate hud element but we could keep it as a std::string in case we need to add GPU indices (GPU 1,GPU 2 etc)


std::string gpu_text;
if (HUDElements.params->gpu_text.empty())
gpu_text = "GPU";
gpu_text = "GPU ";
else
gpu_text = HUDElements.params->gpu_text.c_str();
ImGui::TextColored(HUDElements.colors.gpu, "%s", gpu_text);
ImGui::TextColored(HUDElements.colors.gpu, "%s", gpu_text.c_str());
ImGui::TableNextRow();
ImGui::TableNextColumn();
ImGui::TextColored(HUDElements.colors.gpu, "%s", per_gpu_info.second.deviceName.c_str());
ImGui::TableNextRow();
ImGui::TableNextColumn();
auto text_color = HUDElements.colors.text;
if (HUDElements.params->enabled[OVERLAY_PARAM_ENABLED_gpu_load_change]){
Expand All @@ -150,21 +156,22 @@ void HudElements::gpu_stats(){
HUDElements.params->gpu_load_value[1]
};

auto load_color = change_on_load_temp(gpu_data, gpu_info.load);
right_aligned_text(load_color, HUDElements.ralign_width, "%i", gpu_info.load);

auto load_color = change_on_load_temp(gpu_data, per_gpu_info.second.load);
right_aligned_text(load_color, HUDElements.ralign_width, "%i", per_gpu_info.second.load);
ImGui::SameLine(0, 1.0f);
ImGui::TextColored(load_color,"%%");
}
else {
right_aligned_text(text_color, HUDElements.ralign_width, "%i", gpu_info.load);
right_aligned_text(text_color, HUDElements.ralign_width, "%i", per_gpu_info.second.load);
ImGui::SameLine(0, 1.0f);
ImGui::TextColored(text_color,"%%");
// ImGui::SameLine(150);
// ImGui::Text("%s", "%");
}
if (HUDElements.params->enabled[OVERLAY_PARAM_ENABLED_gpu_temp]){
ImGui::TableNextColumn();
right_aligned_text(text_color, HUDElements.ralign_width, "%i", gpu_info.temp);
right_aligned_text(text_color, HUDElements.ralign_width, "%i", per_gpu_info.second.temp);
ImGui::SameLine(0, 1.0f);
ImGui::Text("°C");
}
Expand All @@ -173,20 +180,23 @@ void HudElements::gpu_stats(){
}
if (HUDElements.params->enabled[OVERLAY_PARAM_ENABLED_gpu_core_clock]){
ImGui::TableNextColumn();
right_aligned_text(text_color, HUDElements.ralign_width, "%i", gpu_info.CoreClock);
right_aligned_text(text_color, HUDElements.ralign_width, "%i", per_gpu_info.second.CoreClock);
ImGui::SameLine(0, 1.0f);
ImGui::PushFont(HUDElements.sw_stats->font1);
ImGui::Text("MHz");
ImGui::PopFont();
}
if (HUDElements.params->enabled[OVERLAY_PARAM_ENABLED_gpu_power]) {
ImGui::TableNextColumn();
right_aligned_text(text_color, HUDElements.ralign_width, "%i", gpu_info.powerUsage);
right_aligned_text(text_color, HUDElements.ralign_width, "%i", per_gpu_info.second.powerUsage);
ImGui::SameLine(0, 1.0f);
ImGui::PushFont(HUDElements.sw_stats->font1);
ImGui::Text("W");
ImGui::PopFont();
}


}
}
}

Expand Down Expand Up @@ -328,22 +338,30 @@ void HudElements::io_stats(){

void HudElements::vram(){
if (HUDElements.params->enabled[OVERLAY_PARAM_ENABLED_vram]){
ImGui::TableNextRow(); ImGui::TableNextColumn();
ImGui::TextColored(HUDElements.colors.vram, "VRAM");
for(auto per_gpu_info : gpu_info){
ImGui::TableNextRow();ImGui::TableNextColumn();
ImGui::TextColored(HUDElements.colors.vram, "VRAM" );
ImGui::TableNextRow();
ImGui::TableNextColumn();
ImGui::TextColored(HUDElements.colors.vram, "%s",per_gpu_info.second.deviceName.c_str() );
ImGui::TableNextRow();
ImGui::TableNextColumn();
right_aligned_text(HUDElements.colors.text, HUDElements.ralign_width, "%.1f", gpu_info.memoryUsed);
right_aligned_text(HUDElements.colors.text, HUDElements.ralign_width, "%.1f", per_gpu_info.second.memoryUsed);
ImGui::SameLine(0,1.0f);
ImGui::PushFont(HUDElements.sw_stats->font1);
ImGui::Text("GiB");
ImGui::PopFont();
if (HUDElements.params->enabled[OVERLAY_PARAM_ENABLED_gpu_mem_clock]){
ImGui::TableNextColumn();
right_aligned_text(HUDElements.colors.text, HUDElements.ralign_width, "%i", gpu_info.MemClock);
right_aligned_text(HUDElements.colors.text, HUDElements.ralign_width, "%i", per_gpu_info.second.MemClock);
ImGui::SameLine(0, 1.0f);
ImGui::PushFont(HUDElements.sw_stats->font1);
ImGui::Text("MHz");
ImGui::PopFont();
}

}

}
}

Expand Down Expand Up @@ -777,9 +795,11 @@ void HudElements::graphs(){
arr.erase(arr.begin());
}

HUDElements.max = gpu_info.memoryTotal;
for(auto per_gpu_info: gpu_info){
HUDElements.max = per_gpu_info.second.memoryTotal;
HUDElements.min = 0;
ImGui::TextColored(HUDElements.colors.engine, "%s", "VRAM");
}
}
#ifdef __gnu_linux__
if (value == "ram"){
Expand Down
4 changes: 2 additions & 2 deletions src/keybinds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include "logging.h"
#include "keybinds.h"

void check_keybinds(struct swapchain_stats& sw_stats, struct overlay_params& params, uint32_t vendorID){
void check_keybinds(struct swapchain_stats& sw_stats, struct overlay_params& params, uint32_t vendorID,int32_t deviceID){
using namespace std::chrono_literals;
bool pressed = false; // FIXME just a placeholder until wayland support
auto now = Clock::now(); /* us */
Expand Down Expand Up @@ -33,7 +33,7 @@ void check_keybinds(struct swapchain_stats& sw_stats, struct overlay_params& par
} else {
logger->start_logging();
std::thread(update_hw_info, std::ref(sw_stats), std::ref(params),
vendorID)
vendorID,deviceID)
.detach();
benchmark.fps_data.clear();
}
Expand Down
Loading