From a20e93f4db719f59903aaca0bffe507939e615ce Mon Sep 17 00:00:00 2001 From: Dr-Noob Date: Tue, 21 Dec 2021 17:02:08 +0100 Subject: [PATCH] [v0.20] Print help message when no GPU is detected to help people understand whats going on --- CMakeLists.txt | 10 +++++----- src/common/ascii.hpp | 27 +-------------------------- src/common/colors.hpp | 31 +++++++++++++++++++++++++++++++ src/common/main.cpp | 9 +++++++++ src/common/master.cpp | 22 ++++++++++++++++++++++ src/common/master.hpp | 2 ++ 6 files changed, 70 insertions(+), 31 deletions(-) create mode 100644 src/common/colors.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index a97d1b6..b6d3569 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -106,14 +106,14 @@ endif() message(STATUS "----------------------") message(STATUS "gpufetch build report:") -if(ENABLE_INTEL_BACKEND) - message(STATUS "Intel backend: ${BoldGreen}ON${ColorReset}") -else() - message(STATUS "Intel backend: ${BoldRed}OFF${ColorReset}") -endif() if(ENABLE_CUDA_BACKEND) message(STATUS "CUDA backend: ${BoldGreen}ON${ColorReset}") else() message(STATUS "CUDA backend: ${BoldRed}OFF${ColorReset}") endif() +if(ENABLE_INTEL_BACKEND) + message(STATUS "Intel backend: ${BoldGreen}ON${ColorReset}") +else() + message(STATUS "Intel backend: ${BoldRed}OFF${ColorReset}") +endif() message(STATUS "----------------------") diff --git a/src/common/ascii.hpp b/src/common/ascii.hpp index ee6a470..00a8254 100644 --- a/src/common/ascii.hpp +++ b/src/common/ascii.hpp @@ -1,32 +1,7 @@ #ifndef __ASCII__ #define __ASCII__ -#define C_NONE "" -#define C_FG_BLACK "\x1b[30;1m" -#define C_FG_RED "\x1b[31;1m" -#define C_FG_GREEN "\x1b[32;1m" -#define C_FG_YELLOW "\x1b[33;1m" -#define C_FG_BLUE "\x1b[34;1m" -#define C_FG_MAGENTA "\x1b[35;1m" -#define C_FG_CYAN "\x1b[36;1m" -#define C_FG_WHITE "\x1b[37;1m" -#define C_BG_BLACK "\x1b[40;1m" -#define C_BG_RED "\x1b[41;1m" -#define C_BG_GREEN "\x1b[42;1m" -#define C_BG_YELLOW "\x1b[43;1m" -#define C_BG_BLUE "\x1b[44;1m" -#define C_BG_MAGENTA "\x1b[45;1m" -#define C_BG_CYAN "\x1b[46;1m" -#define C_BG_WHITE "\x1b[47;1m" -#define C_FG_B_BLACK "\x1b[90;1m" -#define C_FG_B_RED "\x1b[91;1m" -#define C_FG_B_GREEN "\x1b[92;1m" -#define C_FG_B_YELLOW "\x1b[93;1m" -#define C_FG_B_BLUE "\x1b[94;1m" -#define C_FG_B_MAGENTA "\x1b[95;1m" -#define C_FG_B_CYAN "\x1b[96;1m" -#define C_FG_B_WHITE "\x1b[97;1m" -#define C_RESET "\x1b[m" +#include "colors.hpp" struct ascii_logo { const char* art; diff --git a/src/common/colors.hpp b/src/common/colors.hpp new file mode 100644 index 0000000..f2dc5df --- /dev/null +++ b/src/common/colors.hpp @@ -0,0 +1,31 @@ +#ifndef __COLORS__ +#define __COLORS__ + +#define C_NONE "" +#define C_FG_BLACK "\x1b[30;1m" +#define C_FG_RED "\x1b[31;1m" +#define C_FG_GREEN "\x1b[32;1m" +#define C_FG_YELLOW "\x1b[33;1m" +#define C_FG_BLUE "\x1b[34;1m" +#define C_FG_MAGENTA "\x1b[35;1m" +#define C_FG_CYAN "\x1b[36;1m" +#define C_FG_WHITE "\x1b[37;1m" +#define C_BG_BLACK "\x1b[40;1m" +#define C_BG_RED "\x1b[41;1m" +#define C_BG_GREEN "\x1b[42;1m" +#define C_BG_YELLOW "\x1b[43;1m" +#define C_BG_BLUE "\x1b[44;1m" +#define C_BG_MAGENTA "\x1b[45;1m" +#define C_BG_CYAN "\x1b[46;1m" +#define C_BG_WHITE "\x1b[47;1m" +#define C_FG_B_BLACK "\x1b[90;1m" +#define C_FG_B_RED "\x1b[91;1m" +#define C_FG_B_GREEN "\x1b[92;1m" +#define C_FG_B_YELLOW "\x1b[93;1m" +#define C_FG_B_BLUE "\x1b[94;1m" +#define C_FG_B_MAGENTA "\x1b[95;1m" +#define C_FG_B_CYAN "\x1b[96;1m" +#define C_FG_B_WHITE "\x1b[97;1m" +#define C_RESET "\x1b[m" + +#endif diff --git a/src/common/main.cpp b/src/common/main.cpp index 3e9e351..a5cba6b 100644 --- a/src/common/main.cpp +++ b/src/common/main.cpp @@ -71,6 +71,15 @@ int main(int argc, char* argv[]) { return print_gpus_list(list); } + if(get_num_gpus_available(list) == 0) { + printErr("No GPU was detected, or the detected GPU is not supported by gpufetch"); + printf("Please, make sure that the appropiate backend is enabled:\n"); + print_enabled_backends(); + printf("Visit https://github.com/Dr-Noob/gpufetch#2-backends for more information\n"); + + return EXIT_FAILURE; + } + set_log_level(true); printf("[WARNING]: gpufetch is in beta. The provided information may be incomplete or wrong.\n\ diff --git a/src/common/master.cpp b/src/common/master.cpp index fe27de8..735992d 100644 --- a/src/common/master.cpp +++ b/src/common/master.cpp @@ -1,6 +1,7 @@ #include #include +#include "colors.hpp" #include "master.hpp" #include "../cuda/cuda.hpp" #include "../intel/intel.hpp" @@ -56,6 +57,27 @@ bool print_gpus_list(struct gpu_list* list) { return true; } +void print_enabled_backends() { + printf("- CUDA backend: "); +#ifdef BACKEND_CUDA + printf("%sON%s\n", C_FG_GREEN, C_RESET); +#else + printf("%sOFF%s\n", C_FG_RED, C_RESET); +#endif + + printf("- Intel backend: "); +#ifdef BACKEND_INTEL + printf("%sON%s\n", C_FG_GREEN, C_RESET); +#else + printf("%sOFF%s\n", C_FG_RED, C_RESET); +#endif +} + +int get_num_gpus_available(struct gpu_list* list) { + return list->num_gpus; +} + struct gpu_info* get_gpu_info(struct gpu_list* list, int idx) { return list->gpus[idx]; } + diff --git a/src/common/master.hpp b/src/common/master.hpp index 5863cbc..ad710c5 100644 --- a/src/common/master.hpp +++ b/src/common/master.hpp @@ -7,6 +7,8 @@ struct gpu_list; struct gpu_list* get_gpu_list(); bool print_gpus_list(struct gpu_list* list); +int get_num_gpus_available(struct gpu_list* list); +void print_enabled_backends(); struct gpu_info* get_gpu_info(struct gpu_list* list, int idx); #endif