[v0.25] Add option to print all GPUs as requested in #33
This commit is contained in:
@@ -246,12 +246,23 @@ bool parse_args(int argc, char* argv[]) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(opt == args_chr[ARG_GPU]) {
|
else if(opt == args_chr[ARG_GPU]) {
|
||||||
|
// Check for "a" option
|
||||||
|
if(strcmp(optarg, "a") == 0) {
|
||||||
|
args.gpu_idx = -1;
|
||||||
|
}
|
||||||
|
else {
|
||||||
args.gpu_idx = getarg_int(optarg);
|
args.gpu_idx = getarg_int(optarg);
|
||||||
if(errn != 0) {
|
if(errn != 0) {
|
||||||
printErr("Option %s: %s", args_str[ARG_GPU], getarg_error());
|
printErr("Option %s: %s", args_str[ARG_GPU], getarg_error());
|
||||||
args.help_flag = true;
|
args.help_flag = true;
|
||||||
return false;
|
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]) {
|
else if(opt == args_chr[ARG_LIST]) {
|
||||||
args.list_gpus = true;
|
args.list_gpus = true;
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ void print_help(char *argv[]) {
|
|||||||
printf("Options: \n");
|
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 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 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 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(" --%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])), "");
|
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());
|
set_log_level(verbose_enabled());
|
||||||
|
|
||||||
int idx = get_gpu_idx();
|
int idx = get_gpu_idx();
|
||||||
if(!gpu_idx_valid(idx)) {
|
|
||||||
return EXIT_FAILURE;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct gpu_list* list = get_gpu_list();
|
struct gpu_list* list = get_gpu_list();
|
||||||
if(list_gpus()) {
|
if(list_gpus()) {
|
||||||
@@ -91,7 +88,20 @@ int main(int argc, char* argv[]) {
|
|||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct gpu_info* gpu = get_gpu_info(list, idx);
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
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)
|
if(gpu == NULL)
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
|
|
||||||
@@ -100,8 +110,11 @@ If you want to help to improve gpufetch, please compare the output of the progra
|
|||||||
with a reliable source which you know is right (e.g, techpowerup.com) and report\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");
|
any inconsistencies to https://github.com/Dr-Noob/gpufetch/issues\n");
|
||||||
|
|
||||||
if(print_gpufetch(gpu, get_style(), get_colors()))
|
if(!print_gpufetch(gpu, get_style(), get_colors())) {
|
||||||
return EXIT_SUCCESS;
|
print_failed = true;
|
||||||
else
|
}
|
||||||
return EXIT_FAILURE;
|
}
|
||||||
|
|
||||||
|
if(print_failed) return EXIT_SUCCESS;
|
||||||
|
else return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -81,15 +81,6 @@ int get_num_gpus_available(struct gpu_list* list) {
|
|||||||
return list->num_gpus;
|
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) {
|
struct gpu_info* get_gpu_info(struct gpu_list* list, int idx) {
|
||||||
if(idx >= list->num_gpus || idx < 0) {
|
if(idx >= list->num_gpus || idx < 0) {
|
||||||
printErr("Specified GPU index is out of range: %d", idx);
|
printErr("Specified GPU index is out of range: %d", idx);
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ struct gpu_list* get_gpu_list();
|
|||||||
bool print_gpus_list(struct gpu_list* list);
|
bool print_gpus_list(struct gpu_list* list);
|
||||||
int get_num_gpus_available(struct gpu_list* list);
|
int get_num_gpus_available(struct gpu_list* list);
|
||||||
void print_enabled_backends();
|
void print_enabled_backends();
|
||||||
bool gpu_idx_valid(int idx);
|
|
||||||
struct gpu_info* get_gpu_info(struct gpu_list* list, int idx);
|
struct gpu_info* get_gpu_info(struct gpu_list* list, int idx);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user