Skip to content

Commit fe800ba

Browse files
mpucciosawenzel
authored andcommitted
Enable CUDA and HIP optionally to build GPU reconstruction code
Credits @davidrohr, @mconcas, @dberzano
1 parent d4e415a commit fe800ba

File tree

5 files changed

+844
-1
lines changed

5 files changed

+844
-1
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# and the experiment part.
77

88
# Check IF cmake has the required version
9-
CMAKE_MINIMUM_REQUIRED(VERSION 2.8.11 FATAL_ERROR)
9+
CMAKE_MINIMUM_REQUIRED(VERSION 3.11.0 FATAL_ERROR)
1010

1111
### CMP0025 Compiler id for Apple Clang is now AppleClang.
1212
### CMP0042 MACOSX_RPATH is enabled by default.

cmake/O2Dependencies.cmake

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,52 @@ if (DDS_FOUND)
7575
set(OPTIONAL_DDS_INCLUDE_DIR ${DDS_INCLUDE_DIR})
7676
endif ()
7777

78+
if (ENABLE_CUDA)
79+
include(CheckLanguage)
80+
check_language(CUDA)
81+
if(NOT CMAKE_CUDA_COMPILER)
82+
message(FATAL "No CUDA compiler found")
83+
endif()
84+
if(CMAKE_BUILD_TYPE STREQUAL "DEBUG")
85+
set(CMAKE_CUDA_FLAGS "-Xptxas -O0 -Xcompiler -O0")
86+
else()
87+
set(CMAKE_CUDA_FLAGS "-Xptxas -O4 -Xcompiler -O4 -use_fast_math")
88+
endif()
89+
if(CUDA_GCCBIN)
90+
message(STATUS "Using as CUDA GCC version: ${CUDA_GCCBIN}")
91+
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} --compiler-bindir ${CUDA_GCCBIN}")
92+
endif()
93+
enable_language(CUDA)
94+
if(CUDA_GCCBIN)
95+
#Ugly hack! Otherwise CUDA includes unwanted old GCC libraries leading to version conflicts
96+
set(CMAKE_CUDA_IMPLICIT_LINK_DIRECTORIES "$ENV{CUDA_PATH}/lib64")
97+
endif()
98+
add_definitions(-DENABLE_CUDA)
99+
set(CMAKE_CUDA_STANDARD 14)
100+
set(CMAKE_CUDA_STANDARD_REQUIRED ON)
101+
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} --expt-relaxed-constexpr --compiler-options \"${CMAKE_CXX_FLAGS_${CMAKE_BUILD_TYPE}} -std=c++14\"")
102+
message(STATUS "CUDA FOUND: Version ${CUDA_VERSION}")
103+
endif()
104+
105+
if (ENABLE_HIP)
106+
if(NOT DEFINED HIP_PATH)
107+
if(NOT DEFINED ENV{HIP_PATH})
108+
set(HIP_PATH "/opt/rocm/hip" CACHE PATH "Path to which HIP has been installed")
109+
else()
110+
set(HIP_PATH $ENV{HIP_PATH} CACHE PATH "Path to which HIP has been installed")
111+
endif()
112+
endif()
113+
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${HIP_PATH}/cmake")
114+
if(NOT DEFINED HCC_PATH)
115+
# Workaround to fix a potential FindHIP bug: find HCC_PATH ourselves
116+
set(_HCC_PATH "${HIP_PATH}/../hcc")
117+
get_filename_component(HCC_PATH ${_HCC_PATH} ABSOLUTE CACHE)
118+
unset(_HCC_PATH)
119+
endif()
120+
find_package(HIP REQUIRED)
121+
add_definitions(-DENABLE_HIP)
122+
endif()
123+
78124
# todo this should really not be needed. ROOT, Pythia, and FairRoot should comply with CMake best practices
79125
# todo but they do not properly return DEPENDENCIES with absolute path.
80126
link_directories(

0 commit comments

Comments
 (0)