diff --git a/CMakeLists.txt b/CMakeLists.txt index 7ec324e..f65bdf4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,8 +9,6 @@ set(COMMON_DIR "${SRC_DIR}/common") set(CUDA_DIR "${SRC_DIR}/cuda") 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) set(ENABLE_INTEL_BACKEND true) endif() @@ -47,15 +45,26 @@ else() link_libraries(${PCIUTILS_LIBRARIES}) 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(CMAKE_CXX_FLAGS "${SANITY_FLAGS} -Wall -Wextra -pedantic -fstack-protector-all -pedantic") if(ENABLE_INTEL_BACKEND) + target_compile_definitions(gpufetch PUBLIC BACKEND_INTEL) + 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) endif() if(ENABLE_CUDA_BACKEND) + target_compile_definitions(gpufetch PUBLIC BACKEND_CUDA) + # https://en.wikipedia.org/w/index.php?title=CUDA§ion=5#GPUs_supported # https://raw.githubusercontent.com/PointCloudLibrary/pcl/master/cmake/pcl_find_cuda.cmake if(${CMAKE_CUDA_COMPILER_VERSION} VERSION_GREATER_EQUAL "11.0") diff --git a/src/common/master.cpp b/src/common/master.cpp index 49cec7a..ae45d45 100644 --- a/src/common/master.cpp +++ b/src/common/master.cpp @@ -1,8 +1,10 @@ #include -#include -#include +#include +#include #include "master.hpp" +#include "../cuda/cuda.hpp" +#include "../intel/intel.hpp" #define MAX_GPUS 1000 @@ -12,14 +14,13 @@ struct gpu_list { }; struct gpu_list* get_gpu_list() { + int idx = 0; bool valid = true; struct gpu_list* list = (struct gpu_list*) malloc(sizeof(struct gpu_list)); list->num_gpus = 0; list->gpus = (struct gpu_info**) malloc(sizeof(struct info*) * MAX_GPUS); -#ifdef ENABLE_CUDA_BACKEND - int idx = 0; - +#ifdef BACKEND_CUDA while(valid) { list->gpus[idx] = get_gpu_info_cuda(idx); if(list->gpus[idx] != NULL) idx++; @@ -29,7 +30,7 @@ struct gpu_list* get_gpu_list() { list->num_gpus += idx; #endif -#ifdef ENABLE_INTEL_BACKEND +#ifdef BACKEND_INTEL list->gpus[idx] = get_gpu_info_intel(); if(list->gpus[idx] != NULL) list->num_gpus++; #endif @@ -38,7 +39,21 @@ struct gpu_list* get_gpu_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) { diff --git a/src/common/printer.cpp b/src/common/printer.cpp index abc341d..23b14db 100644 --- a/src/common/printer.cpp +++ b/src/common/printer.cpp @@ -342,13 +342,13 @@ void print_ascii_generic(struct ascii* art, uint32_t la, int32_t text_space, con 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) { return false; } #endif -#ifdef ENABLE_CUDA_BACKEND +#ifdef BACKEND_CUDA 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); @@ -457,13 +457,13 @@ bool print_gpufetch(struct gpu_info* gpu, STYLE s, struct color** cs) { struct terminal* term = get_terminal_size(); if(gpu->vendor == GPU_VENDOR_NVIDIA) - #ifdef ENABLE_CUDA_BACKEND + #ifdef BACKEND_CUDA return print_gpufetch_cuda(gpu, s, cs, term); #else return false; #endif else { - #ifdef ENABLE_INTEL_BACKEND + #ifdef BACKEND_INTEL return print_gpufetch_intel(gpu, s, cs, term); #else return false; diff --git a/src/cuda/cuda.cpp b/src/cuda/cuda.cpp index a400145..03c295b 100644 --- a/src/cuda/cuda.cpp +++ b/src/cuda/cuda.cpp @@ -42,6 +42,10 @@ int print_gpus_list_deprecated() { return EXIT_SUCCESS; } +bool print_gpu_cuda(struct gpu_info* gpu) { + return false; +} + struct cache* get_cache_info(cudaDeviceProp prop) { struct cache* cach = (struct cache*) emalloc(sizeof(struct cache)); diff --git a/src/cuda/cuda.hpp b/src/cuda/cuda.hpp index 076ba76..931bf29 100644 --- a/src/cuda/cuda.hpp +++ b/src/cuda/cuda.hpp @@ -4,6 +4,7 @@ #include "../common/gpu.hpp" 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); diff --git a/src/intel/intel.cpp b/src/intel/intel.cpp index da27624..dd51c6f 100644 --- a/src/intel/intel.cpp +++ b/src/intel/intel.cpp @@ -1,3 +1,5 @@ +#include + #include "intel.hpp" #include "uarch.hpp" #include "../common/pci.hpp" @@ -8,3 +10,11 @@ struct gpu_info* get_gpu_info_intel() { 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; +} diff --git a/src/intel/intel.hpp b/src/intel/intel.hpp index 7fd5e9a..94ea86c 100644 --- a/src/intel/intel.hpp +++ b/src/intel/intel.hpp @@ -3,6 +3,7 @@ #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