forked from deepmodeling/abacus-develop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
413 lines (374 loc) · 11.4 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
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
cmake_minimum_required(VERSION 3.16)
if(POLICY CMP0135) # https://cmake.org/cmake/help/git-stage/policy/CMP0135.html
cmake_policy(SET CMP0135 NEW) # Otherwise this policy generates a warning on CMake 3.24
endif()
project(ABACUS
VERSION 3.0.0
DESCRIPTION "ABACUS is an electronic structure package based on DFT."
HOMEPAGE_URL "https://github.com/deepmodeling/abacus-develop"
LANGUAGES CXX
)
option(ENABLE_LCAO "Enable LCAO calculation." ON)
option(ENABLE_DEEPKS "Enable DeePKS functionality" OFF)
option(ENABLE_LIBXC "Enable LibXC functionality" OFF)
option(USE_CUDA "Enable support to CUDA for PW." OFF)
option(USE_CUSOLVER_LCAO "Enable support to CUSOLVER for LCAO." OFF)
option(USE_ROCM "Enable support to ROCm." OFF)
option(USE_OPENMP " Enable OpenMP in abacus." ON)
option(ENABLE_ASAN "Enable AddressSanitizer" OFF)
option(BUILD_TESTING "Build ABACUS unit tests" OFF)
option(GENERATE_TEST_REPORTS "Enable test report generation" OFF)
option(INFO "Enable gathering of math library information" OFF)
option(ENABLE_COVERAGE "Enable coverage build." OFF)
if(ENABLE_LCAO)
set(ABACUS_BIN_NAME abacus)
else()
set(ABACUS_BIN_NAME abacus_pw)
endif()
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
if(ENABLE_COVERAGE)
find_package(codecov)
if(NOT codecov)
include(FetchContent)
FetchContent_Declare(
cmakecodecov
URL https://github.com/RWTH-HPC/CMake-codecov/archive/refs/heads/master.zip
)
FetchContent_Populate(cmakecodecov)
list(APPEND CMAKE_MODULE_PATH ${cmakecodecov_SOURCE_DIR}/cmake)
find_package(codecov REQUIRED)
endif()
endif()
set(ABACUS_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/source)
set(ABACUS_TEST_DIR ${CMAKE_CURRENT_SOURCE_DIR}/tests)
set(ABACUS_BIN_PATH ${CMAKE_CURRENT_BINARY_DIR}/${ABACUS_BIN_NAME})
include_directories(${ABACUS_SOURCE_DIR})
add_executable(${ABACUS_BIN_NAME} source/main.cpp)
if(ENABLE_COVERAGE)
add_coverage(${ABACUS_BIN_NAME})
endif()
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
if (CMAKE_COMPILER_IS_GNUCXX AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5)
message(WARNING "GCC4 is not fully supported.")
endif()
add_compile_options(-Wno-write-strings)
set(FETCHCONTENT_QUIET FALSE) # Notify user when cloning git repo
find_program(CCACHE ccache)
if (CCACHE)
set (CMAKE_CXX_COMPILER_LAUNCHER ${CCACHE} ${CMAKE_CXX_COMPILER_LAUNCHER})
set (CMAKE_C_COMPILER_LAUNCHER ${CCACHE} ${CMAKE_C_COMPILER_LAUNCHER})
endif()
# Select 'Release' configuration for best performance;
# this will disable all assertions.
# Other default configurations are also available, see:
# https://cmake.org/cmake/help/latest/manual/cmake-buildsystem.7.html#default-and-custom-configurations
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
if(NOT ENABLE_COVERAGE)
add_compile_options(-O2 -g) # default flag
else()
add_compile_options(-g)
endif()
endif()
if(ENABLE_LCAO)
find_package(Cereal REQUIRED)
include_directories(${CEREAL_INCLUDE_DIR})
add_compile_definitions(USE_CEREAL_SERIALIZATION)
find_package(ELPA REQUIRED)
include_directories(${ELPA_INCLUDE_DIR})
target_link_libraries(${ABACUS_BIN_NAME} ELPA::ELPA)
add_compile_definitions(__LCAO)
else()
set(ENABLE_DEEPKS OFF)
endif()
find_package(MPI REQUIRED)
include_directories(${MPI_CXX_INCLUDE_PATH})
target_link_libraries(${ABACUS_BIN_NAME} MPI::MPI_CXX)
add_compile_definitions(__MPI)
list(APPEND math_libs MPI::MPI_CXX)
find_package(Threads REQUIRED)
target_link_libraries(${ABACUS_BIN_NAME} Threads::Threads)
if(USE_OPENMP)
find_package(OpenMP REQUIRED)
target_link_libraries(${ABACUS_BIN_NAME} OpenMP::OpenMP_CXX)
add_compile_options(${OpenMP_CXX_FLAGS})
add_link_options(${OpenMP_CXX_LIBRARIES})
endif()
include(CheckLanguage)
check_language(CUDA)
if(CMAKE_CUDA_COMPILER)
if(NOT DEFINED USE_CUDA OR NOT DEFINED USE_CUSOLVER_LCAO)
if (NOT DEFINED USE_CUDA AND NOT DEFINED USE_CUSOLVER_LCAO)
message("CUDA components detected. \nWill build the CUDA for PW version of ABACUS by default.")
set(USE_CUDA ON)
set(USE_CUSOLVER_LCAO OFF)
elseif (NOT DEFINED USE_CUDA)
set(USE_CUDA OFF)
else()
set(USE_CUSOLVER_LCAO OFF)
endif()
else()
if(NOT USE_CUDA AND NOT USE_CUSOLVER_LCAO)
message(STATUS "CUDA components detected, but both USE_CUDA and USE_CUSOLVER_LCAO set to OFF. NOT building CUDA version of ABACUS.")
elseif (USE_CUDA AND USE_CUSOLVER_LCAO)
message(FATAL_ERROR "USE_CUDA and USE_CUSOLVER_LCAO set, but now they not allowed to coexist.")
endif()
endif()
else() # CUDA not found
if (USE_CUDA OR USE_CUSOLVER_LCAO)
message(FATAL_ERROR "USE_CUDA or USE_CUSOLVER_LCAO set but no CUDA components found.")
set(USE_CUDA OFF)
set(USE_CUSOLVER_LCAO OFF)
endif()
endif()
if(USE_CUDA OR USE_CUSOLVER_LCAO)
cmake_minimum_required(VERSION 3.18) # required by `CUDA_ARCHITECTURES` below
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_EXTENSIONS ON)
set(CMAKE_CUDA_STANDARD ${CMAKE_CXX_STANDARD})
set(CMAKE_CUDA_STANDARD_REQUIRED ON)
set(CMAKE_CUDA_HOST_COMPILER ${CMAKE_CXX_COMPILER})
enable_language(CUDA)
target_link_libraries(${ABACUS_BIN_NAME}
-lcufft
-lcublas
-lcudart
-lcusolver
-lnvToolsExt
)
set_property(TARGET ${ABACUS_BIN_NAME}
PROPERTY CUDA_ARCHITECTURES
60 # P100
70 # V100
75 # T4
80 # A100
)
include_directories(${CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES})
if (USE_CUDA)
add_compile_definitions(__CUDA)
add_compile_definitions(__UT_USE_CUDA)
endif()
if (USE_CUSOLVER_LCAO)
add_compile_definitions(__CUSOLVER_LCAO)
endif()
endif()
# Warning: CMake add support to HIP in version 3.21. This is rather a new version.
# Use cmake with AMD-ROCm: https://rocmdocs.amd.com/en/latest/Installation_Guide/Using-CMake-with-AMD-ROCm.html
if(USE_ROCM)
SET(CMAKE_HIP_STANDARD ${CMAKE_CXX_STANDARD})
list(APPEND CMAKE_PREFIX_PATH /opt/rocm/hip /opt/rocm)
list(APPEND CMAKE_SYSTEM_PREFIX_PATH "/opt/rocm/hip")
# find_package(ROCM REQUIRED)
find_package(hip REQUIRED)
find_package(hipfft REQUIRED)
find_package(hipblas REQUIRED)
include_directories(
/opt/rocm/hip/include
/opt/rocm/hipfft/include
/opt/rocm/hipblas/include
)
target_link_libraries(${ABACUS_BIN_NAME}
hip::device
hip::host
hip::hipfft
roc::hipblas
)
add_compile_definitions(__ROCM)
add_compile_definitions(__UT_USE_ROCM)
endif()
if(ENABLE_ASAN)
if (CMAKE_CXX_COMPILER_ID STREQUAL "Intel")
message(FATAL_ERROR "Address Sanitizer is not supported on Intel compiler.")
endif()
add_compile_options(
-fsanitize=address
-fno-omit-frame-pointer
)
add_link_options(
-fsanitize=address
)
# `add_link_options` only affects executables added after.
target_link_libraries(${ABACUS_BIN_NAME} -fsanitize=address)
endif()
if(DEFINED ENV{MKLROOT} AND NOT DEFINED MKLROOT)
set(MKLROOT "$ENV{MKLROOT}")
endif()
if(MKLROOT)
find_package(IntelMKL REQUIRED)
add_definitions(-D__MKL)
include_directories(${MKL_INCLUDE_DIRS} ${MKL_INCLUDE_DIRS}/fftw)
# Since libtorch will find its own MKL, the fftw part conflicts with the original one.
# When enable deepks, mkl will be linked within ${TORCH_LIBRARIES}.
if(NOT ENABLE_DEEPKS)
list(APPEND math_libs IntelMKL::MKL)
endif()
else()
find_package(FFTW3 REQUIRED)
find_package(LAPACK REQUIRED)
find_package(ScaLAPACK REQUIRED)
include_directories(${FFTW3_INCLUDE_DIRS})
list(APPEND math_libs
FFTW3::FFTW3
LAPACK::LAPACK
ScaLAPACK::ScaLAPACK
)
if(CMAKE_CXX_COMPILER_ID MATCHES GNU)
list(APPEND math_libs -lgfortran)
elseif(CMAKE_CXX_COMPILER_ID MATCHES Intel)
list(APPEND math_libs -lifcore)
else()
message(WARNING "Cannot find the correct library for Fortran.")
endif()
endif()
if(ENABLE_DEEPKS)
set(CMAKE_CXX_STANDARD 14)
find_package(Torch REQUIRED)
include_directories(${TORCH_INCLUDE_DIRS})
target_link_libraries(${ABACUS_BIN_NAME} deepks)
list(APPEND math_libs ${TORCH_LIBRARIES})
add_compile_options(${TORCH_CXX_FLAGS})
find_path(libnpy_SOURCE_DIR
npy.hpp
HINTS ${libnpy_INCLUDE_DIR}
)
if(NOT libnpy_SOURCE_DIR)
include(FetchContent)
FetchContent_Declare(
libnpy
GIT_REPOSITORY https://github.com/llohse/libnpy.git
GIT_SHALLOW TRUE
GIT_PROGRESS TRUE
)
FetchContent_MakeAvailable(libnpy)
endif()
include_directories(${libnpy_SOURCE_DIR}/include)
add_compile_definitions(__DEEPKS)
endif()
list(APPEND math_libs m)
target_link_libraries(${ABACUS_BIN_NAME} ${math_libs})
if(DEFINED Libxc_DIR)
set(ENABLE_LIBXC ON)
endif()
if(ENABLE_LIBXC)
find_package(Libxc 5.1.7 REQUIRED HINTS ${Libxc_DIR}/share/cmake/Libxc)
if(${Libxc_FOUND})
message(STATUS "Found Libxc: version " ${Libxc_VERSION})
target_link_libraries(${ABACUS_BIN_NAME} Libxc::xc)
include_directories(${Libxc_INCLUDE_DIRS})
add_compile_definitions(USE_LIBXC)
endif()
endif()
if(DEFINED DeePMD_DIR)
add_compile_definitions(
__DPMD
HIGH_PREC
)
add_compile_options(-Wl,--no-as-needed)
find_package(DeePMD REQUIRED)
include_directories(${DeePMD_DIR}/include)
target_link_libraries(${ABACUS_BIN_NAME}
DeePMD::deepmd_cc
DeePMD::deepmd_op
DeePMD::deepmd_op_cuda
DeePMD::tensorflow_cc
)
if(NOT DEFINED TensorFlow_DIR)
message(FATAL_ERROR "Please define TensorFlow_DIR!")
endif()
endif()
if(DEFINED TensorFlow_DIR)
include_directories(${TensorFlow_DIR}/include)
if(NOT DEFINED DeePMD_DIR)
message(FATAL_ERROR "Please define DeePMD_DIR!")
endif()
endif()
add_compile_definitions(
__FFTW3
__SELINV
METIS
__EXX
EXX_DM=3
EXX_H_COMM=2
TEST_EXX_LCAO=0
TEST_EXX_RADIAL=1
)
if(INFO)
message(STATUS "Will gather math lib info.")
add_compile_definitions(GATHER_INFO)
# modifications on blas_connector and lapack_connector
endif()
IF (BUILD_TESTING)
set(CMAKE_CXX_STANDARD 14) # Required in orbital
include(CTest)
enable_testing()
find_package(GTest HINTS /usr/local/lib/ ${GTEST_DIR})
if(NOT ${GTest_FOUND})
include(FetchContent)
FetchContent_Declare(
googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG "origin/main"
GIT_SHALLOW TRUE
GIT_PROGRESS TRUE
)
FetchContent_MakeAvailable(googletest)
endif()
# TODO: Try the GoogleTest module.
# https://cmake.org/cmake/help/latest/module/GoogleTest.html
add_subdirectory(tests) # Contains integration tests
function(AddTest) # function for UT
cmake_parse_arguments(UT "DYN" "TARGET" "LIBS;DYN_LIBS;STATIC_LIBS;SOURCES;DEPENDS" ${ARGN})
add_executable(${UT_TARGET} ${UT_SOURCES})
if(ENABLE_COVERAGE)
add_coverage(${UT_TARGET})
endif()
#dependencies & link library
target_link_libraries(${UT_TARGET} ${UT_LIBS}
Threads::Threads GTest::gtest_main GTest::gmock_main)
if(USE_OPENMP)
target_link_libraries(${UT_TARGET} OpenMP::OpenMP_CXX)
endif()
install(TARGETS ${UT_TARGET} DESTINATION ${CMAKE_BINARY_DIR}/tests )
add_test(NAME ${UT_TARGET}
COMMAND ${UT_TARGET}
WORKING_DIRECTORY $<TARGET_FILE_DIR:${UT_TARGET}>
)
endfunction(AddTest)
endif()
add_subdirectory(source)
target_link_libraries(${ABACUS_BIN_NAME}
base
cell
symmetry
md
planewave
surchem
neighbor
io
relax
ri
parallel
pw
driver
xc_
hsolver
elecstate
hamilt
psi
esolver
vdw
)
if(ENABLE_LCAO)
target_link_libraries(${ABACUS_BIN_NAME}
lcao
orb
gint
mrrr
pdiag
genelpa
rpa
)
endif()
if(ENABLE_COVERAGE)
coverage_evaluate()
endif()