[v0.01] Reading PCI vendor/device values, needed to deduce the GPU chip and thus manufacturing process

This commit is contained in:
Dr-Noob
2021-08-13 11:31:51 +02:00
parent 8bc37d9d71
commit bdc4fd7c45
7 changed files with 134 additions and 3 deletions

View File

@@ -2,6 +2,7 @@
#include <cuda_runtime.h>
#include "cuda.hpp"
#include "nvmlb.hpp"
#include "uarch.hpp"
#include "../common/global.hpp"
@@ -29,6 +30,7 @@ int64_t get_peak_performance(struct gpu_info* gpu) {
struct gpu_info* get_gpu_info() {
struct gpu_info* gpu = (struct gpu_info*) emalloc(sizeof(struct gpu_info));
gpu->pci = NULL;
printf("Waiting for CUDA driver to start...\n");
int dev = 0;
@@ -41,6 +43,11 @@ struct gpu_info* get_gpu_info() {
strcpy(gpu->name, deviceProp.name);
gpu->freq = 10000;
gpu->nvmld = nvml_init();
if(nvml_get_pci_info(dev, gpu->nvmld)) {
gpu->pci = get_pci_from_nvml(gpu->nvmld);
}
gpu->arch = get_uarch_from_cuda(gpu);
gpu->cach = get_cache_info(gpu);
gpu->topo = get_topology_info(gpu);

70
src/cuda/nvmlb.cpp Normal file
View File

@@ -0,0 +1,70 @@
#include <nvml.h>
#include "nvmlb.hpp"
#include "../common/global.hpp"
struct nvml_data {
bool nvml_started;
nvmlPciInfo_t pci;
};
struct nvml_data* nvml_init() {
struct nvml_data* data = (struct nvml_data*) emalloc(sizeof(struct nvml_data));
data->nvml_started = false;
nvmlReturn_t result;
if ((result = nvmlInit()) != NVML_SUCCESS) {
printErr("nvmlInit: %s\n", nvmlErrorString(result));
return NULL;
}
data->nvml_started = true;
return data;
}
bool nvml_get_pci_info(int dev, struct nvml_data* data) {
nvmlReturn_t result;
nvmlDevice_t device;
if(!data->nvml_started) {
printErr("nvml_get_pci_info: nvml was not started");
return false;
}
if ((result = nvmlDeviceGetHandleByIndex(dev, &device)) != NVML_SUCCESS) {
printErr("nvmlDeviceGetHandleByIndex: %s\n", nvmlErrorString(result));
return false;
}
if ((result = nvmlDeviceGetPciInfo(device, &data->pci)) != result) {
printErr("nvmlDeviceGetPciInfo: %s\n", nvmlErrorString(result));
return false;
}
return true;
}
uint16_t nvml_get_pci_vendor_id(struct nvml_data* data) {
return data->pci.pciDeviceId & 0x0000FFFF;
}
uint16_t nvml_get_pci_device_id(struct nvml_data* data) {
return (data->pci.pciDeviceId & 0xFFFF0000) >> 16;
}
bool nvml_shutdown(struct nvml_data* data) {
nvmlReturn_t result;
if(!data->nvml_started) {
printWarn("nvml_get_pci_info: nvml was not started");
return true;
}
if ((result = nvmlShutdown()) != NVML_SUCCESS) {
printErr("nvmlShutdown: %s\n", nvmlErrorString(result));
return false;
}
return true;
}

16
src/cuda/nvmlb.hpp Normal file
View File

@@ -0,0 +1,16 @@
// NVML Backend
#ifndef __NVMLB__
#define __NVMLB__
#include <stdbool.h>
#include <stdint.h>
struct nvml_data;
struct nvml_data* nvml_init();
bool nvml_get_pci_info(int dev, struct nvml_data* data);
uint16_t nvml_get_pci_vendor_id(struct nvml_data* data);
uint16_t nvml_get_pci_device_id(struct nvml_data* data);
bool nvml_shutdown(struct nvml_data* data);
#endif

22
src/cuda/pci.cpp Normal file
View File

@@ -0,0 +1,22 @@
#include <stdio.h>
#include "pci.hpp"
#include "nvmlb.hpp"
#include "../common/global.hpp"
struct pci {
uint16_t vendor_id;
uint16_t device_id;
};
struct pci* get_pci_from_nvml(struct nvml_data* data) {
struct pci* pci = (struct pci*) emalloc(sizeof(struct pci));
pci->vendor_id = nvml_get_pci_vendor_id(data);
pci->device_id = nvml_get_pci_device_id(data);
printf("pci->vendor_id=0x%.4X\n", pci->vendor_id);
printf("pci->device_id=0x%.4X\n", pci->device_id);
return pci;
}

11
src/cuda/pci.hpp Normal file
View File

@@ -0,0 +1,11 @@
#ifndef __PCI__
#define __PCI__
#include <stdint.h>
#include "nvmlb.hpp"
struct pci;
struct pci* get_pci_from_nvml(struct nvml_data* data);
#endif