-
Notifications
You must be signed in to change notification settings - Fork 41
/
CMakeLists.txt
333 lines (282 loc) · 12.6 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
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
# Specifiy the cmake version range, currenty work under 3.18
cmake_minimum_required(VERSION 3.18)
project(OPS C CXX Fortran)
# if show the compiling process in detail
option(OPS_VERBOSE_WARNING "Turn on verbose warning messages" OFF)
option(OPS_TEST "Turn on tests for Apps" OFF)
option(OPS_HIP "Turn on the HIP backend" OFF)
option(ENABLE_IEEE "Enable IEEE flags" OFF)
option(LEGACY_CODEGEN "Build apps with Legacy code-gen" OFF)
option(BUILD_OPS_CXX "Build CXX version of OPS" ON)
option(BUILD_OPS_FORTRAN "Build FORTRAN version of OPS" OFF)
option(BUILD_OPS_APPS "Build Sample OPS applications" OFF)
if(NOT OPS_VERBOSE_WARNING)
message(
"We show concise compiling information by default \n! Use -DOPS_VERBOSE_WARNING=ON to switch on."
)
endif()
set(CMAKE_VERBOSE_MAKEFILE ${OPS_VERBOSE_WARNING})
# Use the Release mode by default
if(NOT CMAKE_BUILD_TYPE)
message("Using default mode. Please use -DCMAKE_BUILD_TYPE to change to Release or Debug.")
set(CMAKE_BUILD_TYPE "")
endif()
message(
WARNING
"The installation directory is ${CMAKE_INSTALL_PREFIX} \n! Use -DCMAKE_INSTALL_PREFIX to change"
)
# Tridiagonal library
if(NOT LIBTRID_PATH)
message(
WARNING
"The install path of the scalar tridiagonal solver library (LIBTRID_PATH) is not specified and it will not compiled!"
)
endif()
# Configure C Compiler
set(CMAKE_C_STANDARD 99)
if(${CMAKE_C_COMPILER_ID} STREQUAL GNU)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3 -std=c99 -fPIC -Wall -ffloat-store -g -ftree-vectorize -fopenmp")
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -O3 -std=c99 -fPIC -Wall -ffloat-store -g -ftree-vectorize -fopenmp")
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -O0 -std=c99 -fPIC -Wall -ffloat-store -g -fopenmp")
elseif(${CMAKE_C_COMPILER_ID} STREQUAL Clang)
set(CMAKE_C_FLAGS "-fPIC -DUNIX -Wall")
set(CMAKE_C_FLAGS_RELEASE "-O3")
set(CMAKE_C_FLAGS_DEBUG "-g -O0")
elseif(${CMAKE_C_COMPILER_ID} STREQUAL MSVC)
set(CMAKE_C_FLAGS "-W1")
set(CMAKE_C_FLAGS_RELEASE "/O2 /Ot ")
set(CMAKE_C_FLAGS_DEBUG "/Z7 /DEBUG")
elseif(${CMAKE_C_COMPILER_ID} STREQUAL NVHPC)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3 -fast -gopt")
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -O3 -fast -gopt")
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -O0 -g")
elseif(${CMAKE_C_COMPILER_ID} STREQUAL Intel)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3 -g -xHost -std=c99 -qopenmp -qopt-report")
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -O3 -g -xHost -std=c99 -qopenmp -qopt-report")
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -O0 -xHost -g -std=c99")
else()
message(
WARNING
"There is no default flag for the chosen C compiler! Please use -DCFLAG=XXX to supply!"
)
endif()
# Configure C++ Compiler
set(CMAKE_CXX_STANDARD 11)
if(${CMAKE_CXX_COMPILER_ID} STREQUAL GNU)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 -fPIC -Wall -ffloat-store -g -std=c++11 -fopenmp")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3 -fPIC -Wall -ffloat-store -g -std=c++11 -fopenmp")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0 -fPIC -Wall -ffloat-store -g -std=c++11")
elseif(${CMAKE_CXX_COMPILER_ID} STREQUAL Clang)
set(CMAKE_CXX_FLAGS "-fPIC -DUNIX -Wall")
set(CMAKE_CXX_FLAGS_RELEASE "-O3")
set(CMAKE_CXX_FLAGS_DEBUG "-g -O0")
elseif(${CMAKE_CXX_COMPILER_ID} STREQUAL MSVC)
set(CMAKE_CXX_FLAGS "-W1")
set(CMAKE_CXX_FLAGS_RELEASE "/O2 /Ot ")
set(CMAKE_CXX_FLAGS_DEBUG "/Z7 /DEBUG")
elseif(${CMAKE_C_COMPILER_ID} STREQUAL NVHPC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 -fast -gopt -std=c++11 -mp")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3 -fast -gopt -std=c++11 -mp")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0 -g -std=c++11 -mp")
elseif(${CMAKE_CXX_COMPILER_ID} STREQUAL Intel)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 -g -xHost -qopenmp -qopt-report -std=c++11 -qopt-zmm-usage=high")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3 -g -xHost -qopenmp -qopt-report -std=c++11 -qopt-zmm-usage=high")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0 -g -xHost -DOPS_DEBUG -std=c++11 -DOPS_DEBUG")
else()
message(
WARNING
"There is no default flag for the chosen C++ compiler! Please use -DCXXFLAG=XXX to supply!"
)
endif()
# Adding CFLAGS provided to CMAKE_C_FLAGS
if(CFLAG)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CFLAG}")
else()
message(
"Extra C compiler options can be provided using CFLAG, e.g., -DCFLAG=\"-ffloat-store\" for GNU!"
)
endif()
# Adding CXXFLAGS provided to CMAKE_CXX_FLAGS
if(CXXFLAG)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CXXFLAG}")
else()
message(
"Extra CXX compiler options can be provided using CXXFLAG, e.g., -DCXXFLAG=\"-ffloat-store\" for GNU!"
)
endif()
# If IEEE is enabled
if(ENABLE_IEEE)
# Add IEEE flags to CMAKE_CXX_FLAGS
if(${CMAKE_CXX_COMPILER_ID} STREQUAL Intel)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fp-model strict -fp-model source -prec-div -prec-sqrt")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fp-model strict -fp-model source -prec-div -prec-sqrt")
elseif(${CMAKE_C_COMPILER_ID} STREQUAL NVHPC)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Kieee -nofma")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Kieee -nofma")
else()
message(
WARNING
"There is no default IEEE flags for chosen compiler"
)
endif()
endif()
if(CMAKE_BUILD_TYPE STREQUAL "Release")
message(STATUS "CMAKE_C_FLAGS_RELEASE: ${CMAKE_C_FLAGS_RELEASE}")
message(STATUS "CMAKE_CXX_FLAGS_RELEASE: ${CMAKE_CXX_FLAGS_RELEASE}")
elseif(CMAKE_BUILD_TYPE STREQUAL "Debug")
message(STATUS "CMAKE_C_FLAGS_DEBUG: ${CMAKE_C_FLAGS_DEBUG}")
message(STATUS "CMAKE_CXX_FLAGS_DEBUG: ${CMAKE_CXX_FLAGS_DEBUG}")
elseif(CMAKE_BUILD_TYPE STREQUAL "")
message(STATUS "CMAKE_C_FLAGS: ${CMAKE_C_FLAGS}")
message(STATUS "CMAKE_CXX_FLAGS: ${CMAKE_CXX_FLAGS}")
else()
message(STATUS "Unknown build type: ${CMAKE_BUILD_TYPE}")
endif()
# include(GenerateExportHeader)
include(CMakePackageConfigHelpers)
set(VERSION latest)
set(ConfigPackageLocation ${CMAKE_INSTALL_PREFIX}/lib/cmake)
# if (CFLAG) add_compile_options(${CFLAG}) endif () Add find scripts
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
set(HDF5_PREFER_PARALLEL true)
# Try to find the required dependency
find_package(MPI QUIET)
find_package(HDF5 QUIET COMPONENTS C HL)
find_package(CUDAToolkit QUIET)
find_package(OpenMP REQUIRED)
find_package(Python3 3.8 REQUIRED)
if(NOT Python3_FOUND)
message(
WARNING
"We cannot find Python3 and the OPS code-generator needs Python3! Please use -DPython3_EXECUTABLE to specify the path."
)
endif()
if(OPS_HIP)
# Search for rocm in common locations
list(APPEND CMAKE_PREFIX_PATH /opt/rocm/hip /opt/rocm)
# Find hip
find_package(hip)
# enable_language(HIP) message($ENV{HIP_PLATFORM})
set(ENV{HIP_PLATFORM} "nvidia")
# message($ENV{HIP_PLATFORM})
set(HIP_FOUND TRUE)
if({$hip::host} STREQUAL "" OR {$hip::device} STREQUAL "")
message(
WARNING
"We cannot find the HIP environment. The HIP codes won't work! You might need to use CMAKE_PREFIX_PATH to specify the path for HIP!"
)
set(HIP_FOUND FALSE)
endif()
endif()
# Configure the "include" dir for compiling
if(NOT HDF5_FOUND)
message(
WARNING
"We cannot find the parallel HDF5 library. The HDF5 IO routines won't work! Please use -DHDF5_ROOT to specify the path!"
)
endif()
if(NOT MPI_FOUND)
message(
WARNING "We cannot find a MPI environment! The MPI codes won't compile!")
endif()
if(LIBTRID_PATH)
include_directories(${LIBTRID_PATH}/include)
endif()
if(CUDAToolkit_FOUND)
set(CMAKE_CUDA_COMPILER ${CUDAToolkit_NVCC_EXECUTABLE})
if(GPU_ARCH)
set(CMAKE_CUDA_ARCHITECTURES
${GPU_ARCH}
CACHE STRING "CUDA architectures")
else()
set(CMAKE_CUDA_ARCHITECTURES
70
CACHE STRING "CUDA architectures")
message(WARNING "Using Volta architecure for compiling CUDA. \n If different please provide correct GPU architecture using -DGPU_ARCH=XXX where XXX is compute capability of an architecture \n For ex. -DGPU_ARCH=70 if you want to target sm_70")
endif()
enable_language(CUDA)
else()
message(WARNING "We cannot find a CUDA toolkit! The CUDA codes won't compile!")
endif()
if(USE_NCCL)
find_package(NCCL)
if(NOT NCCL_FOUND)
message(
WARNING
"We cannot find NCCL! Tridiagonal library wrapper will be compiled with NCCL"
)
endif()
endif()
# option(OPS_ERROR_ON_WARNING "Error upon encountering a warning" ON)
# option(CHECKPOINTING "Enable OPS checkpointing support" OFF)
# option(OPS_INSTALL_TRANSLATOR "Install OPS Source Translator" ON)
# option(OPS_INSTALL_HEADERS "Install OPS Dev Headers" ON)
# option(OPS_INSTALL_LIBS "Install OPS Libraries" ON)
# Turn on all the warnings if(OPS_VERBOSE_WARNINGS) if (WIN32) list(APPEND
# OPS_WARNINGS /W4) list(APPEND OPS_WARNINGS /wd4849) list(APPEND OPS_WARNINGS
# /wd4127) list(APPEND OPS_WARNINGS /D_CRT_SECURE_NO_WARNINGS) else()
# list(APPEND OPS_WARNINGS -Wall -Wextra -pedantic -Wno-unused-function
# -Wno-unused-parameter) endif() foreach(flag IN LISTS OPS_WARNINGS) # NVCC
# complicates life a little here # 1) We want to pass our warning flags to the
# compiler, not NVCC, so # each need prefaced with -Xcompiler # 2) NVCC
# generates code which is not pedantically compliant, so need # to filter the
# -pedantic from compiling cuda code
# add_compile_options("$<IF:$<COMPILE_LANGUAGE:CUDA>,$<$<NOT:$<STREQUAL:-pedantic,${flag}>>:SHELL:-Xcompiler
# ${flag}>,${flag}>") endforeach() endif() if(OPS_ERROR_ON_WARNING) if (WIN32)
# set(werrorFlag "/WX") else() set(werrorFlag "-Werror") endif()
# add_compile_options("$<$<COMPILE_LANGUAGE:CUDA>:SHELL:-Xcompiler
# >${werrorFlag}") endif()
# install python translator
if(LEGACY_CODEGEN)
add_subdirectory(ops_translator_legacy)
else()
add_subdirectory(ops_translator)
endif()
# Configure the C/C++ library compiling
if(BUILD_OPS_CXX)
add_subdirectory(ops/c)
endif()
# Configure the installation of "include"
file(GLOB_RECURSE INCLUDE "${CMAKE_CURRENT_SOURCE_DIR}/ops/c/include/*.h"
"${CMAKE_CURRENT_SOURCE_DIR}/ops/fortran/include/*.inc")
install(FILES ${INCLUDE} DESTINATION include)
# prepare the script for setting OPS environment variable
if(UNIX)
install(
CODE "file(WRITE \"${CMAKE_INSTALL_PREFIX}/bin/ops_env\" \"export OPS_INSTALL_PATH=${CMAKE_INSTALL_PREFIX}\n\")"
)
if(NOT ((CMAKE_INSTALL_PREFIX STREQUAL "/usr")
OR (CMAKE_INSTALL_PREFIX STREQUAL "/usr/local")))
install(
CODE "file(APPEND \"${CMAKE_INSTALL_PREFIX}/bin/ops_env\" \"export PATH=$PATH:${CMAKE_INSTALL_PREFIX}/bin\n\")"
)
endif()
endif()
if(BUILD_OPS_FORTRAN)
add_subdirectory(ops/fortran)
endif()
# prepare ctest
if(OPS_TEST)
enable_testing()
include(ProcessorCount)
ProcessorCount(CPU_NUMBER)
if(CPU_NUMBER GREATER 12)
set(CPU_NUMBER 12)
endif()
if(NOT GPU_NUMBER)
message(
WARNING "GPU tests are disabled! Please use -DGPU_NUMBER to specify!")
endif()
endif()
if(BUILD_OPS_CXX)
install(FILES "${CMAKE_BINARY_DIR}/OPSConfig.cmake"
DESTINATION ${ConfigPackageLocation})
endif()
if(BUILD_OPS_APPS)
if(BUILD_OPS_CXX)
add_subdirectory(apps/c)
endif()
if(BUILD_OPS_FORTRAN)
add_subdirectory(apps/fortran)
endif()
endif()