Skip to content

Commit

Permalink
enable GPU by default
Browse files Browse the repository at this point in the history
  • Loading branch information
bjia56 committed Jan 17, 2025
1 parent eeaf4f9 commit f5a7b60
Show file tree
Hide file tree
Showing 11 changed files with 19 additions and 183 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ if(${TARGET} STREQUAL "host")
find_package(Threads REQUIRED)
target_link_libraries(cosmotop.com Threads::Threads)

target_compile_definitions(cosmotop.com PRIVATE GPU_SUPPORT FMT_HEADER_ONLY _FILE_OFFSET_BITS=64)
target_compile_definitions(cosmotop.com PRIVATE FMT_HEADER_ONLY _FILE_OFFSET_BITS=64)

elseif(${TARGET} STREQUAL "plugin")

Expand Down Expand Up @@ -179,7 +179,7 @@ elseif(${TARGET} STREQUAL "plugin")
endif()

target_include_directories(${BINARY_NAME} PRIVATE ${THIRD_PARTY_INCLUDES})
target_compile_definitions(${BINARY_NAME} PRIVATE GPU_SUPPORT FMT_HEADER_ONLY _FILE_OFFSET_BITS=64)
target_compile_definitions(${BINARY_NAME} PRIVATE FMT_HEADER_ONLY _FILE_OFFSET_BITS=64)
if(CMAKE_SYSTEM MATCHES "Windows")
target_compile_options(${BINARY_NAME} PRIVATE /utf-8)
target_compile_definitions(${BINARY_NAME} PRIVATE UNICODE _UNICODE)
Expand Down
30 changes: 3 additions & 27 deletions src/cosmotop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,11 +265,7 @@ void term_resize(bool force) {
if (force and refreshed) force = false;
}
else return;
#ifdef GPU_SUPPORT
static const array<string, 10> all_boxes = {"gpu5", "cpu", "mem", "net", "proc", "gpu0", "gpu1", "gpu2", "gpu3", "gpu4"};
#else
static const array<string, 5> all_boxes = {"", "cpu", "mem", "net", "proc"};
#endif
Global::resized = true;
if (Runner::active) Runner::stop();
Term::refresh();
Expand Down Expand Up @@ -309,12 +305,8 @@ void term_resize(bool force) {
clean_quit(0);
else if (key.size() == 1 and isint(key)) {
auto intKey = stoi(key);
#ifdef GPU_SUPPORT
auto gpu_count = Gpu::get_count();
if ((intKey == 0 and gpu_count >= 5) or (intKey >= 5 and intKey - 4 <= gpu_count)) {
#else
if (intKey > 0 and intKey < 5) {
#endif
auto box = all_boxes.at(intKey);
Config::current_preset = -1;
Config::toggle_box(box);
Expand Down Expand Up @@ -353,10 +345,8 @@ void clean_quit(int sig) {
#endif
}

#ifdef GPU_SUPPORT
Gpu::Nvml::shutdown();
Gpu::Rsmi::shutdown();
#endif

Config::write();

Expand Down Expand Up @@ -620,13 +610,7 @@ namespace Runner {
//! DEBUG stats
if (Global::debug) {
if (debug_bg.empty() or redraw)
Runner::debug_bg = Draw::createBox(2, 2, 33,
#ifdef GPU_SUPPORT
9,
#else
8,
#endif
"", true, "μs");
Runner::debug_bg = Draw::createBox(2, 2, 33, 9, "", true, "μs");

debug_times.clear();
debug_times["total"] = {0, 0};
Expand All @@ -636,7 +620,6 @@ namespace Runner {

//* Run collection and draw functions for all boxes
try {
#ifdef GPU_SUPPORT
//? GPU data collection
const bool gpu_in_cpu_panel = Gpu::get_gpu_names().size() > 0 and (
Config::getS("cpu_graph_lower").starts_with("gpu-") or Config::getS("cpu_graph_upper").starts_with("gpu-")
Expand All @@ -655,9 +638,6 @@ namespace Runner {
if (Global::debug) debug_timer("gpu", collect_done);
}
auto& gpus_ref = gpus;
#else
vector<Gpu::gpu_info> gpus_ref{};
#endif

//? CPU
if (v_contains(conf.boxes, "cpu")) {
Expand Down Expand Up @@ -686,7 +666,7 @@ namespace Runner {
throw std::runtime_error("Cpu:: -> " + string{e.what()});
}
}
#ifdef GPU_SUPPORT

//? GPU
if (not gpu_panels.empty() and not gpus_ref.empty()) {
try {
Expand All @@ -703,7 +683,7 @@ namespace Runner {
throw std::runtime_error("Gpu:: -> " + string{e.what()});
}
}
#endif

//? MEM
if (v_contains(conf.boxes, "mem")) {
try {
Expand Down Expand Up @@ -820,11 +800,7 @@ namespace Runner {
"post"_a = Theme::c("main_fg") + Fx::ub
);
static auto loc = std::locale(std::locale::classic(), new MyNumPunct);
#ifdef GPU_SUPPORT
for (const string name : {"cpu", "mem", "net", "proc", "gpu", "total"}) {
#else
for (const string name : {"cpu", "mem", "net", "proc", "total"}) {
#endif
if (not debug_times.contains(name)) debug_times[name] = {0,0};
const auto& [time_collect, time_draw] = debug_times.at(name);
if (name == "total") output += Fx::b;
Expand Down
18 changes: 4 additions & 14 deletions src/cosmotop_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ namespace Config {
"#* Note that \"tty\" only has half the horizontal resolution of the other two, so will show a shorter historical view."},

{"graph_symbol_cpu", "# Graph symbol to use for graphs in cpu box, \"default\", \"braille\", \"block\" or \"tty\"."},
#ifdef GPU_SUPPORT

{"graph_symbol_gpu", "# Graph symbol to use for graphs in gpu box, \"default\", \"braille\", \"block\" or \"tty\"."},
#endif

{"graph_symbol_mem", "# Graph symbol to use for graphs in cpu box, \"default\", \"braille\", \"block\" or \"tty\"."},

{"graph_symbol_net", "# Graph symbol to use for graphs in cpu box, \"default\", \"braille\", \"block\" or \"tty\"."},
Expand Down Expand Up @@ -124,9 +124,9 @@ namespace Config {

{"cpu_graph_lower", "#* Sets the CPU stat shown in lower half of the CPU graph, \"total\" is always available.\n"
"#* Select from a list of detected attributes from the options menu."},
#ifdef GPU_SUPPORT

{"show_gpu_info", "#* If gpu info should be shown in the cpu box. Available values = \"Auto\", \"On\" and \"Off\"."},
#endif

{"cpu_invert_lower", "#* Toggles if the lower CPU graph should be inverted."},

{"cpu_single_graph", "#* Set to True to completely disable the lower CPU graph."},
Expand Down Expand Up @@ -209,7 +209,6 @@ namespace Config {

{"log_level", "#* Set loglevel for \"~/.config/cosmotop/cosmotop.log\" levels are: \"ERROR\" \"WARNING\" \"INFO\" \"DEBUG\".\n"
"#* The level set includes all lower levels, i.e. \"DEBUG\" will show all logging info."},
#ifdef GPU_SUPPORT

{"nvml_measure_pcie_speeds",
"#* Measure PCIe throughput on NVIDIA cards, may impact performance on certain cards."},
Expand All @@ -225,7 +224,6 @@ namespace Config {

{"intel_gpu_exporter", "#* HTTP endpoint to pull Intel GPU metrics from, if Intel PMU is not available.\n"
"#* Use with https://github.com/bjia56/intel-gpu-exporter"},
#endif
};

std::unordered_map<std::string_view, string> strings = {
Expand Down Expand Up @@ -256,7 +254,6 @@ namespace Config {
{"proc_command", ""},
{"selected_name", ""},
{"detailed_name", ""},
#ifdef GPU_SUPPORT
{"custom_gpu_name0", ""},
{"custom_gpu_name1", ""},
{"custom_gpu_name2", ""},
Expand All @@ -265,7 +262,6 @@ namespace Config {
{"custom_gpu_name5", ""},
{"show_gpu_info", "Auto"},
{"intel_gpu_exporter", ""}
#endif
};
std::unordered_map<std::string_view, string> stringsTmp;

Expand Down Expand Up @@ -317,11 +313,9 @@ namespace Config {
{"show_detailed", false},
{"proc_filtering", false},
{"proc_aggregate", false},
#ifdef GPU_SUPPORT
{"nvml_measure_pcie_speeds", true},
{"rsmi_measure_pcie_speeds", true},
{"gpu_mirror_graph", true}
#endif
};
std::unordered_map<std::string_view, bool> boolsTmp;

Expand Down Expand Up @@ -556,10 +550,8 @@ namespace Config {
return true;
}

#ifdef GPU_SUPPORT
else if (name == "show_gpu_info" and not v_contains(show_gpu_values, value))
validError = "Invalid value for show_gpu_info: " + value;
#endif

else if (name == "presets" and not presetsValid(value))
return false;
Expand Down Expand Up @@ -663,12 +655,10 @@ namespace Config {
auto new_boxes = ssplit(boxes);
for (auto& box : new_boxes) {
if (not v_contains(valid_boxes, box)) return false;
#ifdef GPU_SUPPORT
if (box.starts_with("gpu")) {
int gpu_num = stoi(box.substr(3)) + 1;
if (gpu_num > Gpu::get_count()) return false;
}
#endif
}
current_boxes = std::move(new_boxes);
return true;
Expand Down
10 changes: 3 additions & 7 deletions src/cosmotop_config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,11 @@ namespace Config {
const vector<string> valid_graph_symbols = { "braille", "block", "tty" };
const vector<string> valid_graph_symbols_def = { "default", "braille", "block", "tty" };
const vector<string> valid_boxes = {
"cpu", "mem", "net", "proc"
#ifdef GPU_SUPPORT
,"gpu0", "gpu1", "gpu2", "gpu3", "gpu4", "gpu5"
#endif
};
"cpu", "mem", "net", "proc",
"gpu0", "gpu1", "gpu2", "gpu3", "gpu4", "gpu5"
};
const vector<string> temp_scales = { "celsius", "fahrenheit", "kelvin", "rankine" };
#ifdef GPU_SUPPORT
const vector<string> show_gpu_values = { "Auto", "On", "Off" };
#endif
extern vector<string> current_boxes;
extern vector<string> preset_list;
extern vector<string> available_batteries;
Expand Down
Loading

0 comments on commit f5a7b60

Please sign in to comment.