[v0.10] Replace nvml by pciutils to get pci ids. Needs work to integrate it properly. NVML is enough in the case of NVIDIA GPUs, but because more GPUs will be added in the future, a solution like pciutils is needed

This commit is contained in:
Dr-Noob
2021-09-04 12:19:42 +02:00
parent 4b4d1bc030
commit 039e7c350d
10 changed files with 69 additions and 109 deletions

View File

@@ -2,7 +2,6 @@
#define __GLOBAL__
#include <stdbool.h>
#include <stddef.h>
#include <cstddef>
#define STRING_UNKNOWN "Unknown"

View File

@@ -4,7 +4,6 @@
#include <stdint.h>
#include <stdbool.h>
#include "../cuda/nvmlb.hpp"
#include "../cuda/pci.hpp"
#define UNKNOWN_FREQ -1
@@ -57,7 +56,6 @@ struct gpu_info {
char* name;
int64_t freq;
struct pci* pci;
struct nvml_data* nvmld;
struct topology* topo;
struct memory* mem;
struct cache* cach;

37
src/common/pci.cpp Normal file
View File

@@ -0,0 +1,37 @@
#include "pci.hpp"
#include <cstddef>
/*
* doc: https://wiki.osdev.org/PCI#Class_Codes
* https://pci-ids.ucw.cz/read/PC
*/
#define VENDOR_ID_NVIDIA 0x10de
#define CLASS_VGA_CONTROLLER 0x0300
uint16_t pciutils_get_pci_vendor_id(struct pci_dev *devices) {
for(struct pci_dev *dev=devices; dev != NULL; dev=dev->next) {
if(dev->vendor_id == VENDOR_ID_NVIDIA && dev->device_class == CLASS_VGA_CONTROLLER) {
return dev->vendor_id;
}
}
return 0;
}
uint16_t pciutils_get_pci_device_id(struct pci_dev *devices) {
for(struct pci_dev *dev=devices; dev != NULL; dev=dev->next) {
if(dev->vendor_id == VENDOR_ID_NVIDIA && dev->device_class == CLASS_VGA_CONTROLLER) {
return dev->device_id;
}
}
return 0;
}
struct pci_dev *get_pci_devices_from_pciutils() {
struct pci_access *pacc;
pacc = pci_alloc();
pci_init(pacc);
pci_scan_bus(pacc);
return pacc->devices;
}

13
src/common/pci.hpp Normal file
View File

@@ -0,0 +1,13 @@
#ifndef __GPUFETCH_PCI__
#define __GPUFETCH_PCI__
#include <cstdint>
extern "C" {
#include <pci/pci.h>
}
uint16_t pciutils_get_pci_vendor_id(struct pci_dev *devices);
uint16_t pciutils_get_pci_device_id(struct pci_dev *devices);
struct pci_dev *get_pci_devices_from_pciutils();
#endif