[v0.11] Working for future support of Intel iGPUs
This commit is contained in:
@@ -7,23 +7,22 @@ project(gpufetch CXX)
|
||||
set(SRC_DIR "src")
|
||||
set(COMMON_DIR "${SRC_DIR}/common")
|
||||
set(CUDA_DIR "${SRC_DIR}/cuda")
|
||||
set(INTEL_DIR "${SRC_DIR}/intel")
|
||||
|
||||
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")
|
||||
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()
|
||||
|
||||
if(NOT DEFINED ENABLE_CUDA_BACKEND OR ENABLE_CUDA_BACKEND)
|
||||
check_language(CUDA)
|
||||
if(CMAKE_CUDA_COMPILER)
|
||||
enable_language(CUDA)
|
||||
set(ENABLE_CUDA_BACKEND true)
|
||||
else()
|
||||
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 false)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")
|
||||
@@ -51,6 +50,12 @@ endif()
|
||||
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)
|
||||
add_library(intel_backend STATIC ${INTEL_DIR}/intel.cpp)
|
||||
target_link_libraries(gpufetch intel_backend pci z)
|
||||
endif()
|
||||
|
||||
if(ENABLE_CUDA_BACKEND)
|
||||
# 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")
|
||||
@@ -66,7 +71,6 @@ endif()
|
||||
link_directories(${CMAKE_CUDA_COMPILER_TOOLKIT_ROOT}/targets/x86_64-linux/lib)
|
||||
|
||||
add_library(cuda_backend STATIC ${CUDA_DIR}/cuda.cpp ${CUDA_DIR}/uarch.cpp ${CUDA_DIR}/pci.cpp)
|
||||
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_dependencies(cuda_backend pciutils)
|
||||
@@ -77,5 +81,31 @@ target_include_directories(cuda_backend PUBLIC ${CMAKE_CUDA_COMPILER_TOOLKIT_ROO
|
||||
|
||||
target_link_libraries(cuda_backend cudart)
|
||||
target_link_libraries(gpufetch cuda_backend pci z)
|
||||
endif()
|
||||
|
||||
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 "----------------------")
|
||||
|
||||
@@ -9,7 +9,8 @@
|
||||
#define UNKNOWN_FREQ -1
|
||||
|
||||
enum {
|
||||
GPU_VENDOR_NVIDIA
|
||||
GPU_VENDOR_NVIDIA,
|
||||
GPU_VENDOR_INTEL
|
||||
};
|
||||
|
||||
enum {
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
#include "args.hpp"
|
||||
#include "global.hpp"
|
||||
#include "master.hpp"
|
||||
#include "../cuda/cuda.hpp"
|
||||
#include "../cuda/uarch.hpp"
|
||||
|
||||
@@ -65,8 +66,9 @@ int main(int argc, char* argv[]) {
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
struct gpu_list* list = get_gpu_list();
|
||||
if(list_gpus()) {
|
||||
return print_gpus_list();
|
||||
return print_gpus_list(list);
|
||||
}
|
||||
|
||||
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\
|
||||
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)
|
||||
return EXIT_FAILURE;
|
||||
|
||||
|
||||
46
src/common/master.cpp
Normal file
46
src/common/master.cpp
Normal 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
12
src/common/master.hpp
Normal 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
|
||||
@@ -342,6 +342,13 @@ void print_ascii_generic(struct ascii* art, uint32_t la, int32_t text_space, con
|
||||
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) {
|
||||
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;
|
||||
}
|
||||
#endif
|
||||
|
||||
struct terminal* get_terminal_size() {
|
||||
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) {
|
||||
struct terminal* term = get_terminal_size();
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
#include "../common/pci.hpp"
|
||||
#include "../common/global.hpp"
|
||||
|
||||
int print_gpus_list() {
|
||||
int print_gpus_list_deprecated() {
|
||||
cudaError_t err = cudaSuccess;
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
#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);
|
||||
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);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#ifndef __UARCH__
|
||||
#define __UARCH__
|
||||
#ifndef __CUDA_UARCH__
|
||||
#define __CUDA_UARCH__
|
||||
|
||||
#include "../common/gpu.hpp"
|
||||
|
||||
|
||||
10
src/intel/intel.cpp
Normal file
10
src/intel/intel.cpp
Normal 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
8
src/intel/intel.hpp
Normal 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
6
src/intel/uarch.hpp
Normal file
@@ -0,0 +1,6 @@
|
||||
#ifndef __INTEL_UARCH__
|
||||
#define __INTEL_UARCH__
|
||||
|
||||
#include "../common/gpu.hpp"
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user