[v0.24] Small fixes; improve PCI report when no GPU is found, speedup invalid GPU idx detection
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1 +1,2 @@
|
|||||||
gpufetch
|
gpufetch
|
||||||
|
build/
|
||||||
|
|||||||
@@ -71,6 +71,11 @@ int main(int argc, char* argv[]) {
|
|||||||
|
|
||||||
set_log_level(verbose_enabled());
|
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();
|
struct gpu_list* list = get_gpu_list();
|
||||||
if(list_gpus()) {
|
if(list_gpus()) {
|
||||||
return print_gpus_list(list);
|
return print_gpus_list(list);
|
||||||
@@ -86,7 +91,7 @@ int main(int argc, char* argv[]) {
|
|||||||
return EXIT_FAILURE;
|
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)
|
if(gpu == NULL)
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
#include "global.hpp"
|
#include "global.hpp"
|
||||||
#include "colors.hpp"
|
#include "colors.hpp"
|
||||||
#include "master.hpp"
|
#include "master.hpp"
|
||||||
|
#include "args.hpp"
|
||||||
#include "../cuda/cuda.hpp"
|
#include "../cuda/cuda.hpp"
|
||||||
#include "../intel/intel.hpp"
|
#include "../intel/intel.hpp"
|
||||||
|
|
||||||
@@ -80,9 +81,19 @@ 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);
|
||||||
|
printf("Run gpufetch with the --%s option to check out valid GPU indexes\n", args_str[ARG_LIST]);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
return list->gpus[idx];
|
return list->gpus[idx];
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ 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
|
||||||
|
|||||||
@@ -99,18 +99,23 @@ void print_gpus_list_pci() {
|
|||||||
struct pci_dev *devices = get_pci_devices_from_pciutils();
|
struct pci_dev *devices = get_pci_devices_from_pciutils();
|
||||||
|
|
||||||
for(struct pci_dev *dev=devices; dev != NULL; dev=dev->next) {
|
for(struct pci_dev *dev=devices; dev != NULL; dev=dev->next) {
|
||||||
if(dev->device_class == CLASS_VGA_CONTROLLER) {
|
if(dev->device_class == CLASS_VGA_CONTROLLER) {
|
||||||
printf("- GPU %d: ", i);
|
printf("- GPU %d:\n", i);
|
||||||
|
printf(" * Vendor: ");
|
||||||
if(dev->vendor_id == PCI_VENDOR_ID_NVIDIA) {
|
if(dev->vendor_id == PCI_VENDOR_ID_NVIDIA) {
|
||||||
printf("NVIDIA ");
|
printf("NVIDIA");
|
||||||
}
|
}
|
||||||
else if(dev->vendor_id == PCI_VENDOR_ID_INTEL) {
|
else if(dev->vendor_id == PCI_VENDOR_ID_INTEL) {
|
||||||
printf("Intel ");
|
printf("Intel");
|
||||||
}
|
}
|
||||||
else if(dev->vendor_id == PCI_VENDOR_ID_AMD) {
|
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++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user