From 8d2f50b398bc670257de533c2d83d27bad59c430 Mon Sep 17 00:00:00 2001 From: Dr-Noob Date: Tue, 28 Dec 2021 15:40:29 +0100 Subject: [PATCH] [v0.21] Print GPU list even when no valid GPU is detected, to improve user understanding --- src/common/main.cpp | 3 ++- src/common/pci.cpp | 27 +++++++++++++++++++++++++++ src/common/pci.hpp | 1 + 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/src/common/main.cpp b/src/common/main.cpp index 0bf2bea..d6d5367 100644 --- a/src/common/main.cpp +++ b/src/common/main.cpp @@ -75,7 +75,8 @@ int main(int argc, char* argv[]) { } if(get_num_gpus_available(list) == 0) { - printErr("No GPU was detected, or the detected GPU is not supported by gpufetch"); + printErr("No GPU was detected! Available GPUs are:"); + print_gpus_list_pci(); 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"); diff --git a/src/common/pci.cpp b/src/common/pci.cpp index 45a48d2..f7b5d66 100644 --- a/src/common/pci.cpp +++ b/src/common/pci.cpp @@ -1,7 +1,13 @@ #include "global.hpp" #include "pci.hpp" +#include "../cuda/pci.hpp" +#include "../intel/pci.hpp" + +#include #include +// TODO: Move AMD PCI id when possible +#define PCI_VENDOR_ID_AMD 0x1002 #define CLASS_VGA_CONTROLLER 0x0300 bool pciutils_is_vendor_id_present(struct pci_dev *devices, int id) { @@ -71,3 +77,24 @@ struct pci_dev *get_pci_devices_from_pciutils() { return pacc->devices; } + +void print_gpus_list_pci() { + int i=0; + 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->vendor_id == PCI_VENDOR_ID_NVIDIA) { + printf("NVIDIA "); + } + else if(dev->vendor_id == PCI_VENDOR_ID_INTEL) { + printf("Intel "); + } + else if(dev->vendor_id == PCI_VENDOR_ID_AMD) { + printf("AMD "); + } + printf("%.4x:%.4x\n", dev->vendor_id, dev->device_id); + } + } +} diff --git a/src/common/pci.hpp b/src/common/pci.hpp index 7214545..cdedfd5 100644 --- a/src/common/pci.hpp +++ b/src/common/pci.hpp @@ -17,5 +17,6 @@ struct pci { struct pci* get_pci_from_pciutils(struct pci_dev *devices, int id); struct pci_dev *get_pci_devices_from_pciutils(); +void print_gpus_list_pci(); #endif