Skip to content

Commit 1e538d8

Browse files
author
Mathieu Taillefumier
committed
Build DDalphaAMG automatically when DDalphaAMG is enabled
1 parent 065d6d0 commit 1e538d8

File tree

6 files changed

+455
-14
lines changed

6 files changed

+455
-14
lines changed

.github/workflows/ddalphaamg-build.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,8 @@ jobs:
111111
run: |
112112
CC=mpicc CXX=mpicxx \
113113
LDFLAGS="-fopenmp" \
114-
CFLAGS="-O2 -mtune=haswell -march=haswell -mavx2 -mfma -DOMPI_SKIP_MPICXX -fopenmp" \
115-
CXXFLAGS="-O2 -mtune=haswell -march=haswell -mavx2 -mfma -DOMPI_SKIP_MPICXX -fopenmp" \
114+
CFLAGS="-O3 -ffast-math -mtune=haswell -march=haswell -mavx2 -mfma -DOMPI_SKIP_MPICXX -fopenmp" \
115+
CXXFLAGS="-O3 -ffast-math -mtune=haswell -march=haswell -mavx2 -mfma -DOMPI_SKIP_MPICXX -fopenmp" \
116116
cmake -DCMAKE_PREFIX_PATH="${{github.workspace}}/lime/build/install_dir;${{github.workspace}}/lemon/build/install_dir;${{github.workspace}}/ddalphaamg" \
117117
-DTM_USE_MPI=ON \
118118
-DTM_USE_OMP=ON \

CMakeLists.txt

Lines changed: 82 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ endif()
2424
# PROJECT AND VERSION
2525
include(CMakeDependentOption)
2626
include(GNUInstallDirs)
27+
include(FetchContent)
28+
include(CMakePackageConfigHelpers)
2729

2830
cmake_policy(SET CMP0048 NEW)
2931

@@ -100,7 +102,9 @@ option(TM_USE_SHMEM "Use shmem API" OFF)
100102
option(TM_USE_QUDA "Enable QUDA support" OFF)
101103
option(TM_ENABLE_WARNINGS "Enable all warnings" ON)
102104
option(TM_ENABLE_TESTS "Enable tests" OFF)
103-
set(TM_QPHIX_SOALEN "4" CACHE STRING "QPhiX specific parameter")
105+
set(TM_QPHIX_SOALEN
106+
"4"
107+
CACHE STRING "QPhiX specific parameter")
104108
# MPI dependent options
105109
cmake_dependent_option(
106110
TM_PERSISTENT_MPI "Use persistent MPI calls for halfspinor [default=no]" OFF
@@ -126,6 +130,44 @@ cmake_dependent_option(TM_USE_LEMON "Use the lemon io library" OFF "TM_USE_MPI"
126130
cmake_dependent_option(TM_USE_NVHPC "Enable Nvidia HPC toolkit" OFF
127131
"TM_USE_CUDA" OFF)
128132

133+
# DDAlphaAMG specific options
134+
135+
cmake_dependent_option(
136+
DDalphaAMG_ENABLE_PARAMOUNT_OUTPUT "Enable paramount output support" ON
137+
"TM_USE_DDalphaAMG" OFF)
138+
139+
cmake_dependent_option(DDalphaAMG_ENABLE_FGMRES_RESTEST "Enable GMRES test" OFF
140+
"TM_USE_DDalphaAMG" OFF)
141+
142+
cmake_dependent_option(
143+
DDalphaAMG_ENABLE_PROFILING "Enable paramount output support" OFF
144+
"TM_USE_DDalphaAMG" OFF)
145+
146+
cmake_dependent_option(DDalphaAMG_ENABLE_TRACK_RES "Enable track res support"
147+
ON "TM_USE_DDalphaAMG" OFF)
148+
149+
cmake_dependent_option(
150+
DDalphaAMG_ENABLE_SINGLE_ALLREDUCE_ARNOLDI OFF
151+
"Enable paramount output support" OFF "TM_USE_DDalphaAMG" OFF)
152+
153+
cmake_dependent_option(
154+
DDalphaAMG_ENABLE_COARSE_RES "Enable paramount output support" OFF
155+
"TM_USE_DDalphaAMG" OFF)
156+
157+
cmake_dependent_option(
158+
DDalphaAMG_ENABLE_SCHWARZ_RES "Enable paramount output support" OFF
159+
"TM_USE_DDalphaAMG" OFF)
160+
161+
cmake_dependent_option(DDalphaAMG_ENABLE_OMP "Enable OpenMP support" ON
162+
"TM_USE_DDalphaAMG" OFF)
163+
164+
cmake_dependent_option(
165+
DDalphaAMG_ENABLE_TESTVECTOR_ANALYSIS "Enable vector analysis support" OFF
166+
"TM_USE_DDalphaAMG" OFF)
167+
168+
cmake_dependent_option(DDalphaAMG_ENABLE_HDF5 "Enable HDF5 support" OFF
169+
"TM_USE_DDalphaAMG" OFF)
170+
129171
# search for blas and lapack
130172
find_package(BLAS REQUIRED)
131173
#
@@ -144,12 +186,16 @@ set(ALIGN_BASE "0")
144186
set(ALIGN_BASE32 "0")
145187
set(ALIGN32 " ")
146188

147-
message("${TM_ENABLE_ALIGNMENT}")
189+
# DO NOT MERGE the two if statements as otherwise the automatic alignment will
190+
# not be taken into account
191+
148192
if(${TM_ENABLE_ALIGNMENT} STREQUAL "auto")
149193
include(cmake/DetectSimdAndAlignment.cmake)
150-
message(STATUS "SIMD: ${SIMD_LEVEL} (${SIMD_ARCH_FAMILY}), align=${SIMD_ALIGNMENT}")
194+
message(
195+
STATUS "SIMD: ${SIMD_LEVEL} (${SIMD_ARCH_FAMILY}), align=${SIMD_ALIGNMENT}")
151196
endif()
152-
if (${TM_ENABLE_ALIGNMENT} STREQUAL "none")
197+
198+
if(${TM_ENABLE_ALIGNMENT} STREQUAL "none")
153199
set(ALIGN_BASE "0x00")
154200
set(ALIGN " ")
155201
set(ALIGN_BASE32 "0x00")
@@ -195,7 +241,11 @@ if(TM_USE_HDF5)
195241
endif()
196242

197243
if(TM_USE_LEMON)
198-
find_package(lemon REQUIRED)
244+
FetchContent_Declare(lemon
245+
GIT_REPOSITORY https://github.com/etmc/lemon
246+
GIT_TAG 187de3435d604251e078eb083016131f035d6a51
247+
FIND_PACKAGE_ARGS NAMES lemon)
248+
FetchContent_MakeAvailable(lemon)
199249
endif()
200250

201251
find_package(CLime REQUIRED)
@@ -255,7 +305,7 @@ if(TM_USE_FFTW)
255305
endif()
256306

257307
if(TM_USE_DDalphaAMG)
258-
find_package(DDalphaAMG REQUIRED)
308+
add_subdirectory(DDalphaAMG)
259309
endif()
260310

261311
if(TM_ENABLE_WARNINGS)
@@ -289,8 +339,11 @@ if(TM_USE_MPI)
289339
endif()
290340
endif()
291341

292-
if (TM_USE_HALFSPINOR AND NOT TM_USE_GAUGE_COPY)
293-
message(FATAL_ERROR "The TM_USE_GAUGE_COPY option should also be set to ON when TM_USE_HALFSPINOR is ON")
342+
if(TM_USE_HALFSPINOR AND NOT TM_USE_GAUGE_COPY)
343+
message(
344+
FATAL_ERROR
345+
"The TM_USE_GAUGE_COPY option should also be set to ON when TM_USE_HALFSPINOR is ON"
346+
)
294347
endif()
295348
# keep the autotool config.h header.
296349
configure_file("${PROJECT_SOURCE_DIR}/cmake/tmlqcd_config_internal.h.in"
@@ -323,3 +376,24 @@ endif()
323376
configure_file(cmake/git_hash.c.in git_hash.c @ONLY)
324377
add_subdirectory(src/lib)
325378
add_subdirectory(src/bin)
379+
380+
write_basic_package_version_file(
381+
"${PROJECT_BINARY_DIR}/tmlQCDConfigVersion.cmake"
382+
VERSION "${PROJECT_VERSION}"
383+
COMPATIBILITY SameMajorVersion)
384+
385+
configure_file("${PROJECT_SOURCE_DIR}/cmake/tmlQCD-config.cmake.in"
386+
"${PROJECT_BINARY_DIR}/tmlQCD-config.cmake" @ONLY)
387+
388+
install(FILES "${PROJECT_BINARY_DIR}/tmlQCD-config.cmake"
389+
"${PROJECT_BINARY_DIR}/tmlQCDConfigVersion.cmake"
390+
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/tmlQCD")
391+
392+
install(FILES "${PROJECT_BINARY_DIR}/libtmlQCD.pc"
393+
DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
394+
395+
install(
396+
DIRECTORY "${PROJECT_SOURCE_DIR}/cmake"
397+
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/tmlQCD"
398+
FILES_MATCHING
399+
PATTERN "*.cmake")

DDalphaAMG/CMakeLists.txt

Lines changed: 216 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,216 @@
1+
# there is a lot of custom directories to circonvent the deletion of the
2+
# CMakeLists.txt contained in the DDalphaAMG directory. CMake will clone the
3+
# source code and build it with the default options used in the ci/cd. More
4+
# options are available in the main CMakeLists.txt.
5+
6+
include(GNUInstallDirs)
7+
8+
set(DDalphaAMG_SRC_DIR ${CMAKE_SOURCE_DIR}/DDalphaAMG/deps)
9+
10+
FetchContent_Declare(
11+
DDalphaAMG
12+
GIT_REPOSITORY https://github.com/etmc/DDalphaAMG.git
13+
SOURCE_DIR ${DDalphaAMG_SRC_DIR})
14+
15+
FetchContent_MakeAvailable(DDalphaAMG)
16+
17+
list(
18+
APPEND
19+
DDalphaAMG_SRC_GENERIC
20+
interpolation_generic.c
21+
gathering_generic.c
22+
sse_interpolation_generic.c
23+
coarse_oddeven_generic.c
24+
operator_generic.c
25+
oddeven_generic.c
26+
linalg_generic.c
27+
init_generic.c
28+
vcycle_generic.c
29+
dirac_generic.c
30+
coarse_operator_generic.c
31+
coarsening_generic.c
32+
schwarz_generic.c
33+
ghost_generic.c
34+
vectorization_dirac_generic.c
35+
linsolve_generic.c
36+
sse_coarse_operator_generic.c
37+
data_generic.c
38+
setup_generic.c
39+
sse_linalg_generic.c)
40+
41+
list(
42+
APPEND
43+
DDalphaAMG_HEADER_GENERIC
44+
interpolation_generic.h
45+
gathering_generic.h
46+
sse_interpolation_generic.h
47+
coarse_oddeven_generic.h
48+
operator_generic.h
49+
oddeven_generic.h
50+
linalg_generic.h
51+
init_generic.h
52+
vcycle_generic.h
53+
dirac_generic.h
54+
coarse_operator_generic.h
55+
coarsening_generic.h
56+
schwarz_generic.h
57+
ghost_generic.h
58+
vectorization_dirac_generic.h
59+
linsolve_generic.h
60+
sse_coarse_operator_generic.h
61+
data_generic.h
62+
setup_generic.h
63+
sse_linalg_generic.h
64+
main_pre_def_generic.h
65+
main_post_def_generic.h)
66+
67+
list(
68+
APPEND
69+
DDalphaAMG_SRC_GENERAL
70+
${DDalphaAMG_SRC_DIR}/src/preconditioner.c
71+
${DDalphaAMG_SRC_DIR}/src/threading.c
72+
${DDalphaAMG_SRC_DIR}/src/main.c
73+
${DDalphaAMG_SRC_DIR}/src/sse_dirac.c
74+
${DDalphaAMG_SRC_DIR}/src/var_table.c
75+
${DDalphaAMG_SRC_DIR}/src/data_layout.c
76+
${DDalphaAMG_SRC_DIR}/src/linsolve.c
77+
${DDalphaAMG_SRC_DIR}/src/ghost.c
78+
${DDalphaAMG_SRC_DIR}/src/top_level.c
79+
${DDalphaAMG_SRC_DIR}/src/dirac.c
80+
${DDalphaAMG_SRC_DIR}/src/linalg.c
81+
${DDalphaAMG_SRC_DIR}/src/init.c
82+
${DDalphaAMG_SRC_DIR}/src/DDalphaAMG_interface.c
83+
${DDalphaAMG_SRC_DIR}/src/lime_io.c
84+
${DDalphaAMG_SRC_DIR}/src/sse_linalg.c
85+
${DDalphaAMG_SRC_DIR}/src/solver_analysis.c
86+
${DDalphaAMG_SRC_DIR}/src/io.c)
87+
88+
foreach(f IN LISTS DDalphaAMG_SRC_GENERIC)
89+
string(REPLACE "_generic" "_float" f_float "${f}")
90+
91+
add_custom_command(
92+
OUTPUT "${CMAKE_BINARY_DIR}/DDalphaAMG/${f_float}.sed-done"
93+
COMMAND
94+
sed -f "${DDalphaAMG_SRC_DIR}/float.sed" "${DDalphaAMG_SRC_DIR}/src/${f}"
95+
> "${CMAKE_BINARY_DIR}/DDalphaAMG/${f_float}"
96+
COMMAND ${CMAKE_COMMAND} -E touch
97+
"${CMAKE_BINARY_DIR}/DDalphaAMG/${f_float}.sed-done"
98+
DEPENDS "${DDalphaAMG_SRC_DIR}/src/${f}" "${DDalphaAMG_SRC_DIR}/float.sed"
99+
VERBATIM)
100+
list(APPEND SED_MARKERS "${CMAKE_BINARY_DIR}/DDalphaAMG/${f_float}.sed-done")
101+
list(APPEND DDalphaAMG_SRC_SINGLE_DOUBLE ${f_float})
102+
103+
string(REPLACE "_generic" "_double" f_double "${f}")
104+
add_custom_command(
105+
OUTPUT "${CMAKE_BINARY_DIR}/DDalphaAMG/${f_double}.sed-done"
106+
COMMAND
107+
sed -f "${DDalphaAMG_SRC_DIR}/double.sed" "${DDalphaAMG_SRC_DIR}/src/${f}"
108+
> "${CMAKE_BINARY_DIR}/DDalphaAMG/${f_double}"
109+
COMMAND ${CMAKE_COMMAND} -E touch
110+
"${CMAKE_BINARY_DIR}/DDalphaAMG/${f_double}.sed-done"
111+
DEPENDS "${DDalphaAMG_SRC_DIR}/src/${f}" "${DDalphaAMG_SRC_DIR}/double.sed"
112+
VERBATIM)
113+
list(APPEND SED_MARKERS "${CMAKE_BINARY_DIR}/DDalphaAMG/${f_double}.sed-done")
114+
list(APPEND DDalphaAMG_SRC_SINGLE_DOUBLE ${f_double})
115+
endforeach()
116+
117+
# now parse the header
118+
foreach(f IN LISTS DDalphaAMG_HEADER_GENERIC)
119+
string(REPLACE "_generic" "_float" f_float "${f}")
120+
add_custom_command(
121+
OUTPUT "${CMAKE_BINARY_DIR}/DDalphaAMG/${f_float}.sed-done"
122+
COMMAND
123+
sed -f "${DDalphaAMG_SRC_DIR}/float.sed" "${DDalphaAMG_SRC_DIR}/src/${f}"
124+
> "${CMAKE_BINARY_DIR}/DDalphaAMG/${f_float}"
125+
COMMAND ${CMAKE_COMMAND} -E touch
126+
"${CMAKE_BINARY_DIR}/DDalphaAMG/${f_float}.sed-done"
127+
DEPENDS "${DDalphaAMG_SRC_DIR}/src/${f}" "${DDalphaAMG_SRC_DIR}/float.sed"
128+
VERBATIM)
129+
list(APPEND SED_MARKERS "${CMAKE_BINARY_DIR}/DDalphaAMG/${f_float}.sed-done")
130+
list(APPEND DDalphaAMG_HEADER_SINGLE_DOUBLE ${f_float})
131+
132+
string(REPLACE "_generic" "_double" f_double "${f}")
133+
add_custom_command(
134+
OUTPUT "${CMAKE_BINARY_DIR}/DDalphaAMG/${f_double}.sed-done"
135+
COMMAND
136+
sed -f "${DDalphaAMG_SRC_DIR}/double.sed" "${DDalphaAMG_SRC_DIR}/src/${f}"
137+
> "${CMAKE_BINARY_DIR}/DDalphaAMG/${f_double}"
138+
COMMAND ${CMAKE_COMMAND} -E touch
139+
"${CMAKE_BINARY_DIR}/DDalphaAMG/${f_double}.sed-done"
140+
DEPENDS "${DDalphaAMG_SRC_DIR}/src/${f}" "${DDalphaAMG_SRC_DIR}/double.sed"
141+
VERBATIM)
142+
143+
list(APPEND SED_MARKERS "${CMAKE_BINARY_DIR}/DDalphaAMG/${f_double}.sed-done")
144+
list(APPEND DDalphaAMG_HEADER_SINGLE_DOUBLE ${f_double})
145+
endforeach()
146+
147+
foreach(outfile IN LISTS DDalphaAMG_SRC_SINGLE_DOUBLE
148+
DDalphaAMG_HEADER_SINGLE_DOUBLE)
149+
set_source_files_properties("${CMAKE_BINARY_DIR}/DDalphaAMG/${outfile}"
150+
PROPERTIES GENERATED TRUE)
151+
endforeach()
152+
153+
add_custom_target(run_sed ALL DEPENDS ${SED_MARKERS})
154+
155+
add_library(DDalphaAMG ${DDalphaAMG_SRC_GENERAL}
156+
${DDalphaAMG_SRC_SINGLE_DOUBLE})
157+
158+
target_compile_options(DDalphaAMG
159+
PRIVATE "$<$<COMPILE_LANG_AND_ID:C,GNU>:-O3;-ffast-math;-mavx2;-mfma>")
160+
161+
add_dependencies(DDalphaAMG run_sed)
162+
163+
target_link_libraries(
164+
DDalphaAMG
165+
PUBLIC MPI::MPI_C $<$<BOOL:${DDalphaAMG_ENABLE_HDF5}>:hdf5:hdf5>
166+
$<$<BOOL:${DDalphaAMG_ENABLE_OMP}>:OpenMP::OpenMP_C> tmlqcd::clime)
167+
168+
target_include_directories(
169+
DDalphaAMG
170+
PUBLIC $<INSTALL_INTERFACE:include>
171+
$<BUILD_INTERFACE:${DDalphaAMG_SRC_DIR}/src>
172+
$<BUILD_INTERFACE:${DDalphaAMG_SRC_DIR}/include>
173+
$<BUILD_INTERFACE:${CMAKE_BINARY_DIR}/DDalphaAMG>)
174+
175+
target_compile_definitions(
176+
DDalphaAMG
177+
PUBLIC
178+
$<$<BOOL:${DDalphaAMG_ENABLE_PARAMOUNT_OUTPUT}>:PARAMOUNTOUTPUT>
179+
$<$<BOOL:${DDalphaAMG_ENABLE_FGMRES_RESTEST}>:FGMRES_RESTEST>
180+
$<$<BOOL:${DDalphaAMG_ENABLE_PROFILING}>:PROFILING>
181+
$<$<BOOL:${DDalphaAMG_ENABLE_SINGLE_ALLREDUCE_ARNOLDI}>:SINGLE_ALLREDUCE_ARNOLDI>
182+
$<$<BOOL:${DDalphaAMG_ENABLE_COARSE_RES}>:COARSE_RES>
183+
$<$<BOOL:${DDalphaAMG_ENABLE_SCHWARZ_RES}>:SCHWARZ_RES>
184+
$<$<BOOL:${DDalphaAMG_ENABLE_OMP}>:OPENMP>
185+
$<$<BOOL:${DDalphaAMG_ENABLE_TRACK_RES}>:TRACK_RES>
186+
$<$<BOOL:${DDalphaAMG_ENABLE_TESTVECTOR_ANALYSIS}>:TESTVECTOR_ANALYSIS>
187+
$<$<BOOL:${DDalphaAMG_ENABLE_HDF5}>:HAVE_HDF5>
188+
$<$<CONFIG:Debug>:DEBUG>
189+
SSE)
190+
191+
install(FILES "${CMAKE_SOURCE_DIR}/deps/DDalphaAMG/DDalphaAMG.h"
192+
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}")
193+
194+
write_basic_package_version_file(
195+
"${PROJECT_BINARY_DIR}/DDalphaAMGonfigVersion.cmake"
196+
VERSION "0.0.0"
197+
COMPATIBILITY SameMajorVersion)
198+
199+
install(TARGETS DDalphaAMG
200+
EXPORT DDalphaAMG_targets
201+
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}")
202+
203+
install(EXPORT DDalphaAMG_targets
204+
FILE DDalphaAMG-Targets.cmake
205+
NAMESPACE DDalphaAMG::
206+
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}")
207+
208+
configure_file("${PROJECT_SOURCE_DIR}/cmake/DDalphaAMG-Config.cmake.in"
209+
"${PROJECT_BINARY_DIR}/DDalphaAMG-Config.cmake" @ONLY)
210+
211+
install(FILES "${PROJECT_BINARY_DIR}/DDalphaAMG-Config.cmake"
212+
"${PROJECT_BINARY_DIR}/DDalphaAMG-ConfigVersion.cmake"
213+
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/tmlQCD")
214+
215+
216+
# add_library(tmlqcd::DDalphaAMG alias DDalphaAMG)

0 commit comments

Comments
 (0)