forked from AliceO2Group/AliceO2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFindO2GPU.cmake
More file actions
156 lines (144 loc) · 4.81 KB
/
Copy pathFindO2GPU.cmake
File metadata and controls
156 lines (144 loc) · 4.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# Copyright CERN and copyright holders of ALICE O2. This software is distributed
# under the terms of the GNU General Public License v3 (GPL Version 3), copied
# verbatim in the file "COPYING".
#
# See http://alice-o2.web.cern.ch/license for full licensing information.
#
# In applying this license CERN does not waive the privileges and immunities
# granted to it by virtue of its status as an Intergovernmental Organization or
# submit itself to any jurisdiction.
if(NOT DEFINED ENABLE_CUDA)
set(ENABLE_CUDA "AUTO")
endif()
if(NOT DEFINED ENABLE_OPENCL1)
set(ENABLE_OPENCL1 "AUTO")
endif()
if(NOT DEFINED ENABLE_OPENCL2)
set(ENABLE_OPENCL2 "AUTO")
endif()
if(NOT DEFINED ENABLE_HIP)
set(ENABLE_HIP "AUTO")
endif()
string(TOUPPER "${ENABLE_CUDA}" ENABLE_CUDA)
string(TOUPPER "${ENABLE_OPENCL1}" ENABLE_OPENCL1)
string(TOUPPER "${ENABLE_OPENCL2}" ENABLE_OPENCL2)
string(TOUPPER "${ENABLE_HIP}" ENABLE_HIP)
# Detect and enable CUDA
if(ENABLE_CUDA)
set(CUDA_MINIMUM_VERSION "10.1")
if(CUDA_GCCBIN)
message(STATUS "Using as CUDA GCC version: ${CUDA_GCCBIN}")
set(CUDA_HOST_COMPILER "${CUDA_GCCBIN}")
endif()
set(CMAKE_CUDA_STANDARD 14)
set(CMAKE_CUDA_STANDARD_REQUIRED TRUE)
include(CheckLanguage)
check_language(CUDA)
if(CMAKE_CUDA_COMPILER)
enable_language(CUDA)
get_property(LANGUAGES GLOBAL PROPERTY ENABLED_LANGUAGES)
if(NOT CUDA IN_LIST LANGUAGES)
message(FATAL_ERROR "CUDA was found but cannot be enabled")
endif()
set(CMAKE_CUDA_FLAGS "--expt-relaxed-constexpr")
set(CMAKE_CUDA_FLAGS_DEBUG "-Xptxas -O0 -Xcompiler -O0")
set(CMAKE_CUDA_FLAGS_RELEASE "-Xptxas -O4 -Xcompiler -O4 -use_fast_math")
set(CMAKE_CUDA_FLAGS_RELWITHDEBINFO "${CMAKE_CUDA_FLAGS_RELEASE}")
set(CMAKE_CUDA_FLAGS_COVERAGE "${CMAKE_CUDA_FLAGS_RELEASE}")
if(CUDA_COMPUTETARGET)
set(
CMAKE_CUDA_FLAGS
"${CMAKE_CUDA_FLAGS} -gencode arch=compute_${CUDA_COMPUTETARGET},code=compute_${CUDA_COMPUTETARGET}"
)
endif()
set(CUDA_ENABLED ON)
message(STATUS "CUDA found (Version ${CMAKE_CUDA_COMPILER_VERSION})")
elseif(NOT ENABLE_CUDA STREQUAL "AUTO")
message(FATAL_ERROR "CUDA not found")
endif()
endif()
# Detect and enable OpenCL 1.2 from AMD
if(ENABLE_OPENCL1 OR ENABLE_OPENCL2)
find_package(OpenCL)
if((ENABLE_OPENCL1 AND NOT ENABLE_OPENCL1 STREQUAL "AUTO")
OR (ENABLE_OPENCL2 AND NOT ENABLE_OPENCL2 STREQUAL "AUTO"))
set_package_properties(OpenCL PROPERTIES TYPE REQUIRED)
else()
set_package_properties(OpenCL PROPERTIES TYPE OPTIONAL)
endif()
endif()
if(ENABLE_OPENCL1)
if(NOT AMDAPPSDKROOT)
set(AMDAPPSDKROOT "$ENV{AMDAPPSDKROOT}")
endif()
if(OpenCL_FOUND
AND OpenCL_VERSION_STRING VERSION_GREATER_EQUAL 1.2
AND AMDAPPSDKROOT
AND EXISTS "${AMDAPPSDKROOT}")
set(OPENCL1_ENABLED ON)
message(STATUS "Found AMD OpenCL 1.2")
elseif(NOT ENABLE_OPENCL1 STREQUAL "AUTO")
message(FATAL_ERROR "AMD OpenCL 1.2 not available")
endif()
endif()
# Detect and enable OpenCL 2.x
if(ENABLE_OPENCL2)
if(OpenCL_VERSION_STRING VERSION_GREATER_EQUAL 2.0
AND Clang_FOUND
AND LLVM_FOUND
AND LLVM_PACKAGE_VERSION VERSION_GREATER_EQUAL 9.0)
set(OPENCL2_ENABLED ON)
message(
STATUS
"Found OpenCL 2 (${OpenCL_VERSION_STRING} compiled by LLVM/Clang ${LLVM_PACKAGE_VERSION})"
)
elseif(NOT ENABLE_OPENCL2 STREQUAL "AUTO")
# message(FATAL_ERROR "OpenCL 2.x not yet implemented")
endif()
endif()
# Detect and enable HIP
if(ENABLE_HIP)
if(NOT DEFINED HIP_PATH)
if(NOT DEFINED ENV{HIP_PATH})
set(HIP_PATH
"/opt/rocm/hip"
CACHE PATH "Path to which HIP has been installed")
else()
set(HIP_PATH
$ENV{HIP_PATH}
CACHE PATH "Path to which HIP has been installed")
endif()
endif()
if(NOT DEFINED HCC_HOME)
if(NOT DEFINED ENV{HCC_HOME})
set(HCC_HOME
"${HIP_PATH}/../hcc"
CACHE PATH "Path to which HCC has been installed")
else()
set(HCC_HOME
$ENV{HCC_HOME}
CACHE PATH "Path to which HCC has been installed")
endif()
endif()
if(HIP_PATH AND EXISTS "${HIP_PATH}" AND HCC_HOME AND EXISTS "${HCC_HOME}")
get_filename_component(hip_ROOT "${HIP_PATH}" ABSOLUTE)
get_filename_component(hcc_ROOT "${HCC_HOME}" ABSOLUTE)
find_package(hip)
if(ENABLE_HIP STREQUAL "AUTO")
set_package_properties(hip PROPERTIES TYPE OPTIONAL)
else()
set_package_properties(hip PROPERTIES TYPE REQUIRED)
endif()
if(hip_HIPCC_EXECUTABLE)
set(HIP_ENABLED ON)
message(STATUS "HIP Found")
endif()
elseif(NOT ENABLE_HIP STREQUAL "AUTO")
message(
FATAL_ERROR
"HIP requested but HIP_PATH=${HIP_PATH} or HCC_HOME=${HCC_HOME} does not exist"
)
endif()
endif()
# if we end up here without a FATAL, it means we have found the "O2GPU" package
set(O2GPU_FOUND TRUE)