[v0.11] Working in master GPU handler for supporting diverse GPU vendors

This commit is contained in:
Dr-Noob
2021-11-26 08:22:30 +01:00
parent 149e5ad62c
commit 461e0d2ede
7 changed files with 54 additions and 14 deletions

View File

@@ -9,8 +9,6 @@ set(COMMON_DIR "${SRC_DIR}/common")
set(CUDA_DIR "${SRC_DIR}/cuda") set(CUDA_DIR "${SRC_DIR}/cuda")
set(INTEL_DIR "${SRC_DIR}/intel") set(INTEL_DIR "${SRC_DIR}/intel")
add_executable(gpufetch ${COMMON_DIR}/main.cpp ${COMMON_DIR}/args.cpp ${COMMON_DIR}/gpu.cpp ${COMMON_DIR}/pci.cpp ${COMMON_DIR}/global.cpp ${COMMON_DIR}/printer.cpp ${COMMON_DIR}/master.cpp)
if(NOT DEFINED ENABLE_INTEL_BACKEND) if(NOT DEFINED ENABLE_INTEL_BACKEND)
set(ENABLE_INTEL_BACKEND true) set(ENABLE_INTEL_BACKEND true)
endif() endif()
@@ -47,15 +45,26 @@ else()
link_libraries(${PCIUTILS_LIBRARIES}) link_libraries(${PCIUTILS_LIBRARIES})
endif() endif()
add_executable(gpufetch ${COMMON_DIR}/main.cpp ${COMMON_DIR}/args.cpp ${COMMON_DIR}/gpu.cpp ${COMMON_DIR}/pci.cpp ${COMMON_DIR}/global.cpp ${COMMON_DIR}/printer.cpp ${COMMON_DIR}/master.cpp)
set(SANITY_FLAGS "-Wfloat-equal -Wshadow -Wpointer-arith") set(SANITY_FLAGS "-Wfloat-equal -Wshadow -Wpointer-arith")
set(CMAKE_CXX_FLAGS "${SANITY_FLAGS} -Wall -Wextra -pedantic -fstack-protector-all -pedantic") set(CMAKE_CXX_FLAGS "${SANITY_FLAGS} -Wall -Wextra -pedantic -fstack-protector-all -pedantic")
if(ENABLE_INTEL_BACKEND) if(ENABLE_INTEL_BACKEND)
target_compile_definitions(gpufetch PUBLIC BACKEND_INTEL)
add_library(intel_backend STATIC ${INTEL_DIR}/intel.cpp) add_library(intel_backend STATIC ${INTEL_DIR}/intel.cpp)
if(NOT ${PCIUTILS_FOUND})
add_dependencies(intel_backend pciutils)
add_dependencies(gpufetch pciutils)
endif()
target_link_libraries(gpufetch intel_backend pci z) target_link_libraries(gpufetch intel_backend pci z)
endif() endif()
if(ENABLE_CUDA_BACKEND) if(ENABLE_CUDA_BACKEND)
target_compile_definitions(gpufetch PUBLIC BACKEND_CUDA)
# https://en.wikipedia.org/w/index.php?title=CUDA&section=5#GPUs_supported # https://en.wikipedia.org/w/index.php?title=CUDA&section=5#GPUs_supported
# https://raw.githubusercontent.com/PointCloudLibrary/pcl/master/cmake/pcl_find_cuda.cmake # https://raw.githubusercontent.com/PointCloudLibrary/pcl/master/cmake/pcl_find_cuda.cmake
if(${CMAKE_CUDA_COMPILER_VERSION} VERSION_GREATER_EQUAL "11.0") if(${CMAKE_CUDA_COMPILER_VERSION} VERSION_GREATER_EQUAL "11.0")

View File

@@ -1,8 +1,10 @@
#include <stdbool.h> #include <stdbool.h>
#include <cstddef> #include <stdlib.h>
#include <cstdlib> #include <stdio.h>
#include "master.hpp" #include "master.hpp"
#include "../cuda/cuda.hpp"
#include "../intel/intel.hpp"
#define MAX_GPUS 1000 #define MAX_GPUS 1000
@@ -12,14 +14,13 @@ struct gpu_list {
}; };
struct gpu_list* get_gpu_list() { struct gpu_list* get_gpu_list() {
int idx = 0;
bool valid = true; bool valid = true;
struct gpu_list* list = (struct gpu_list*) malloc(sizeof(struct gpu_list)); struct gpu_list* list = (struct gpu_list*) malloc(sizeof(struct gpu_list));
list->num_gpus = 0; list->num_gpus = 0;
list->gpus = (struct gpu_info**) malloc(sizeof(struct info*) * MAX_GPUS); list->gpus = (struct gpu_info**) malloc(sizeof(struct info*) * MAX_GPUS);
#ifdef ENABLE_CUDA_BACKEND #ifdef BACKEND_CUDA
int idx = 0;
while(valid) { while(valid) {
list->gpus[idx] = get_gpu_info_cuda(idx); list->gpus[idx] = get_gpu_info_cuda(idx);
if(list->gpus[idx] != NULL) idx++; if(list->gpus[idx] != NULL) idx++;
@@ -29,7 +30,7 @@ struct gpu_list* get_gpu_list() {
list->num_gpus += idx; list->num_gpus += idx;
#endif #endif
#ifdef ENABLE_INTEL_BACKEND #ifdef BACKEND_INTEL
list->gpus[idx] = get_gpu_info_intel(); list->gpus[idx] = get_gpu_info_intel();
if(list->gpus[idx] != NULL) list->num_gpus++; if(list->gpus[idx] != NULL) list->num_gpus++;
#endif #endif
@@ -38,7 +39,21 @@ struct gpu_list* get_gpu_list() {
} }
bool print_gpus_list(struct gpu_list* list) { bool print_gpus_list(struct gpu_list* list) {
return false; for(int i=0; i < list->num_gpus; i++) {
printf("GPU %d: ", i);
if(list->gpus[i]->vendor == GPU_VENDOR_NVIDIA) {
#ifdef ENABLE_CUDA_BACKEND
print_gpu_cuda(list->gpus[i]);
#endif
}
else if(list->gpus[i]->vendor == GPU_VENDOR_INTEL) {
#ifdef ENABLE_INTEL_BACKEND
print_gpu_intel(list->gpus[i]);
#endif
}
}
return true;
} }
struct gpu_info* get_gpu_info(struct gpu_list* list, int idx) { struct gpu_info* get_gpu_info(struct gpu_list* list, int idx) {

View File

@@ -342,13 +342,13 @@ void print_ascii_generic(struct ascii* art, uint32_t la, int32_t text_space, con
printf("\n"); printf("\n");
} }
#ifdef ENABLE_INTEL_BACKEND #ifdef BACKEND_INTEL
bool print_gpufetch_intel(struct gpu_info* gpu, STYLE s, struct color** cs, struct terminal* term) { bool print_gpufetch_intel(struct gpu_info* gpu, STYLE s, struct color** cs, struct terminal* term) {
return false; return false;
} }
#endif #endif
#ifdef ENABLE_CUDA_BACKEND #ifdef BACKEND_CUDA
bool print_gpufetch_cuda(struct gpu_info* gpu, STYLE s, struct color** cs, struct terminal* term) { bool print_gpufetch_cuda(struct gpu_info* gpu, STYLE s, struct color** cs, struct terminal* term) {
struct ascii* art = set_ascii(get_gpu_vendor(gpu), s); struct ascii* art = set_ascii(get_gpu_vendor(gpu), s);
@@ -457,13 +457,13 @@ bool print_gpufetch(struct gpu_info* gpu, STYLE s, struct color** cs) {
struct terminal* term = get_terminal_size(); struct terminal* term = get_terminal_size();
if(gpu->vendor == GPU_VENDOR_NVIDIA) if(gpu->vendor == GPU_VENDOR_NVIDIA)
#ifdef ENABLE_CUDA_BACKEND #ifdef BACKEND_CUDA
return print_gpufetch_cuda(gpu, s, cs, term); return print_gpufetch_cuda(gpu, s, cs, term);
#else #else
return false; return false;
#endif #endif
else { else {
#ifdef ENABLE_INTEL_BACKEND #ifdef BACKEND_INTEL
return print_gpufetch_intel(gpu, s, cs, term); return print_gpufetch_intel(gpu, s, cs, term);
#else #else
return false; return false;

View File

@@ -42,6 +42,10 @@ int print_gpus_list_deprecated() {
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }
bool print_gpu_cuda(struct gpu_info* gpu) {
return false;
}
struct cache* get_cache_info(cudaDeviceProp prop) { struct cache* get_cache_info(cudaDeviceProp prop) {
struct cache* cach = (struct cache*) emalloc(sizeof(struct cache)); struct cache* cach = (struct cache*) emalloc(sizeof(struct cache));

View File

@@ -4,6 +4,7 @@
#include "../common/gpu.hpp" #include "../common/gpu.hpp"
struct gpu_info* get_gpu_info_cuda(int gpu_idx); 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_sm(struct gpu_info* gpu);
char* get_str_cores_sm(struct gpu_info* gpu); char* get_str_cores_sm(struct gpu_info* gpu);
char* get_str_cuda_cores(struct gpu_info* gpu); char* get_str_cuda_cores(struct gpu_info* gpu);

View File

@@ -1,3 +1,5 @@
#include <stdio.h>
#include "intel.hpp" #include "intel.hpp"
#include "uarch.hpp" #include "uarch.hpp"
#include "../common/pci.hpp" #include "../common/pci.hpp"
@@ -8,3 +10,11 @@ struct gpu_info* get_gpu_info_intel() {
return gpu; return gpu;
} }
bool print_gpu_intel(struct gpu_info* gpu) {
if(gpu->vendor != GPU_VENDOR_INTEL) return false;
printf("%s\n", gpu->name);
return true;
}

View File

@@ -3,6 +3,7 @@
#include "../common/gpu.hpp" #include "../common/gpu.hpp"
struct gpu_info* get_gpu_info_intel(int gpu_idx); struct gpu_info* get_gpu_info_intel();
bool print_gpu_intel(struct gpu_info* gpu);
#endif #endif