[v0.30] Add support for AMD GPUs
Adds very basic support for AMD (experimental). The only install
requirement is ROCm. Unlike NVIDIA, we don't need the CUDA equivalent
(HIP) to make gpufetch work, which reduces the installation
requirements quite significantly.
Major changes:
* CMakeLists:
- Make CUDA not compiled by default (since we now may want to target
AMD only)
- Set build flags on gpufetch cmake target instead of doing
"set(CMAKE_CXX_FLAGS". This fixes a warning coming from ROCm.
- Assumes that the ROCm CMake files are installed (should be fixed
later)
* hsa folder: AMD support is implemented via HSA (Heterogeneous System
Architecture) calls. Therefore, HSA is added as a new backend to
gpufetch. We only print basic stuff for now, so we may need more
things in the future to give full support for AMD GPUs.
NOTE: This commit will probably break AUR packages since we used to
build CUDA by default, which is no longer the case. The AUR package
should be updated and use -DENABLE_CUDA_BACKEND or -DENABLE_HSA_BACKEND
as appropriate.
This commit is contained in:
@@ -7,17 +7,18 @@ project(gpufetch CXX)
|
||||
set(SRC_DIR "src")
|
||||
set(COMMON_DIR "${SRC_DIR}/common")
|
||||
set(CUDA_DIR "${SRC_DIR}/cuda")
|
||||
set(HSA_DIR "${SRC_DIR}/hsa")
|
||||
set(INTEL_DIR "${SRC_DIR}/intel")
|
||||
|
||||
# Enable Intel backend by default
|
||||
if(NOT DEFINED ENABLE_INTEL_BACKEND)
|
||||
set(ENABLE_INTEL_BACKEND true)
|
||||
endif()
|
||||
|
||||
if(NOT DEFINED ENABLE_CUDA_BACKEND OR ENABLE_CUDA_BACKEND)
|
||||
if(ENABLE_CUDA_BACKEND)
|
||||
check_language(CUDA)
|
||||
if(CMAKE_CUDA_COMPILER)
|
||||
enable_language(CUDA)
|
||||
set(ENABLE_CUDA_BACKEND true)
|
||||
# Must link_directories early so add_executable(gpufetch ...) gets the right directories
|
||||
link_directories(cuda_backend ${CMAKE_CUDA_COMPILER_TOOLKIT_ROOT}/targets/x86_64-linux/lib)
|
||||
else()
|
||||
@@ -25,6 +26,34 @@ if(NOT DEFINED ENABLE_CUDA_BACKEND OR ENABLE_CUDA_BACKEND)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(ENABLE_HSA_BACKEND)
|
||||
# TODO: Needs rocm-cmake, what if its not insalled?
|
||||
find_package(ROCmCMakeBuildTools)
|
||||
if (ROCmCMakeBuildTools_FOUND)
|
||||
find_package(hsa-runtime64 1.0 REQUIRED)
|
||||
link_directories(hsa_backend hsa-runtime64::hsa-runtime64)
|
||||
|
||||
# Find HSA headers
|
||||
# ROCm does not seem to provide this, which is quite frustrating.
|
||||
find_path(HSA_INCLUDE_DIR
|
||||
NAMES hsa/hsa.h
|
||||
HINTS
|
||||
$ENV{ROCM_PATH}/include # allow users override via env variable
|
||||
/opt/rocm/include # common default path
|
||||
/usr/include
|
||||
/usr/local/include
|
||||
)
|
||||
|
||||
if(NOT HSA_INCLUDE_DIR)
|
||||
message(STATUS "${BoldYellow}HSA not found, disabling HSA backend${ColorReset}")
|
||||
set(ENABLE_HSA_BACKEND false)
|
||||
endif()
|
||||
else()
|
||||
set(ENABLE_HSA_BACKEND false)
|
||||
message(STATUS "${BoldYellow}ROCm not found${ColorReset}")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")
|
||||
find_package(PCIUTILS)
|
||||
if(NOT ${PCIUTILS_FOUND})
|
||||
@@ -50,8 +79,9 @@ else()
|
||||
endif()
|
||||
|
||||
add_executable(gpufetch ${COMMON_DIR}/main.cpp ${COMMON_DIR}/args.cpp ${COMMON_DIR}/gpu.cpp ${COMMON_DIR}/pci.cpp ${COMMON_DIR}/sort.cpp ${COMMON_DIR}/global.cpp ${COMMON_DIR}/printer.cpp ${COMMON_DIR}/master.cpp ${COMMON_DIR}/uarch.cpp)
|
||||
set(SANITY_FLAGS "-Wfloat-equal -Wshadow -Wpointer-arith")
|
||||
set(CMAKE_CXX_FLAGS "${SANITY_FLAGS} -Wall -Wextra -pedantic -fstack-protector-all -pedantic -std=c++11")
|
||||
set(SANITY_FLAGS -Wfloat-equal -Wshadow -Wpointer-arith -Wall -Wextra -pedantic -fstack-protector-all -pedantic)
|
||||
target_compile_features(gpufetch PRIVATE cxx_std_11)
|
||||
target_compile_options(gpufetch PRIVATE ${SANITY_FLAGS})
|
||||
|
||||
if(ENABLE_INTEL_BACKEND)
|
||||
target_compile_definitions(gpufetch PUBLIC BACKEND_INTEL)
|
||||
@@ -94,6 +124,22 @@ if(ENABLE_CUDA_BACKEND)
|
||||
target_link_libraries(gpufetch cuda_backend)
|
||||
endif()
|
||||
|
||||
if(ENABLE_HSA_BACKEND)
|
||||
target_compile_definitions(gpufetch PUBLIC BACKEND_HSA)
|
||||
|
||||
add_library(hsa_backend STATIC ${HSA_DIR}/hsa.cpp)
|
||||
|
||||
if(NOT ${PCIUTILS_FOUND})
|
||||
add_dependencies(hsa_backend pciutils)
|
||||
endif()
|
||||
|
||||
target_include_directories(hsa_backend PRIVATE "${HSA_INCLUDE_DIR}")
|
||||
message(STATUS "Found HSA: ${HSA_INCLUDE_DIR}")
|
||||
|
||||
target_link_libraries(hsa_backend PRIVATE hsa-runtime64::hsa-runtime64)
|
||||
target_link_libraries(gpufetch hsa_backend)
|
||||
endif()
|
||||
|
||||
target_link_libraries(gpufetch pci z)
|
||||
install(TARGETS gpufetch DESTINATION bin)
|
||||
|
||||
@@ -115,6 +161,11 @@ if(ENABLE_CUDA_BACKEND)
|
||||
else()
|
||||
message(STATUS "CUDA backend: ${BoldRed}OFF${ColorReset}")
|
||||
endif()
|
||||
if(ENABLE_HSA_BACKEND)
|
||||
message(STATUS "HSA backend: ${BoldGreen}ON${ColorReset}")
|
||||
else()
|
||||
message(STATUS "HSA backend: ${BoldRed}OFF${ColorReset}")
|
||||
endif()
|
||||
if(ENABLE_INTEL_BACKEND)
|
||||
message(STATUS "Intel backend: ${BoldGreen}ON${ColorReset}")
|
||||
else()
|
||||
|
||||
Reference in New Issue
Block a user