diff --git a/.gitignore b/.gitignore index 17a84ce..f74d71c 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ gpufetch +build/ diff --git a/src/common/main.cpp b/src/common/main.cpp index f0b16af..2561966 100644 --- a/src/common/main.cpp +++ b/src/common/main.cpp @@ -71,6 +71,11 @@ 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()) { return print_gpus_list(list); @@ -86,7 +91,7 @@ int main(int argc, char* argv[]) { return EXIT_FAILURE; } - struct gpu_info* gpu = get_gpu_info(list, get_gpu_idx()); + struct gpu_info* gpu = get_gpu_info(list, idx); if(gpu == NULL) return EXIT_FAILURE; diff --git a/src/common/master.cpp b/src/common/master.cpp index b78ccc6..2a65a2d 100644 --- a/src/common/master.cpp +++ b/src/common/master.cpp @@ -5,6 +5,7 @@ #include "global.hpp" #include "colors.hpp" #include "master.hpp" +#include "args.hpp" #include "../cuda/cuda.hpp" #include "../intel/intel.hpp" @@ -80,9 +81,19 @@ 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); + printf("Run gpufetch with the --%s option to check out valid GPU indexes\n", args_str[ARG_LIST]); return NULL; } return list->gpus[idx]; diff --git a/src/common/master.hpp b/src/common/master.hpp index ad710c5..8de7b3a 100644 --- a/src/common/master.hpp +++ b/src/common/master.hpp @@ -9,6 +9,7 @@ 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 diff --git a/src/common/pci.cpp b/src/common/pci.cpp index 692f9b5..3cc4d8b 100644 --- a/src/common/pci.cpp +++ b/src/common/pci.cpp @@ -99,18 +99,23 @@ void print_gpus_list_pci() { struct pci_dev *devices = get_pci_devices_from_pciutils(); for(struct pci_dev *dev=devices; dev != NULL; dev=dev->next) { - if(dev->device_class == CLASS_VGA_CONTROLLER) { - printf("- GPU %d: ", i); + if(dev->device_class == CLASS_VGA_CONTROLLER) { + printf("- GPU %d:\n", i); + printf(" * Vendor: "); if(dev->vendor_id == PCI_VENDOR_ID_NVIDIA) { - printf("NVIDIA "); + printf("NVIDIA"); } else if(dev->vendor_id == PCI_VENDOR_ID_INTEL) { - printf("Intel "); + printf("Intel"); } else if(dev->vendor_id == PCI_VENDOR_ID_AMD) { - printf("AMD "); + printf("AMD"); } - printf("%.4x:%.4x\n", dev->vendor_id, dev->device_id); + else { + printf("Unknown"); + } + printf("\n * PCI id: %.4x:%.4x\n", dev->vendor_id, dev->device_id); + i++; } } }