-
Notifications
You must be signed in to change notification settings - Fork 6
/
CMakeLists.txt
227 lines (205 loc) · 7.34 KB
/
CMakeLists.txt
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
cmake_minimum_required(VERSION 3.8)
project(ChapelGPUAPI)
# FindCUDA
include(CheckLanguage)
check_language(CUDA QUIET)
# FindHIP
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()
set(CMAKE_MODULE_PATH "${HIP_PATH}/cmake" ${CMAKE_MODULE_PATH})
find_package(HIP QUIET)
# FindOpenCL
find_package(OpenCL QUIET)
# FindDPC++
find_program(DPCPP_FOUND dpcpp QUIET)
if(CMAKE_CUDA_COMPILER)
enable_language(CUDA)
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -O3")
add_library(GPUAPICUDA SHARED ${CMAKE_CURRENT_SOURCE_DIR}/src/GPUAPI.cu)
add_library(GPUAPICUDA_static STATIC ${CMAKE_CURRENT_SOURCE_DIR}/src/GPUAPI.cu)
set_target_properties(GPUAPICUDA PROPERTIES PUBLIC_HEADER ${CMAKE_CURRENT_SOURCE_DIR}/src/GPUAPI.h)
endif()
if(HIP_FOUND)
find_program(
CHPL_GPU_HIPIFY_EXECUTABLE
NAMES hipify-perl
PATHS
${HIP_ROOT_DIR}
PATH_SUFFIXES bin
NO_DEFAULT_PATH)
if(CHPL_GPU_HIPIFY_EXECUTABLE)
message(STATUS "Found HIP: " ${HIP_VERSION})
message(STATUS "Found HIPIFY: " ${CHPL_GPU_HIPIFY_EXECUTABLE})
add_custom_command(
OUTPUT GPUAPI.hip.cc
COMMAND ${CHPL_GPU_HIPIFY_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/src/GPUAPI.cu > GPUAPI.hip.cc
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/src/GPUAPI.cu
COMMENT "Convering GPUAPI.cu to GPUAPI.hip.cc"
)
set(CMAKE_CXX_COMPILER ${HIP_HIPCC_EXECUTABLE})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 -fno-gpu-rdc -fPIC")
hip_add_library(GPUAPIHIP SHARED GPUAPI.hip.cc)
hip_add_library(GPUAPIHIP_static STATIC GPUAPI.hip.cc)
set_target_properties(GPUAPIHIP PROPERTIES PUBLIC_HEADER ${CMAKE_CURRENT_SOURCE_DIR}/src/GPUAPI.h)
else ()
message(STATUS "Found HIP, but HIPIFY NOTFOUND")
set(HIP_FOUND OFF)
endif()
else()
message(STATUS "HIP NOTFOUND")
endif()
if(OpenCL_FOUND)
message(STATUS "Found OpenCL: " ${OpenCL_VERSION_STRING})
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3")
add_library(GPUAPIOPENCL SHARED ${CMAKE_CURRENT_SOURCE_DIR}/src/GPUAPI.opencl.c)
add_library(GPUAPIOPENCL_static STATIC ${CMAKE_CURRENT_SOURCE_DIR}/src/GPUAPI.opencl.c)
target_link_libraries(GPUAPIOPENCL OpenCL::OpenCL)
target_link_libraries(GPUAPIOPENCL_static OpenCL::OpenCL)
set_target_properties(GPUAPIOPENCL PROPERTIES PUBLIC_HEADER ${CMAKE_CURRENT_SOURCE_DIR}/src/GPUAPI.h)
else()
message(STATUS "OpenCL Not Found")
endif()
if(DPCPP_FOUND)
find_program(DPCT_FOUND dpct QUIET)
if(DPCT_FOUND)
message(STATUS "Found DPC++: " ${DPCPP_FOUND})
message(STATUS "Found DPCT: " ${DPCT_FOUND})
if(CMAKE_CUDA_COMPILER)
set(CUDA_INCLUDE_PATH ${CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES})
elseif(DEFINED ENV{CUDA_HOME})
set(CUDA_INCLUDE_PATH $ENV{CUDA_HOME}/include)
else()
message(FATAL_ERROR "Unable to find CUDA cmake or CUDA_HOME environment variable")
endif()
add_custom_command(
OUTPUT GPUAPI.dp.cpp
COMMAND dpct --in-root=${CMAKE_CURRENT_SOURCE_DIR}/src/ --out-root=. --cuda-include-path=${CUDA_INCLUDE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/src/GPUAPI.cu
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/src/GPUAPI.cu
COMMENT "Convering GPUAPI.cu to GPUAPI.dp.cpp"
)
else()
message(STATUS "Found DPC++, but DPCT NOTFOUND")
set(DPCPP_FOUND OFF)
endif()
set(CMAKE_CXX_COMPILER "dpcpp")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 -fPIC")
add_library(GPUAPIDPCPP SHARED GPUAPI.dp.cpp)
add_library(GPUAPIDPCPP_static STATIC GPUAPI.dp.cpp)
set_target_properties(GPUAPIDPCPP PROPERTIES PUBLIC_HEADER ${CMAKE_CURRENT_SOURCE_DIR}/src/GPUAPI.h)
else()
message(STATUS "DPC++ Not Found")
endif()
if(NOT (CMAKE_CUDA_COMPILER OR HIP_FOUND OR OpenCL_FOUND OR DPCPP_FOUND))
message(FATAL_ERROR "No GPU compiler found")
endif()
# Installation
if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
set (CMAKE_INSTALL_PREFIX "${CMAKE_CURRENT_SOURCE_DIR}/install" CACHE PATH "default install path" FORCE)
endif()
include(GNUInstallDirs)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR})
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/${CMAKE_INSTALL_BINDIR})
# Offer the user the choice of overriding the installation directories
set(INSTALL_LIBDIR ${CMAKE_INSTALL_LIBDIR} CACHE PATH "Installation directory for libraries")
set(INSTALL_INCLUDEDIR ${CMAKE_INSTALL_INCLUDEDIR} CACHE PATH "Installation directory for header files")
set(INSTALL_BINDIR ${CMAKE_INSTALL_BINDIR} CACHE PATH "Installation directory for executables")
if(WIN32 AND NOT CYGWIN)
set(DEF_INSTALL_CMAKEDIR CMake)
else()
set(DEF_INSTALL_CMAKEDIR share/cmake/${PROJECT_NAME})
endif()
set(INSTALL_CMAKEDIR ${DEF_INSTALL_CMAKEDIR} CACHE PATH "Installation directory for CMake files")
set(INSTALL_MODULEDIR modules CACHE PATH "Installation directory for Chapel module files")
# Report to user
foreach(p LIB INCLUDE MODULE CMAKE)
file(TO_NATIVE_PATH ${CMAKE_INSTALL_PREFIX}/${INSTALL_${p}DIR} _path )
message(STATUS "${p} components will be installed to ${_path}")
unset(_path)
endforeach()
if(CMAKE_CUDA_COMPILER)
install(
TARGETS GPUAPICUDA GPUAPICUDA_static
EXPORT gpuapicuda-export
ARCHIVE DESTINATION ${INSTALL_LIBDIR}
LIBRARY DESTINATION ${INSTALL_LIBDIR}
INCLUDES DESTINATION ${INSTALL_INCLUDEDIR}
PUBLIC_HEADER DESTINATION ${INSTALL_INCLUDEDIR}
)
install(
EXPORT gpuapicuda-export
FILE gpuapicuda-config.cmake
DESTINATION ${INSTALL_CMAKEDIR}
EXPORT_LINK_INTERFACE_LIBRARIES
)
endif()
if (HIP_FOUND)
install(
TARGETS GPUAPIHIP GPUAPIHIP_static
EXPORT gpuapihip-export
ARCHIVE DESTINATION ${INSTALL_LIBDIR}
LIBRARY DESTINATION ${INSTALL_LIBDIR}
INCLUDES DESTINATION ${INSTALL_INCLUDEDIR}
PUBLIC_HEADER DESTINATION ${INSTALL_INCLUDEDIR}
)
install(
EXPORT gpuapihip-export
FILE gpuapihip-config.cmake
DESTINATION ${INSTALL_CMAKEDIR}
EXPORT_LINK_INTERFACE_LIBRARIES
)
endif()
if(OpenCL_FOUND)
install(
TARGETS GPUAPIOPENCL GPUAPIOPENCL_static
ARCHIVE DESTINATION ${INSTALL_LIBDIR}
LIBRARY DESTINATION ${INSTALL_LIBDIR}
PUBLIC_HEADER DESTINATION ${INSTALL_INCLUDEDIR}
)
endif()
if(DPCPP_FOUND)
install(
TARGETS GPUAPIDPCPP GPUAPIDPCPP_static
EXPORT gpuapidpcpp-export
ARCHIVE DESTINATION ${INSTALL_LIBDIR}
LIBRARY DESTINATION ${INSTALL_LIBDIR}
PUBLIC_HEADER DESTINATION ${INSTALL_INCLUDEDIR}
)
install(
EXPORT gpuapidpcpp-export
FILE gpuapidpcpp-config.cmake
DESTINATION ${INSTALL_CMAKEDIR}
EXPORT_LINK_INTERFACE_LIBRARIES
)
endif()
if(CMAKE_CUDA_COMPILER OR HIP_FOUND OR DPCPP_FOUND)
install(
FILES
${CMAKE_CURRENT_SOURCE_DIR}/src/lambda.h
DESTINATION ${INSTALL_INCLUDEDIR}
)
endif()
install(
FILES
${CMAKE_CURRENT_SOURCE_DIR}/cmake/BuildGPUCode.cmake
DESTINATION ${INSTALL_CMAKEDIR}
)
install(
FILES
${CMAKE_CURRENT_SOURCE_DIR}/src/GPUIterator.chpl
${CMAKE_CURRENT_SOURCE_DIR}/src/GPUAPI.chpl
DESTINATION ${INSTALL_MODULEDIR}
)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/env.sh.in env.sh @ONLY)
install(
PROGRAMS
${CMAKE_CURRENT_BINARY_DIR}/env.sh
DESTINATION ${INSTALL_BINDIR}
)