|
| 1 | +cmake_minimum_required(VERSION 3.24) |
| 2 | + |
| 3 | +project( |
| 4 | + tmlqcd |
| 5 | + DESCRIPTION "tmlQCD" |
| 6 | + HOMEPAGE_URL "http://www.itkp.uni-bonn.de/~urbach/software.html" |
| 7 | + VERSION "6.0.0" |
| 8 | + LANGUAGES C CXX) |
| 9 | + |
| 10 | +# include our cmake snippets |
| 11 | +set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake) |
| 12 | + |
| 13 | +# ================================================================================================= |
| 14 | +# REQUIRE OUT-OF-SOURCE BUILDS |
| 15 | +file(TO_CMAKE_PATH "${PROJECT_BINARY_DIR}/CMakeLists.txt" LOC_PATH) |
| 16 | +if(EXISTS "${LOC_PATH}") |
| 17 | + message( |
| 18 | + FATAL_ERROR |
| 19 | + "You cannot build in a source directory (or any directory with a CMakeLists.txt file). Please make a build subdirectory." |
| 20 | + ) |
| 21 | +endif() |
| 22 | + |
| 23 | +# ================================================================================================= |
| 24 | +# PROJECT AND VERSION |
| 25 | +include(CMakeDependentOption) |
| 26 | +include(CheckSymbolExists) |
| 27 | +include(CheckLibraryExists) |
| 28 | +include(CheckFunctionExists) |
| 29 | +include(GNUInstallDirs) |
| 30 | + |
| 31 | +cmake_policy(SET CMP0048 NEW) |
| 32 | + |
| 33 | +if(POLICY CMP0144) |
| 34 | + cmake_policy(SET CMP0144 NEW) |
| 35 | +endif() |
| 36 | + |
| 37 | +if(NOT DEFINED CMAKE_CUDA_STANDARD) |
| 38 | + set(CMAKE_CUDA_STANDARD 14) |
| 39 | + set(CMAKE_CUDA_STANDARD_REQUIRED ON) |
| 40 | +endif() |
| 41 | + |
| 42 | +if(NOT DEFINED CMAKE_CXX_STANDARD) |
| 43 | + set(CMAKE_CXX_STANDARD 17) |
| 44 | + set(CMAKE_CXX_STANDARD_REQUIRED ON) |
| 45 | +endif() |
| 46 | + |
| 47 | +if(NOT DEFINED CMAKE_C_STANDARD) |
| 48 | + set(CMAKE_C_STANDARD 11) |
| 49 | + set(CMAKE_C_STANDARD_REQUIRED ON) |
| 50 | +endif() |
| 51 | + |
| 52 | +if(NOT DEFINED CMAKE_HIP_STANDARD) |
| 53 | + set(CMAKE_HIP_STANDARD 14) |
| 54 | + set(CMAKE_HIP_STANDARD_REQUIRED ON) |
| 55 | +endif() |
| 56 | + |
| 57 | +find_package(PkgConfig) |
| 58 | + |
| 59 | +# ############################################################################## |
| 60 | +# Define the paths for static libraries and executables |
| 61 | +# ############################################################################## |
| 62 | +set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY |
| 63 | + ${cp2k_BINARY_DIR}/lib |
| 64 | + CACHE PATH "Single output directory for building all libraries.") |
| 65 | + |
| 66 | +# Search for rocm in common locations |
| 67 | +foreach(__var ROCM_ROOT CRAY_ROCM_ROOT ORNL_ROCM_ROOT CRAY_ROCM_PREFIX |
| 68 | + ROCM_PREFIX CRAY_ROCM_DIR) |
| 69 | + if($ENV{${__var}}) |
| 70 | + list(APPEND CMAKE_PREFIX_PATH $ENV{__var}) |
| 71 | + set(ROCM_PATH |
| 72 | + $ENV{__var} |
| 73 | + CACHE PATH "Path to ROCm installation") |
| 74 | + endif() |
| 75 | +endforeach() |
| 76 | + |
| 77 | +option(CMAKE_POSITION_INDEPENDENT_CODE "Enable position independent code" ON) |
| 78 | + |
| 79 | +option(TMLQCD_USE_FFTW "Enable fftw support" OFF) |
| 80 | +option(TMLQCD_USE_MPI "Enable MPI support" OFF) |
| 81 | +option(TMLQCD_USE_CUDA "Enable QUDA support" OFF) |
| 82 | +option(TMLQCD_USE_HIP "Enable HIP support" OFF) |
| 83 | +option(TMLQCD_USE_DDALPHAAMG "Enable DDalphaAMG support" OFF) |
| 84 | +option(TMLCDQ_USE_OPENMP "Enable openMP" ON) |
| 85 | +option(TMLQCD_FIXED_VOLUME "fix volume at compile time" OFF) |
| 86 | +option( |
| 87 | + TMLQCD_ENABLE_ALIGNMENT |
| 88 | + "Automatically or expliclty align arrays to byte number. auto, none, 16, 32, 64" |
| 89 | + "auto") |
| 90 | +option(TMLQCD_BGL_DRAM "use BGL dram window (BGL only!)" ON) |
| 91 | +option(TMLQCD_USE_OPTIMIZATION "enable optimisation" ON) |
| 92 | +option(TMLQCD_USE_GAUGE_COPY "Enable use of a copy of the gauge field" ON) |
| 93 | +option(TMLQCD_USE_HALFSPINOR "Use a Dirac Op. with halfspinor exchange" ON) |
| 94 | +option(TMLQCD_USE_TSPLITPAR "Enable timeslice-splitted communications" ON) |
| 95 | +option(TMLQCD_USE_QPHIX "enable QPhiX" OFF) |
| 96 | +option(TMLQCD_USE_SHMEM "Use shmem API" OFF) |
| 97 | +option(TMLQCD_USE_QUDA "Enable QUDA support" OFF) |
| 98 | +# MPI dependent options |
| 99 | +cmake_dependent_option( |
| 100 | + TMLQCD_PERSISTENT_MPI "Use persistent MPI calls for halfspinor [default=no]" |
| 101 | + OFF "TMLQCD_USE_MPI" OFF) |
| 102 | +cmake_dependent_option( |
| 103 | + TMLQCD_NONBLOCKING_MPI "Use non-blocking MPI calls for spinor and gaug" ON |
| 104 | + "TMLQCD_USE_MPI" OFF) |
| 105 | + |
| 106 | +# need to do it properly. Just a place holder |
| 107 | +cmake_dependent_option( |
| 108 | + TMLQCD_MPI_DIMENSION "Use n dimensional parallelisation [default=4]" 4 |
| 109 | + "TMLQCD_USE_MPI" OFF) |
| 110 | + |
| 111 | +# HIP dependent options |
| 112 | +cmake_dependent_option(TMLQCD_USE_CUDA_HIP "Enable CUDA support in HIP" OFF |
| 113 | + "TMLQCD_USE_HIP" OFF) |
| 114 | + |
| 115 | +# clime and lemon depend on MPI |
| 116 | +cmake_dependent_option(TMLQCD_USE_LEMON "Use the lemon io library" OFF |
| 117 | + "TMLQCD_USE_MPI" ON) |
| 118 | + |
| 119 | +# GPU dependent options |
| 120 | +cmake_dependent_option(TMLQCD_USE_QUDA_EXPERIMENTAL "Enable QUDA support" ON |
| 121 | + "TMLQCD_USE_QUDA" OFF) |
| 122 | +cmake_dependent_option( |
| 123 | + TMLQCD_QUDA_FERMIONIC_FORCES "Enable support for fermionic forces using QUDA" |
| 124 | + ON "TMLQCD_USE_QUDA" OFF) |
| 125 | + |
| 126 | +cmake_dependent_option(TMLQCD_USE_NVHPC "Enable Nvidia HPC toolkit" OFF |
| 127 | + "TMLQCD_USE_CUDA" OFF) |
| 128 | + |
| 129 | +# search for blas and lapack |
| 130 | +find_package(BLAS REQUIRED) |
| 131 | +# |
| 132 | +find_package(LAPACK REQUIRED) |
| 133 | +set(HAVE_LAPACK ON) |
| 134 | +find_package(FLEX REQUIRED) |
| 135 | +# do we need bison ? |
| 136 | +find_package(BISON REQUIRED) |
| 137 | + |
| 138 | +set(PACKAGE_NAME ${PROJECT_DESCRIPTION}) |
| 139 | +set(PACKAGE_VERSION ${PROJECT_VERSION}) |
| 140 | +set(PACKAGE_TARNAME "tmlqcd") |
| 141 | +set(PACKAGE_BUGREPORT "curbach@gmx.de") |
| 142 | +set(PACKAGE_STRING "${PROJECT_DESCRIPTION} ${PROJECT_VERSION}") |
| 143 | + |
| 144 | +unset(TM_USE_MPI) |
| 145 | +unset(TM_USE_OMP) |
| 146 | +unset(HAVE_LIBLEMON) |
| 147 | +unset(HAVE_LIBLIME) |
| 148 | +unset(FIXEDVOLUME) |
| 149 | +unset(_PERSISTENT) |
| 150 | +unset(_NON_BLOCKING) |
| 151 | +unset(HAVE_LIBQUDA) |
| 152 | +unset(TM_USE_QUDA) |
| 153 | +unset(TM_QUDA_EXPERIMENTAL) |
| 154 | +unset(TM_QUDA_FERMIONIC_FORCES) |
| 155 | +unset(DDalphaAMG) |
| 156 | +unset(TM_USE_QPHIX) |
| 157 | +unset(QPHIX_SOALEN) |
| 158 | +unset(_NEW_GEOMETRY) |
| 159 | +unset(_NON_BLOCKING) |
| 160 | +unset(_USE_SHMEM) |
| 161 | +unset(_USE_HALFSPINOR) |
| 162 | +set(ALIGN " ") |
| 163 | +set(ALIGN_BASE "0") |
| 164 | +set(ALIGN_BASE32 "0") |
| 165 | +set(ALIGN32 " ") |
| 166 | + |
| 167 | +if(TMLQCD_USE_HALFSPINOR) |
| 168 | + set(_USE_HALFSPINOR ON) |
| 169 | +endif() |
| 170 | + |
| 171 | +if(TMLQCD_FIXED_VOLUME) |
| 172 | + set(FIXEDVOLUME ON) |
| 173 | +endif() |
| 174 | + |
| 175 | +if(TMLQCD_PERSISTENT_MPI) |
| 176 | + set(_PERSISTENT ON) |
| 177 | +endif() |
| 178 | + |
| 179 | +if(TMLQCD_USE_MPI) |
| 180 | + find_package(MPI REQUIRED) |
| 181 | + set(TM_USE_MPI ON) |
| 182 | + if(TMLQCD_NONBLOCKING_MPI) |
| 183 | + set(_NON_BLOCKING ON) |
| 184 | + endif() |
| 185 | +endif() |
| 186 | + |
| 187 | +if(TMLQCD_USE_OPENMP) |
| 188 | + find_package(OpenMP REQUIRED COMPONENTS C CXX) |
| 189 | + set(TM_USE_OMP ON) |
| 190 | +endif() |
| 191 | + |
| 192 | +if(TMLQCD_USE_HDF5) |
| 193 | + find_package(HDF5 REQUIRED COMPONENTS C) |
| 194 | +endif() |
| 195 | + |
| 196 | +if(TMLQCD_USE_LEMON) |
| 197 | + find_package(Clemon REQUIRED) |
| 198 | + set(HAVE_LIBLEMON ON) |
| 199 | +endif() |
| 200 | + |
| 201 | +find_package(CLime REQUIRED) |
| 202 | +set(HAVE_LIBLIME ON) |
| 203 | + |
| 204 | +if(TMLQCD_USE_QUDA) |
| 205 | + find_package(QUDA REQUIRED config) |
| 206 | + set(HAVE_LIBQUDA ON) |
| 207 | + if(TMLQCD_USE_QUDA_EXPERIMENTAL) |
| 208 | + set(TM_QUDA_EXPERIMENTAL ON) |
| 209 | + endif() |
| 210 | + if(TMLQCD_QUDA_FERMIONIC_FORCES) |
| 211 | + set(TM_QUDA_FERMIONIC_FORCES ON) |
| 212 | + endif() |
| 213 | + if(TMLQCD_USE_CUDA OR TMLQCD_USE_HIP) |
| 214 | + set(TM_USE_QUDA ON) |
| 215 | + endif() |
| 216 | +endif() |
| 217 | + |
| 218 | +if(TMLQCD_USE_CUDA AND TMLQCD_USE_HIP) |
| 219 | + message( |
| 220 | + ERROR |
| 221 | + "HIP and CUDA are mutually exclusive. Please choose one GPU support only") |
| 222 | +endif() |
| 223 | + |
| 224 | +if(TMLQCD_USE_CUDA OR QUDA_TARGET_CUDA) |
| 225 | + enable_language(CUDA) |
| 226 | + if(TMLQCD_USE_NVHPC) |
| 227 | + find_package(NVHPC REQUIRED COMPONENTS CUDA MATH HOSTUTILS NCCL) |
| 228 | + else() |
| 229 | + find_package(CUDAToolkit REQUIRED) |
| 230 | + endif() |
| 231 | +endif() |
| 232 | + |
| 233 | +message("QUDA_TARGET: ${QUDA_TARGET_CUDA}") |
| 234 | +if(TMLQCD_USE_HIP OR QUDA_TARGET_HIP) |
| 235 | + enable_language(hip) |
| 236 | + |
| 237 | + # we may want to use hip-cuda for development or debugging purposes especially |
| 238 | + # if AMD GPU access is not possible. So allow it |
| 239 | + if(TMLQCD_USE_CUDA_HIP) |
| 240 | + find_package(CUDA) |
| 241 | + endif() |
| 242 | + |
| 243 | + if(CMAKE_HIP_PLATFORM MATCHES "amd") |
| 244 | + set(TMLQCD_GPU_PLATFORM_DFLAGS "__HIP_PLATFORM_AMD__") |
| 245 | + else() |
| 246 | + set(TMLQCD_GPU_PLATFORM_DFLAGS "__HIP_PLATFORM_NVIDIA__") |
| 247 | + endif() |
| 248 | +endif() |
| 249 | + |
| 250 | +if(TMLQCD_USE_SHMEM) |
| 251 | + set(_USE_SHMEM ON) |
| 252 | +endif() |
| 253 | + |
| 254 | +if(TMLQCD_USE_QPIHX) |
| 255 | + find_package(QphiX REQUIRED) |
| 256 | + set(TM_USE_QPHIX ON) |
| 257 | +endif() |
| 258 | + |
| 259 | +# check for fftw3 (rely on pkgconfig). |
| 260 | +if(TMLQCD_USE_FFTW) |
| 261 | + pkg_search_module(tmlqcd_fftw3 IMPORTED_TARGET GLOBAL fftw3) |
| 262 | + if(tmlqcd_fftw3_FOUND) |
| 263 | + add_library(tmlqcd::fftw3 ALIAS PkgConfig::tmlqcd_fftw3) |
| 264 | + endif() |
| 265 | +endif() |
| 266 | + |
| 267 | +# check for the presence of clock_gettime in libc or librt |
| 268 | +check_symbol_exists(clock_gettime "time.h" HAVE_CLOCK_GETTIME) |
| 269 | +check_library_exists(rt clock_gettime "" HAVE_CLOCK_GETTIME_IN_RT) |
| 270 | +check_function_exists(fseeko HAVE_FSEEKO) |
| 271 | + |
| 272 | +# set the parallelization |
| 273 | + |
| 274 | +if(TMLQCD_USE_MPI) |
| 275 | + if(TMLQCD_MPI_DIMENSION EQUAL "1") |
| 276 | + # T parallelisation |
| 277 | + set(PARALLELT ON) |
| 278 | + elseif(TMLQCD_MPI_DIMENSION EQUAL "2") |
| 279 | + # XT parallelisation |
| 280 | + set(PARALLELXT ON) |
| 281 | + elseif(TMLQCD_MPI_DIMENSION EQUAL "3") |
| 282 | + set(PARALLELXYT ON) |
| 283 | + # XYZ parallelisation |
| 284 | + elseif(TMLQCD_MPI_DIMENSION EQUAL "4") |
| 285 | + # timeslice-splitted communications |
| 286 | + set(PARALLELXYZT ON) |
| 287 | + elseif(TMLQCD_MPI_DIMENSION EQUAL "X") |
| 288 | + set(PARALLELX ON) |
| 289 | + elseif(TMLQCD_MPI_DIMENSION EQUAL "XY") |
| 290 | + set(PARALLELXY ON) |
| 291 | + elseif(TMLQCD_MPI_DIMENSION EQUAL "XYZ") |
| 292 | + set(PARALLELXYZ ON) |
| 293 | + else() |
| 294 | + set(PARALLELXYZT ON) |
| 295 | + endif() |
| 296 | +endif() |
| 297 | + |
| 298 | +# keep the autotool config.h header. |
| 299 | +configure_file("${PROJECT_SOURCE_DIR}/cmake/tmlqcd_config_internal.h.in" |
| 300 | + "${PROJECT_BINARY_DIR}/tmlqcd_config_internal.h" @ONLY) |
| 301 | +configure_file("${PROJECT_SOURCE_DIR}/fixed_volume.h.in" |
| 302 | + "${PROJECT_BINARY_DIR}/fixed_volume.h" @ONLY) |
| 303 | +# check if git command exists |
| 304 | +find_program(GIT_EXE NAMES git) |
| 305 | + |
| 306 | +# generate version header |
| 307 | +string(TIMESTAMP TMLQCD_TIMESTAMP "%Y-%m-%d %H:%M:%S") |
| 308 | +if(DEFINED GIT_EXE AND EXISTS "${PROJECT_SOURCE_DIR}/.git") |
| 309 | + execute_process( |
| 310 | + COMMAND git rev-parse HEAD |
| 311 | + OUTPUT_VARIABLE TMLQCD_SHA |
| 312 | + WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}" |
| 313 | + ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE) |
| 314 | + execute_process( |
| 315 | + COMMAND git describe --all |
| 316 | + OUTPUT_VARIABLE TMLQCD_GIT_BRANCH |
| 317 | + WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}" |
| 318 | + ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE) |
| 319 | + message(STATUS "git hash ${TMLQCD_SHA}") |
| 320 | +else() |
| 321 | + # set(TMLQCD_GIT_BRANCH "release v${SIRIUS_VERSION}") |
| 322 | + set(TMLQCD_SHA |
| 323 | + "https://github.com/etmc/tmLQCD/releases/tag/rel-${TMLQCD_VERSION_MAJOR}-${TMLQCD_VERSION_MINOR}" |
| 324 | + ) |
| 325 | +endif() |
| 326 | + |
| 327 | +configure_file(cmake/git_hash.h.in git_hash.h @ONLY) |
| 328 | +add_subdirectory(src/lib) |
| 329 | +add_subdirectory(src/bin) |
0 commit comments