[v0.11] Working for future support of Intel iGPUs

This commit is contained in:
Dr-Noob
2021-11-25 19:03:52 +01:00
parent 3502f48f71
commit 149e5ad62c
12 changed files with 181 additions and 47 deletions

View File

@@ -7,23 +7,22 @@ project(gpufetch CXX)
set(SRC_DIR "src") set(SRC_DIR "src")
set(COMMON_DIR "${SRC_DIR}/common") set(COMMON_DIR "${SRC_DIR}/common")
set(CUDA_DIR "${SRC_DIR}/cuda") set(CUDA_DIR "${SRC_DIR}/cuda")
set(INTEL_DIR "${SRC_DIR}/intel")
if(NOT WIN32) 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)
string(ASCII 27 Esc)
set(ColorReset "${Esc}[m") if(NOT DEFINED ENABLE_INTEL_BACKEND)
set(ColorBold "${Esc}[1m") set(ENABLE_INTEL_BACKEND true)
set(Red "${Esc}[31m")
set(Green "${Esc}[32m")
set(BoldRed "${Esc}[1;31m")
set(BoldGreen "${Esc}[1;32m")
set(BoldYellow "${Esc}[1;33m")
endif() endif()
check_language(CUDA) if(NOT DEFINED ENABLE_CUDA_BACKEND OR ENABLE_CUDA_BACKEND)
if(CMAKE_CUDA_COMPILER) check_language(CUDA)
enable_language(CUDA) if(CMAKE_CUDA_COMPILER)
else() enable_language(CUDA)
message(FATAL_ERROR "${BoldRed}[ERROR]${ColorReset} Unable to find CUDA compiler. You may use -DCMAKE_CUDA_COMPILER and -DCMAKE_CUDA_COMPILER_TOOLKIT_ROOT if CUDA is installed but not detected by CMake") set(ENABLE_CUDA_BACKEND true)
else()
set(ENABLE_CUDA_BACKEND false)
endif()
endif() endif()
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake") list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")
@@ -51,31 +50,62 @@ endif()
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")
# https://en.wikipedia.org/w/index.php?title=CUDA&section=5#GPUs_supported if(ENABLE_INTEL_BACKEND)
# https://raw.githubusercontent.com/PointCloudLibrary/pcl/master/cmake/pcl_find_cuda.cmake add_library(intel_backend STATIC ${INTEL_DIR}/intel.cpp)
if(${CMAKE_CUDA_COMPILER_VERSION} VERSION_GREATER_EQUAL "11.0") target_link_libraries(gpufetch intel_backend pci z)
set(CMAKE_CUDA_ARCHITECTURES 35 37 50 52 53 60 61 62 70 72 75 80 86)
elseif(${CMAKE_CUDA_COMPILER_VERSION} VERSION_GREATER_EQUAL "10.0")
set(CMAKE_CUDA_ARCHITECTURES 30 32 35 37 50 52 53 60 61 62 70 72 75)
elseif(${CMAKE_CUDA_COMPILER_VERSION} VERSION_GREATER_EQUAL "9.0")
set(CMAKE_CUDA_ARCHITECTURES 30 32 35 37 50 52 53 60 61 62 70 72)
elseif(${CMAKE_CUDA_COMPILER_VERSION} VERSION_EQUAL "8.0")
set(CMAKE_CUDA_ARCHITECTURES 20 21 30 32 35 37 50 52 53 60 61 62)
endif() endif()
link_directories(${CMAKE_CUDA_COMPILER_TOOLKIT_ROOT}/targets/x86_64-linux/lib) if(ENABLE_CUDA_BACKEND)
# 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
if(${CMAKE_CUDA_COMPILER_VERSION} VERSION_GREATER_EQUAL "11.0")
set(CMAKE_CUDA_ARCHITECTURES 35 37 50 52 53 60 61 62 70 72 75 80 86)
elseif(${CMAKE_CUDA_COMPILER_VERSION} VERSION_GREATER_EQUAL "10.0")
set(CMAKE_CUDA_ARCHITECTURES 30 32 35 37 50 52 53 60 61 62 70 72 75)
elseif(${CMAKE_CUDA_COMPILER_VERSION} VERSION_GREATER_EQUAL "9.0")
set(CMAKE_CUDA_ARCHITECTURES 30 32 35 37 50 52 53 60 61 62 70 72)
elseif(${CMAKE_CUDA_COMPILER_VERSION} VERSION_EQUAL "8.0")
set(CMAKE_CUDA_ARCHITECTURES 20 21 30 32 35 37 50 52 53 60 61 62)
endif()
add_library(cuda_backend STATIC ${CUDA_DIR}/cuda.cpp ${CUDA_DIR}/uarch.cpp ${CUDA_DIR}/pci.cpp) link_directories(${CMAKE_CUDA_COMPILER_TOOLKIT_ROOT}/targets/x86_64-linux/lib)
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)
if(NOT ${PCIUTILS_FOUND}) add_library(cuda_backend STATIC ${CUDA_DIR}/cuda.cpp ${CUDA_DIR}/uarch.cpp ${CUDA_DIR}/pci.cpp)
add_dependencies(cuda_backend pciutils)
add_dependencies(gpufetch pciutils) if(NOT ${PCIUTILS_FOUND})
add_dependencies(cuda_backend pciutils)
add_dependencies(gpufetch pciutils)
endif()
target_include_directories(cuda_backend PUBLIC ${CMAKE_CUDA_COMPILER_TOOLKIT_ROOT}/samples/common/inc ${CMAKE_CUDA_COMPILER_TOOLKIT_ROOT}/targets/x86_64-linux/include)
target_link_libraries(cuda_backend cudart)
target_link_libraries(gpufetch cuda_backend pci z)
endif() endif()
target_include_directories(cuda_backend PUBLIC ${CMAKE_CUDA_COMPILER_TOOLKIT_ROOT}/samples/common/inc ${CMAKE_CUDA_COMPILER_TOOLKIT_ROOT}/targets/x86_64-linux/include)
target_link_libraries(cuda_backend cudart)
target_link_libraries(gpufetch cuda_backend pci z)
install(TARGETS gpufetch DESTINATION bin) install(TARGETS gpufetch DESTINATION bin)
if(NOT WIN32)
string(ASCII 27 Esc)
set(ColorReset "${Esc}[m")
set(ColorBold "${Esc}[1m")
set(Red "${Esc}[31m")
set(Green "${Esc}[32m")
set(BoldRed "${Esc}[1;31m")
set(BoldGreen "${Esc}[1;32m")
set(BoldYellow "${Esc}[1;33m")
endif()
message(STATUS "----------------------")
message(STATUS "gpufetch build report:")
if(ENABLE_INTEL_BACKEND)
message(STATUS "Intel backend: ${BoldGreen}ON${ColorReset}")
else()
message(STATUS "Intel backend: ${BoldRed}OFF${ColorReset}")
endif()
if(ENABLE_CUDA_BACKEND)
message(STATUS "CUDA backend: ${BoldGreen}ON${ColorReset}")
else()
message(STATUS "CUDA backend: ${BoldRed}OFF${ColorReset}")
endif()
message(STATUS "----------------------")

View File

@@ -9,7 +9,8 @@
#define UNKNOWN_FREQ -1 #define UNKNOWN_FREQ -1
enum { enum {
GPU_VENDOR_NVIDIA GPU_VENDOR_NVIDIA,
GPU_VENDOR_INTEL
}; };
enum { enum {

View File

@@ -4,6 +4,7 @@
#include "args.hpp" #include "args.hpp"
#include "global.hpp" #include "global.hpp"
#include "master.hpp"
#include "../cuda/cuda.hpp" #include "../cuda/cuda.hpp"
#include "../cuda/uarch.hpp" #include "../cuda/uarch.hpp"
@@ -65,8 +66,9 @@ int main(int argc, char* argv[]) {
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }
struct gpu_list* list = get_gpu_list();
if(list_gpus()) { if(list_gpus()) {
return print_gpus_list(); return print_gpus_list(list);
} }
set_log_level(true); set_log_level(true);
@@ -76,7 +78,7 @@ If you want to help to improve gpufetch, please compare the output of the progra
with a reliable source which you know is right (e.g, techpowerup.com) and report\n\ with a reliable source which you know is right (e.g, techpowerup.com) and report\n\
any inconsistencies to https://github.com/Dr-Noob/gpufetch/issues"); any inconsistencies to https://github.com/Dr-Noob/gpufetch/issues");
struct gpu_info* gpu = get_gpu_info(get_gpu_idx()); struct gpu_info* gpu = get_gpu_info(list, get_gpu_idx());
if(gpu == NULL) if(gpu == NULL)
return EXIT_FAILURE; return EXIT_FAILURE;

46
src/common/master.cpp Normal file
View File

@@ -0,0 +1,46 @@
#include <stdbool.h>
#include <cstddef>
#include <cstdlib>
#include "master.hpp"
#define MAX_GPUS 1000
struct gpu_list {
struct gpu_info ** gpus;
int num_gpus;
};
struct gpu_list* get_gpu_list() {
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;
while(valid) {
list->gpus[idx] = get_gpu_info_cuda(idx);
if(list->gpus[idx] != NULL) idx++;
else valid = false;
}
list->num_gpus += idx;
#endif
#ifdef ENABLE_INTEL_BACKEND
list->gpus[idx] = get_gpu_info_intel();
if(list->gpus[idx] != NULL) list->num_gpus++;
#endif
return list;
}
bool print_gpus_list(struct gpu_list* list) {
return false;
}
struct gpu_info* get_gpu_info(struct gpu_list* list, int idx) {
return list->gpus[idx];
}

12
src/common/master.hpp Normal file
View File

@@ -0,0 +1,12 @@
#ifndef __GPU_LIST__
#define __GPU_LIST__
#include "gpu.hpp"
struct gpu_list;
struct gpu_list* get_gpu_list();
bool print_gpus_list(struct gpu_list* list);
struct gpu_info* get_gpu_info(struct gpu_list* list, int idx);
#endif

View File

@@ -342,6 +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
bool print_gpufetch_intel(struct gpu_info* gpu, STYLE s, struct color** cs, struct terminal* term) {
return false;
}
#endif
#ifdef ENABLE_CUDA_BACKEND
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);
@@ -416,6 +423,7 @@ bool print_gpufetch_cuda(struct gpu_info* gpu, STYLE s, struct color** cs, struc
return true; return true;
} }
#endif
struct terminal* get_terminal_size() { struct terminal* get_terminal_size() {
struct terminal* term = (struct terminal*) emalloc(sizeof(struct terminal)); struct terminal* term = (struct terminal*) emalloc(sizeof(struct terminal));
@@ -448,5 +456,17 @@ struct terminal* get_terminal_size() {
bool print_gpufetch(struct gpu_info* gpu, STYLE s, struct color** cs) { bool print_gpufetch(struct gpu_info* gpu, STYLE s, struct color** cs) {
struct terminal* term = get_terminal_size(); struct terminal* term = get_terminal_size();
return print_gpufetch_cuda(gpu, s, cs, term); if(gpu->vendor == GPU_VENDOR_NVIDIA)
#ifdef ENABLE_CUDA_BACKEND
return print_gpufetch_cuda(gpu, s, cs, term);
#else
return false;
#endif
else {
#ifdef ENABLE_INTEL_BACKEND
return print_gpufetch_intel(gpu, s, cs, term);
#else
return false;
#endif
}
} }

View File

@@ -6,7 +6,7 @@
#include "../common/pci.hpp" #include "../common/pci.hpp"
#include "../common/global.hpp" #include "../common/global.hpp"
int print_gpus_list() { int print_gpus_list_deprecated() {
cudaError_t err = cudaSuccess; cudaError_t err = cudaSuccess;
int num_gpus = -1; int num_gpus = -1;
@@ -113,7 +113,7 @@ int64_t get_peak_performance_t(struct gpu_info* gpu) {
return gpu->freq * 1000000 * 4 * 4 * 8 * gpu->topo->tensor_cores; return gpu->freq * 1000000 * 4 * 4 * 8 * gpu->topo->tensor_cores;
} }
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)); struct gpu_info* gpu = (struct gpu_info*) emalloc(sizeof(struct gpu_info));
gpu->pci = NULL; gpu->pci = NULL;
gpu->idx = gpu_idx; gpu->idx = gpu_idx;

View File

@@ -1,10 +1,9 @@
#ifndef __CUDA__ #ifndef __CUDA_GPU__
#define __CUDA__ #define __CUDA_GPU__
#include "../common/gpu.hpp" #include "../common/gpu.hpp"
struct gpu_info* get_gpu_info(int gpu_idx); struct gpu_info* get_gpu_info_cuda(int gpu_idx);
int print_gpus_list();
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,5 +1,5 @@
#ifndef __UARCH__ #ifndef __CUDA_UARCH__
#define __UARCH__ #define __CUDA_UARCH__
#include "../common/gpu.hpp" #include "../common/gpu.hpp"

10
src/intel/intel.cpp Normal file
View File

@@ -0,0 +1,10 @@
#include "intel.hpp"
#include "uarch.hpp"
#include "../common/pci.hpp"
#include "../common/global.hpp"
struct gpu_info* get_gpu_info_intel() {
struct gpu_info* gpu = (struct gpu_info*) emalloc(sizeof(struct gpu_info));
return gpu;
}

8
src/intel/intel.hpp Normal file
View File

@@ -0,0 +1,8 @@
#ifndef __INTEL_GPU__
#define __INTEL_GPU__
#include "../common/gpu.hpp"
struct gpu_info* get_gpu_info_intel(int gpu_idx);
#endif

6
src/intel/uarch.hpp Normal file
View File

@@ -0,0 +1,6 @@
#ifndef __INTEL_UARCH__
#define __INTEL_UARCH__
#include "../common/gpu.hpp"
#endif