-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathCMakeLists.txt
282 lines (239 loc) · 7.93 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
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
# Example cmake command to build TALSH
# -DTALSH_GPU=ON
# (CUDA) -DTALSH_GPU_ARCH=70 [-DWITH_CUTENSOR=ON -DCUTENSOR_ROOT=/opt/cutensor]
# (AMD) -DROCM_ROOT=$ROCM_PATH -DUSE_HIP=ON [-DTALSH_GPU_ARCH=gfx908]
# (Optional) -DUSE_OPENMP=ON -DBUILD_TESTS=ON -DTALSH_FINE_TIMING=ON
cmake_minimum_required(VERSION 3.18.0 FATAL_ERROR)
project (TALSH VERSION 0.1.0 LANGUAGES C CXX Fortran)
if(NOT CMAKE_BUILD_TYPE)
set (CMAKE_BUILD_TYPE Release)
endif()
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_NO_SYSTEM_FROM_IMPORTED ON)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
set(CMAKE_FIND_PACKAGE_NO_PACKAGE_REGISTRY ON)
option(USE_HIP OFF)
option(USE_OPENMP OFF)
option(LINUX_GNU_ASAN OFF)
option(BUILD_TESTS OFF)
# find_package(MPI REQUIRED)
if(USE_OPENMP)
find_package(OpenMP REQUIRED)
else()
set(NO_OMP NO_OMP)
endif()
#TODO:
#Cray, Clang compiler flags
# DF := -WF, when using IBM compilers
# HIP, ASAN_COMPILE
set(TALSH_GPU_DEFS NO_GPU)
if (TALSH_GPU)
if(USE_HIP)
set(TALSH_GPU_DEFS USE_HIP)
#TODO: check if ROCM_ROOT is valid
list (APPEND CMAKE_PREFIX_PATH ${ROCM_ROOT} ${ROCM_ROOT}/hip ${ROCM_ROOT}/hipblas)
if(TALSH_GPU_ARCH)
set(GPU_TARGETS ${TALSH_GPU_ARCH} CACHE STRING "GPU targets to compile for")
endif()
find_package(hip REQUIRED)
find_package(hipblas REQUIRED)
else()
set(TALSH_GPU_DEFS "CUDA_ARCH=${TALSH_GPU_ARCH}0")
enable_language(CUDA)
set(CMAKE_CUDA_STANDARD 11)
set(CMAKE_CUDA_EXTENSIONS OFF)
set(CMAKE_CUDA_STANDARD_REQUIRED ON)
# set(CMAKE_CUDA_SEPARABLE_COMPILATION ON)
set(CMAKE_CUDA_HOST_COMPILER ${CMAKE_CXX_COMPILER})
find_package(CUDAToolkit REQUIRED COMPONENTS cublas)
endif()
endif()
if(WITH_CUTENSOR)
list(APPEND TALSH_GPU_DEFS USE_CUTENSOR)
endif()
if(EXATN_SERVICE)
list(APPEND TALSH_GPU_DEFS EXATN_SERVICE)
endif()
if(CMAKE_Fortran_COMPILER_ID STREQUAL "Intel")
set(TALSH_Fortran_FLAGS ${TALSH_Fortran_FLAGS} -fpp -vec-threshold4 -mkl=parallel)
elseif(CMAKE_Fortran_COMPILER_ID STREQUAL "PGI")
set(TALSH_Fortran_FLAGS ${TALSH_Fortran_FLAGS} -Mcache_align -Mstandard -Mallocatable=03)
elseif(CMAKE_Fortran_COMPILER_ID STREQUAL "XL")
set(TALSH_Fortran_FLAGS ${TALSH_Fortran_FLAGS} -qpic=large)
elseif(CMAKE_Fortran_COMPILER_ID STREQUAL "Cray")
set(TALSH_Fortran_FLAGS ${TALSH_FORTRAN_FLAGS} -hpic)
endif()
if(CMAKE_CXX_COMPILER_ID STREQUAL "PGI")
set(TALSH_CXX_FLAGS ${TALSH_CXX_FLAGS} -silent -w -Mnovect)
# elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Cray")
# set(TALSH_CXX_FLAGS ${TALSH_CXX_FLAGS} -h)
endif()
if (NOT TALSH_BLAS)
set(NO_BLAS NO_BLAS)
endif()
set(TALSH_CXX_COMPILE_DEFS ${TALSH_GPU_DEFS} ${NO_BLAS} ${NO_OMP} NO_AMD NO_PHI LINUX)
set(TALSH_Fortran_COMPILE_DEFS ${TALSH_GPU_DEFS} ${NO_BLAS} ${NO_OMP} NO_AMD NO_PHI LINUX)
if (TALSH_GPU AND NOT USE_HIP)
set(TALSH_INCLUDES ${CUDAToolkit_INCLUDE_DIRS})
if(WITH_CUTENSOR)
list(APPEND TALSH_INCLUDES ${CUTENSOR_ROOT}/include)
endif()
# else()
# set(TALSH_INCLUDES ${MPI_C_INCLUDE_PATH} ${MPI_Fortran_INCLUDE_PATH})
endif()
set(TALSH_FORTRAN_SOURCES
dil_basic.F90
stsubs.F90
combinatoric.F90
symm_index.F90
timers.F90
tensor_algebra.F90
tensor_algebra_cpu.F90
tensor_algebra_cpu_phi.F90
tensor_dil_omp.F90
talshf.F90
)
set(TALSH_CXX_SOURCES
timer.cpp
byte_packet.cpp
nvtx_profile.c
tensor_algebra_gpu.cpp
talshc.cpp
talsh_task.cpp
talshxx.cpp
)
if(USE_HIP)
list(APPEND TALSH_CXX_SOURCES mem_manager.hip.cpp)
else()
list(APPEND TALSH_CXX_SOURCES mem_manager.cpp)
endif()
if(TALSH_GPU)
set(TALSH_CUDA_SOURCES tensor_algebra_gpu_nvidia.cu)
set(TALSH_HIP_SOURCES tensor_algebra_gpu_nvidia.hip.cu)
endif()
if(USE_HIP)
configure_file(tensor_algebra_gpu_nvidia.hip.cu ${PROJECT_SOURCE_DIR}/tensor_algebra_gpu_nvidia.cpp COPYONLY)
list(APPEND TALSH_CXX_SOURCES tensor_algebra_gpu_nvidia.cpp)
elseif(NOT TALSH_GPU)
configure_file(tensor_algebra_gpu_nvidia.cu ${PROJECT_SOURCE_DIR}/tensor_algebra_gpu_nvidia.cpp COPYONLY)
list(APPEND TALSH_CXX_SOURCES tensor_algebra_gpu_nvidia.cpp)
endif()
if(TALSH_GPU)
set(TALSH_CUDA_FLAGS ${TALSH_CUDA_FLAGS} -lineinfo -w -D_FORCE_INLINES -m64
-Xptxas --warn-on-spills;-gencode arch=compute_${TALSH_GPU_ARCH},code=sm_${TALSH_GPU_ARCH}; -ccbin ${CMAKE_CXX_COMPILER})
if(TALSH_FINE_TIMING)
list(APPEND TALSH_CXX_COMPILE_DEFS GPU_FINE_TIMING)
list(APPEND TALSH_Fortran_COMPILE_DEFS GPU_FINE_TIMING)
endif()
endif()
add_library(talsh_cxx OBJECT ${TALSH_CXX_SOURCES})
target_include_directories(talsh_cxx PRIVATE ${TALSH_INCLUDES})
target_compile_definitions(talsh_cxx PRIVATE ${TALSH_CXX_COMPILE_DEFS})
target_compile_options(talsh_cxx PRIVATE ${TALSH_CXX_FLAGS})
if(USE_HIP)
target_link_libraries(talsh_cxx PRIVATE hip::device)
endif()
if(TALSH_GPU)
add_library(talsh_fort OBJECT ${TALSH_FORTRAN_SOURCES})
target_include_directories(talsh_fort PRIVATE ${TALSH_INCLUDES})
target_compile_definitions(talsh_fort PRIVATE ${TALSH_Fortran_COMPILE_DEFS})
target_compile_options(talsh_fort PRIVATE ${TALSH_Fortran_FLAGS})
if(USE_HIP)
add_library(talsh STATIC ${TALSH_HIP_SOURCES} $<TARGET_OBJECTS:talsh_cxx> $<TARGET_OBJECTS:talsh_fort>)
else()
set_source_files_properties(${TALSH_CUDA_SOURCES} PROPERTIES CUDA_SOURCE_PROPERTY_FORMAT OBJ)
add_library(talsh STATIC ${TALSH_CUDA_SOURCES} $<TARGET_OBJECTS:talsh_cxx> $<TARGET_OBJECTS:talsh_fort>)
target_compile_options(talsh PRIVATE ${TALSH_CUDA_FLAGS})
endif()
if(USE_HIP)
set(GPU_BLAS roc::hipblas hip::device)
else()
set(GPU_BLAS CUDA::cublas)
endif()
if(USE_OPENMP)
target_link_libraries(talsh PUBLIC ${GPU_BLAS} OpenMP::OpenMP_C)
else()
target_link_libraries(talsh PUBLIC ${GPU_BLAS})
endif()
else()
add_library(talsh STATIC ${TALSH_FORTRAN_SOURCES} $<TARGET_OBJECTS:talsh_cxx>)
target_include_directories(talsh PUBLIC ${TALSH_INCLUDES})
target_compile_definitions(talsh PRIVATE ${TALSH_Fortran_COMPILE_DEFS})
target_compile_options(talsh PRIVATE ${TALSH_Fortran_FLAGS})
if(USE_OPENMP)
target_link_libraries(talsh PUBLIC OpenMP::OpenMP_C)
endif()
endif()
add_library(talsh::talsh ALIAS talsh)
set(TALSH_HEADERS
timer.h
byte_packet.h
nvtx_profile.h
mem_manager.h
tensor_algebra.h
talsh.h
tensor_method.hpp
talsh_task.hpp
talshxx.hpp
)
if(USE_HIP)
list(APPEND TALSH_HEADERS
device_algebra.hip.h
talsh_complex.hip.h)
else()
list(APPEND TALSH_HEADERS
device_algebra.h
talsh_complex.h)
endif()
if(BUILD_TESTS)
enable_testing()
add_executable(talsh_test main.F90 test.cpp)
target_link_libraries(talsh_test talsh::talsh)
target_compile_definitions(talsh_test PRIVATE ${TALSH_Fortran_COMPILE_DEFS})
target_compile_options(talsh_test PRIVATE ${TALSH_Fortran_FLAGS})
add_test(NAME talsh_test COMMAND talsh_test)
endif()
set_target_properties(talsh PROPERTIES EXPORT_NAME talsh)
# Install
include(GNUInstallDirs)
set(INSTALL_CONFIGDIR ${CMAKE_INSTALL_LIBDIR}/cmake/talsh)
install(TARGETS talsh
EXPORT talsh-targets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
)
install(FILES ${TALSH_HEADERS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/talsh)
#Export the targets to a script
install(EXPORT talsh-targets
FILE
talsh-targets.cmake
NAMESPACE
talsh::
DESTINATION
${INSTALL_CONFIGDIR}
)
#Create a ConfigVersion.cmake file
include(CMakePackageConfigHelpers)
write_basic_package_version_file(
${CMAKE_CURRENT_BINARY_DIR}/talsh-config-version.cmake
VERSION ${PROJECT_VERSION}
COMPATIBILITY AnyNewerVersion
)
configure_package_config_file(${CMAKE_CURRENT_LIST_DIR}/cmake/talsh-config.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/talsh-config.cmake
INSTALL_DESTINATION ${INSTALL_CONFIGDIR}
PATH_VARS CMAKE_INSTALL_INCLUDEDIR
)
#Install the config, configversion files
install(FILES
${CMAKE_CURRENT_BINARY_DIR}/talsh-config.cmake
${CMAKE_CURRENT_BINARY_DIR}/talsh-config-version.cmake
DESTINATION ${INSTALL_CONFIGDIR}
)
export(EXPORT talsh-targets
FILE ${CMAKE_CURRENT_BINARY_DIR}/talsh-targets.cmake
NAMESPACE talsh::)
#Register package in user's package registry
export(PACKAGE talsh)