[v0.21] Print GPU list even when no valid GPU is detected, to improve user understanding

This commit is contained in:
Dr-Noob
2021-12-28 15:40:29 +01:00
parent 8bfe88f9f6
commit 8d2f50b398
3 changed files with 30 additions and 1 deletions

View File

@@ -1,7 +1,13 @@
#include "global.hpp"
#include "pci.hpp"
#include "../cuda/pci.hpp"
#include "../intel/pci.hpp"
#include <cstdio>
#include <cstddef>
// 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);
}
}
}