[v0.20] Merge Intel iGPU branch for preeliminary Intel GPU support
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
#ifndef __GPUCHIPS__
|
||||
#define __GPUCHIPS__
|
||||
#ifndef __CUDA_GPUCHIPS__
|
||||
#define __CUDA_GPUCHIPS__
|
||||
|
||||
typedef uint32_t GPUCHIP;
|
||||
|
||||
enum {
|
||||
CHIP_UNKNOWN,
|
||||
CHIP_UNKNOWN_CUDA,
|
||||
CHIP_G80,
|
||||
CHIP_G80GL,
|
||||
CHIP_G84,
|
||||
|
||||
@@ -6,40 +6,12 @@
|
||||
#include "../common/pci.hpp"
|
||||
#include "../common/global.hpp"
|
||||
|
||||
int print_gpus_list() {
|
||||
cudaError_t err = cudaSuccess;
|
||||
int num_gpus = -1;
|
||||
bool print_gpu_cuda(struct gpu_info* gpu) {
|
||||
char* cc = get_str_cc(gpu->arch);
|
||||
printf("%s (Compute Capability %s)\n", gpu->name, cc);
|
||||
free(cc);
|
||||
|
||||
if ((err = cudaGetDeviceCount(&num_gpus)) != cudaSuccess) {
|
||||
printErr("%s: %s", cudaGetErrorName(err), cudaGetErrorString(err));
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
printf("CUDA GPUs available: %d\n", num_gpus);
|
||||
|
||||
if(num_gpus > 0) {
|
||||
cudaDeviceProp deviceProp;
|
||||
int max_len = 0;
|
||||
|
||||
for(int idx=0; idx < num_gpus; idx++) {
|
||||
if ((err = cudaGetDeviceProperties(&deviceProp, idx)) != cudaSuccess) {
|
||||
printErr("%s: %s", cudaGetErrorName(err), cudaGetErrorString(err));
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
max_len = max(max_len, (int) strlen(deviceProp.name));
|
||||
}
|
||||
|
||||
for(int i=0; i < max_len + 32; i++) putchar('-');
|
||||
putchar('\n');
|
||||
for(int idx=0; idx < num_gpus; idx++) {
|
||||
if ((err = cudaGetDeviceProperties(&deviceProp, idx)) != cudaSuccess) {
|
||||
printErr("%s: %s", cudaGetErrorName(err), cudaGetErrorString(err));
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
printf("GPU %d: %s (Compute Capability %d.%d)\n", idx, deviceProp.name, deviceProp.major, deviceProp.minor);
|
||||
}
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
return true;
|
||||
}
|
||||
|
||||
struct cache* get_cache_info(cudaDeviceProp prop) {
|
||||
@@ -104,12 +76,12 @@ struct memory* get_memory_info(struct gpu_info* gpu, cudaDeviceProp prop) {
|
||||
}
|
||||
|
||||
// Compute peak performance when using CUDA cores
|
||||
int64_t get_peak_performance(struct gpu_info* gpu) {
|
||||
int64_t get_peak_performance_cuda(struct gpu_info* gpu) {
|
||||
return gpu->freq * 1000000 * gpu->topo->cuda_cores * 2;
|
||||
}
|
||||
|
||||
// Compute peak performance when using tensor cores
|
||||
int64_t get_peak_performance_t(cudaDeviceProp prop, struct gpu_info* gpu) {
|
||||
int64_t get_peak_performance_tcu(cudaDeviceProp prop, struct gpu_info* gpu) {
|
||||
// Volta / Turing tensor cores performs 4x4x4 FP16 matrix multiplication
|
||||
// Ampere tensor cores performs 8x4x8 FP16 matrix multiplicacion
|
||||
if(prop.major == 7) return gpu->freq * 1000000 * 4 * 4 * 4 * 2 * gpu->topo->tensor_cores;
|
||||
@@ -117,7 +89,7 @@ int64_t get_peak_performance_t(cudaDeviceProp prop, struct gpu_info* gpu) {
|
||||
else return 0;
|
||||
}
|
||||
|
||||
struct gpu_info* get_gpu_info(int gpu_idx) {
|
||||
struct gpu_info* get_gpu_info_cuda(int gpu_idx) {
|
||||
struct gpu_info* gpu = (struct gpu_info*) emalloc(sizeof(struct gpu_info));
|
||||
gpu->pci = NULL;
|
||||
gpu->idx = gpu_idx;
|
||||
@@ -127,8 +99,10 @@ struct gpu_info* get_gpu_info(int gpu_idx) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
printf("Waiting for CUDA driver to start...");
|
||||
fflush(stdout);
|
||||
if(gpu_idx == 0) {
|
||||
printf("Waiting for CUDA driver to start...");
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
int num_gpus = -1;
|
||||
cudaError_t err = cudaSuccess;
|
||||
@@ -136,7 +110,10 @@ struct gpu_info* get_gpu_info(int gpu_idx) {
|
||||
printErr("%s: %s", cudaGetErrorName(err), cudaGetErrorString(err));
|
||||
return NULL;
|
||||
}
|
||||
printf("\r ");
|
||||
|
||||
if(gpu_idx == 0) {
|
||||
printf("\r");
|
||||
}
|
||||
|
||||
if(num_gpus <= 0) {
|
||||
printErr("No CUDA capable devices found!");
|
||||
@@ -144,7 +121,7 @@ struct gpu_info* get_gpu_info(int gpu_idx) {
|
||||
}
|
||||
|
||||
if(gpu->idx+1 > num_gpus) {
|
||||
printErr("Requested GPU index %d in a system with %d GPUs", gpu->idx, num_gpus);
|
||||
// Master is trying to query an invalid GPU
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -160,25 +137,22 @@ struct gpu_info* get_gpu_info(int gpu_idx) {
|
||||
strcpy(gpu->name, deviceProp.name);
|
||||
|
||||
struct pci_dev *devices = get_pci_devices_from_pciutils();
|
||||
gpu->pci = get_pci_from_pciutils(devices);
|
||||
gpu->pci = get_pci_from_pciutils(devices, PCI_VENDOR_ID_NVIDIA);
|
||||
gpu->arch = get_uarch_from_cuda(gpu);
|
||||
gpu->cach = get_cache_info(deviceProp);
|
||||
gpu->mem = get_memory_info(gpu, deviceProp);
|
||||
gpu->topo = get_topology_info(deviceProp);
|
||||
<<<<<<< HEAD
|
||||
gpu->peak_performance = get_peak_performance(gpu);
|
||||
gpu->peak_performance_t = get_peak_performance_t(deviceProp, gpu);
|
||||
=======
|
||||
gpu->peak_performance = get_peak_performance_cuda(gpu);
|
||||
gpu->peak_performance_tcu = get_peak_performance_tcu(gpu);
|
||||
>>>>>>> origin/intel
|
||||
|
||||
return gpu;
|
||||
}
|
||||
|
||||
char* get_str_generic(int32_t data) {
|
||||
// Largest int is 10, +1 for possible negative, +1 for EOL
|
||||
uint32_t max_size = 12;
|
||||
char* dummy = (char *) ecalloc(max_size, sizeof(char));
|
||||
snprintf(dummy, max_size, "%d", data);
|
||||
return dummy;
|
||||
}
|
||||
|
||||
char* get_str_sm(struct gpu_info* gpu) {
|
||||
return get_str_generic(gpu->topo->streaming_mp);
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
#ifndef __CUDA__
|
||||
#define __CUDA__
|
||||
#ifndef __CUDA_GPU__
|
||||
#define __CUDA_GPU__
|
||||
|
||||
#include "../common/gpu.hpp"
|
||||
|
||||
struct gpu_info* get_gpu_info(int gpu_idx);
|
||||
int print_gpus_list();
|
||||
struct gpu_info* get_gpu_info_cuda(int gpu_idx);
|
||||
bool print_gpu_cuda(struct gpu_info* gpu);
|
||||
char* get_str_sm(struct gpu_info* gpu);
|
||||
char* get_str_cores_sm(struct gpu_info* gpu);
|
||||
char* get_str_cuda_cores(struct gpu_info* gpu);
|
||||
|
||||
@@ -8,21 +8,7 @@
|
||||
#define CHECK_PCI_START if (false) {}
|
||||
#define CHECK_PCI(pci, id, chip) \
|
||||
else if (pci->device_id == id) return chip;
|
||||
#define CHECK_PCI_END else { printBug("TODOO"); return CHIP_UNKNOWN; }
|
||||
|
||||
struct pci {
|
||||
uint16_t vendor_id;
|
||||
uint16_t device_id;
|
||||
};
|
||||
|
||||
struct pci* get_pci_from_pciutils(struct pci_dev *devices) {
|
||||
struct pci* pci = (struct pci*) emalloc(sizeof(struct pci));
|
||||
|
||||
pci->vendor_id = pciutils_get_pci_vendor_id(devices);
|
||||
pci->device_id = pciutils_get_pci_device_id(devices);
|
||||
|
||||
return pci;
|
||||
}
|
||||
#define CHECK_PCI_END else { printBug("Unkown CUDA device id: 0x%.4X", pci->device_id); return CHIP_UNKNOWN_CUDA; }
|
||||
|
||||
/*
|
||||
* pci ids were retrieved using https://github.com/pciutils/pciids
|
||||
@@ -33,7 +19,7 @@ struct pci* get_pci_from_pciutils(struct pci_dev *devices) {
|
||||
* or in pci.ids itself)
|
||||
*/
|
||||
|
||||
GPUCHIP get_chip_from_pci(struct pci* pci) {
|
||||
GPUCHIP get_chip_from_pci_cuda(struct pci* pci) {
|
||||
CHECK_PCI_START
|
||||
CHECK_PCI(pci, 0x25e5, CHIP_GA107BM)
|
||||
CHECK_PCI(pci, 0x25e2, CHIP_GA107BM)
|
||||
|
||||
@@ -6,9 +6,14 @@
|
||||
#include "../common/pci.hpp"
|
||||
#include "chips.hpp"
|
||||
|
||||
/*
|
||||
* doc: https://wiki.osdev.org/PCI#Class_Codes
|
||||
* https://pci-ids.ucw.cz/read/PC
|
||||
*/
|
||||
#define PCI_VENDOR_ID_NVIDIA 0x10de
|
||||
|
||||
struct pci;
|
||||
|
||||
struct pci* get_pci_from_pciutils(struct pci_dev *devices);
|
||||
GPUCHIP get_chip_from_pci(struct pci* pci);
|
||||
GPUCHIP get_chip_from_pci_cuda(struct pci* pci);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -3,21 +3,14 @@
|
||||
#include <stdint.h>
|
||||
#include <cstddef>
|
||||
|
||||
#include "../common/uarch.hpp"
|
||||
#include "../common/global.hpp"
|
||||
#include "../common/gpu.hpp"
|
||||
#include "chips.hpp"
|
||||
|
||||
typedef uint32_t MICROARCH;
|
||||
|
||||
// Any clock multiplier
|
||||
#define CM_ANY -1
|
||||
|
||||
// Data not available
|
||||
#define NA -1
|
||||
|
||||
// Unknown manufacturing process
|
||||
#define UNK -1
|
||||
|
||||
// MICROARCH values
|
||||
enum {
|
||||
UARCH_UNKNOWN,
|
||||
@@ -43,23 +36,10 @@ static const char *uarch_str[] = {
|
||||
/*[ARCH_AMPERE] = */ "Ampere",
|
||||
};
|
||||
|
||||
struct uarch {
|
||||
int32_t cc_major;
|
||||
int32_t cc_minor;
|
||||
int32_t compute_capability;
|
||||
|
||||
MICROARCH uarch;
|
||||
GPUCHIP chip;
|
||||
|
||||
int32_t process;
|
||||
char* uarch_str;
|
||||
char* chip_str;
|
||||
};
|
||||
|
||||
#define CHECK_UARCH_START if (false) {}
|
||||
#define CHECK_UARCH(arch, chip_, str, uarch, process) \
|
||||
else if (arch->chip == chip_) fill_uarch(arch, str, uarch, process);
|
||||
#define CHECK_UARCH_END else { printBug("map_chip_to_uarch: Unknown chip id: %d", arch->chip); fill_uarch(arch, STRING_UNKNOWN, UARCH_UNKNOWN, 0); }
|
||||
#define CHECK_UARCH_END else { if(arch->chip != CHIP_UNKNOWN_CUDA) printBug("map_chip_to_uarch_cuda: Unknown chip id: %d", arch->chip); fill_uarch(arch, STRING_UNKNOWN, UARCH_UNKNOWN, 0); }
|
||||
|
||||
void fill_uarch(struct uarch* arch, char const *str, MICROARCH u, uint32_t process) {
|
||||
arch->chip_str = (char *) emalloc(sizeof(char) * (strlen(str)+1));
|
||||
@@ -74,7 +54,7 @@ void fill_uarch(struct uarch* arch, char const *str, MICROARCH u, uint32_t proce
|
||||
* o CHIP_XXXGL: indicates a professional-class (Quadro/Tesla) chip
|
||||
* o CHIP_XXXM: indicates a mobile chip
|
||||
*/
|
||||
void map_chip_to_uarch(struct uarch* arch) {
|
||||
void map_chip_to_uarch_cuda(struct uarch* arch) {
|
||||
CHECK_UARCH_START
|
||||
// TESLA (1.0, 1.1, 1.2, 1.3) //
|
||||
CHECK_UARCH(arch, CHIP_G80, "G80", UARCH_TESLA, 90)
|
||||
@@ -263,9 +243,8 @@ struct uarch* get_uarch_from_cuda(struct gpu_info* gpu) {
|
||||
arch->cc_major = deviceProp.major;
|
||||
arch->cc_minor = deviceProp.minor;
|
||||
arch->compute_capability = deviceProp.major * 10 + deviceProp.minor;
|
||||
arch->chip = get_chip_from_pci(gpu->pci);
|
||||
|
||||
map_chip_to_uarch(arch);
|
||||
arch->chip = get_chip_from_pci_cuda(gpu->pci);
|
||||
map_chip_to_uarch_cuda(arch);
|
||||
|
||||
return arch;
|
||||
}
|
||||
@@ -335,10 +314,6 @@ MEMTYPE guess_memtype_from_cmul_and_uarch(int clkm, struct uarch* arch) {
|
||||
CHECK_MEMTYPE_END
|
||||
}
|
||||
|
||||
const char* get_str_uarch(struct uarch* arch) {
|
||||
return uarch_str[arch->uarch];
|
||||
}
|
||||
|
||||
char* get_str_cc(struct uarch* arch) {
|
||||
uint32_t max_size = 4;
|
||||
char* cc = (char *) ecalloc(max_size, sizeof(char));
|
||||
@@ -346,31 +321,14 @@ char* get_str_cc(struct uarch* arch) {
|
||||
return cc;
|
||||
}
|
||||
|
||||
char* get_str_process(struct uarch* arch) {
|
||||
char* str = (char *) emalloc(sizeof(char) * (strlen(STRING_UNKNOWN)+1));
|
||||
int32_t process = arch->process;
|
||||
|
||||
if(process == UNK) {
|
||||
snprintf(str, strlen(STRING_UNKNOWN)+1, STRING_UNKNOWN);
|
||||
}
|
||||
else if(process > 100) {
|
||||
sprintf(str, "%.2fum", (double)process/100);
|
||||
}
|
||||
else if(process > 0){
|
||||
sprintf(str, "%dnm", process);
|
||||
}
|
||||
else {
|
||||
snprintf(str, strlen(STRING_UNKNOWN)+1, STRING_UNKNOWN);
|
||||
printBug("Found invalid process: '%d'", process);
|
||||
}
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
char* get_str_chip(struct uarch* arch) {
|
||||
return arch->chip_str;
|
||||
}
|
||||
|
||||
const char* get_str_uarch_cuda(struct uarch* arch) {
|
||||
return uarch_str[arch->uarch];
|
||||
}
|
||||
|
||||
void free_uarch_struct(struct uarch* arch) {
|
||||
free(arch->uarch_str);
|
||||
free(arch->chip_str);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#ifndef __UARCH__
|
||||
#define __UARCH__
|
||||
#ifndef __CUDA_UARCH__
|
||||
#define __CUDA_UARCH__
|
||||
|
||||
#include "../common/gpu.hpp"
|
||||
|
||||
@@ -8,7 +8,7 @@ struct uarch;
|
||||
struct uarch* get_uarch_from_cuda(struct gpu_info* gpu);
|
||||
bool clkm_possible_for_uarch(int clkm, struct uarch* arch);
|
||||
MEMTYPE guess_memtype_from_cmul_and_uarch(int ddr, struct uarch* arch);
|
||||
char* get_str_uarch(struct uarch* arch);
|
||||
char* get_str_uarch_cuda(struct uarch* arch);
|
||||
char* get_str_cc(struct uarch* arch);
|
||||
char* get_str_chip(struct uarch* arch);
|
||||
char* get_str_process(struct uarch* arch);
|
||||
|
||||
Reference in New Issue
Block a user