Skip to content

Commit

Permalink
Add multi-GPU support for NVML data collection
Browse files Browse the repository at this point in the history
  • Loading branch information
romner-set committed May 15, 2023
1 parent 2d27f2f commit 917d568
Show file tree
Hide file tree
Showing 4 changed files with 204 additions and 198 deletions.
4 changes: 2 additions & 2 deletions src/btop.cpp
Expand Up @@ -532,12 +532,12 @@ namespace Runner {
if (Global::debug) debug_timer("gpu", collect_begin);

//? Start collect
auto gpu = Gpu::collect(conf.no_update);
auto gpus = Gpu::collect(conf.no_update);

if (Global::debug) debug_timer("gpu", draw_begin);

//? Draw box
if (not pause_output and Gpu::Nvml::initialized) output += Gpu::draw(gpu, conf.force_redraw, conf.no_update);
if (not pause_output and Gpu::Nvml::initialized) output += Gpu::draw(gpus, conf.force_redraw, conf.no_update);

if (Global::debug) debug_timer("gpu", draw_done);
}
Expand Down
6 changes: 4 additions & 2 deletions src/btop_draw.cpp
Expand Up @@ -745,7 +745,7 @@ namespace Gpu {
Draw::Meter pwr_meter;
string box;

string draw(const gpu_info& gpu, bool force_redraw, bool data_same) {
string draw(const vector<gpu_info>& gpus, bool force_redraw, bool data_same) {
if (Runner::stopping) return "";
if (force_redraw) redraw = true;
bool show_temps = (Config::getB("check_temp"));
Expand All @@ -757,6 +757,7 @@ namespace Gpu {
string out;
out.reserve(width * height);

auto gpu = gpus[0]; // TODO: mutli-gpu support

//* Redraw elements not needed to be updated every cycle
if (redraw) {
Expand Down Expand Up @@ -1796,6 +1797,7 @@ namespace Draw {
using namespace Gpu;
width = Term::width;
height = max(Gpu::min_height, Cpu::shown ? Cpu::height : (int)ceil((double)Term::height * (trim(boxes) == "gpu" ? 100 : height_p) / 100));
height += height+Cpu::height == Term::height-1;
x = 1; y = 1 + Cpu::shown*Cpu::height;
box = createBox(x, y, width, height, Theme::c("cpu_box"), true, "gpu", "", 5); // TODO gpu_box

Expand All @@ -1809,7 +1811,7 @@ namespace Draw {
b_x = x + width - b_width - 1;
b_y = y + ceil((double)(height - 2) / 2) - ceil((double)(b_height/*+bproc_height*/) / 2) + 1;

box += createBox(b_x, b_y, b_width, b_height, "", false, gpu_name);
box += createBox(b_x, b_y, b_width, b_height, "", false, gpu_names[0]);

//? TODO: Processes box
/*bproc_x = x + width - bproc_width - 1;
Expand Down
18 changes: 9 additions & 9 deletions src/btop_shared.hpp
Expand Up @@ -318,15 +318,15 @@ namespace Gpu {
extern string box;
extern int x, y, width, height, min_width, min_height;
extern bool shown, redraw;
extern string gpu_name;
extern vector<string> gpu_names;

const array mem_names { "used"s, "free"s };

//* Container for process information
struct proc_info {
//* Container for process information // TODO
/*struct proc_info {
unsigned int pid;
unsigned long long mem;
};
};*/

//* Per-device container for GPU info
struct gpu_info {
Expand All @@ -351,8 +351,8 @@ namespace Gpu {
unsigned int pcie_tx = 0; // KB/s
unsigned int pcie_rx = 0;

vector<proc_info> graphics_processes = {};
vector<proc_info> compute_processes = {};
// vector<proc_info> graphics_processes = {}; // TODO
// vector<proc_info> compute_processes = {};
};

namespace Nvml {
Expand All @@ -361,8 +361,8 @@ namespace Gpu {
}

//* Collect gpu stats and temperatures
auto collect(bool no_update = false) -> gpu_info&;
auto collect(bool no_update = false) -> vector<gpu_info>&;

//* Draw contents of gpu box using <gpu> as source
string draw(const gpu_info& gpu, bool force_redraw, bool data_same);
//* Draw contents of gpu box using <gpus> as source
string draw(const vector<gpu_info>& gpus, bool force_redraw, bool data_same);
}

0 comments on commit 917d568

Please sign in to comment.