[v0.25] Add option to print all GPUs as requested in #33

This commit is contained in:
Dr-Noob
2022-12-03 18:04:50 +01:00
parent 06dc50b6a5
commit 774550307c
4 changed files with 41 additions and 27 deletions

View File

@@ -246,11 +246,22 @@ bool parse_args(int argc, char* argv[]) {
}
}
else if(opt == args_chr[ARG_GPU]) {
args.gpu_idx = getarg_int(optarg);
if(errn != 0) {
printErr("Option %s: %s", args_str[ARG_GPU], getarg_error());
args.help_flag = true;
return false;
// Check for "a" option
if(strcmp(optarg, "a") == 0) {
args.gpu_idx = -1;
}
else {
args.gpu_idx = getarg_int(optarg);
if(errn != 0) {
printErr("Option %s: %s", args_str[ARG_GPU], getarg_error());
args.help_flag = true;
return false;
}
if(args.gpu_idx < 0) {
printErr("Specified GPU index is out of range: %d. ", args.gpu_idx);
printf("Run gpufetch with the --%s option to check out valid GPU indexes\n", args_str[ARG_LIST]);
return false;
}
}
}
else if(opt == args_chr[ARG_LIST]) {

View File

@@ -21,7 +21,7 @@ void print_help(char *argv[]) {
printf("Options: \n");
printf(" -%c, --%s %*s Set the color scheme (by default, gpufetch uses the system color scheme) See COLORS section for a more detailed explanation\n", c[ARG_COLOR], t[ARG_COLOR], (int) (max_len-strlen(t[ARG_COLOR])), "");
printf(" -%c, --%s %*s List the available GPUs in the system\n", c[ARG_LIST], t[ARG_LIST], (int) (max_len-strlen(t[ARG_LIST])), "");
printf(" -%c, --%s %*s Select the GPU to use (default: 0)\n", c[ARG_GPU], t[ARG_GPU], (int) (max_len-strlen(t[ARG_GPU])), "");
printf(" -%c, --%s %*s Select the GPU to print (default: 0). Use 'a' to print all GPUs\n", c[ARG_GPU], t[ARG_GPU], (int) (max_len-strlen(t[ARG_GPU])), "");
printf(" --%s %*s Show the short version of the logo\n", t[ARG_LOGO_SHORT], (int) (max_len-strlen(t[ARG_LOGO_SHORT])), "");
printf(" --%s %*s Show the long version of the logo\n", t[ARG_LOGO_LONG], (int) (max_len-strlen(t[ARG_LOGO_LONG])), "");
printf(" -%c, --%s %*s Enable verbose output\n", c[ARG_VERBOSE], t[ARG_VERBOSE], (int) (max_len-strlen(t[ARG_VERBOSE])), "");
@@ -72,9 +72,6 @@ int main(int argc, char* argv[]) {
set_log_level(verbose_enabled());
int idx = get_gpu_idx();
if(!gpu_idx_valid(idx)) {
return EXIT_FAILURE;
}
struct gpu_list* list = get_gpu_list();
if(list_gpus()) {
@@ -91,17 +88,33 @@ int main(int argc, char* argv[]) {
return EXIT_FAILURE;
}
struct gpu_info* gpu = get_gpu_info(list, idx);
if(gpu == NULL)
return EXIT_FAILURE;
int first_idx, last_idx;
if(idx == -1) {
first_idx = 0;
last_idx = get_num_gpus_available(list);
}
else {
first_idx = idx;
last_idx = idx+1;
}
printf("[NOTE]: gpufetch is in beta. The provided information may be incomplete or wrong.\n\
bool print_failed = false;
struct gpu_info* gpu = NULL;
for(int gpu_idx = first_idx; !print_failed && gpu_idx < last_idx; gpu_idx++) {
gpu = get_gpu_info(list, gpu_idx);
if(gpu == NULL)
return EXIT_FAILURE;
printf("[NOTE]: gpufetch is in beta. The provided information may be incomplete or wrong.\n\
If you want to help to improve gpufetch, please compare the output of the program\n\
with a reliable source which you know is right (e.g, techpowerup.com) and report\n\
any inconsistencies to https://github.com/Dr-Noob/gpufetch/issues\n");
if(print_gpufetch(gpu, get_style(), get_colors()))
return EXIT_SUCCESS;
else
return EXIT_FAILURE;
if(!print_gpufetch(gpu, get_style(), get_colors())) {
print_failed = true;
}
}
if(print_failed) return EXIT_SUCCESS;
else return EXIT_FAILURE;
}

View File

@@ -81,15 +81,6 @@ int get_num_gpus_available(struct gpu_list* list) {
return list->num_gpus;
}
bool gpu_idx_valid(int idx) {
if(idx < 0) {
printErr("Specified GPU index is out of range: %d. ", idx);
printf("Run gpufetch with the --%s option to check out valid GPU indexes\n", args_str[ARG_LIST]);
return false;
}
return true;
}
struct gpu_info* get_gpu_info(struct gpu_list* list, int idx) {
if(idx >= list->num_gpus || idx < 0) {
printErr("Specified GPU index is out of range: %d", idx);

View File

@@ -9,7 +9,6 @@ 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();
bool gpu_idx_valid(int idx);
struct gpu_info* get_gpu_info(struct gpu_list* list, int idx);
#endif