diff --git a/config.yaml b/config.yaml index 9e88a495..ae723c23 100644 --- a/config.yaml +++ b/config.yaml @@ -16,16 +16,8 @@ clusters: uarch: 'gh200' partition: 'normal' variables: - # new daint has a custom url (temporary?) - F7T_URL: "https://firecrest-hpc.v1.svc.cscs.ch" + F7T_URL: "https://api.cscs.ch/hpc/firecrest/v1" runner: f7t - #targets: - # - - # uarch: 'gh200' - # partition: 'normal' - #runner: - # slurm-tag: daint-spack-stack-builder - # baremetal-tag: daint-login-baremetal eiger: targets: - @@ -57,9 +49,9 @@ clusters: - uarch: 'gh200' partition: 'normal' - runner: - slurm-tag: todi-spack-stack-builder - baremetal-tag: todi-login-baremetal + variables: + F7T_URL: "https://api.cscs.ch/cscs/firecrest/v1" + runner: f7t uenvs: arbor: "v0.9": @@ -120,6 +112,10 @@ uenvs: recipes: gh200: 2024.2/gh200 zen2: 2024.2/mc + "2024.3": + recipes: + gh200: 2024.3/gh200 + zen2: 2024.3/mc deploy: daint: [gh200] todi: [gh200] diff --git a/recipes/cp2k/2024.3/gh200/compilers.yaml b/recipes/cp2k/2024.3/gh200/compilers.yaml new file mode 100644 index 00000000..0dca2adf --- /dev/null +++ b/recipes/cp2k/2024.3/gh200/compilers.yaml @@ -0,0 +1,5 @@ +bootstrap: + spec: gcc@12 +gcc: + specs: + - gcc@12.3 diff --git a/recipes/cp2k/2024.3/gh200/config.yaml b/recipes/cp2k/2024.3/gh200/config.yaml new file mode 100644 index 00000000..0337e381 --- /dev/null +++ b/recipes/cp2k/2024.3/gh200/config.yaml @@ -0,0 +1,6 @@ +name: cp2k +store: /user-environment +spack: + repo: https://github.com/spack/spack.git + commit: v0.22.1 +modules: True diff --git a/recipes/cp2k/2024.3/gh200/environments.yaml b/recipes/cp2k/2024.3/gh200/environments.yaml new file mode 100644 index 00000000..2aa766f2 --- /dev/null +++ b/recipes/cp2k/2024.3/gh200/environments.yaml @@ -0,0 +1,44 @@ +cp2k: + compiler: + - toolchain: gcc + spec: gcc@12.3 + unify: true + specs: + - cmake + - ninja + - cuda@12.2 # Can't be newer than driver version, for DBCSR + - openblas threads=openmp + - netlib-scalapack + - fftw + - libxc ~cuda + - libint + - spglib + - spla + - elpa + - plumed + # COSMA + - tiled-mm + - costa + - cosma +gpu_direct + # SIRIUS + - hdf5 + - spfft + - sirius ~memory_pool + # CP2K + - dbcsr@2.7.0 + - cp2k@2024.3 +libxc +libint +spglib +cosma +spla +elpa +sirius +plumed lmax=5 build_system=cmake + variants: + - +mpi + - +openmp + - +cuda + - cuda_arch=90 + - build_type=Release + mpi: + spec: cray-mpich@8.1.30 + gpu: cuda + views: + develop: + link: roots + exclude: ["cp2k"] + cp2k: + link: roots diff --git a/recipes/cp2k/2024.3/gh200/modules.yaml b/recipes/cp2k/2024.3/gh200/modules.yaml new file mode 100644 index 00000000..910cda25 --- /dev/null +++ b/recipes/cp2k/2024.3/gh200/modules.yaml @@ -0,0 +1,21 @@ +modules: + prefix_inspections: + bin: + - PATH + lib: + - LD_LIBRARY_PATH + lib64: + - LD_LIBRARY_PATH + + default: + arch_folder: false + roots: + tcl: /user-environment/modules + tcl: + all: + autoload: none + hash_length: 0 + exclude_implicits: true + exclude: ['%gcc@7.5.0', 'gcc %gcc@7.5.0'] + projections: + all: '{name}/{version}' diff --git a/recipes/cp2k/2024.3/gh200/repo/packages/cosma/fj-ssl2.patch b/recipes/cp2k/2024.3/gh200/repo/packages/cosma/fj-ssl2.patch new file mode 100644 index 00000000..3e09383d --- /dev/null +++ b/recipes/cp2k/2024.3/gh200/repo/packages/cosma/fj-ssl2.patch @@ -0,0 +1,104 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index 1fd1e55..41a041b 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -19,7 +19,7 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS "YES") # always write compile_commands.json + + set(COSMA_GPU_BACKENDS_LIST "CUDA" "ROCM") + set(COSMA_SCALAPACK_LIST "OFF" "MKL" "CRAY_LIBSCI" "CUSTOM") +-set(COSMA_BLAS_LIST "auto" "MKL" "OPENBLAS" "CRAY_LIBSCI" "CUSTOM" "BLIS" "ATLAS" "CUDA" "ROCM" "OFF") ++set(COSMA_BLAS_LIST "auto" "MKL" "SSL2" "OPENBLAS" "CRAY_LIBSCI" "CUSTOM" "BLIS" "ATLAS" "CUDA" "ROCM" "OFF") + option(COSMA_WITH_TESTS "Generate the test target." ON) + option(COSMA_WITH_APPS "Generate the miniapp targets." ON) + option(COSMA_WITH_BENCHMARKS "Generate the benchmark targets." ON) +@@ -45,7 +45,7 @@ if (COSMA_BLAS MATCHES "CUDA|ROCM") + set(COSMA_GPU_BACKEND ${COSMA_BLAS}) + else() + if(COSMA_BLAS STREQUAL "OFF") +- message(FATAL_ERROR "A Blas implementation is needed when running on CPU only: choices are : auto, MKL, OPENBLAS, CRAY_LIBSCI, CUSTOM, BLIS, ATLAS, FLEXIBLAS, ARMPL, GenericBLAS") ++ message(FATAL_ERROR "A Blas implementation is needed when running on CPU only: choices are : auto, MKL, SSL2, OPENBLAS, CRAY_LIBSCI, CUSTOM, BLIS, ATLAS, FLEXIBLAS, ARMPL, GenericBLAS") + else() + set(COSMA_BLAS_VENDOR ${COSMA_BLAS}) + endif() +@@ -190,6 +190,7 @@ install(FILES "${cosma_BINARY_DIR}/cosmaConfig.cmake" + "${cosma_BINARY_DIR}/cosmaConfigVersion.cmake" + "${cosma_BINARY_DIR}/cosmaConfigVersion.cmake" + "${cosma_SOURCE_DIR}/cmake/FindMKL.cmake" ++ "${cosma_SOURCE_DIR}/cmake/FindSSL2.cmake" + "${cosma_SOURCE_DIR}/cmake/FindBlas.cmake" + "${cosma_SOURCE_DIR}/cmake/FindSCALAPACK.cmake" + "${cosma_SOURCE_DIR}/cmake/FindOPENBLAS.cmake" +diff --git a/cmake/FindBlas.cmake b/cmake/FindBlas.cmake +index aef956c..3c47561 100644 +--- a/cmake/FindBlas.cmake ++++ b/cmake/FindBlas.cmake +@@ -14,6 +14,7 @@ endif() + set(COSMA_BLAS_VENDOR_LIST + "auto" + "MKL" ++ "SSL2" + "OPENBLAS" + "FLEXIBLAS" + "ARMPL" +diff --git a/cmake/FindSSL2.cmake b/cmake/FindSSL2.cmake +new file mode 100644 +index 0000000..f0e11bf +--- /dev/null ++++ b/cmake/FindSSL2.cmake +@@ -0,0 +1,56 @@ ++#.rst: ++# FindSSL2 ++# ----------- ++# ++# This module tries to find the SSL2 library. ++# ++# The following variables are set ++# ++# :: ++# ++# SSL2_FOUND - True if ssl2 is found ++# SSL2_LIBRARIES - The required libraries ++# SSL2_INCLUDE_DIRS - The required include directory ++# ++# The following import target is created ++# ++# :: ++# ++# SSL2::ssl2 ++ ++#set paths to look for library from ROOT variables.If new policy is set, find_library() automatically uses them. ++# if(NOT POLICY CMP0074) ++set(_SSL2_PATHS ${SSL2_ROOT} ++ $ENV{SSL2_ROOT} ++ $ENV{SSL2ROOT} ++ $ENV{SSL2_DIR} ++ $ENV{SSL2DIR}) ++# endif() ++ ++find_library( ++ COSMA_SSL2_LINK_LIBRARIES ++ NAMES "fjlapackex" ++ HINTS ${_SSL2_PATHS} ++ PATH_SUFFIXES "lib64" ++) ++find_path( ++ COSMA_SSL2_INCLUDE_DIRS ++ NAMES "cblas.h" ++ HINTS ${_SSL2_PATHS} ++ PATH_SUFFIXES "include" ++) ++ ++# check if found ++include(FindPackageHandleStandardArgs) ++find_package_handle_standard_args(SSL2 REQUIRED_VARS COSMA_SSL2_INCLUDE_DIRS COSMA_SSL2_LINK_LIBRARIES) ++ ++# add target to link against ++if(NOT TARGET cosma::BLAS::SSL2::ssl2) ++ add_library(cosma::BLAS::SSL2::ssl2 INTERFACE IMPORTED) ++ add_library(cosma::BLAS::SSL2::blas ALIAS cosma::BLAS::SSL2::ssl2) ++endif() ++set_property(TARGET cosma::BLAS::SSL2::ssl2 PROPERTY INTERFACE_LINK_LIBRARIES ${COSMA_SSL2_LINK_LIBRARIES}) ++set_property(TARGET cosma::BLAS::SSL2::ssl2 PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${COSMA_SSL2_INCLUDE_DIRS}) ++ ++# prevent clutter in cache ++MARK_AS_ADVANCED(SSL2_FOUND SSL2_LIBRARIES SSL2_INCLUDE_DIRS) diff --git a/recipes/cp2k/2024.3/gh200/repo/packages/cosma/mpi-view.patch b/recipes/cp2k/2024.3/gh200/repo/packages/cosma/mpi-view.patch new file mode 100644 index 00000000..ef6a2857 --- /dev/null +++ b/recipes/cp2k/2024.3/gh200/repo/packages/cosma/mpi-view.patch @@ -0,0 +1,13 @@ +diff --git a/cmake/cosmaConfig.cmake.in b/cmake/cosmaConfig.cmake.in +index cf7038f..1527c53 100644 +--- a/cmake/cosmaConfig.cmake.in ++++ b/cmake/cosmaConfig.cmake.in +@@ -11,7 +11,7 @@ if(NOT TARGET cosma::cosma) + set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR} ${CMAKE_MODULE_PATH}) + + set(MKL_ROOT "@MKL_ROOT@") +- set(MPI_CXX_COMPILER "@MPI_CXX_COMPILER@") ++ # set(MPI_CXX_COMPILER "@MPI_CXX_COMPILER@") + set(MPI_DETERMINE_LIBRARY_VERSION TRUE) + find_package(MPI COMPONENTS "CXX" REQUIRED) + diff --git a/recipes/cp2k/2024.3/gh200/repo/packages/cosma/package.py b/recipes/cp2k/2024.3/gh200/repo/packages/cosma/package.py new file mode 100644 index 00000000..78c162ce --- /dev/null +++ b/recipes/cp2k/2024.3/gh200/repo/packages/cosma/package.py @@ -0,0 +1,135 @@ +# Copyright 2013-2024 Lawrence Livermore National Security, LLC and other +# Spack Project Developers. See the top-level COPYRIGHT file for details. +# +# SPDX-License-Identifier: (Apache-2.0 OR MIT) + + +from spack.package import * + + +class Cosma(CMakePackage): + """ + Distributed Communication-Optimal Matrix-Matrix Multiplication Library + """ + + maintainers("haampie", "kabicm", "teonnik", "simonpintarelli", "mtaillefumier") + homepage = "https://github.com/eth-cscs/COSMA" + url = "https://github.com/eth-cscs/COSMA/archive/refs/tags/v2.6.6.tar.gz" + git = "https://github.com/eth-cscs/COSMA.git" + + license("BSD-3-Clause") + + # note: The default archives produced with github do not have the archives + # of the submodules. + version("master", branch="master", submodules=False) + version("2.6.6", sha256="1604be101e77192fbcc5551236bc87888d336e402f5409bbdd9dea900401cc37") + version("2.6.5", sha256="10d9b7ecc1ce44ec5b9e0c0bf89278a63029912ec3ea99661be8576b553ececf") + version("2.6.4", sha256="6d7bd5e3005874af9542a329c93e7ccd29ca1a5573dae27618fac2704fa2b6ab") + version("2.6.3", sha256="c2a3735ea8f860930bea6706d968497d72a1be0498c689b5bc4a951ffc2d1146") + version("2.6.2", sha256="2debb5123cc35aeebc5fd2f8a46cfd6356d1e27618c9bb57129ecd09aa400940") + version("2.6.1", sha256="69aa6634a030674f0d9be61e7b0bf0dc17acf0fc9e7a90b40e3179e2254c8d67") + version("2.5.1", sha256="085b7787597374244bbb1eb89bc69bf58c35f6c85be805e881e1c0b25166c3ce") + version("2.5.0", sha256="7f68bb0ee5c80f9b8df858afcbd017ad4ed87ac09439d13d7d890844dbdd3d54") + version("2.4.0", sha256="5714315ce06d48037f86cfee2d7f19340643fee95e9d7f1e92dc1b623b67e395") + version("2.3.0", sha256="0c01c2deb5a0cd177952178350188a62c42ce55e604d7948ac472f55bf0d4815") + version("2.2.0", sha256="1eb92a98110df595070a12193b9221eecf9d103ced8836c960f6c79a2bd553ca") + version("2.0.7", sha256="8d70bfcbda6239b6a8fbeaca138790bbe58c0c3aa576879480d2632d4936cf7e") + version("2.0.2", sha256="4f3354828bc718f3eef2f0098c3bdca3499297497a220da32db1acd57920c68d") + + # We just need the libraries of cuda and rocm, so no need to extend + # CudaPackage or ROCmPackage. + variant("cuda", default=False, description="Build with cuBLAS support") + variant("rocm", default=False, description="Build with rocBLAS support") + variant("scalapack", default=False, description="Build with ScaLAPACK API") + variant("shared", default=True, description="Build the shared library version") + variant("tests", default=False, description="Build tests") + variant("apps", default=False, description="Build miniapp") + variant("profiling", default=False, description="Enable profiling") + variant("gpu_direct", default=False, description="GPU aware MPI") + + with when("+cuda"): + variant("nccl", default=False, description="Use cuda nccl") + + with when("+rocm"): + variant("rccl", default=False, description="Use rocm rccl") + + depends_on("cmake@3.22:", type="build") + depends_on("mpi@3:") + depends_on("blas", when="~cuda ~rocm") + depends_on("scalapack", when="+scalapack") + depends_on("cuda", when="+cuda") + depends_on("rocblas", when="+rocm") + depends_on("nccl", when="+nccl") + depends_on("rccl", when="+rccl") + + with when("@2.6.3:"): + depends_on("tiled-mm@2.2:+cuda", when="+cuda") + depends_on("tiled-mm@2.2:+rocm", when="+rocm") + + with when("@2.6.1:2.6.2"): + depends_on("tiled-mm@2.0+rocm", when="+rocm") + depends_on("tiled-mm@2.0+cuda", when="+cuda") + + with when("@2.6.1:"): + depends_on("costa") + depends_on("costa+scalapack", when="+scalapack") + depends_on("cxxopts", when="+apps") + depends_on("cxxopts", when="+tests") + depends_on("semiprof", when="+profiling") + depends_on("costa+profiling", when="+profiling") + + patch("fj-ssl2.patch", when="^fujitsu-ssl2") + patch("mpi-view.patch") + + def setup_build_environment(self, env): + if "+cuda" in self.spec: + env.set("CUDA_PATH", self.spec["cuda"].prefix) + + def cosma_blas_cmake_arg(self): + query_to_cmake_arg = [ + ("+cuda", "CUDA"), + ("+rocm", "ROCM"), + ("^intel-mkl", "MKL"), + ("^intel-oneapi-mkl", "MKL"), + ("^cray-libsci", "CRAY_LIBSCI"), + ("^netlib-lapack", "CUSTOM"), + ("^openblas", "OPENBLAS"), + ("^fujitsu-ssl2", "SSL2"), + ] + + if self.version >= Version("2.4.0"): + query_to_cmake_arg.extend( + [("^blis", "BLIS"), ("^amdblis", "BLIS"), ("^atlas", "ATLAS")] + ) + + for query, cmake_arg in query_to_cmake_arg: + if query in self.spec: + return cmake_arg + + return "CUSTOM" + + def cosma_scalapack_cmake_arg(self): + spec = self.spec + + if "~scalapack" in spec: + return "OFF" + elif "^intel-mkl" in spec or "^intel-oneapi-mkl" in spec: + return "MKL" + elif "^cray-libsci" in spec: + return "CRAY_LIBSCI" + + return "CUSTOM" + + def cmake_args(self): + return [ + self.define_from_variant("COSMA_WITH_TESTS", "tests"), + self.define_from_variant("COSMA_WITH_APPS", "apps"), + self.define_from_variant("COSMA_WITH_NCCL", "nccl"), + self.define_from_variant("COSMA_WITH_RCCL", "rccl"), + self.define_from_variant("COSMA_WITH_GPU_AWARE_MPI", "gpu_direct"), + self.define_from_variant("COSMA_WITH_PROFILING", "profiling"), + self.define("COSMA_WITH_BENCHMARKS", False), + self.define("COSMA_BLAS", self.cosma_blas_cmake_arg()), + self.define("COSMA_SCALAPACK", self.cosma_scalapack_cmake_arg()), + self.define_from_variant("BUILD_SHARED_LIBS", "shared"), + ] diff --git a/recipes/cp2k/2024.3/gh200/repo/packages/costa/mpi-view.patch b/recipes/cp2k/2024.3/gh200/repo/packages/costa/mpi-view.patch new file mode 100644 index 00000000..be6d7060 --- /dev/null +++ b/recipes/cp2k/2024.3/gh200/repo/packages/costa/mpi-view.patch @@ -0,0 +1,13 @@ +diff --git a/cmake/costaConfig.cmake.in b/cmake/costaConfig.cmake.in +index 8fae534..d744c90 100644 +--- a/cmake/costaConfig.cmake.in ++++ b/cmake/costaConfig.cmake.in +@@ -10,7 +10,7 @@ include(CMakeFindDependencyMacro) + set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR} ${CMAKE_MODULE_PATH}) + + set(MKL_ROOT "@MKL_ROOT@") +-set(MPI_CXX_COMPILER "@MPI_CXX_COMPILER@") ++#set(MPI_CXX_COMPILER "@MPI_CXX_COMPILER@") + + set(MPI_DETERMINE_LIBRARY_VERSION TRUE) + set(COSTA_SCALAPACK "@COSTA_SCALAPACK@") diff --git a/recipes/cp2k/2024.3/gh200/repo/packages/costa/package.py b/recipes/cp2k/2024.3/gh200/repo/packages/costa/package.py new file mode 100644 index 00000000..6b78f17c --- /dev/null +++ b/recipes/cp2k/2024.3/gh200/repo/packages/costa/package.py @@ -0,0 +1,77 @@ +# Copyright 2013-2024 Lawrence Livermore National Security, LLC and other +# Spack Project Developers. See the top-level COPYRIGHT file for details. +# +# SPDX-License-Identifier: (Apache-2.0 OR MIT) + + +from spack.package import * + + +class Costa(CMakePackage): + """ + Distributed Communication-Optimal Matrix Transpose and Reshuffle Library + Based on the paper: https://arxiv.org/abs/2106.06601 + """ + + maintainers("haampie", "kabicm", "RMeli", "mtaillefumier") + homepage = "https://github.com/eth-cscs/COSTA" + git = "https://github.com/eth-cscs/COSTA.git" + + license("BSD-3-Clause") + + # note: The default archives produced with github do not have the archives + # of the submodules. + version("master", branch="master", submodules=True) + version("2.2.2", sha256="e87bc37aad14ac0c5922237be5d5390145c9ac6aef0350ed17d86cb2d994e67c") + version("2.2.1", sha256="aa8aa2a4a79de094f857c22293825de270ff72becd6bd736ff9f2dd8c192446d") + version("2.2", sha256="3e7333f012af76ec3508276ea90800313f6136504667021fe229e710bf6acdc7") + version("2.1", sha256="c1e86452415083f7470b292d93ec60708b7c8dbafc2bac383636bb4b28135866") + version("2.0", sha256="de250197f31f7d23226c6956a687c3ff46fb0ff6c621a932428236c3f7925fe4") + + variant("scalapack", default=False, description="Build with ScaLAPACK API") + variant("shared", default=True, description="Build shared libraries") + variant("profiling", default=False, description="Enable profiling") + variant("tests", default=False, description="Enable tests") + variant("apps", default=False, description="Enable miniapp") + variant("benchmarks", default=False, description="Enable benchmarks") + + depends_on("cmake@3.22:", type="build") + depends_on("mpi@3:") + depends_on("scalapack", when="+scalapack") + depends_on("cxxopts", when="+apps") + depends_on("cxxopts", when="+tests") + depends_on("semiprof", when="+profiling") + + patch("mpi-view.patch") + + def url_for_version(self, version): + if version == Version("2.0"): + return "https://github.com/eth-cscs/COSTA/releases/download/v{0}/COSTA-v{1}.tar.gz".format( + version, version + ) + return "https://github.com/eth-cscs/COSTA/archive/refs/tags/v{0}.tar.gz".format(version) + + def setup_build_environment(self, env): + return + + def costa_scalapack_cmake_arg(self): + spec = self.spec + + if "~scalapack" in spec: + return "OFF" + elif "^intel-mkl" in spec or "^intel-oneapi-mkl" in spec: + return "MKL" + elif "^cray-libsci" in spec: + return "CRAY_LIBSCI" + + return "CUSTOM" + + def cmake_args(self): + return [ + self.define_from_variant("COSTA_WITH_BENCHMARKS", "benchmarks"), + self.define_from_variant("COSTA_WITH_APPS", "apps"), + self.define_from_variant("COSTA_WITH_TESTS", "tests"), + self.define_from_variant("COSTA_WITH_PROFILING", "profiling"), + self.define_from_variant("BUILD_SHARED_LIBS", "shared"), + self.define("COSTA_SCALAPACK", self.costa_scalapack_cmake_arg()), + ] diff --git a/recipes/cp2k/2024.3/gh200/repo/packages/cp2k/backport_avoid_null_2022.x.patch b/recipes/cp2k/2024.3/gh200/repo/packages/cp2k/backport_avoid_null_2022.x.patch new file mode 100644 index 00000000..ecd3db97 --- /dev/null +++ b/recipes/cp2k/2024.3/gh200/repo/packages/cp2k/backport_avoid_null_2022.x.patch @@ -0,0 +1,21 @@ +diff -Naru a/src/qs_kpp1_env_methods.F b/src/qs_kpp1_env_methods.F +--- a/src/qs_kpp1_env_methods.F 2022-10-03 01:14:25.720416300 +0530 ++++ b/src/qs_kpp1_env_methods.F 2023-06-14 02:33:05.205287205 +0530 +@@ -214,7 +214,6 @@ + output_unit + LOGICAL :: gapw, gapw_xc, lsd, my_calc_forces + REAL(KIND=dp) :: alpha, energy_hartree, energy_hartree_1c +- REAL(KIND=dp), DIMENSION(:, :, :, :), POINTER :: vxg + TYPE(atomic_kind_type), DIMENSION(:), POINTER :: atomic_kind_set + TYPE(cp_logger_type), POINTER :: logger + TYPE(cp_para_env_type), POINTER :: para_env +@@ -373,7 +372,8 @@ + + CALL xc_calc_2nd_deriv(v_xc, v_xc_tau, p_env%kpp1_env%deriv_set, p_env%kpp1_env%rho_set, & + rho1_r_pw, rho1_g_pw, tau1_r_pw, auxbas_pw_pool, xc_section, .FALSE., & +- NULL(vxg), lsd_singlets, do_excitations, do_triplet, do_tddft, & ++ lsd_singlets=lsd_singlets, do_excitations=do_excitations, & ++ do_triplet=do_triplet, do_tddft=do_tddft, & + compute_virial=calc_virial, virial_xc=virial) + + DO ispin = 1, nspins diff --git a/recipes/cp2k/2024.3/gh200/repo/packages/cp2k/backport_avoid_null_9.1.patch b/recipes/cp2k/2024.3/gh200/repo/packages/cp2k/backport_avoid_null_9.1.patch new file mode 100644 index 00000000..7f580a04 --- /dev/null +++ b/recipes/cp2k/2024.3/gh200/repo/packages/cp2k/backport_avoid_null_9.1.patch @@ -0,0 +1,21 @@ +diff -Naru a/src/qs_kpp1_env_methods.F b/src/qs_kpp1_env_methods.F +--- a/src/qs_kpp1_env_methods.F 2021-11-20 14:35:36.103103400 +0530 ++++ b/src/qs_kpp1_env_methods.F 2023-06-14 12:00:52.350584708 +0530 +@@ -220,7 +220,6 @@ + output_unit + LOGICAL :: gapw, gapw_xc, lsd, my_calc_forces + REAL(KIND=dp) :: alpha, energy_hartree, energy_hartree_1c +- REAL(KIND=dp), DIMENSION(:, :, :, :), POINTER :: vxg + TYPE(atomic_kind_type), DIMENSION(:), POINTER :: atomic_kind_set + TYPE(cp_logger_type), POINTER :: logger + TYPE(cp_para_env_type), POINTER :: para_env +@@ -361,7 +360,8 @@ + + CALL xc_calc_2nd_deriv(v_xc, p_env%kpp1_env%deriv_set, p_env%kpp1_env%rho_set, & + rho1_r_pw, rho1_g_pw, auxbas_pw_pool, xc_section, .FALSE., & +- NULL(vxg), lsd_singlets, do_excitations, do_triplet, do_tddft, & ++ lsd_singlets=lsd_singlets, do_excitations=do_excitations, & ++ do_triplet=do_triplet, do_tddft=do_tddft, & + compute_virial=calc_virial, virial_xc=virial) + + DO ispin = 1, nspins diff --git a/recipes/cp2k/2024.3/gh200/repo/packages/cp2k/cmake-fixes-2023.2.patch b/recipes/cp2k/2024.3/gh200/repo/packages/cp2k/cmake-fixes-2023.2.patch new file mode 100644 index 00000000..985edad3 --- /dev/null +++ b/recipes/cp2k/2024.3/gh200/repo/packages/cp2k/cmake-fixes-2023.2.patch @@ -0,0 +1,714 @@ +From b75eb217115820059aba26d1ff1a8657e3841e7d Mon Sep 17 00:00:00 2001 +From: Mathieu Taillefumier +Date: Mon, 23 Oct 2023 15:50:44 +0200 +Subject: [PATCH] cmake-fixes-2023.2 + +--- + CMakeLists.txt | 63 +++++++----- + cmake/FindBlas.cmake | 174 +++++++++++++++++----------------- + cmake/FindLapack.cmake | 47 ++++----- + cmake/cp2k.pc.in | 19 ---- + cmake/cp2kConfig.cmake.in | 195 ++++++++++++++++++++------------------ + cmake/libcp2k.pc.in | 11 +++ + src/CMakeLists.txt | 18 ++-- + 7 files changed, 276 insertions(+), 251 deletions(-) + delete mode 100644 cmake/cp2k.pc.in + create mode 100644 cmake/libcp2k.pc.in + +diff --git a/CMakeLists.txt b/CMakeLists.txt +index 3f81c7b52..f2d85d033 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -49,7 +49,8 @@ if(NOT DEFINED CMAKE_CUDA_STANDARD) + endif() + + # set language and standard +-set(CMAKE_CXX_STANDARD 11) ++set(CMAKE_CXX_STANDARD 14) ++set(CMAKE_C_STANDARD 11) + + find_package(PkgConfig) + +@@ -108,6 +109,10 @@ option(CP2K_USE_LIBXSMM "Use libxsmm for small gemms (supports x86 platforms)" + OFF) + option(CP2K_BUILD_DBCSR "Duild dbcsr at the same time than cp2k." OFF) + option(BUILD_SHARED_LIBS "Build cp2k shared library" ON) ++option( ++ CP2K_USE_FFTW3_WITH_MKL ++ "If set to ON use the original implementation of fftw3 instead of the MKL implementation." ++ OFF) + + cmake_dependent_option(CP2K_ENABLE_ELPA_OPENMP_SUPPORT + "Enable elpa openmp support" ON "CP2K_USE_ELPA" OFF) +@@ -115,8 +120,8 @@ cmake_dependent_option(CP2K_ENABLE_FFTW3_OPENMP_SUPPORT + "Enable FFTW openmp support" ON "CP2K_USE_FFTW3" OFF) + cmake_dependent_option(CP2K_ENABLE_FFTW3_THREADS_SUPPORT + "Enable FFTW THREADS support" OFF "CP2K_USE_FFTW3" OFF) +-cmake_dependent_option(CP2K_ENABLE_F08_MPI "Enable MPI Fortran 2008 interface" +- OFF "CP2K_USE_MPI" OFF) ++cmake_dependent_option(CP2K_USE_MPI_F08 "Enable MPI Fortran 2008 interface" OFF ++ "CP2K_USE_MPI" OFF) + + cmake_dependent_option( + DBCSR_USE_ACCEL +@@ -527,7 +532,7 @@ if(CP2K_USE_ACCEL MATCHES "CUDA") + endif() + + set(CP2K_USE_CUDA ON) +- message(STATUS ``"-- CUDA compiler and libraries found") ++ message(STATUS "-- CUDA compiler and libraries found") + elseif(CP2K_USE_ACCEL MATCHES "HIP") + enable_language(HIP) + # Find hip +@@ -620,27 +625,36 @@ endif() + + # FFTW3 + ++set(CP2K_USE_FFTW3_ OFF) + if(CP2K_USE_FFTW3) +- find_package(Fftw REQUIRED) +- if(CP2K_ENABLE_FFTW3_THREADS_SUPPORT AND CP2K_ENABLE_FFTW3_OPENMP_SUPPORT) +- message( +- FATAL_ERROR +- "Fftw3 threads and openmp supports can not be used at the same time") +- endif() ++ if(CP2K_USE_FFTW3_WITH_MKL OR NOT CP2K_BLAS_VENDOR MATCHES "MKL") ++ find_package(Fftw REQUIRED) ++ if(CP2K_ENABLE_FFTW3_THREADS_SUPPORT AND CP2K_ENABLE_FFTW3_OPENMP_SUPPORT) ++ message( ++ FATAL_ERROR ++ "Fftw3 threads and openmp supports can not be used at the same time") ++ endif() + +- if((CP2K_ENABLE_FFTW3_THREADS_SUPPORT) AND (NOT TARGET +- CP2K::FFTW3::fftw3_threads)) +- message( +- FATAL_ERROR +- "fftw3 was compiled without multithreading support (--enable-threads option in fftw build system)." +- ) +- endif() ++ if((CP2K_ENABLE_FFTW3_THREADS_SUPPORT) AND (NOT TARGET ++ CP2K::FFTW3::fftw3_threads)) ++ message( ++ FATAL_ERROR ++ "fftw3 was compiled without multithreading support (--enable-threads option in fftw build system)." ++ ) ++ endif() + +- if((CP2K_ENABLE_FFTW3_OPENMP_SUPPORT) AND (NOT TARGET CP2K::FFTW3::fftw3_omp)) +- message( +- FATAL_ERROR +- "fftw3 was compiled without openmp support (--enable-openmp option in fftw build system)." +- ) ++ if((CP2K_ENABLE_FFTW3_OPENMP_SUPPORT) AND (NOT TARGET CP2K::FFTW3::fftw3_omp ++ )) ++ message( ++ FATAL_ERROR ++ "fftw3 was compiled without openmp support (--enable-openmp option in fftw build system)." ++ ) ++ endif() ++ # we use this variable later on to include the fftw target whenever mkl is ++ # found or not ++ set(CP2K_USE_FFTW3_ ON) ++ else() ++ message("-- Using the MKL implementation of FFTW3.") + endif() + endif() + +@@ -748,7 +762,7 @@ add_subdirectory(src) + include(GNUInstallDirs) + + get_target_property(CP2K_LIBS cp2k_link_libs INTERFACE_LINK_LIBRARIES) +-configure_file(cmake/cp2k.pc.in cp2k.pc @ONLY) ++configure_file(cmake/libcp2k.pc.in libcp2k.pc @ONLY) + + message( + STATUS "--------------------------------------------------------------------") +@@ -1039,6 +1053,9 @@ install(FILES "${PROJECT_BINARY_DIR}/cp2kConfig.cmake" + "${PROJECT_BINARY_DIR}/cp2kConfigVersion.cmake" + DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/cp2k") + ++install(FILES "${PROJECT_BINARY_DIR}/libcp2k.pc" ++ DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig") ++ + install( + DIRECTORY "${PROJECT_SOURCE_DIR}/cmake" + DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/cp2k" +diff --git a/cmake/FindBlas.cmake b/cmake/FindBlas.cmake +index 6e5fb7824..335cbd964 100644 +--- a/cmake/FindBlas.cmake ++++ b/cmake/FindBlas.cmake +@@ -15,104 +15,108 @@ if(NOT + OR CMAKE_Fortran_COMPILER_LOADED)) + message(FATAL_ERROR "FindBLAS requires Fortran, C, or C++ to be enabled.") + endif() ++if(NOT CP2K_CONFIG_PACKAGE) ++ set(CP2K_BLAS_VENDOR_LIST ++ "auto" ++ "MKL" ++ "OpenBLAS" ++ "SCI" ++ "GenericBLAS" ++ "Armpl" ++ "FlexiBLAS" ++ "Atlas" ++ "NVHPCBlas" ++ "CUSTOM") ++ ++ set(__BLAS_VENDOR_LIST ${CP2K_BLAS_VENDOR_LIST}) ++ list(REMOVE_ITEM __BLAS_VENDOR_LIST "auto") ++ list(REMOVE_ITEM __BLAS_VENDOR_LIST "CUSTOM") ++ ++ # set(CP2K_BLAS_VENDOR "auto" CACHE STRING "Blas library for computations on ++ # host") ++ set_property(CACHE CP2K_BLAS_VENDOR PROPERTY STRINGS ${CP2K_BLAS_VENDOR_LIST}) ++ ++ if(NOT ${CP2K_BLAS_VENDOR} IN_LIST CP2K_BLAS_VENDOR_LIST) ++ message(FATAL_ERROR "Invalid Host BLAS backend") ++ endif() + +-set(CP2K_BLAS_VENDOR_LIST +- "auto" +- "MKL" +- "OpenBLAS" +- "SCI" +- "GenericBLAS" +- "Armpl" +- "FlexiBLAS" +- "Atlas" +- "NVHPCBlas" +- "CUSTOM") +- +-set(__BLAS_VENDOR_LIST ${CP2K_BLAS_VENDOR_LIST}) +-list(REMOVE_ITEM __BLAS_VENDOR_LIST "auto") +-list(REMOVE_ITEM __BLAS_VENDOR_LIST "CUSTOM") +- +-# set(CP2K_BLAS_VENDOR "auto" CACHE STRING "Blas library for computations on +-# host") +-set_property(CACHE CP2K_BLAS_VENDOR PROPERTY STRINGS ${CP2K_BLAS_VENDOR_LIST}) +- +-if(NOT ${CP2K_BLAS_VENDOR} IN_LIST CP2K_BLAS_VENDOR_LIST) +- message(FATAL_ERROR "Invalid Host BLAS backend") +-endif() +- +-set(CP2K_BLAS_THREAD_LIST "sequential" "thread" "gnu-thread" "intel-thread" +- "tbb-thread" "openmp") +- +-set(CP2K_BLAS_THREADING +- "sequential" +- CACHE STRING "threaded blas library") +-set_property(CACHE CP2K_BLAS_THREADING PROPERTY STRINGS +- ${CP2K_BLAS_THREAD_LIST}) +- +-if(NOT ${CP2K_BLAS_THREADING} IN_LIST CP2K_BLAS_THREAD_LIST) +- message(FATAL_ERROR "Invalid threaded BLAS backend") +-endif() ++ set(CP2K_BLAS_THREAD_LIST "sequential" "thread" "gnu-thread" "intel-thread" ++ "tbb-thread" "openmp") + +-set(CP2K_BLAS_INTERFACE_BITS_LIST "32bits" "64bits") +-set(CP2K_BLAS_INTERFACE +- "32bits" +- CACHE STRING +- "32 bits integers are used for indices, matrices and vectors sizes") +-set_property(CACHE CP2K_BLAS_INTERFACE +- PROPERTY STRINGS ${CP2K_BLAS_INTERFACE_BITS_LIST}) +- +-if(NOT ${CP2K_BLAS_INTERFACE} IN_LIST CP2K_BLAS_INTERFACE_BITS_LIST) +- message( +- FATAL_ERROR +- "Invalid parameters. Blas and lapack can exist in two flavors 32 or 64 bits interfaces (relevant mostly for mkl)" +- ) +-endif() ++ set(CP2K_BLAS_THREADING ++ "sequential" ++ CACHE STRING "threaded blas library") ++ set_property(CACHE CP2K_BLAS_THREADING PROPERTY STRINGS ++ ${CP2K_BLAS_THREAD_LIST}) + +-set(CP2K_BLAS_FOUND FALSE) ++ if(NOT ${CP2K_BLAS_THREADING} IN_LIST CP2K_BLAS_THREAD_LIST) ++ message(FATAL_ERROR "Invalid threaded BLAS backend") ++ endif() + +-# first check for a specific implementation if requested ++ set(CP2K_BLAS_INTERFACE_BITS_LIST "32bits" "64bits") ++ set(CP2K_BLAS_INTERFACE ++ "32bits" ++ CACHE STRING ++ "32 bits integers are used for indices, matrices and vectors sizes") ++ set_property(CACHE CP2K_BLAS_INTERFACE ++ PROPERTY STRINGS ${CP2K_BLAS_INTERFACE_BITS_LIST}) + +-if(NOT CP2K_BLAS_VENDOR MATCHES "auto|CUSTOM") +- find_package(${CP2K_BLAS_VENDOR} REQUIRED) +- if(TARGET CP2K::BLAS::${CP2K_BLAS_VENDOR}::blas) +- get_target_property( +- CP2K_BLAS_INCLUDE_DIRS CP2K::BLAS::${CP2K_BLAS_VENDOR}::blas +- INTERFACE_INCLUDE_DIRECTORIES) +- get_target_property( +- CP2K_BLAS_LINK_LIBRARIES CP2K::BLAS::${CP2K_BLAS_VENDOR}::blas +- INTERFACE_LINK_LIBRARIES) +- set(CP2K_BLAS_FOUND TRUE) +- endif() +-else() +- if(CP2K_BLAS_VENDOR MATCHES "CUSTOM" AND NOT DEFINED CP2K_BLAS_LINK_LIBRARIES) ++ if(NOT ${CP2K_BLAS_INTERFACE} IN_LIST CP2K_BLAS_INTERFACE_BITS_LIST) + message( + FATAL_ERROR +- "Setting CP2K_BLAS_VENDOR=CUSTOM imply setting CP2K_BLAS_LINK_LIBRARIES\n and CP2K_LAPACK_LINK_LIBRARIES to the right libraries. See the README_cmake.md for more details" ++ "Invalid parameters. Blas and lapack can exist in two flavors 32 or 64 bits interfaces (relevant mostly for mkl)" + ) + endif() + +- if(DEFINED CP2K_BLAS_LINK_LIBRARIES) +- set(CP2K_BLAS_FOUND TRUE) ++ set(CP2K_BLAS_FOUND FALSE) ++ ++ # first check for a specific implementation if requested ++ ++ if(NOT CP2K_BLAS_VENDOR MATCHES "auto|CUSTOM") ++ find_package(${CP2K_BLAS_VENDOR} REQUIRED) ++ if(TARGET CP2K::BLAS::${CP2K_BLAS_VENDOR}::blas) ++ get_target_property( ++ CP2K_BLAS_INCLUDE_DIRS CP2K::BLAS::${CP2K_BLAS_VENDOR}::blas ++ INTERFACE_INCLUDE_DIRECTORIES) ++ get_target_property( ++ CP2K_BLAS_LINK_LIBRARIES CP2K::BLAS::${CP2K_BLAS_VENDOR}::blas ++ INTERFACE_LINK_LIBRARIES) ++ set(CP2K_BLAS_FOUND TRUE) ++ endif() + else() +- # search for any blas implementation and exit immediately if one is found. +- # we could also give a full list of found implementation and let the user +- # choose which implementation to use +- foreach(_libs ${__BLAS_VENDOR_LIST}) +- # I exclude the first item of the list +- find_package(${_libs}) +- if(TARGET CP2K::BLAS::${_libs}::blas) +- get_target_property(CP2K_BLAS_INCLUDE_DIRS CP2K::BLAS::${_libs}::blas +- INTERFACE_INCLUDE_DIRECTORIES) +- get_target_property(CP2K_BLAS_LINK_LIBRARIES CP2K::BLAS::${_libs}::blas +- INTERFACE_LINK_LIBRARIES) +- set(CP2K_BLAS_VENDOR "${_libs}") +- set(CP2K_BLAS_FOUND TRUE) +- break() +- endif() +- endforeach() ++ if(CP2K_BLAS_VENDOR MATCHES "CUSTOM" AND NOT DEFINED ++ CP2K_BLAS_LINK_LIBRARIES) ++ message( ++ FATAL_ERROR ++ "Setting CP2K_BLAS_VENDOR=CUSTOM imply setting CP2K_BLAS_LINK_LIBRARIES\n and CP2K_LAPACK_LINK_LIBRARIES to the right libraries. See the README_cmake.md for more details" ++ ) ++ endif() ++ ++ if(DEFINED CP2K_BLAS_LINK_LIBRARIES) ++ set(CP2K_BLAS_FOUND TRUE) ++ else() ++ # search for any blas implementation and exit immediately if one is found. ++ # we could also give a full list of found implementation and let the user ++ # choose which implementation to use ++ foreach(_libs ${__BLAS_VENDOR_LIST}) ++ # I exclude the first item of the list ++ find_package(${_libs}) ++ if(TARGET CP2K::BLAS::${_libs}::blas) ++ get_target_property(CP2K_BLAS_INCLUDE_DIRS CP2K::BLAS::${_libs}::blas ++ INTERFACE_INCLUDE_DIRECTORIES) ++ get_target_property( ++ CP2K_BLAS_LINK_LIBRARIES CP2K::BLAS::${_libs}::blas ++ INTERFACE_LINK_LIBRARIES) ++ set(CP2K_BLAS_VENDOR "${_libs}") ++ set(CP2K_BLAS_FOUND TRUE) ++ break() ++ endif() ++ endforeach() ++ endif() + endif() ++else() ++ set(CP2K_BLAS_FOUND ON) + endif() +- + # we exclude the CP2K_BLAS_INCLUDE_DIRS from the list of mandatory variables as + # having the fortran interface is usually enough. C, C++ and others languages + # might require this information though +diff --git a/cmake/FindLapack.cmake b/cmake/FindLapack.cmake +index 966e0d78d..77a1e0425 100644 +--- a/cmake/FindLapack.cmake ++++ b/cmake/FindLapack.cmake +@@ -20,33 +20,34 @@ include(FindPackageHandleStandardArgs) + find_package(PkgConfig) + find_package(Blas REQUIRED) + +-if(CP2K_BLAS_FOUND) +- # LAPACK in the Intel MKL 10+ library? +- if(CP2K_BLAS_VENDOR MATCHES "MKL|OpenBLAS|Armpl|SCI|FlexiBLAS|NVHPC") +- # we just need to create the interface that's all +- set(CP2K_LAPACK_FOUND TRUE) +- get_target_property(CP2K_LAPACK_INCLUDE_DIRS CP2K::BLAS::blas +- INTERFACE_INCLUDE_DIRECTORIES) +- get_target_property(CP2K_LAPACK_LINK_LIBRARIES CP2K::BLAS::blas +- INTERFACE_LINK_LIBRARIES) +- else() +- # we might get lucky to find a pkgconfig package for lapack (fedora provides +- # one for instance) +- if(PKG_CONFIG_FOUND) +- pkg_check_modules(CP2K_LAPACK lapack) +- endif() ++if(NOT CP2K_CONFIG_PACKAGE) ++ if(CP2K_BLAS_FOUND) ++ # LAPACK in the Intel MKL 10+ library? ++ if(CP2K_BLAS_VENDOR MATCHES "MKL|OpenBLAS|Armpl|SCI|FlexiBLAS|NVHPC") ++ # we just need to create the interface that's all ++ set(CP2K_LAPACK_FOUND TRUE) ++ get_target_property(CP2K_LAPACK_INCLUDE_DIRS CP2K::BLAS::blas ++ INTERFACE_INCLUDE_DIRECTORIES) ++ get_target_property(CP2K_LAPACK_LINK_LIBRARIES CP2K::BLAS::blas ++ INTERFACE_LINK_LIBRARIES) ++ else() ++ # we might get lucky to find a pkgconfig package for lapack (fedora ++ # provides one for instance) ++ if(PKG_CONFIG_FOUND) ++ pkg_check_modules(CP2K_LAPACK lapack) ++ endif() + +- if(NOT CP2K_LAPACK_FOUND) +- find_library( +- CP2K_LAPACK_LINK_LIBRARIES +- NAMES "lapack" "lapack64" +- PATH_SUFFIXES "openblas" "openblas64" "openblas-pthread" +- "openblas-openmp" "lib" "lib64" +- NO_DEFAULT_PATH) ++ if(NOT CP2K_LAPACK_FOUND) ++ find_library( ++ CP2K_LAPACK_LINK_LIBRARIES ++ NAMES "lapack" "lapack64" ++ PATH_SUFFIXES "openblas" "openblas64" "openblas-pthread" ++ "openblas-openmp" "lib" "lib64" ++ NO_DEFAULT_PATH) ++ endif() + endif() + endif() + endif() +- + # check if found + find_package_handle_standard_args(Lapack + REQUIRED_VARS CP2K_LAPACK_LINK_LIBRARIES) +diff --git a/cmake/cp2k.pc.in b/cmake/cp2k.pc.in +deleted file mode 100644 +index 5b4a09566..000000000 +--- a/cmake/cp2k.pc.in ++++ /dev/null +@@ -1,19 +0,0 @@ +-# this template is filled-in by CMake `configure_file(... @ONLY)` +-# the `@....@` are filled in by CMake configure_file(), +-# from variables set in your CMakeLists.txt or by CMake itself +-# +-# Good tutoral for understanding .pc files: +-# https://people.freedesktop.org/~dbn/pkg-config-guide.html +- +-prefix="@CMAKE_INSTALL_PREFIX@" +-exec_prefix="${prefix}" +-libdir="${prefix}/lib" +-includedir="${prefix}/include" +- +-Name: @PROJECT_NAME@ +-Description: @CMAKE_PROJECT_DESCRIPTION@ +-URL: @CMAKE_PROJECT_HOMEPAGE_URL@ +-Version: @PROJECT_VERSION@ +-Cflags: -I"${includedir}" +-Libs: -L"${libdir}" -lcp2k -lcp2k_dbm -lcp2k_grid -lcp2k_offload +-#Libs.private: -L"${libdir}" @CP2K_LIBS@ +\ No newline at end of file +diff --git a/cmake/cp2kConfig.cmake.in b/cmake/cp2kConfig.cmake.in +index a3acd4744..1c310e19b 100644 +--- a/cmake/cp2kConfig.cmake.in ++++ b/cmake/cp2kConfig.cmake.in +@@ -5,112 +5,121 @@ + #! SPDX-License-Identifier: GPL-2.0-or-later ! + #!-------------------------------------------------------------------------------------------------! + +- + cmake_minimum_required(VERSION 3.22) ++include(CMakeFindDependencyMacro) ++ ++if(NOT TARGET cp2k::cp2k) ++ set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/modules" ++ ${CMAKE_MODULE_PATH}) ++ ++ # store CXX compiler id. Used in MKL package. ++ set(CP2K_CXX_COMPILER_ID @CMAKE_CXX_COMPILER_ID@) ++ if(NOT ${CMAKE_CXX_COMPILER_ID}) ++ set(CMAKE_CXX_COMPILER_ID ${CP2K_CXX_COMPILER_ID}) ++ endif() ++ ++ set(CP2K_BLAS_VENDOR @CP2K_BLAS_VENDOR@) ++ set(CP2K_SCALAPACK_VENDOR @CP2K_SCALAPACK_VENDOR@) ++ set(CP2K_BLAS_LINK_LIBRARIES @CP2K_BLAS_LINK_LIBRARIES@) ++ set(CP2K_LAPACK_LINK_LIBRARIES @CP2K_LAPACK_LINK_LIBRARIES@) ++ set(CP2K_SCALAPACK_LINK_LIBRARIES @CP2K_SCALAPACK_LINK_LIBRARIES@) ++ ++ set(CP2K_CONFIG_PACKAGE ON) ++ find_dependency(Lapack REQUIRED) ++ ++ # define lapack and blas TARGETS ++ ++ if(@CP2K_USE_MPI@) ++ find_dependency(SCALAPACK REQUIRED) ++ endif() ++ unset(CP2K_CONFIG_PACKAGE) ++ ++ set(cp2k_VERSION @cp2k_VERSION@) ++ ++ find_dependency(DBCSR 2.5 REQUIRED) ++ ++ if(@CP2K_USE_LIBXSMM@) ++ find_dependency(LibXSMM REQUIRED) ++ endif() ++ ++ if(@CP2K_USE_HIP@) ++ # Find hip ++ find_dependency(hipfft REQUIRED IMPORTED CONFIG) ++ find_dependency(hipblas REQUIRED IMPORTED CONFIG) ++ endif() ++ ++ if(@CP2K_USE_CUDA@) ++ find_dependency(CUDAToolkit REQUIRED) ++ endif() ++ if(@CP2K_USE_ELPA@) ++ find_dependency(Elpa REQUIRED) ++ endif() ++ ++ if(@CP2K_USE_LIBXC@) ++ find_dependency(LibXC 6 REQUIRED EXACT) ++ endif() ++ ++ if(@CP2K_USE_COSMA@) ++ find_dependency(cosma REQUIRED) ++ endif() ++ ++ if(@CP2K_USE_MPI@) ++ find_dependency(MPI REQUIRED) ++ endif() ++ ++ if(@CP2K_USE_FFTW3@ OR @CP2K_USE_FFTW3_WITH_MKL@) ++ find_dependency(Fftw REQUIRED) ++ endif() ++ ++ # QUIP ++ if(@CP2K_USE_QUIP@) ++ find_dependency(Quip REQUIRED) ++ endif() + +-# store CXX compiler id. Used in MKL package. +-set(SIRIUS_CXX_COMPILER_ID @CMAKE_CXX_COMPILER_ID@) +-if(NOT ${CMAKE_CXX_COMPILER_ID}) +- set(CMAKE_CXX_COMPILER_ID ${SIRIUS_CXX_COMPILER_ID}) +-endif() +- +-set(CP2K_BLAS_VENDOR @CP2K_BLAS_VENDOR@) +-set(CP2K_SCALAPACK_VENDOR @CP2K_SCALAPACK_VENDOR@) +- +-if (@CP2K_BLAS_VENDOR@ MATCHES "CUSTOM") +- set(CP2K_BLAS_LINK_LIBRARIES @CP2K_BLAS_LINK_LIBRARIES@) +- set(CP2K_LAPACK_LINK_LIBRARIES @CP2K_LAPACK_LINK_LIBRARIES@) +-endif() +- +-if (@CP2K_SCALAPACK_VENDOR@ MATCHES "CUSTOM") +- set(CP2K_SCALAPACK_LINK_LIBRARIES @CP2K_SCALAPACK_LINK_LIBRARIES@) +-endif() +- +-find_package(Lapack REQUIRED) +-find_package(DBCSR 2.4 REQUIRED) +- +-if(@CP2K_USE_LIBXSMM@ +- find_package(LibXSMM REQUIRED) +-endif() +- +-if (@@CP2K_USE_HIP@) +- # Find hip +- find_package(hipfft REQUIRED IMPORTED CONFIG) +- find_package(hipblas REQUIRED IMPORTED CONFIG) +-endif() +- +-if (@@CP2K_USE_CUDA@) +- find_package(CUDAToolkit REQUIRED) +-endif() +-if(@CP2K_USE_ELPA@) +- find_package(Elpa REQUIRED) +-endif() +- +-if(@CP2K_USE_LIBXC@) +- find_package(LibXC 6 REQUIRED EXACT) +-endif() +- +-if(@CP2K_USE_COSMA@) +- find_package(cosma REQUIRED) +-endif() ++ # libint + +-if (@@CP2K_USE_MPI@) +- find_package(MPI REQUIRED) +- find_package(SCALAPACK REQUIRED) +-endif() ++ if(@CP2K_USE_LIBINT2@) ++ find_dependency(Libint2 REQUIRED) ++ endif() + +-if(@CP2K_USE_FFTW3@) +- find_package(Fftw REQUIRED) +-endif() +- # QUIP +-if(@CP2K_USE_QUIP@) +- find_package(Quip REQUIRED) +-endif() ++ # spglib + +-# libint ++ if(@CP2K_USE_SPGLIB@) ++ find_dependency(LibSPG REQUIRED) ++ endif() + +-if(@CP2K_USE_LIBINT2@) +- find_package(Libint2 REQUIRED) +-endif() ++ if(@CP2K_USE_SPLA@) ++ find_dependency(SPLA REQUIRED) ++ endif() + +-# spglib ++ if(@CP2K_USE_SIRIUS@) ++ find_dependency(sirius REQUIRED) ++ endif() + +-if(@CP2K_USE_SPGLIB@) +- find_package(LibSPG REQUIRED) +-endif() ++ if(@CP2K_USE_SUPERLU@) ++ find_dependency(SuperLU REQUIRED) ++ endif() + +-if(@CP2K_USE_SPLA@) +- find_package(SPLA REQUIRED) +-endif() ++ if(@CP2K_USE_METIS@) ++ find_dependency(Metis) ++ endif() + +-if(@CP2K_USE_SIRIUS@) +- find_package(sirius REQUIRED) +-endif() +- +-if(@CP2K_USE_SUPERLU@) +- find_package(SuperLU REQUIRED) +-endif() ++ if(@CP2K_USE_PEXSI@) ++ # PEXSI 1.2 uses cmake as build system ++ find_dependency(PEXSI REQUIRED) ++ endif() + +-if(@CP2K_USE_PARMETIS@) +- find_package(Metis) +-endif() ++ if(@CP2K_USE_PLUMED@) ++ find_dependency(Plumed REQUIRED) ++ endif() + +-if(@CP2K_USE_PTSCOTCH@) +- find_package(Ptscotch REQUIRED) +-endif() ++ if(@CP2K_USE_LIBTORCH@) ++ find_dependency(Torch REQUIRED) ++ endif() + +-if(@CP2K_USE_PEXSI@) +- # PEXSI 1.2 uses cmake as build system +- find_package(PEXSI REQUIRED) +-endif() ++ include("${CMAKE_CURRENT_LIST_DIR}/cp2kTargets.cmake") + +-if(@CP2K_USE_PLUMED@) +- find_package(Plumed REQUIRED) +-endif() ++ # Clean-up module path. ++ list(REMOVE_ITEM CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/modules") + +-if(@CP2K_USE_LIBTORCH@) +- find_package(Torch REQUIRED) + endif() +- +-# Include SIRIUS target +-include("${CMAKE_CURRENT_LIST_DIR}/cp2kTargets.cmake") +diff --git a/cmake/libcp2k.pc.in b/cmake/libcp2k.pc.in +new file mode 100644 +index 000000000..618af55e2 +--- /dev/null ++++ b/cmake/libcp2k.pc.in +@@ -0,0 +1,11 @@ ++prefix="@CMAKE_INSTALL_PREFIX@" ++exec_prefix="${prefix}" ++libdir="${prefix}/@CMAKE_INSTALL_LIBDIR@" ++includedir="${prefix}/@CMAKE_INSTALL_INCLUDEDIR@" ++ ++Name: @PROJECT_NAME@ ++Description: @CMAKE_PROJECT_DESCRIPTION@ ++URL: @CMAKE_PROJECT_HOMEPAGE_URL@ ++Version: @PROJECT_VERSION@ ++Cflags: -I"${includedir}/cp2k" -I"${includedir}/cp2k/@CMAKE_Fortran_COMPILER_ID@-@CMAKE_Fortran_COMPILER_VERSION@" ++Libs: -L"${libdir}" -lcp2k +diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt +index dbc955885..1178101ad 100644 +--- a/src/CMakeLists.txt ++++ b/src/CMakeLists.txt +@@ -1536,9 +1536,9 @@ target_link_libraries( + $<$:CP2K::LIBSPG::libspg> + $<$:CP2K::Libxc::xc> + $<$:CP2K::ELPA::elpa> +- $<$:CP2K::FFTW3::fftw3> +- $<$:CP2K::FFTW3::fftw3_threads> +- $<$:CP2K::FFTW3::fftw3_omp> ++ $<$:CP2K::FFTW3::fftw3> ++ $<$,$>:CP2K::FFTW3::fftw3_threads> ++ $<$,$>:CP2K::FFTW3::fftw3_omp> + $<$:SPLA::spla> + $<$:CP2K::Libint2::int2> + $<$:${TORCH_LIBRARIES}> +@@ -1555,7 +1555,7 @@ target_compile_definitions( + cp2k + PUBLIC $<$:__parallel> + $<$:__SCALAPACK> +- $<$:__MPI_08> ++ $<$:__MPI_F08> + __COMPILE_DATE=\"${CP2K_TIMESTAMP}\" + __COMPILE_HOST=\"${CP2K_HOST_NAME}\" + __COMPILE_REVISION=\"${CP2K_GIT_HASH}\" +@@ -1577,7 +1577,7 @@ target_compile_definitions( + $<$:__OFFLOAD_GEMM> + $<$:__ELPA> + $<$:__LIBXC> +- $<$:__FFTW3> ++ $<$:__FFTW3> + $<$:__LIBINT> + $<$:__LIBPEXSI> + $<$:__LIBTORCH> +@@ -1774,12 +1774,14 @@ install( + EXPORT cp2k_targets + FILE cp2kTargets.cmake + NAMESPACE cp2k:: +- DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/cp2k") ++ DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}") + +-install(FILES start/libcp2k.h DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/cp2k") ++install(FILES start/libcp2k.h ++ DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}") + + install( + DIRECTORY "${PROJECT_BINARY_DIR}/src/mod_files" +- DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/cp2k" ++ DESTINATION ++ "${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}/${CMAKE_Fortran_COMPILER_ID}-${CMAKE_Fortran_COMPILER_VERSION}" + FILES_MATCHING + PATTERN "*.mod") +-- +2.41.0 + diff --git a/recipes/cp2k/2024.3/gh200/repo/packages/cp2k/cmake-relwithdebinfo-2024.1.patch b/recipes/cp2k/2024.3/gh200/repo/packages/cp2k/cmake-relwithdebinfo-2024.1.patch new file mode 100644 index 00000000..b974527b --- /dev/null +++ b/recipes/cp2k/2024.3/gh200/repo/packages/cp2k/cmake-relwithdebinfo-2024.1.patch @@ -0,0 +1,23 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index 4526160ad..8218a7a3d 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -63,6 +63,18 @@ string(REPLACE "-DNDEBUG" "" CMAKE_C_FLAGS_RELEASE ${CMAKE_C_FLAGS_RELEASE}) + string(REPLACE "-DNDEBUG" "" CMAKE_CXX_FLAGS_RELEASE ${CMAKE_CXX_FLAGS_RELEASE}) + string(REPLACE "-DNDEBUG" "" CMAKE_Fortran_FLAGS_RELEASE + ${CMAKE_Fortran_FLAGS_RELEASE}) ++string(REPLACE "-DNDEBUG" "" CMAKE_C_FLAGS_RELWITHDEBINFO ++ ${CMAKE_C_FLAGS_RELWITHDEBINFO}) ++string(REPLACE "-DNDEBUG" "" CMAKE_CXX_FLAGS_RELWITHDEBINFO ++ ${CMAKE_CXX_FLAGS_RELWITHDEBINFO}) ++string(REPLACE "-DNDEBUG" "" CMAKE_Fortran_FLAGS_RELWITHDEBINFO ++ ${CMAKE_Fortran_FLAGS_RELWITHDEBINFO}) ++string(REPLACE "-DNDEBUG" "" CMAKE_C_FLAGS_MINSIZEREL ++ ${CMAKE_C_FLAGS_MINSIZEREL}) ++string(REPLACE "-DNDEBUG" "" CMAKE_CXX_FLAGS_MINSIZEREL ++ ${CMAKE_CXX_FLAGS_MINSIZEREL}) ++string(REPLACE "-DNDEBUG" "" CMAKE_Fortran_FLAGS_MINSIZEREL ++ ${CMAKE_Fortran_FLAGS_MINSIZEREL}) + + find_package(PkgConfig) + diff --git a/recipes/cp2k/2024.3/gh200/repo/packages/cp2k/package.py b/recipes/cp2k/2024.3/gh200/repo/packages/cp2k/package.py new file mode 100644 index 00000000..89413c93 --- /dev/null +++ b/recipes/cp2k/2024.3/gh200/repo/packages/cp2k/package.py @@ -0,0 +1,1016 @@ +# Copyright 2013-2024 Lawrence Livermore National Security, LLC and other +# Spack Project Developers. See the top-level COPYRIGHT file for details. +# +# SPDX-License-Identifier: (Apache-2.0 OR MIT) +import copy +import os +import os.path +import sys + +import spack.platforms +import spack.util.environment +import spack.util.executable +from spack.build_environment import dso_suffix +from spack.build_systems import cmake, makefile +from spack.package import * + +GPU_MAP = { + "35": "K40", + "37": "K80", + "60": "P100", + "70": "V100", + "80": "A100", + "90": "H100", + "gfx906": "Mi50", + "gfx908": "Mi100", + "gfx90a": "Mi250", + "gfx90a:xnack-": "Mi250", + "gfx90a:xnack+": "Mi250", +} + + +class Cp2k(MakefilePackage, CMakePackage, CudaPackage, ROCmPackage): + """CP2K is a quantum chemistry and solid state physics software package + that can perform atomistic simulations of solid state, liquid, molecular, + periodic, material, crystal, and biological systems + """ + + build_system(conditional("cmake", when="@2023.2:"), "makefile", default="cmake") + + homepage = "https://www.cp2k.org" + url = "https://github.com/cp2k/cp2k/releases/download/v3.0.0/cp2k-3.0.tar.bz2" + git = "https://github.com/cp2k/cp2k.git" + list_url = "https://github.com/cp2k/cp2k/releases" + + maintainers("dev-zero", "mtaillefumier") + + license("GPL-2.0-or-later") + + version("2024.3", sha256="a6eeee773b6b1fb417def576e4049a89a08a0ed5feffcd7f0b33c7d7b48f19ba") + version("2024.2", sha256="cc3e56c971dee9e89b705a1103765aba57bf41ad39a11c89d3de04c8b8cdf473") + version("2024.1", sha256="a7abf149a278dfd5283dc592a2c4ae803b37d040df25d62a5e35af5c4557668f") + version("2023.2", sha256="adbcc903c1a78cba98f49fe6905a62b49f12e3dfd7cedea00616d1a5f50550db") + version("2023.1", sha256="dff343b4a80c3a79363b805429bdb3320d3e1db48e0ff7d20a3dfd1c946a51ce") + version("2022.2", sha256="1a473dea512fe264bb45419f83de432d441f90404f829d89cbc3a03f723b8354") + version("2022.1", sha256="2c34f1a7972973c62d471cd35856f444f11ab22f2ff930f6ead20f3454fd228b") + version("9.1", sha256="fedb4c684a98ad857cd49b69a3ae51a73f85a9c36e9cb63e3b02320c74454ce6") + version("8.2", sha256="2e24768720efed1a5a4a58e83e2aca502cd8b95544c21695eb0de71ed652f20a") + version("8.1", sha256="7f37aead120730234a60b2989d0547ae5e5498d93b1e9b5eb548c041ee8e7772") + version("7.1", sha256="ccd711a09a426145440e666310dd01cc5772ab103493c4ae6a3470898cd0addb") + version("master", branch="master", submodules="True") + + variant("mpi", default=True, description="Enable MPI support") + variant("openmp", default=True, description="Enable OpenMP support") + variant( + "smm", + default="libxsmm", + values=("libxsmm", "libsmm", "blas"), + description="Library for small matrix multiplications", + ) + variant("plumed", default=False, description="Enable PLUMED support") + variant( + "libint", default=True, description="Use libint, required for HFX (and possibly others)" + ) + variant("libxc", default=True, description="Support additional functionals via libxc") + variant( + "pexsi", + default=False, + description="Enable the alternative PEXSI method for density matrix evaluation", + when="+mpi", + ) + variant( + "elpa", + default=False, + description="Enable optimised diagonalisation routines from ELPA", + when="+mpi", + ) + variant( + "dlaf", + default=False, + description="Enable DLA-Future eigensolver and Cholesky decomposition", + when="@2024.1: build_system=cmake +mpi", + ) + # sirius support was introduced in 7, but effectively usable starting from CP2K 9 + variant( + "sirius", + default=False, + description="Enable planewave electronic structure calculations via SIRIUS", + when="@9: +mpi", + ) + variant("cosma", default=False, description="Use COSMA for p?gemm", when="@8: +mpi") + variant( + "libvori", + default=False, + description="Enable support for Voronoi integration and BQB compression", + when="@8:", + ) + variant("spglib", default=False, description="Enable support for spglib") + variant( + "spla", + default=False, + description="Use SPLA off-loading functionality. Only relevant when CUDA or ROCM" + " are enabled", + ) + variant("pytorch", default=False, description="Enable libtorch support") + variant("quip", default=False, description="Enable quip support") + variant("mpi_f08", default=False, description="Use MPI F08 module") + + variant( + "enable_regtests", + default=False, + description="Configure cp2k to run the regtests afterwards." + " It build cp2k normally but put the executables in exe/cmake-build-* instead of the" + " conventional location. This option is only relevant when regtests need to be run.", + ) + + with when("+cuda"): + variant( + "cuda_arch_35_k20x", + default=False, + description=( + "CP2K (resp. DBCSR) has specific parameter sets for" + " different GPU models. Enable this when building" + " with cuda_arch=35 for a K20x instead of a K40" + ), + ) + variant( + "cuda_fft", default=False, description="Use CUDA also for FFTs in the PW part of CP2K" + ) + variant( + "cuda_blas", + default=False, + when="@:7", # req in CP2K v8+ + description="Use CUBLAS for general matrix operations in DBCSR", + ) + + HFX_LMAX_RANGE = range(4, 8) + + variant( + "lmax", + description="Maximum supported angular momentum (HFX and others)", + default="5", + values=[str(x) for x in HFX_LMAX_RANGE], + multi=False, + ) + + depends_on("python@3", type="build") + + depends_on("blas") + depends_on("lapack") + depends_on("fftw-api@3") + + # Force openmp propagation on some providers of blas / fftw-api + with when("+openmp"): + depends_on("fftw+openmp", when="^[virtuals=fftw-api] fftw") + depends_on("amdfftw+openmp", when="^[virtuals=fftw-api] amdfftw") + depends_on("cray-fftw+openmp", when="^[virtuals=fftw-api] cray-fftw") + depends_on("armpl-gcc threads=openmp", when="^[virtuals=blas] armpl-gcc") + depends_on("openblas threads=openmp", when="^[virtuals=blas] openblas") + # The Cray compiler wrappers will automatically add libsci_mp with + # -fopenmp. Since CP2K unconditionally links blas/lapack/scalapack + # we have to be consistent. + depends_on("cray-libsci+openmp", when="^[virtuals=blas] cray-libsci") + + with when("smm=libxsmm"): + depends_on("libxsmm~header-only") + # require libxsmm-1.11+ since 1.10 can leak file descriptors in Fortran + depends_on("libxsmm@1.11:") + depends_on("libxsmm@1.17:", when="@9.1:") + # build needs to be fixed for libxsmm@2 once it is released + depends_on("libxsmm@:1") + # use pkg-config (support added in libxsmm-1.10) to link to libxsmm + depends_on("pkgconfig", type="build") + + with when("+libint"): + depends_on("pkgconfig", type="build", when="@7.0:") + for lmax in HFX_LMAX_RANGE: + depends_on( + "libint@2.6.0:+fortran tune=cp2k-lmax-{0}".format(lmax), + when="@7.0: lmax={0}".format(lmax), + ) + + with when("+libxc"): + depends_on("pkgconfig", type="build", when="@7.0:") + depends_on("libxc@4.0.3:4", when="@7.0:8.1") + depends_on("libxc@5.1.3:5.1", when="@8.2:8") + depends_on("libxc@5.1.7:5.1", when="@9:2022.2") + depends_on("libxc@6.1:", when="@2023.1:") + depends_on("libxc@6.2:", when="@2023.2:") + + with when("+spla"): + depends_on("spla+cuda+fortran", when="+cuda") + depends_on("spla+rocm+fortran", when="+rocm") + + with when("+mpi"): + depends_on("mpi@2:") + depends_on("mpi@3:", when="@2023.1:") + depends_on("scalapack") + depends_on("mpich+fortran", when="^[virtuals=mpi] mpich") + conflicts("~mpi_f08", when="^mpich@4.1:") + + with when("+cosma"): + depends_on("cosma+scalapack") + depends_on("cosma@2.5.1:", when="@9:") + depends_on("cosma@2.6.3:", when="@2023.2:") + depends_on("cosma+cuda", when="+cuda") + depends_on("cosma+rocm", when="+rocm") + + with when("+elpa"): + depends_on("elpa+openmp", when="+openmp") + depends_on("elpa~openmp", when="~openmp") + depends_on("elpa+cuda", when="+cuda") + depends_on("elpa~cuda", when="~cuda") + depends_on("elpa+rocm", when="+rocm") + depends_on("elpa~rocm", when="~rocm") + depends_on("elpa@2021.05:", when="@8.3:") + depends_on("elpa@2021.11.001:", when="@9.1:") + depends_on("elpa@2023.05.001:", when="@2023.2:") + + with when("+dlaf"): + with when("@:2024.1"): + depends_on("dla-future@0.2.1: +scalapack") + depends_on("dla-future ~cuda", when="~cuda") + depends_on("dla-future ~rocm", when="~rocm") + depends_on("dla-future +cuda", when="+cuda") + depends_on("dla-future +rocm", when="+rocm") + + with when("@2024.2:"): + depends_on("dla-future-fortran@0.1.0:") + + # Use a direct dependency on dla-future so that constraints can be expressed + # WARN: In the concretizer output, dla-future will appear as dependency of CP2K + # instead of dla-future-fortran + depends_on("dla-future ~cuda", when="~cuda") + depends_on("dla-future ~rocm", when="~rocm") + depends_on("dla-future +cuda", when="+cuda") + depends_on("dla-future +rocm", when="+rocm") + + conflicts( + "+plumed", + when="@:2024.1 build_system=cmake", + msg="PLUMED support is broken in cp2k@:2024.1 with CMake", + ) + with when("+plumed"): + depends_on("plumed+shared") + depends_on("plumed+mpi", when="+mpi") + depends_on("plumed~mpi", when="~mpi") + + # while we link statically against PEXSI, its own deps may be linked in + # dynamically, therefore can't set this as pure build-type dependency. + depends_on("pexsi+fortran@0.10.0:", when="+pexsi") + + # only OpenMP should be consistently used, all other common things + # like ELPA, SCALAPACK are independent and Spack will ensure that + # a consistent/compatible combination is pulled into the dependency graph. + with when("+sirius"): + depends_on("sirius+fortran+shared") + depends_on("sirius+cuda", when="+cuda") + depends_on("sirius+rocm", when="+rocm") + depends_on("sirius+openmp", when="+openmp") + depends_on("sirius~openmp", when="~openmp") + depends_on("sirius@7.3:", when="@9.1") + depends_on("sirius@7.4:7.5", when="@2023.2") + depends_on("sirius@7.5:", when="@2024.1:") + depends_on("sirius@7.6: +pugixml", when="@2024.2:") + with when("+libvori"): + depends_on("libvori@201219:", when="@8.1") + depends_on("libvori@210412:", when="@8.2:") + depends_on("libvori@220621:", when="@2023.1:") + + # the bundled libcusmm uses numpy in the parameter prediction (v7+) + # which is written using Python 3 + depends_on("py-numpy", when="@7:+cuda") + depends_on("python@3.6:", when="@7:+cuda") + depends_on("py-fypp") + + depends_on("spglib", when="+spglib") + + with when("build_system=cmake"): + depends_on("cmake@3.22:", type="build") + + # DBCSR as external dependency + depends_on("dbcsr@2.6: ~examples") + depends_on("dbcsr+openmp", when="+openmp") + depends_on("dbcsr+mpi", when="+mpi") + depends_on("dbcsr+cuda", when="+cuda") + depends_on("dbcsr+rocm", when="+rocm") + depends_on("dbcsr smm=libxsmm", when="smm=libxsmm") + depends_on("dbcsr smm=blas", when="smm=blas") + + with when("@2022: +rocm"): + depends_on("hipblas") + depends_on("hipfft") + + # CP2K needs compiler specific compilation flags, e.g. optflags + conflicts("%apple-clang") + conflicts("%clang") + conflicts("%nag") + conflicts( + "%aocc@:3.2", + msg="Please use AOCC 4.0+ that better support modern Fortran features CP2K requires", + ) + + conflicts("~openmp", when="@8:", msg="Building without OpenMP is not supported in CP2K 8+") + + # We only support specific cuda_archs for which we have parameter files + # for optimal kernels. Note that we don't override the cuda_archs property + # from the parent class, since the parent class defines constraints for all + # versions. Instead just mark all unsupported cuda archs as conflicting. + + supported_cuda_arch_list = ("35", "37", "60", "70", "80", "90") + supported_rocm_arch_list = ("gfx906", "gfx908", "gfx90a", "gfx90a:xnack-", "gfx90a:xnack+") + cuda_msg = "cp2k only supports cuda_arch {0}".format(supported_cuda_arch_list) + rocm_msg = "cp2k only supports amdgpu_target {0}".format(supported_rocm_arch_list) + + conflicts("+cuda", when="cuda_arch=none") + + # ROCm already emits an error if +rocm amdgpu_target=none is given + + with when("+cuda"): + for arch in CudaPackage.cuda_arch_values: + if arch not in supported_cuda_arch_list: + conflicts("+cuda", when="cuda_arch={0}".format(arch), msg=cuda_msg) + + with when("+rocm"): + for arch in ROCmPackage.amdgpu_targets: + if arch not in supported_rocm_arch_list: + conflicts("+rocm", when="amdgpu_target={0}".format(arch), msg=rocm_msg) + + # Fix 2- and 3-center integral calls to libint + patch( + "https://github.com/cp2k/cp2k/commit/5eaf864ed2bd21fb1b05a9173bb77a815ad4deda.patch?full_index=1", + sha256="3617abb877812c4b933f601438c70f95e21c6161bea177277b1d4125fd1c0bf9", + when="@8.2", + ) + + # Patch for compilers with stricter C99 checks + patch("posix_c_source.patch", when="@7.1%aocc@4.0:") + patch("posix_c_source.patch", when="@7.1%gcc@13:") + + # Fix missing variable in OpenMP private clause + patch( + "https://github.com/cp2k/cp2k/commit/be86bd7f6cd6af7d68f8957dcdb67e7c3d586741.patch?full_index=1", + sha256="1bb5a8e80603684a743e7821d24d41b31b60ccbb7d4257df1d2da53a3630e5bf", + when="@2022.1:2022.2", + ) + + # Avoid using NULL() as subroutine argument as doing so breaks some versions of AOCC compiler + # These patches backport 2023.x fixes to previous versions + patch("backport_avoid_null_2022.x.patch", when="@2022.1:2022.2 %aocc@:4.0") + patch("backport_avoid_null_9.1.patch", when="@9.1 %aocc@:4.0") + patch("cmake-fixes-2023.2.patch", when="@2023.2 build_system=cmake") + + # Allow compilation with build_type=RelWithDebInfo and build_type=MinSizeRel + # after NDEBUG support was dropped in https://github.com/cp2k/cp2k/pull/3172 + # The patch applies https://github.com/cp2k/cp2k/pull/3251 to version 2024.1 + patch("cmake-relwithdebinfo-2024.1.patch", when="@2024.1 build_system=cmake") + + # Patch for an undefined constant due to incompatible changes in ELPA + @when("@9.1:2022.2 +elpa") + def patch(self): + if self.spec["elpa"].satisfies("@2022.05.001:"): + filter_file( + r"ELPA_2STAGE_REAL_INTEL_GPU", + "ELPA_2STAGE_REAL_INTEL_GPU_SYCL", + "src/fm/cp_fm_elpa.F", + ) + + def url_for_version(self, version): + url = "https://github.com/cp2k/cp2k/releases/download/v{0}/cp2k-{0}.tar.bz2" + return url.format(version) + + +class MakefileBuilder(makefile.MakefileBuilder): + def edit(self, pkg, spec, prefix): + pkgconf = which("pkg-config") + + fftw = spec["fftw-api:openmp" if "+openmp" in spec else "fftw-api"] + fftw_header_dir = fftw.headers.directories[0] + + # some providers (mainly Intel) keep the fftw headers in a subdirectory, find it + for incdir in [join_path(f, "fftw") for f in fftw.headers.directories]: + if os.path.exists(incdir): + fftw_header_dir = incdir + break + + optimization_flags = { + "gcc": ["-O2", "-funroll-loops", "-ftree-vectorize"], + "intel": ["-O2", "-pc64", "-unroll"], + "pgi": ["-fast"], + "nvhpc": ["-fast"], + "cce": ["-O2"], + "xl": ["-O3"], + "aocc": ["-O2"], + } + + dflags = ["-DNDEBUG"] if spec.satisfies("@:2023.2") else [] + if fftw.name in ("intel-mkl", "intel-parallel-studio", "intel-oneapi-mkl"): + cppflags = ["-D__FFTW3_MKL", "-I{0}".format(fftw_header_dir)] + else: + cppflags = ["-D__FFTW3", "-I{0}".format(fftw_header_dir)] + + # CP2K requires MPI 3 starting at version 2023.1 + # and __MPI_VERSION is not supported anymore. + if spec.satisfies("@:2022.2"): + if spec.satisfies("^mpi@3:"): + cppflags.append("-D__MPI_VERSION=3") + elif spec.satisfies("^mpi@2:"): + cppflags.append("-D__MPI_VERSION=2") + + cflags = optimization_flags[spec.compiler.name][:] + cxxflags = optimization_flags[spec.compiler.name][:] + fcflags = optimization_flags[spec.compiler.name][:] + nvflags = ["-O3"] + ldflags = [] + libs = [] + + # CP2K Makefile doesn't set C standard + if spec.satisfies("@2023.2:"): + # Use of DBL_DECIMAL_DIG + cflags.append(pkg.compiler.c11_flag) + else: + # C99-style for-loops with inline definition of iterating variable. + cflags.append(pkg.compiler.c99_flag) + + if spec.satisfies("%intel"): + cflags.append("-fp-model precise") + cxxflags.append("-fp-model precise") + fcflags += ["-fp-model precise", "-heap-arrays 64", "-g", "-traceback"] + elif spec.satisfies("%gcc"): + fcflags += [ + "-ffree-form", + "-ffree-line-length-none", + "-ggdb", # make sure we get proper Fortran backtraces + ] + elif spec.satisfies("%aocc"): + fcflags += ["-ffree-form", "-Mbackslash"] + elif spec.satisfies("%pgi") or spec.satisfies("%nvhpc"): + fcflags += ["-Mfreeform", "-Mextend"] + elif spec.satisfies("%cce"): + fcflags += ["-emf", "-ffree", "-hflex_mp=strict"] + elif spec.satisfies("%xl"): + fcflags += ["-qpreprocess", "-qstrict", "-q64"] + ldflags += ["-Wl,--allow-multiple-definition"] + + if "%gcc@10: +mpi" in spec and spec["mpi"].name in ["mpich", "cray-mpich"]: + fcflags += [ + "-fallow-argument-mismatch" + ] # https://github.com/pmodels/mpich/issues/4300 + if spec.satisfies("@7.1%gcc@13:"): + fcflags.append("-fallow-argument-mismatch") + + if spec.satisfies("+openmp"): + cflags.append(pkg.compiler.openmp_flag) + cxxflags.append(pkg.compiler.openmp_flag) + fcflags.append(pkg.compiler.openmp_flag) + ldflags.append(pkg.compiler.openmp_flag) + nvflags.append('-Xcompiler="{0}"'.format(pkg.compiler.openmp_flag)) + elif spec.satisfies("%cce"): # Cray enables OpenMP by default + cflags += ["-hnoomp"] + cxxflags += ["-hnoomp"] + fcflags += ["-hnoomp"] + ldflags += ["-hnoomp"] + + if spec.satisfies("@7:"): # recent versions of CP2K use C++14 CUDA code + cxxflags.append(pkg.compiler.cxx14_flag) + nvflags.append(pkg.compiler.cxx14_flag) + + ldflags.append(fftw.libs.search_flags) + + if spec.satisfies("^superlu-dist@4.3"): + ldflags.insert(0, "-Wl,--allow-multiple-definition") + + if spec.satisfies("+libint"): + cppflags += ["-D__LIBINT"] + + if spec.satisfies("@:6.9"): + cppflags += ["-D__LIBINT_MAX_AM=6", "-D__LIBDERIV_MAX_AM1=5"] + + # libint-1.x.y has to be linked statically to work around + # inconsistencies in its Fortran interface definition + # (short-int vs int) which otherwise causes segfaults at + # runtime due to wrong offsets into the shared library + # symbols. + libs.extend( + [ + join_path(spec["libint"].libs.directories[0], "libderiv.a"), + join_path(spec["libint"].libs.directories[0], "libint.a"), + ] + ) + else: + fcflags += pkgconf("--cflags", "libint2", output=str).split() + libs += pkgconf("--libs", "libint2", output=str).split() + + if spec.satisfies("+libxc"): + cppflags += ["-D__LIBXC"] + + if spec.satisfies("@:6.9"): + libxc = spec["libxc:fortran,static"] + cppflags += [libxc.headers.cpp_flags] + ldflags.append(libxc.libs.search_flags) + libs.append(str(libxc.libs)) + else: + fcflags += pkgconf("--cflags", "libxcf03", output=str).split() + # some Fortran functions seem to be direct wrappers of the + # C functions such that we get a direct dependency on them, + # requiring `-lxc` to be present in addition to `-lxcf03` + libs += pkgconf("--libs", "libxcf03", "libxc", output=str).split() + + if spec.satisfies("+pexsi"): + cppflags.append("-D__LIBPEXSI") + fcflags.append("-I" + join_path(spec["pexsi"].prefix, "fortran")) + libs.extend( + [ + join_path(spec["pexsi"].libs.directories[0], "libpexsi.a"), + join_path(spec["superlu-dist"].libs.directories[0], "libsuperlu_dist.a"), + join_path( + spec["parmetis"].libs.directories[0], "libparmetis.{0}".format(dso_suffix) + ), + join_path( + spec["metis"].libs.directories[0], "libmetis.{0}".format(dso_suffix) + ), + ] + ) + + if spec.satisfies("+elpa"): + elpa = spec["elpa"] + elpa_suffix = "_openmp" if "+openmp" in elpa else "" + elpa_incdir = elpa.headers.directories[0] + + fcflags += ["-I{0}".format(join_path(elpa_incdir, "modules"))] + + # Currently AOCC support only static libraries of ELPA + if spec.satisfies("%aocc"): + libs.append( + join_path( + elpa.prefix.lib, ("libelpa{elpa_suffix}.a".format(elpa_suffix=elpa_suffix)) + ) + ) + else: + libs.append( + join_path( + elpa.libs.directories[0], + ( + "libelpa{elpa_suffix}.{dso_suffix}".format( + elpa_suffix=elpa_suffix, dso_suffix=dso_suffix + ) + ), + ) + ) + + if spec.satisfies("@:4"): + if elpa.satisfies("@:2014.5"): + cppflags.append("-D__ELPA") + elif elpa.satisfies("@2014.6:2015.10"): + cppflags.append("-D__ELPA2") + else: + cppflags.append("-D__ELPA3") + else: + cppflags.append( + "-D__ELPA={0}{1:02d}".format(elpa.version[0], int(elpa.version[1])) + ) + fcflags += ["-I{0}".format(join_path(elpa_incdir, "elpa"))] + + if "+cuda" in spec and "+cuda" in elpa: + cppflags += ["-D__ELPA_NVIDIA_GPU"] + + if spec.satisfies("+sirius"): + sirius = spec["sirius"] + cppflags.append("-D__SIRIUS") + fcflags += ["-I{0}".format(sirius.prefix.include.sirius)] + libs += list(sirius.libs) + + if spec.satisfies("+plumed"): + dflags.extend(["-D__PLUMED2"]) + cppflags.extend(["-D__PLUMED2"]) + libs.extend([join_path(spec["plumed"].prefix.lib, "libplumed.{0}".format(dso_suffix))]) + + if spec.satisfies("+libvori"): + cppflags += ["-D__LIBVORI"] + libvori = spec["libvori"].libs + ldflags += [libvori.search_flags] + libs += libvori + libs += ["-lstdc++"] + + if spec.satisfies("+spglib"): + cppflags += ["-D__SPGLIB"] + spglib = spec["spglib"].libs + ldflags += [spglib.search_flags] + libs += spglib + + cc = spack_cc if "~mpi" in spec else spec["mpi"].mpicc + cxx = spack_cxx if "~mpi" in spec else spec["mpi"].mpicxx + fc = spack_fc if "~mpi" in spec else spec["mpi"].mpifc + + # Intel + if spec.satisfies("%intel"): + cppflags.extend(["-D__INTEL", "-D__HAS_ISO_C_BINDING", "-D__USE_CP2K_TRACE"]) + fcflags.extend(["-diag-disable 8290,8291,10010,10212,11060", "-free", "-fpp"]) + + # FFTW, LAPACK, BLAS + lapack = spec["lapack"].libs + blas = spec["blas"].libs + ldflags.append((lapack + blas).search_flags) + libs.extend([str(x) for x in (fftw.libs, lapack, blas)]) + + if spec.satisfies("platform=darwin"): + cppflags.extend(["-D__NO_STATM_ACCESS"]) + + if spec["blas"].name in ("intel-mkl", "intel-parallel-studio", "intel-oneapi-mkl"): + cppflags += ["-D__MKL"] + elif spec["blas"].name == "accelerate": + cppflags += ["-D__ACCELERATE"] + + if spec.satisfies("+cosma"): + # add before ScaLAPACK to override the p?gemm symbols + cosma = spec["cosma"].libs + ldflags.append(cosma.search_flags) + libs.extend(cosma) + + # MPI + if spec.satisfies("+mpi"): + cppflags.extend(["-D__parallel", "-D__SCALAPACK"]) + + if spec["mpi"].name == "intel-oneapi-mpi": + mpi = [join_path(spec["intel-oneapi-mpi"].libs.directories[0], "libmpi.so")] + else: + mpi = spec["mpi:cxx"].libs + + # while intel-mkl has a mpi variant and adds the scalapack + # libs to its libs, intel-oneapi-mkl does not. + if spec["scalapack"].name == "intel-oneapi-mkl": + mpi_impl = "openmpi" if spec["mpi"].name in ["openmpi", "hpcx-mpi"] else "intelmpi" + scalapack = [ + join_path( + spec["intel-oneapi-mkl"].libs.directories[0], "libmkl_scalapack_lp64.so" + ), + join_path( + spec["intel-oneapi-mkl"].libs.directories[0], + "libmkl_blacs_{0}_lp64.so".format(mpi_impl), + ), + ] + else: + scalapack = spec["scalapack"].libs + ldflags.append(scalapack.search_flags) + + libs.extend(scalapack) + libs.extend(mpi) + libs.extend(pkg.compiler.stdcxx_libs) + + if spec.satisfies("+mpi_f08"): + cppflags.append("-D__MPI_F08") + + if spec.satisfies("^wannier90"): + cppflags.append("-D__WANNIER90") + wannier = join_path(spec["wannier90"].libs.directories[0], "libwannier.a") + libs.append(wannier) + + gpuver = "" + if spec.satisfies("+cuda"): + libs += [ + "-L{}".format(spec["cuda"].libs.directories[0]), + "-L{}/stubs".format(spec["cuda"].libs.directories[0]), + "-lcuda", + "-lcudart", + "-lnvrtc", + "-lstdc++", + ] + + if spec.satisfies("@9:"): + if spec.satisfies("@2022:"): + cppflags += ["-D__OFFLOAD_CUDA"] + + acc_compiler_var = "OFFLOAD_CC" + acc_flags_var = "OFFLOAD_FLAGS" + cppflags += ["-D__DBCSR_ACC", "-D__GRID_CUDA", "-DOFFLOAD_TARGET=cuda"] + libs += ["-lcublas"] + + if spec.satisfies("+cuda_fft"): + if spec.satisfies("@:9"): + cppflags += ["-D__PW_CUDA"] + + libs += ["-lcufft"] + else: + if spec.satisfies("@2022:"): + cppflags += ["-D__NO_OFFLOAD_PW"] + else: + acc_compiler_var = "NVCC" + acc_flags_var = "NVFLAGS" + cppflags += ["-D__ACC"] + if spec.satisfies("+cuda_blas"): + cppflags += ["-D__DBCSR_ACC=2"] + libs += ["-lcublas"] + else: + cppflags += ["-D__DBCSR_ACC"] + + if spec.satisfies("+cuda_fft"): + cppflags += ["-D__PW_CUDA"] + libs += ["-lcufft", "-lcublas"] + + cuda_arch = spec.variants["cuda_arch"].value[0] + gpuver = GPU_MAP[cuda_arch] + if cuda_arch == "35" and spec.satisfies("+cuda_arch_35_k20x"): + gpuver = "K20X" + + if spec.satisfies("@2022: +rocm"): + libs += [ + "-L{}".format(spec["rocm"].libs.directories[0]), + "-L{}/stubs".format(spec["rocm"].libs.directories[0]), + "-lhipblas", + "-lhipfft", + "-lstdc++", + ] + + cppflags += ["-D__OFFLOAD_HIP"] + acc_compiler_var = "hipcc" + acc_flags_var = "NVFLAGS" + cppflags += ["-D__ACC"] + cppflags += ["-D__DBCSR_ACC"] + gpuver = GPU_MAP[spec.variants["amdgpu_target"].value[0]] + + if spec.satisfies("smm=libsmm"): + lib_dir = join_path("lib", self.makefile_architecture, self.makefile_version) + mkdirp(lib_dir) + try: + copy(env["LIBSMM_PATH"], join_path(lib_dir, "libsmm.a")) + except KeyError: + raise KeyError( + "Point environment variable LIBSMM_PATH to " + "the absolute path of the libsmm.a file" + ) + except IOError: + raise IOError( + "The file LIBSMM_PATH pointed to does not " + "exist. Note that it must be absolute path." + ) + cppflags.extend(["-D__HAS_smm_dnn", "-D__HAS_smm_vec"]) + libs.append("-lsmm") + + elif spec.satisfies("smm=libxsmm"): + cppflags += ["-D__LIBXSMM"] + cppflags += pkgconf("--cflags-only-other", "libxsmmf", output=str).split() + fcflags += pkgconf("--cflags-only-I", "libxsmmf", output=str).split() + libs += pkgconf("--libs", "libxsmmf", output=str).split() + + dflags.extend(cppflags) + cflags.extend(cppflags) + cxxflags.extend(cppflags) + fcflags.extend(cppflags) + nvflags.extend(cppflags) + + with open(self.makefile, "w") as mkf: + if spec.satisfies("+plumed"): + mkf.write( + "# include Plumed.inc as recommended by" + "PLUMED to include libraries and flags" + ) + mkf.write("include {0}\n".format(spec["plumed"].package.plumed_inc)) + + mkf.write("\n# COMPILER, LINKER, TOOLS\n\n") + mkf.write( + "FC = {0}\n" "CC = {1}\n" "CXX = {2}\n" "LD = {3}\n".format(fc, cc, cxx, fc) + ) + + if spec.satisfies("%intel"): + intel_bin_dir = ancestor(pkg.compiler.cc) + # CPP is a commented command in Intel arch of CP2K + # This is the hack through which cp2k developers avoid doing : + # + # ${CPP} .F > .f90 + # + # and use `-fpp` instead + mkf.write("CPP = # {0} -P\n".format(spack_cc)) + mkf.write("AR = {0}/xiar -qs\n".format(intel_bin_dir)) + else: + mkf.write("CPP = # {0} -E\n".format(spack_cc)) + mkf.write("AR = ar -qs\n") # r = qs is a GNU extension + + if spec.satisfies("+cuda"): + mkf.write( + "{0} = {1}\n".format( + acc_compiler_var, join_path(spec["cuda"].prefix, "bin", "nvcc") + ) + ) + + # Write compiler flags to file + def fflags(var, lst): + return "{0} = {1}\n\n".format(var, " \\\n\t".join(lst)) + + mkf.write("\n# FLAGS & LIBRARIES\n") + mkf.write(fflags("DFLAGS", dflags)) + mkf.write(fflags("CPPFLAGS", cppflags)) + mkf.write(fflags("CFLAGS", cflags)) + mkf.write(fflags("CXXFLAGS", cxxflags)) + if spec.satisfies("+cuda"): + mkf.write(fflags(acc_flags_var, nvflags)) + mkf.write(fflags("FCFLAGS", fcflags)) + mkf.write(fflags("LDFLAGS", ldflags)) + mkf.write(fflags("LIBS", libs)) + + if spec.satisfies("%intel"): + mkf.write(fflags("LDFLAGS_C", ldflags + ["-nofor-main"])) + + mkf.write("# CP2K-specific flags\n\n") + mkf.write("GPUVER = {0}\n".format(gpuver)) + mkf.write("DATA_DIR = {0}\n".format(prefix.share.data)) + + def build(self, pkg, spec, prefix): + if "+cuda" in spec and len(spec.variants["cuda_arch"].value) > 1: + raise InstallError("cp2k supports only one cuda_arch at a time") + + # Apparently the Makefile bases its paths on PWD + # so we need to set PWD = self.build_directory + with spack.util.environment.set_env(PWD=self.build_directory): + super().build(pkg, spec, prefix) + + with working_dir(self.build_directory): + make("libcp2k", *self.build_targets) + + def install(self, pkg, spec, prefix): + exe_dir = join_path("exe", self.makefile_architecture) + lib_dir = join_path("lib", self.makefile_architecture, self.makefile_version) + + install_tree(exe_dir, self.prefix.bin) + install_tree("data", self.prefix.share.data) + install_tree(lib_dir, self.prefix.lib) + + mkdirp(self.prefix.include) + install("src/start/libcp2k.h", join_path(self.prefix.include, "libcp2k.h")) + + @property + def build_directory(self): + build_dir = self.pkg.stage.source_path + + if self.spec.satisfies("@:6"): + # prior to version 7.1 was the Makefile located in makefiles/ + build_dir = join_path(build_dir, "makefiles") + + return build_dir + + @property + def build_targets(self): + return [ + "ARCH={0}".format(self.makefile_architecture), + "VERSION={0}".format(self.makefile_version), + ] + + @property + def makefile(self): + makefile_basename = ".".join([self.makefile_architecture, self.makefile_version]) + return join_path("arch", makefile_basename) + + @property + def makefile_architecture(self): + return "{0.architecture}-{0.compiler.name}".format(self.spec) + + @property + def makefile_version(self): + return "{prefix}{suffix}".format( + prefix="p" if "+mpi" in self.spec else "s", + suffix="smp" if "+openmp" in self.spec else "opt", + ) + + @property + def archive_files(self): + return [join_path(self.pkg.stage.source_path, self.makefile)] + + def check(self): + data_dir = join_path(self.pkg.stage.source_path, "data") + + # CP2K < 7 still uses $PWD to detect the current working dir + # and Makefile is in a subdir, account for both facts here: + with spack.util.environment.set_env(CP2K_DATA_DIR=data_dir, PWD=self.build_directory): + with working_dir(self.build_directory): + make("test", *self.build_targets) + + @run_after("install", when="@9.1:") + def fix_package_config(self): + """ + Default build procedure generates libcp2k.pc with invalid paths, + because they are collected from temporary directory. + + Ignoring invalid paths, most library-related switches are correct + except for fftw and openblas. + + This procedure is appending two missing switches (tested with GROMACS 2022.2 + CP2K). + + In case such approach causes issues in the future, it might be necessary + to generate and override entire libcp2k.pc. + """ + pkgconfig_file = join_path(self.prefix.lib.pkgconfig, "libcp2k.pc") + filter_file(r"(^includedir=).*", r"\1{0}".format(self.prefix.include), pkgconfig_file) + filter_file(r"(^libdir=).*", r"\1{0}".format(self.prefix.lib), pkgconfig_file) + + with open(pkgconfig_file, "r+") as handle: + content = handle.read().rstrip() + + content += " " + self.spec["blas"].libs.ld_flags + content += " " + self.spec["lapack"].libs.ld_flags + content += " " + self.spec["fftw-api"].libs.ld_flags + + fftw = self.spec["fftw-api"] + if fftw.name in ["fftw", "amdfftw"] and fftw.satisfies("+openmp"): + content += " -lfftw3_omp" + + content += "\n" + + handle.seek(0) + handle.write(content) + + +class CMakeBuilder(cmake.CMakeBuilder): + def cmake_args(self): + spec = self.spec + args = [] + + if spec.satisfies("+cuda"): + if (len(spec.variants["cuda_arch"].value) > 1) or spec.satisfies("cuda_arch=none"): + raise InstallError("CP2K supports only one cuda_arch at a time.") + else: + gpu_ver = GPU_MAP[spec.variants["cuda_arch"].value[0]] + args += [ + self.define("CP2K_USE_ACCEL", "CUDA"), + self.define("CP2K_WITH_GPU", gpu_ver), + ] + + if spec.satisfies("+rocm"): + if len(spec.variants["amdgpu_target"].value) > 1: + raise InstallError("CP2K supports only one amdgpu_target at a time.") + else: + gpu_ver = GPU_MAP[spec.variants["amdgpu_target"].value[0]] + args += [ + self.define("CP2K_USE_ACCEL", "HIP"), + self.define("CP2K_WITH_GPU", gpu_ver), + ] + + args += [ + self.define_from_variant("CP2K_ENABLE_REGTESTS", "enable_regtests"), + self.define_from_variant("CP2K_USE_ELPA", "elpa"), + self.define_from_variant("CP2K_USE_DLAF", "dlaf"), + self.define_from_variant("CP2K_USE_LIBINT2", "libint"), + self.define_from_variant("CP2K_USE_SIRIUS", "sirius"), + self.define_from_variant("CP2K_USE_SPLA", "spla"), + self.define_from_variant("CP2K_USE_COSMA", "cosma"), + self.define_from_variant("CP2K_USE_LIBXC", "libxc"), + self.define_from_variant("CP2K_USE_LIBTORCH", "pytorch"), + self.define_from_variant("CP2K_USE_METIS", "pexsi"), + self.define_from_variant("CP2K_USE_SUPERLU", "pexsi"), + self.define_from_variant("CP2K_USE_PLUMED", "plumed"), + self.define_from_variant("CP2K_USE_SPGLIB", "spglib"), + self.define_from_variant("CP2K_USE_VORI", "libvori"), + self.define_from_variant("CP2K_USE_SPLA", "spla"), + self.define_from_variant("CP2K_USE_QUIP", "quip"), + self.define_from_variant("CP2K_USE_MPI_F08", "mpi_f08"), + ] + + # we force the use elpa openmp threading support. might need to be revisited though + args += [ + self.define( + "CP2K_ENABLE_ELPA_OPENMP_SUPPORT", + ("+elpa +openmp" in spec) or ("^elpa +openmp" in spec), + ) + ] + + if "spla" in spec and (spec.satisfies("+cuda") or spec.satisfies("+rocm")): + args += ["-DCP2K_USE_SPLA_GEMM_OFFLOADING=ON"] + + args += ["-DCP2K_USE_FFTW3=ON"] + + if spec.satisfies("smm=libxsmm"): + args += ["-DCP2K_USE_LIBXSMM=ON"] + else: + args += ["-DCP2K_USE_LIBXSMM=OFF"] + + lapack = spec["lapack"] + blas = spec["blas"] + + if blas.name in ["intel-mkl", "intel-parallel-studio", "intel-oneapi-mkl"]: + args += ["-DCP2K_BLAS_VENDOR=MKL"] + if sys.platform == "darwin": + args += [ + self.define("CP2K_BLAS_VENDOR", "CUSTOM"), + self.define("CP2K_SCALAPACK_VENDOR", "GENERIC"), + self.define( + "CP2K_SCALAPACK_LINK_LIBRARIES", spec["scalapack"].libs.joined(";") + ), + ] + else: + args += ["-DCP2K_SCALAPACK_VENDOR=MKL"] + else: + args.extend( + [ + self.define("CP2K_LAPACK_FOUND", True), + self.define("CP2K_LAPACK_LINK_LIBRARIES", lapack.libs.joined(";")), + self.define("CP2K_BLAS_FOUND", True), + self.define("CP2K_BLAS_LINK_LIBRARIES", blas.libs.joined(";")), + self.define("CP2K_SCALAPACK_FOUND", True), + self.define("CP2K_SCALAPACK_INCLUDE_DIRS", spec["scalapack"].prefix.include), + self.define("CP2K_BLAS_VENDOR", "CUSTOM"), + self.define("CP2K_SCALAPACK_VENDOR", "GENERIC"), + self.define( + "CP2K_SCALAPACK_LINK_LIBRARIES", spec["scalapack"].libs.joined(";") + ), + ] + ) + + return args diff --git a/recipes/cp2k/2024.3/gh200/repo/packages/cp2k/posix_c_source.patch b/recipes/cp2k/2024.3/gh200/repo/packages/cp2k/posix_c_source.patch new file mode 100644 index 00000000..87a544a7 --- /dev/null +++ b/recipes/cp2k/2024.3/gh200/repo/packages/cp2k/posix_c_source.patch @@ -0,0 +1,12 @@ +--- a/src/sockets.c 2019-12-24 01:41:57.000000000 +0530 ++++ b/src/sockets.c 2023-05-15 18:35:33.941236292 +0530 +@@ -35,6 +35,7 @@ + */ + #ifndef __NO_IPI_DRIVER + ++#define _POSIX_C_SOURCE 200112L + #include + #include + #include + + diff --git a/recipes/cp2k/2024.3/gh200/repo/packages/dbcsr/package.py b/recipes/cp2k/2024.3/gh200/repo/packages/dbcsr/package.py new file mode 100644 index 00000000..112c4293 --- /dev/null +++ b/recipes/cp2k/2024.3/gh200/repo/packages/dbcsr/package.py @@ -0,0 +1,184 @@ +# Copyright 2013-2024 Lawrence Livermore National Security, LLC and other +# Spack Project Developers. See the top-level COPYRIGHT file for details. +# +# SPDX-License-Identifier: (Apache-2.0 OR MIT) + +from spack.package import * + + +class Dbcsr(CMakePackage, CudaPackage, ROCmPackage): + """Distributed Block Compressed Sparse Row matrix library.""" + + homepage = "https://github.com/cp2k/dbcsr" + git = "https://github.com/cp2k/dbcsr.git" + url = "https://github.com/cp2k/dbcsr/releases/download/v2.2.0/dbcsr-2.2.0.tar.gz" + list_url = "https://github.com/cp2k/dbcsr/releases" + + maintainers("dev-zero", "mtaillefumier") + + license("GPL-2.0-or-later") + + version("develop", branch="develop") + version("2.7.0", sha256="25c367b49fb108c5230bcfb127f05fc16deff2bb467f437023dfa6045aff66f6") + version("2.6.0", sha256="c67b02ff9abc7c1f529af446a9f01f3ef9e5b0574f220259128da8d5ca7e9dc6") + version("2.5.0", sha256="91fda9b2502e5d0a2a6cdd5a73ef096253cc7e75bd01ba5189a4726ad86aef08") + version("2.4.1", sha256="b3d5ae62ca582b72707a2c932e8074a4f2f61d61085d97bd374213c70b8dbdcf") + version("2.4.0", sha256="cf2b774328c9a30677501f49b79955841bd08915a7ca53c8533bfdf14a8f9bd4") + version("2.3.0", sha256="f750de586cffa66852b646f7f85eb831eeb64fa2d25ce50ed10e1df016dd3364") + version("2.2.0", sha256="245b0382ddc7b80f85af8288f75bd03d56ec51cdfb6968acb4931529b35173ec") + version("2.1.0", sha256="9e58fd998f224632f356e479d18b5032570d00d87b86736b6a6ac2d03f8d4b3c") + version("2.0.1", sha256="61d5531b661e1dab043353a1d67939ddcde3893d3dc7b0ab3d05074d448b485c") + + variant("mpi", default=True, description="Compile with MPI") + variant("openmp", default=False, description="Build with OpenMP support") + variant("shared", default=True, description="Build shared library") + variant( + "smm", + default="libxsmm", + values=("libxsmm", "blas"), + description="Library for small matrix multiplications", + ) + variant( + "cuda_arch_35_k20x", + default=False, + description=( + "CP2K (resp. DBCSR) has specific parameter sets for" + " different GPU models. Enable this when building" + " with cuda_arch=35 for a K20x instead of a K40" + ), + ) + variant("examples", default=True, description="Build examples") + + variant("opencl", default=False, description="Enable OpenCL backend") + variant("mpi_f08", default=False, when="@2.6:", description="Use mpi F08 module") + + depends_on("blas") + depends_on("lapack") + depends_on("mpi", when="+mpi") + + with when("smm=libxsmm"): + depends_on("libxsmm~header-only") + depends_on("libxsmm@1.11:1") + + depends_on("cmake@3.10:", type="build") + depends_on("cmake@3.12:", type="build", when="@2.1:") + depends_on("cmake@3.17:", type="build", when="@2.2:") + depends_on("cmake@3.22:", type="build", when="@2.3:") + + depends_on("py-fypp", type="build") + depends_on("py-fypp@3.1:", type="build", when="@2.6:") + depends_on("pkgconfig", type="build") + depends_on("python@3.6:", type="build", when="+cuda") + + depends_on("hipblas", when="+rocm") + + depends_on("opencl", when="+opencl") + + # All examples require MPI + conflicts("+examples", when="~mpi", msg="Examples require MPI") + + # We only support specific gpu archs for which we have parameter files + # for optimal kernels. Note that we don't override the parent class arch + # properties, since the parent class defines constraints for different archs + # Instead just mark all unsupported cuda archs as conflicting. + dbcsr_cuda_archs = ("35", "37", "60", "70", "80", "90") + cuda_msg = "dbcsr only supports cuda_arch {0}".format(dbcsr_cuda_archs) + + for arch in CudaPackage.cuda_arch_values: + if arch not in dbcsr_cuda_archs: + conflicts("+cuda", when="cuda_arch={0}".format(arch), msg=cuda_msg) + + conflicts("+cuda", when="cuda_arch=none", msg=cuda_msg) + + dbcsr_amdgpu_targets = {"gfx906", "gfx910", "gfx90a", "gfx90a:xnack-", "gfx90a:xnack+"} + amd_msg = "DBCSR only supports amdgpu_target {0}".format(dbcsr_amdgpu_targets) + + for arch in ROCmPackage.amdgpu_targets: + if arch not in dbcsr_amdgpu_targets: + conflicts("+rocm", when="amdgpu_target={0}".format(arch), msg=amd_msg) + + accel_msg = "CUDA, ROCm and OpenCL support are mutually exlusive" + conflicts("+cuda", when="+rocm", msg=accel_msg) + conflicts("+cuda", when="+opencl", msg=accel_msg) + conflicts("+rocm", when="+opencl", msg=accel_msg) + + # Require openmp threading for OpenBLAS by making other options conflict + conflicts("^openblas threads=pthreads", when="+openmp") + conflicts("^openblas threads=none", when="+openmp") + + conflicts("smm=blas", when="+opencl") + + with when("+mpi"): + # When using mpich 4.1 or higher, mpi_f08 has to be used, otherwise: + # Error: Type mismatch in argument 'baseptr' at (1); passed TYPE(c_ptr) + # to INTEGER(8) + conflicts("^mpich@4.1:", when="@:2.5") + conflicts("~mpi_f08", when="^mpich@4.1:") + depends_on("mpich+fortran", when="^[virtuals=mpi] mpich") + + generator("ninja") + depends_on("ninja@1.10:", type="build") + + def cmake_args(self): + spec = self.spec + + if "+cuda" in spec and len(spec.variants["cuda_arch"].value) > 1: + raise InstallError("dbcsr supports only one cuda_arch at a time") + + if "+rocm" in spec and len(spec.variants["amdgpu_target"].value) > 1: + raise InstallError("DBCSR supports only one amdgpu_arch at a time") + + args = [ + "-DUSE_SMM=%s" % ("libxsmm" if "smm=libxsmm" in spec else "blas"), + self.define_from_variant("USE_MPI", "mpi"), + self.define_from_variant("USE_OPENMP", "openmp"), + # C API needs MPI + self.define_from_variant("WITH_C_API", "mpi"), + "-DBLAS_FOUND=true", + "-DBLAS_LIBRARIES=%s" % (spec["blas"].libs.joined(";")), + "-DLAPACK_FOUND=true", + "-DLAPACK_LIBRARIES=%s" % (spec["lapack"].libs.joined(";")), + self.define_from_variant("BUILD_SHARED_LIBS", "shared"), + self.define_from_variant("WITH_EXAMPLES", "examples"), + ] + + # Switch necessary as a result of a bug. + if "@2.1:2.2" in spec: + args += ["-DBUILD_TESTING=ON"] + + if self.spec.satisfies("+cuda"): + cuda_arch = self.spec.variants["cuda_arch"].value[0] + + gpu_map = {"35": "K40", "37": "K80", "60": "P100", "70": "V100", "80": "A100", "90": "H100"} + + gpuver = gpu_map[cuda_arch] + if cuda_arch == "35" and self.spec.satisfies("+cuda_arch_35_k20x"): + gpuver = "K20X" + + args += ["-DWITH_GPU=%s" % gpuver, "-DUSE_ACCEL=cuda"] + + if self.spec.satisfies("+rocm"): + amd_arch = self.spec.variants["amdgpu_target"].value[0] + gpuver = { + "gfx906": "Mi50", + "gfx908": "Mi100", + "gfx90a": "Mi250", + "gfx90a:xnack-": "Mi250", + "gfx90a:xnack+": "Mi250", + }[amd_arch] + + args += ["-DWITH_GPU={0}".format(gpuver), "-DUSE_ACCEL=hip"] + + if self.spec.satisfies("+opencl"): + args += ["-DUSE_ACCEL=opencl"] + + if self.spec.satisfies("+mpi_f08"): + args += ["-DUSE_MPI_F08=ON"] + + return args + + def check(self): + """Override CMakePackage's check() to enforce seralized test runs + since they are already parallelized""" + with working_dir(self.build_directory): + self._if_ninja_target_execute("test", parallel=False) diff --git a/recipes/cp2k/2024.3/gh200/repo/packages/dla-future-fortran/package.py b/recipes/cp2k/2024.3/gh200/repo/packages/dla-future-fortran/package.py new file mode 100644 index 00000000..ea6a50c7 --- /dev/null +++ b/recipes/cp2k/2024.3/gh200/repo/packages/dla-future-fortran/package.py @@ -0,0 +1,52 @@ +# Copyright 2013-2024 Lawrence Livermore National Security, LLC and other +# Spack Project Developers. See the top-level COPYRIGHT file for details. +# +# SPDX-License-Identifier: (Apache-2.0 OR MIT) + +# dlaf-no-license-check +from spack.package import * + + +class DlaFutureFortran(CMakePackage): + """ + Fortran interface to the DLA-Future library. + """ + + homepage = "https://github.com/eth-cscs/DLA-Future-Fortran" + url = "https://github.com/eth-cscs/DLA-Future-Fortran/archive/v0.0.0.tar.gz" + git = "https://github.com/eth-cscs/DLA-Future-Fortran.git" + + maintainers("RMeli", "rasolca", "aurianer") + + license("BSD-3-Clause") + + version("main", branch="main") + version("0.2.0", sha256="7fd3e1779c111b35f0d2701a024398b4f6e8dea4af523b6c8617d28c0b7ae61a") + version("0.1.0", sha256="9fd8a105cbb2f3e1daf8a49910f98fce68ca0b954773dba98a91464cf2e7c1da") + + depends_on("fortran", type="build") # generated + + variant("shared", default=True, description="Build shared libraries.") + variant("test", default=False, description="Build tests.") + + generator("ninja") + depends_on("cmake@3.22:", type="build") + + depends_on("dla-future@0.4.1:0.5 +scalapack", when="@0.1.0") + depends_on("dla-future@0.6.0: +scalapack", when="@0.2.0:") + depends_on("dla-future +shared", when="+shared") + + depends_on("mpi", when="+test") + depends_on("py-fypp", when="+test", type="build") + + def cmake_args(self): + args = [] + + args.append(self.define_from_variant("BUILD_SHARED_LIBS", "shared")) + + if self.spec.satisfies("+test"): + args.append(self.define("DLAF_FORTRAN_BUILD_TESTING", True)) + # Tests run with 6 MPI ranks + args.append(self.define("MPIEXEC_MAX_NUMPROCS", 6)) + + return args diff --git a/recipes/cp2k/2024.3/gh200/repo/packages/elpa/fujitsu.patch b/recipes/cp2k/2024.3/gh200/repo/packages/elpa/fujitsu.patch new file mode 100644 index 00000000..d3600cf6 --- /dev/null +++ b/recipes/cp2k/2024.3/gh200/repo/packages/elpa/fujitsu.patch @@ -0,0 +1,65 @@ +From 8bda2149e4398bb6e6b66e601151966c91f9ec78 Mon Sep 17 00:00:00 2001 +From: m-shunji +Date: Wed, 13 Sep 2023 17:58:26 +0900 +Subject: [PATCH] Fix compile error in disabling openmp + +--- + src/elpa_impl_math_template.F90 | 6 +++--- + test/Fortran/test_autotune.F90 | 4 ++-- + 2 files changed, 5 insertions(+), 5 deletions(-) + +diff --git a/src/elpa_impl_math_template.F90 b/src/elpa_impl_math_template.F90 +index f87a0ad..b41c0c3 100644 +--- a/src/elpa_impl_math_template.F90 ++++ b/src/elpa_impl_math_template.F90 +@@ -888,10 +888,10 @@ + #endif + #ifdef COMPLEXCASE + #ifdef DOUBLE_PRECISION_COMPLEX +- & !bind(C, name="elpa_solve_tridiagonal_dc") ++ bind(C, name="elpa_solve_tridiagonal_dc") + #endif + #ifdef SINGLE_PRECISION_COMPLEX +- & !bind(C, name="elpa_solve_tridiagonal_fc") ++ bind(C, name="elpa_solve_tridiagonal_fc") + #endif + #endif + +@@ -913,4 +913,4 @@ + &ELPA_IMPL_SUFFIX& + & (self, d, e, q, error) + end subroutine +- +\ No newline at end of file ++ +diff --git a/test/Fortran/test_autotune.F90 b/test/Fortran/test_autotune.F90 +index 4662564..5355ab3 100644 +--- a/test/Fortran/test_autotune.F90 ++++ b/test/Fortran/test_autotune.F90 +@@ -312,8 +312,8 @@ program test + status = check_correctness_analytic(na, nev, ev, z, nblk, myid, np_rows, np_cols, my_prow, my_pcol, & + .true., .true., print_times=.false.) + a(:,:) = as(:,:) +- call e%autotune_print_state(tune_state) +- call e%autotune_save_state(tune_state, "saved_state_"//trim(iter_string)//".txt") ++ call e%autotune_print_state(tune_state, error_elpa) ++ call e%autotune_save_state(tune_state, "saved_state_"//trim(iter_string)//".txt", error_elpa) + end do + + !! set and print the autotuned-settings +-- +1.8.3.1 +diff --git a/manual_cpp b/manual_cpp +index 6f74a79..dbdfc65 100755 +--- a/manual_cpp ++++ b/manual_cpp +@@ -46,7 +46,7 @@ elif len(files) == 0: + elif len(files) == 1: + file, = files + +-tmp_filename = "manually_preprocessed_" + file.replace("/", "_") ++tmp_filename = "manually_preprocessed_" + file.replace("/", "_").replace("-", "_") + + try: + output = args.index("-o") + diff --git a/recipes/cp2k/2024.3/gh200/repo/packages/elpa/package.py b/recipes/cp2k/2024.3/gh200/repo/packages/elpa/package.py new file mode 100644 index 00000000..eb5b8dd2 --- /dev/null +++ b/recipes/cp2k/2024.3/gh200/repo/packages/elpa/package.py @@ -0,0 +1,238 @@ +# Copyright 2013-2024 Lawrence Livermore National Security, LLC and other +# Spack Project Developers. See the top-level COPYRIGHT file for details. +# +# SPDX-License-Identifier: (Apache-2.0 OR MIT) + +import os + +from spack.package import * + +# +# Please note that you can open issues on the github page of ELPA: +# https://github.com/marekandreas/elpa/issues +# + + +class Elpa(AutotoolsPackage, CudaPackage, ROCmPackage): + """Eigenvalue solvers for Petaflop-Applications (ELPA)""" + + homepage = "https://elpa.mpcdf.mpg.de/" + url = "https://elpa.mpcdf.mpg.de/software/tarball-archive/Releases/2015.11.001/elpa-2015.11.001.tar.gz" + git = "https://gitlab.mpcdf.mpg.de/elpa/elpa.git" + + license("LGPL-3.0-only") + + version("master", branch="master") + + version( + "2024.03.001", sha256="41c6cbf56d2dac26443faaba8a77307d261bf511682a64b96e24def77c813622" + ) + version( + "2023.11.001-patched", + sha256="62ee109afc06539507f459c08b958dc4db65b757dbd77f927678c77f7687415e", + url="https://elpa.mpcdf.mpg.de/software/tarball-archive/Releases/2023.11.001/elpa-2023.11.001-patched.tar.gz", + ) + version( + "2023.05.001", sha256="ec64be5d6522810d601a3b8e6a31720e3c3eb4af33a434d8a64570d76e6462b6" + ) + version( + "2022.11.001", sha256="75db3ac146f9a6a1598e3418ddcab2be2f40a30ef9ec4c00a3b5d3808c99c430" + ) + version( + "2021.11.001", sha256="fb361da6c59946661b73e51538d419028f763d7cb9dacf9d8cd5c9cd3fb7802f" + ) + version( + "2021.05.002_bugfix", + sha256="deabc48de5b9e4b2f073d749d335c8f354a7ce4245b643a23b7951cd6c90224b", + ) + version( + "2021.05.001", sha256="a4f1a4e3964f2473a5f8177f2091a9da5c6b5ef9280b8272dfefcbc3aad44d41" + ) + +# depends_on("c", type="build") # generated +# depends_on("cxx", type="build") # generated +# depends_on("fortran", type="build") # generated + + variant("openmp", default=True, description="Activates OpenMP support") + variant("mpi", default=True, description="Activates MPI support") + + with when("@2021.11.001:"): + variant( + "autotune", default=False, description="Enables autotuning for matrix restribution" + ) + variant( + "gpu_streams", default=True, when="+cuda", description="Activates GPU streams support" + ) + + patch("fujitsu.patch", when="%fj") + + depends_on("autoconf@2.71:", type="build", when="@master") + depends_on("automake", type="build", when="@master") + + depends_on("blas") + depends_on("lapack") + depends_on("mpi", when="+mpi") + depends_on("scalapack", when="+mpi") + depends_on("rocblas", when="+rocm") + depends_on("libtool", type="build") + depends_on("python@3:", type="build") + depends_on("scalapack", when="+autotune") + + # Force openmp propagation on some providers of blas/lapack, as adviced by docs + # https://gitlab.mpcdf.mpg.de/elpa/elpa/-/blob/master/documentation/PERFORMANCE_TUNING.md?ref_type=heads#builds-with-openmp-enabled + with when("+openmp"): + requires("^openblas threads=openmp", when="^[virtuals=blas,lapack] openblas") + requires("^intel-mkl threads=openmp", when="^[virtuals=blas,lapack] intel-mkl") + requires( + "^intel-oneapi-mkl threads=openmp", when="^[virtuals=blas,lapack] intel-oneapi-mkl" + ) + requires( + "^intel-parallel-studio threads=openmp", + when="^[virtuals=blas,lapack] intel-parallel-studio", + ) + + # fails to build due to broken type-bound procedures in OMP parallel regions + conflicts( + "+openmp", + when="@2021.05.001: %gcc@:7", + msg="ELPA-2021.05.001+ requires GCC-8+ for OpenMP support", + ) + conflicts("+mpi", when="+rocm", msg="ROCm support and MPI are not yet compatible") + conflicts( + "+gpu_streams", + when="@:2023.11.001-patched +openmp", + msg="GPU streams currently not supported in combination with OpenMP", + ) + + def url_for_version(self, version): + return "https://elpa.mpcdf.mpg.de/software/tarball-archive/Releases/{0}/elpa-{0}.tar.gz".format( + str(version) + ) + + # override default implementation which returns static lib + @property + def libs(self): + libname = "libelpa_openmp" if "+openmp" in self.spec else "libelpa" + return find_libraries(libname, root=self.prefix, shared=True, recursive=True) + + @property + def headers(self): + suffix = "_openmp" if self.spec.satisfies("+openmp") else "" + + # upstream sometimes adds tarball suffixes not part of the internal version + elpa_version = str(self.spec.version) + for vsuffix in ("_bugfix", "-patched"): + if elpa_version.endswith(vsuffix): # implementation of py3.9 removesuffix + elpa_version = elpa_version[: -len(vsuffix)] + + incdir = os.path.join( + self.spec.prefix.include, + "elpa{suffix}-{version}".format(suffix=suffix, version=elpa_version), + ) + + hlist = find_all_headers(incdir) + hlist.directories = [incdir] + return hlist + + build_directory = "spack-build" + parallel = False + + def configure_args(self): + spec = self.spec + options = [] + + options += self.with_or_without("mpi") + + # New options use the "-kernels" suffix + kernels = "-kernels" if spec.satisfies("@2023.11:") else "" + + # TODO: --disable-sse-assembly, --enable-sparc64, --enable-neon-arch64 + # Don't include vsx; as of 2022.05 it fails (reported upstream). + # Altivec SSE intrinsics are used anyway. + simd_features = ["sse", "avx", "avx2", "avx512", "sve128", "sve256", "sve512"] + + for feature in simd_features: + msg = "--enable-{0}" if feature in spec.target else "--disable-{0}" + options.append(msg.format(feature + kernels)) + + if spec.target.family != "x86_64": + options.append("--disable-sse-assembly") + + if "%aocc" in spec or "%fj" in spec: + options.append("--disable-shared") + options.append("--enable-static") + + # If no features are found, enable the generic ones + if not any(f in spec.target for f in simd_features): + options.append("--enable-generic" + kernels) + + if self.compiler.name == "gcc": + options.extend(["CFLAGS=-O3", "FCFLAGS=-O3 -ffree-line-length-none"]) + + if "%aocc" in spec: + options.extend(["FCFLAGS=-O3", "CFLAGS=-O3"]) + + if "%fj" in spec: + options.append("--disable-Fortran2008-features") + options.append("--enable-FUGAKU") + if "+openmp" in spec: + options.extend(["FCFLAGS=-Kparallel"]) + + cuda_flag = "nvidia-gpu" + if "+cuda" in spec: + prefix = spec["cuda"].prefix + # Can't yet be changed to the new option --enable-nvidia-gpu-kernels + # https://github.com/marekandreas/elpa/issues/55 + options.append(f"--enable-{cuda_flag}") + options.append("--with-cuda-path={0}".format(prefix)) + options.append("--with-cuda-sdk-path={0}".format(prefix)) + + if spec.satisfies("+gpu_streams"): + options.append("--enable-gpu-streams=nvidia") + + cuda_arch = spec.variants["cuda_arch"].value[0] + + if cuda_arch != "none": + options.append( + "--with-{0}-compute-capability=sm_{1}".format(cuda_flag.upper(), cuda_arch) + ) + else: + options.append(f"--disable-{cuda_flag}" + kernels) + + if "+rocm" in spec: + # Can't yet be changed to the new option --enable-amd-gpu-kernels + # https://github.com/marekandreas/elpa/issues/55 + options.append("--enable-amd-gpu") + options.append("CXX={0}".format(self.spec["hip"].hipcc)) + + if spec.satisfies("+gpu_streams"): + options.append("--enable-gpu-streams=amd") + + elif "@2021.05.001:" in self.spec: + options.append("--disable-amd-gpu" + kernels) + + options += self.enable_or_disable("openmp") + + # Additional linker search paths and link libs + ldflags = [spec["blas"].libs.search_flags, spec["lapack"].libs.search_flags, "-lstdc++"] + libs = [spec["lapack"].libs.link_flags, spec["blas"].libs.link_flags] + + options += [f'LDFLAGS={" ".join(ldflags)}', f'LIBS={" ".join(libs)}'] + + if "+mpi" in self.spec: + options += [ + "CC={0}".format(spec["mpi"].mpicc), + "CXX={0}".format(spec["mpi"].mpicxx), + "FC={0}".format(spec["mpi"].mpifc), + "SCALAPACK_LDFLAGS={0}".format(spec["scalapack"].libs.joined()), + ] + + if "+autotune" in self.spec: + options.append("--enable-autotune-redistribute-matrix") + # --enable-autotune-redistribute-matrix requires --enable-scalapack-tests as well + options.append("--enable-scalapack-tests") + + options.append("--disable-silent-rules") + options.append("--without-threading-support-check-during-build") + + return options diff --git a/recipes/cp2k/2024.3/mc/compilers.yaml b/recipes/cp2k/2024.3/mc/compilers.yaml new file mode 100644 index 00000000..0dca2adf --- /dev/null +++ b/recipes/cp2k/2024.3/mc/compilers.yaml @@ -0,0 +1,5 @@ +bootstrap: + spec: gcc@12 +gcc: + specs: + - gcc@12.3 diff --git a/recipes/cp2k/2024.3/mc/config.yaml b/recipes/cp2k/2024.3/mc/config.yaml new file mode 100644 index 00000000..0337e381 --- /dev/null +++ b/recipes/cp2k/2024.3/mc/config.yaml @@ -0,0 +1,6 @@ +name: cp2k +store: /user-environment +spack: + repo: https://github.com/spack/spack.git + commit: v0.22.1 +modules: True diff --git a/recipes/cp2k/2024.3/mc/environments.yaml b/recipes/cp2k/2024.3/mc/environments.yaml new file mode 100644 index 00000000..995f5ff2 --- /dev/null +++ b/recipes/cp2k/2024.3/mc/environments.yaml @@ -0,0 +1,40 @@ +cp2k: + compiler: + - toolchain: gcc + spec: gcc@12.3 + unify: true + specs: + - cmake + - ninja + - intel-oneapi-mkl +cluster +gfortran mpi_family=mpich threads=openmp + - libxc + - libint + - spglib + - spla ^intel-oneapi-mkl + - elpa ^intel-oneapi-mkl + - libxsmm + - plumed + # COSMA dependencies (need to be in the develop view) + - costa ^intel-oneapi-mkl + - cosma ^intel-oneapi-mkl + # SIRIUS dependencies (need to be in the develop view) + - hdf5 + - spfft ^intel-oneapi-mkl + - sirius ~memory_pool ^intel-oneapi-mkl + # CP2K + - dbcsr@2.7.0 ^intel-oneapi-mkl + - cp2k@2024.3 +spglib +cosma +spla +elpa +sirius +plumed ^intel-oneapi-mkl + variants: + - +mpi + - +openmp + - build_type=Release + - ~cuda + - ~rocm + mpi: + spec: cray-mpich@8.1.30 + views: + develop: + link: roots + exclude: ["cp2k"] + cp2k: + link: roots diff --git a/recipes/cp2k/2024.3/mc/modules.yaml b/recipes/cp2k/2024.3/mc/modules.yaml new file mode 100644 index 00000000..910cda25 --- /dev/null +++ b/recipes/cp2k/2024.3/mc/modules.yaml @@ -0,0 +1,21 @@ +modules: + prefix_inspections: + bin: + - PATH + lib: + - LD_LIBRARY_PATH + lib64: + - LD_LIBRARY_PATH + + default: + arch_folder: false + roots: + tcl: /user-environment/modules + tcl: + all: + autoload: none + hash_length: 0 + exclude_implicits: true + exclude: ['%gcc@7.5.0', 'gcc %gcc@7.5.0'] + projections: + all: '{name}/{version}' diff --git a/recipes/cp2k/2024.3/mc/repo/packages/cosma/fj-ssl2.patch b/recipes/cp2k/2024.3/mc/repo/packages/cosma/fj-ssl2.patch new file mode 100644 index 00000000..3e09383d --- /dev/null +++ b/recipes/cp2k/2024.3/mc/repo/packages/cosma/fj-ssl2.patch @@ -0,0 +1,104 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index 1fd1e55..41a041b 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -19,7 +19,7 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS "YES") # always write compile_commands.json + + set(COSMA_GPU_BACKENDS_LIST "CUDA" "ROCM") + set(COSMA_SCALAPACK_LIST "OFF" "MKL" "CRAY_LIBSCI" "CUSTOM") +-set(COSMA_BLAS_LIST "auto" "MKL" "OPENBLAS" "CRAY_LIBSCI" "CUSTOM" "BLIS" "ATLAS" "CUDA" "ROCM" "OFF") ++set(COSMA_BLAS_LIST "auto" "MKL" "SSL2" "OPENBLAS" "CRAY_LIBSCI" "CUSTOM" "BLIS" "ATLAS" "CUDA" "ROCM" "OFF") + option(COSMA_WITH_TESTS "Generate the test target." ON) + option(COSMA_WITH_APPS "Generate the miniapp targets." ON) + option(COSMA_WITH_BENCHMARKS "Generate the benchmark targets." ON) +@@ -45,7 +45,7 @@ if (COSMA_BLAS MATCHES "CUDA|ROCM") + set(COSMA_GPU_BACKEND ${COSMA_BLAS}) + else() + if(COSMA_BLAS STREQUAL "OFF") +- message(FATAL_ERROR "A Blas implementation is needed when running on CPU only: choices are : auto, MKL, OPENBLAS, CRAY_LIBSCI, CUSTOM, BLIS, ATLAS, FLEXIBLAS, ARMPL, GenericBLAS") ++ message(FATAL_ERROR "A Blas implementation is needed when running on CPU only: choices are : auto, MKL, SSL2, OPENBLAS, CRAY_LIBSCI, CUSTOM, BLIS, ATLAS, FLEXIBLAS, ARMPL, GenericBLAS") + else() + set(COSMA_BLAS_VENDOR ${COSMA_BLAS}) + endif() +@@ -190,6 +190,7 @@ install(FILES "${cosma_BINARY_DIR}/cosmaConfig.cmake" + "${cosma_BINARY_DIR}/cosmaConfigVersion.cmake" + "${cosma_BINARY_DIR}/cosmaConfigVersion.cmake" + "${cosma_SOURCE_DIR}/cmake/FindMKL.cmake" ++ "${cosma_SOURCE_DIR}/cmake/FindSSL2.cmake" + "${cosma_SOURCE_DIR}/cmake/FindBlas.cmake" + "${cosma_SOURCE_DIR}/cmake/FindSCALAPACK.cmake" + "${cosma_SOURCE_DIR}/cmake/FindOPENBLAS.cmake" +diff --git a/cmake/FindBlas.cmake b/cmake/FindBlas.cmake +index aef956c..3c47561 100644 +--- a/cmake/FindBlas.cmake ++++ b/cmake/FindBlas.cmake +@@ -14,6 +14,7 @@ endif() + set(COSMA_BLAS_VENDOR_LIST + "auto" + "MKL" ++ "SSL2" + "OPENBLAS" + "FLEXIBLAS" + "ARMPL" +diff --git a/cmake/FindSSL2.cmake b/cmake/FindSSL2.cmake +new file mode 100644 +index 0000000..f0e11bf +--- /dev/null ++++ b/cmake/FindSSL2.cmake +@@ -0,0 +1,56 @@ ++#.rst: ++# FindSSL2 ++# ----------- ++# ++# This module tries to find the SSL2 library. ++# ++# The following variables are set ++# ++# :: ++# ++# SSL2_FOUND - True if ssl2 is found ++# SSL2_LIBRARIES - The required libraries ++# SSL2_INCLUDE_DIRS - The required include directory ++# ++# The following import target is created ++# ++# :: ++# ++# SSL2::ssl2 ++ ++#set paths to look for library from ROOT variables.If new policy is set, find_library() automatically uses them. ++# if(NOT POLICY CMP0074) ++set(_SSL2_PATHS ${SSL2_ROOT} ++ $ENV{SSL2_ROOT} ++ $ENV{SSL2ROOT} ++ $ENV{SSL2_DIR} ++ $ENV{SSL2DIR}) ++# endif() ++ ++find_library( ++ COSMA_SSL2_LINK_LIBRARIES ++ NAMES "fjlapackex" ++ HINTS ${_SSL2_PATHS} ++ PATH_SUFFIXES "lib64" ++) ++find_path( ++ COSMA_SSL2_INCLUDE_DIRS ++ NAMES "cblas.h" ++ HINTS ${_SSL2_PATHS} ++ PATH_SUFFIXES "include" ++) ++ ++# check if found ++include(FindPackageHandleStandardArgs) ++find_package_handle_standard_args(SSL2 REQUIRED_VARS COSMA_SSL2_INCLUDE_DIRS COSMA_SSL2_LINK_LIBRARIES) ++ ++# add target to link against ++if(NOT TARGET cosma::BLAS::SSL2::ssl2) ++ add_library(cosma::BLAS::SSL2::ssl2 INTERFACE IMPORTED) ++ add_library(cosma::BLAS::SSL2::blas ALIAS cosma::BLAS::SSL2::ssl2) ++endif() ++set_property(TARGET cosma::BLAS::SSL2::ssl2 PROPERTY INTERFACE_LINK_LIBRARIES ${COSMA_SSL2_LINK_LIBRARIES}) ++set_property(TARGET cosma::BLAS::SSL2::ssl2 PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${COSMA_SSL2_INCLUDE_DIRS}) ++ ++# prevent clutter in cache ++MARK_AS_ADVANCED(SSL2_FOUND SSL2_LIBRARIES SSL2_INCLUDE_DIRS) diff --git a/recipes/cp2k/2024.3/mc/repo/packages/cosma/mpi-view.patch b/recipes/cp2k/2024.3/mc/repo/packages/cosma/mpi-view.patch new file mode 100644 index 00000000..ef6a2857 --- /dev/null +++ b/recipes/cp2k/2024.3/mc/repo/packages/cosma/mpi-view.patch @@ -0,0 +1,13 @@ +diff --git a/cmake/cosmaConfig.cmake.in b/cmake/cosmaConfig.cmake.in +index cf7038f..1527c53 100644 +--- a/cmake/cosmaConfig.cmake.in ++++ b/cmake/cosmaConfig.cmake.in +@@ -11,7 +11,7 @@ if(NOT TARGET cosma::cosma) + set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR} ${CMAKE_MODULE_PATH}) + + set(MKL_ROOT "@MKL_ROOT@") +- set(MPI_CXX_COMPILER "@MPI_CXX_COMPILER@") ++ # set(MPI_CXX_COMPILER "@MPI_CXX_COMPILER@") + set(MPI_DETERMINE_LIBRARY_VERSION TRUE) + find_package(MPI COMPONENTS "CXX" REQUIRED) + diff --git a/recipes/cp2k/2024.3/mc/repo/packages/cosma/package.py b/recipes/cp2k/2024.3/mc/repo/packages/cosma/package.py new file mode 100644 index 00000000..78c162ce --- /dev/null +++ b/recipes/cp2k/2024.3/mc/repo/packages/cosma/package.py @@ -0,0 +1,135 @@ +# Copyright 2013-2024 Lawrence Livermore National Security, LLC and other +# Spack Project Developers. See the top-level COPYRIGHT file for details. +# +# SPDX-License-Identifier: (Apache-2.0 OR MIT) + + +from spack.package import * + + +class Cosma(CMakePackage): + """ + Distributed Communication-Optimal Matrix-Matrix Multiplication Library + """ + + maintainers("haampie", "kabicm", "teonnik", "simonpintarelli", "mtaillefumier") + homepage = "https://github.com/eth-cscs/COSMA" + url = "https://github.com/eth-cscs/COSMA/archive/refs/tags/v2.6.6.tar.gz" + git = "https://github.com/eth-cscs/COSMA.git" + + license("BSD-3-Clause") + + # note: The default archives produced with github do not have the archives + # of the submodules. + version("master", branch="master", submodules=False) + version("2.6.6", sha256="1604be101e77192fbcc5551236bc87888d336e402f5409bbdd9dea900401cc37") + version("2.6.5", sha256="10d9b7ecc1ce44ec5b9e0c0bf89278a63029912ec3ea99661be8576b553ececf") + version("2.6.4", sha256="6d7bd5e3005874af9542a329c93e7ccd29ca1a5573dae27618fac2704fa2b6ab") + version("2.6.3", sha256="c2a3735ea8f860930bea6706d968497d72a1be0498c689b5bc4a951ffc2d1146") + version("2.6.2", sha256="2debb5123cc35aeebc5fd2f8a46cfd6356d1e27618c9bb57129ecd09aa400940") + version("2.6.1", sha256="69aa6634a030674f0d9be61e7b0bf0dc17acf0fc9e7a90b40e3179e2254c8d67") + version("2.5.1", sha256="085b7787597374244bbb1eb89bc69bf58c35f6c85be805e881e1c0b25166c3ce") + version("2.5.0", sha256="7f68bb0ee5c80f9b8df858afcbd017ad4ed87ac09439d13d7d890844dbdd3d54") + version("2.4.0", sha256="5714315ce06d48037f86cfee2d7f19340643fee95e9d7f1e92dc1b623b67e395") + version("2.3.0", sha256="0c01c2deb5a0cd177952178350188a62c42ce55e604d7948ac472f55bf0d4815") + version("2.2.0", sha256="1eb92a98110df595070a12193b9221eecf9d103ced8836c960f6c79a2bd553ca") + version("2.0.7", sha256="8d70bfcbda6239b6a8fbeaca138790bbe58c0c3aa576879480d2632d4936cf7e") + version("2.0.2", sha256="4f3354828bc718f3eef2f0098c3bdca3499297497a220da32db1acd57920c68d") + + # We just need the libraries of cuda and rocm, so no need to extend + # CudaPackage or ROCmPackage. + variant("cuda", default=False, description="Build with cuBLAS support") + variant("rocm", default=False, description="Build with rocBLAS support") + variant("scalapack", default=False, description="Build with ScaLAPACK API") + variant("shared", default=True, description="Build the shared library version") + variant("tests", default=False, description="Build tests") + variant("apps", default=False, description="Build miniapp") + variant("profiling", default=False, description="Enable profiling") + variant("gpu_direct", default=False, description="GPU aware MPI") + + with when("+cuda"): + variant("nccl", default=False, description="Use cuda nccl") + + with when("+rocm"): + variant("rccl", default=False, description="Use rocm rccl") + + depends_on("cmake@3.22:", type="build") + depends_on("mpi@3:") + depends_on("blas", when="~cuda ~rocm") + depends_on("scalapack", when="+scalapack") + depends_on("cuda", when="+cuda") + depends_on("rocblas", when="+rocm") + depends_on("nccl", when="+nccl") + depends_on("rccl", when="+rccl") + + with when("@2.6.3:"): + depends_on("tiled-mm@2.2:+cuda", when="+cuda") + depends_on("tiled-mm@2.2:+rocm", when="+rocm") + + with when("@2.6.1:2.6.2"): + depends_on("tiled-mm@2.0+rocm", when="+rocm") + depends_on("tiled-mm@2.0+cuda", when="+cuda") + + with when("@2.6.1:"): + depends_on("costa") + depends_on("costa+scalapack", when="+scalapack") + depends_on("cxxopts", when="+apps") + depends_on("cxxopts", when="+tests") + depends_on("semiprof", when="+profiling") + depends_on("costa+profiling", when="+profiling") + + patch("fj-ssl2.patch", when="^fujitsu-ssl2") + patch("mpi-view.patch") + + def setup_build_environment(self, env): + if "+cuda" in self.spec: + env.set("CUDA_PATH", self.spec["cuda"].prefix) + + def cosma_blas_cmake_arg(self): + query_to_cmake_arg = [ + ("+cuda", "CUDA"), + ("+rocm", "ROCM"), + ("^intel-mkl", "MKL"), + ("^intel-oneapi-mkl", "MKL"), + ("^cray-libsci", "CRAY_LIBSCI"), + ("^netlib-lapack", "CUSTOM"), + ("^openblas", "OPENBLAS"), + ("^fujitsu-ssl2", "SSL2"), + ] + + if self.version >= Version("2.4.0"): + query_to_cmake_arg.extend( + [("^blis", "BLIS"), ("^amdblis", "BLIS"), ("^atlas", "ATLAS")] + ) + + for query, cmake_arg in query_to_cmake_arg: + if query in self.spec: + return cmake_arg + + return "CUSTOM" + + def cosma_scalapack_cmake_arg(self): + spec = self.spec + + if "~scalapack" in spec: + return "OFF" + elif "^intel-mkl" in spec or "^intel-oneapi-mkl" in spec: + return "MKL" + elif "^cray-libsci" in spec: + return "CRAY_LIBSCI" + + return "CUSTOM" + + def cmake_args(self): + return [ + self.define_from_variant("COSMA_WITH_TESTS", "tests"), + self.define_from_variant("COSMA_WITH_APPS", "apps"), + self.define_from_variant("COSMA_WITH_NCCL", "nccl"), + self.define_from_variant("COSMA_WITH_RCCL", "rccl"), + self.define_from_variant("COSMA_WITH_GPU_AWARE_MPI", "gpu_direct"), + self.define_from_variant("COSMA_WITH_PROFILING", "profiling"), + self.define("COSMA_WITH_BENCHMARKS", False), + self.define("COSMA_BLAS", self.cosma_blas_cmake_arg()), + self.define("COSMA_SCALAPACK", self.cosma_scalapack_cmake_arg()), + self.define_from_variant("BUILD_SHARED_LIBS", "shared"), + ] diff --git a/recipes/cp2k/2024.3/mc/repo/packages/costa/mpi-view.patch b/recipes/cp2k/2024.3/mc/repo/packages/costa/mpi-view.patch new file mode 100644 index 00000000..be6d7060 --- /dev/null +++ b/recipes/cp2k/2024.3/mc/repo/packages/costa/mpi-view.patch @@ -0,0 +1,13 @@ +diff --git a/cmake/costaConfig.cmake.in b/cmake/costaConfig.cmake.in +index 8fae534..d744c90 100644 +--- a/cmake/costaConfig.cmake.in ++++ b/cmake/costaConfig.cmake.in +@@ -10,7 +10,7 @@ include(CMakeFindDependencyMacro) + set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR} ${CMAKE_MODULE_PATH}) + + set(MKL_ROOT "@MKL_ROOT@") +-set(MPI_CXX_COMPILER "@MPI_CXX_COMPILER@") ++#set(MPI_CXX_COMPILER "@MPI_CXX_COMPILER@") + + set(MPI_DETERMINE_LIBRARY_VERSION TRUE) + set(COSTA_SCALAPACK "@COSTA_SCALAPACK@") diff --git a/recipes/cp2k/2024.3/mc/repo/packages/costa/package.py b/recipes/cp2k/2024.3/mc/repo/packages/costa/package.py new file mode 100644 index 00000000..6b78f17c --- /dev/null +++ b/recipes/cp2k/2024.3/mc/repo/packages/costa/package.py @@ -0,0 +1,77 @@ +# Copyright 2013-2024 Lawrence Livermore National Security, LLC and other +# Spack Project Developers. See the top-level COPYRIGHT file for details. +# +# SPDX-License-Identifier: (Apache-2.0 OR MIT) + + +from spack.package import * + + +class Costa(CMakePackage): + """ + Distributed Communication-Optimal Matrix Transpose and Reshuffle Library + Based on the paper: https://arxiv.org/abs/2106.06601 + """ + + maintainers("haampie", "kabicm", "RMeli", "mtaillefumier") + homepage = "https://github.com/eth-cscs/COSTA" + git = "https://github.com/eth-cscs/COSTA.git" + + license("BSD-3-Clause") + + # note: The default archives produced with github do not have the archives + # of the submodules. + version("master", branch="master", submodules=True) + version("2.2.2", sha256="e87bc37aad14ac0c5922237be5d5390145c9ac6aef0350ed17d86cb2d994e67c") + version("2.2.1", sha256="aa8aa2a4a79de094f857c22293825de270ff72becd6bd736ff9f2dd8c192446d") + version("2.2", sha256="3e7333f012af76ec3508276ea90800313f6136504667021fe229e710bf6acdc7") + version("2.1", sha256="c1e86452415083f7470b292d93ec60708b7c8dbafc2bac383636bb4b28135866") + version("2.0", sha256="de250197f31f7d23226c6956a687c3ff46fb0ff6c621a932428236c3f7925fe4") + + variant("scalapack", default=False, description="Build with ScaLAPACK API") + variant("shared", default=True, description="Build shared libraries") + variant("profiling", default=False, description="Enable profiling") + variant("tests", default=False, description="Enable tests") + variant("apps", default=False, description="Enable miniapp") + variant("benchmarks", default=False, description="Enable benchmarks") + + depends_on("cmake@3.22:", type="build") + depends_on("mpi@3:") + depends_on("scalapack", when="+scalapack") + depends_on("cxxopts", when="+apps") + depends_on("cxxopts", when="+tests") + depends_on("semiprof", when="+profiling") + + patch("mpi-view.patch") + + def url_for_version(self, version): + if version == Version("2.0"): + return "https://github.com/eth-cscs/COSTA/releases/download/v{0}/COSTA-v{1}.tar.gz".format( + version, version + ) + return "https://github.com/eth-cscs/COSTA/archive/refs/tags/v{0}.tar.gz".format(version) + + def setup_build_environment(self, env): + return + + def costa_scalapack_cmake_arg(self): + spec = self.spec + + if "~scalapack" in spec: + return "OFF" + elif "^intel-mkl" in spec or "^intel-oneapi-mkl" in spec: + return "MKL" + elif "^cray-libsci" in spec: + return "CRAY_LIBSCI" + + return "CUSTOM" + + def cmake_args(self): + return [ + self.define_from_variant("COSTA_WITH_BENCHMARKS", "benchmarks"), + self.define_from_variant("COSTA_WITH_APPS", "apps"), + self.define_from_variant("COSTA_WITH_TESTS", "tests"), + self.define_from_variant("COSTA_WITH_PROFILING", "profiling"), + self.define_from_variant("BUILD_SHARED_LIBS", "shared"), + self.define("COSTA_SCALAPACK", self.costa_scalapack_cmake_arg()), + ] diff --git a/recipes/cp2k/2024.3/mc/repo/packages/cp2k/backport_avoid_null_2022.x.patch b/recipes/cp2k/2024.3/mc/repo/packages/cp2k/backport_avoid_null_2022.x.patch new file mode 100644 index 00000000..ecd3db97 --- /dev/null +++ b/recipes/cp2k/2024.3/mc/repo/packages/cp2k/backport_avoid_null_2022.x.patch @@ -0,0 +1,21 @@ +diff -Naru a/src/qs_kpp1_env_methods.F b/src/qs_kpp1_env_methods.F +--- a/src/qs_kpp1_env_methods.F 2022-10-03 01:14:25.720416300 +0530 ++++ b/src/qs_kpp1_env_methods.F 2023-06-14 02:33:05.205287205 +0530 +@@ -214,7 +214,6 @@ + output_unit + LOGICAL :: gapw, gapw_xc, lsd, my_calc_forces + REAL(KIND=dp) :: alpha, energy_hartree, energy_hartree_1c +- REAL(KIND=dp), DIMENSION(:, :, :, :), POINTER :: vxg + TYPE(atomic_kind_type), DIMENSION(:), POINTER :: atomic_kind_set + TYPE(cp_logger_type), POINTER :: logger + TYPE(cp_para_env_type), POINTER :: para_env +@@ -373,7 +372,8 @@ + + CALL xc_calc_2nd_deriv(v_xc, v_xc_tau, p_env%kpp1_env%deriv_set, p_env%kpp1_env%rho_set, & + rho1_r_pw, rho1_g_pw, tau1_r_pw, auxbas_pw_pool, xc_section, .FALSE., & +- NULL(vxg), lsd_singlets, do_excitations, do_triplet, do_tddft, & ++ lsd_singlets=lsd_singlets, do_excitations=do_excitations, & ++ do_triplet=do_triplet, do_tddft=do_tddft, & + compute_virial=calc_virial, virial_xc=virial) + + DO ispin = 1, nspins diff --git a/recipes/cp2k/2024.3/mc/repo/packages/cp2k/backport_avoid_null_9.1.patch b/recipes/cp2k/2024.3/mc/repo/packages/cp2k/backport_avoid_null_9.1.patch new file mode 100644 index 00000000..7f580a04 --- /dev/null +++ b/recipes/cp2k/2024.3/mc/repo/packages/cp2k/backport_avoid_null_9.1.patch @@ -0,0 +1,21 @@ +diff -Naru a/src/qs_kpp1_env_methods.F b/src/qs_kpp1_env_methods.F +--- a/src/qs_kpp1_env_methods.F 2021-11-20 14:35:36.103103400 +0530 ++++ b/src/qs_kpp1_env_methods.F 2023-06-14 12:00:52.350584708 +0530 +@@ -220,7 +220,6 @@ + output_unit + LOGICAL :: gapw, gapw_xc, lsd, my_calc_forces + REAL(KIND=dp) :: alpha, energy_hartree, energy_hartree_1c +- REAL(KIND=dp), DIMENSION(:, :, :, :), POINTER :: vxg + TYPE(atomic_kind_type), DIMENSION(:), POINTER :: atomic_kind_set + TYPE(cp_logger_type), POINTER :: logger + TYPE(cp_para_env_type), POINTER :: para_env +@@ -361,7 +360,8 @@ + + CALL xc_calc_2nd_deriv(v_xc, p_env%kpp1_env%deriv_set, p_env%kpp1_env%rho_set, & + rho1_r_pw, rho1_g_pw, auxbas_pw_pool, xc_section, .FALSE., & +- NULL(vxg), lsd_singlets, do_excitations, do_triplet, do_tddft, & ++ lsd_singlets=lsd_singlets, do_excitations=do_excitations, & ++ do_triplet=do_triplet, do_tddft=do_tddft, & + compute_virial=calc_virial, virial_xc=virial) + + DO ispin = 1, nspins diff --git a/recipes/cp2k/2024.3/mc/repo/packages/cp2k/cmake-fixes-2023.2.patch b/recipes/cp2k/2024.3/mc/repo/packages/cp2k/cmake-fixes-2023.2.patch new file mode 100644 index 00000000..985edad3 --- /dev/null +++ b/recipes/cp2k/2024.3/mc/repo/packages/cp2k/cmake-fixes-2023.2.patch @@ -0,0 +1,714 @@ +From b75eb217115820059aba26d1ff1a8657e3841e7d Mon Sep 17 00:00:00 2001 +From: Mathieu Taillefumier +Date: Mon, 23 Oct 2023 15:50:44 +0200 +Subject: [PATCH] cmake-fixes-2023.2 + +--- + CMakeLists.txt | 63 +++++++----- + cmake/FindBlas.cmake | 174 +++++++++++++++++----------------- + cmake/FindLapack.cmake | 47 ++++----- + cmake/cp2k.pc.in | 19 ---- + cmake/cp2kConfig.cmake.in | 195 ++++++++++++++++++++------------------ + cmake/libcp2k.pc.in | 11 +++ + src/CMakeLists.txt | 18 ++-- + 7 files changed, 276 insertions(+), 251 deletions(-) + delete mode 100644 cmake/cp2k.pc.in + create mode 100644 cmake/libcp2k.pc.in + +diff --git a/CMakeLists.txt b/CMakeLists.txt +index 3f81c7b52..f2d85d033 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -49,7 +49,8 @@ if(NOT DEFINED CMAKE_CUDA_STANDARD) + endif() + + # set language and standard +-set(CMAKE_CXX_STANDARD 11) ++set(CMAKE_CXX_STANDARD 14) ++set(CMAKE_C_STANDARD 11) + + find_package(PkgConfig) + +@@ -108,6 +109,10 @@ option(CP2K_USE_LIBXSMM "Use libxsmm for small gemms (supports x86 platforms)" + OFF) + option(CP2K_BUILD_DBCSR "Duild dbcsr at the same time than cp2k." OFF) + option(BUILD_SHARED_LIBS "Build cp2k shared library" ON) ++option( ++ CP2K_USE_FFTW3_WITH_MKL ++ "If set to ON use the original implementation of fftw3 instead of the MKL implementation." ++ OFF) + + cmake_dependent_option(CP2K_ENABLE_ELPA_OPENMP_SUPPORT + "Enable elpa openmp support" ON "CP2K_USE_ELPA" OFF) +@@ -115,8 +120,8 @@ cmake_dependent_option(CP2K_ENABLE_FFTW3_OPENMP_SUPPORT + "Enable FFTW openmp support" ON "CP2K_USE_FFTW3" OFF) + cmake_dependent_option(CP2K_ENABLE_FFTW3_THREADS_SUPPORT + "Enable FFTW THREADS support" OFF "CP2K_USE_FFTW3" OFF) +-cmake_dependent_option(CP2K_ENABLE_F08_MPI "Enable MPI Fortran 2008 interface" +- OFF "CP2K_USE_MPI" OFF) ++cmake_dependent_option(CP2K_USE_MPI_F08 "Enable MPI Fortran 2008 interface" OFF ++ "CP2K_USE_MPI" OFF) + + cmake_dependent_option( + DBCSR_USE_ACCEL +@@ -527,7 +532,7 @@ if(CP2K_USE_ACCEL MATCHES "CUDA") + endif() + + set(CP2K_USE_CUDA ON) +- message(STATUS ``"-- CUDA compiler and libraries found") ++ message(STATUS "-- CUDA compiler and libraries found") + elseif(CP2K_USE_ACCEL MATCHES "HIP") + enable_language(HIP) + # Find hip +@@ -620,27 +625,36 @@ endif() + + # FFTW3 + ++set(CP2K_USE_FFTW3_ OFF) + if(CP2K_USE_FFTW3) +- find_package(Fftw REQUIRED) +- if(CP2K_ENABLE_FFTW3_THREADS_SUPPORT AND CP2K_ENABLE_FFTW3_OPENMP_SUPPORT) +- message( +- FATAL_ERROR +- "Fftw3 threads and openmp supports can not be used at the same time") +- endif() ++ if(CP2K_USE_FFTW3_WITH_MKL OR NOT CP2K_BLAS_VENDOR MATCHES "MKL") ++ find_package(Fftw REQUIRED) ++ if(CP2K_ENABLE_FFTW3_THREADS_SUPPORT AND CP2K_ENABLE_FFTW3_OPENMP_SUPPORT) ++ message( ++ FATAL_ERROR ++ "Fftw3 threads and openmp supports can not be used at the same time") ++ endif() + +- if((CP2K_ENABLE_FFTW3_THREADS_SUPPORT) AND (NOT TARGET +- CP2K::FFTW3::fftw3_threads)) +- message( +- FATAL_ERROR +- "fftw3 was compiled without multithreading support (--enable-threads option in fftw build system)." +- ) +- endif() ++ if((CP2K_ENABLE_FFTW3_THREADS_SUPPORT) AND (NOT TARGET ++ CP2K::FFTW3::fftw3_threads)) ++ message( ++ FATAL_ERROR ++ "fftw3 was compiled without multithreading support (--enable-threads option in fftw build system)." ++ ) ++ endif() + +- if((CP2K_ENABLE_FFTW3_OPENMP_SUPPORT) AND (NOT TARGET CP2K::FFTW3::fftw3_omp)) +- message( +- FATAL_ERROR +- "fftw3 was compiled without openmp support (--enable-openmp option in fftw build system)." +- ) ++ if((CP2K_ENABLE_FFTW3_OPENMP_SUPPORT) AND (NOT TARGET CP2K::FFTW3::fftw3_omp ++ )) ++ message( ++ FATAL_ERROR ++ "fftw3 was compiled without openmp support (--enable-openmp option in fftw build system)." ++ ) ++ endif() ++ # we use this variable later on to include the fftw target whenever mkl is ++ # found or not ++ set(CP2K_USE_FFTW3_ ON) ++ else() ++ message("-- Using the MKL implementation of FFTW3.") + endif() + endif() + +@@ -748,7 +762,7 @@ add_subdirectory(src) + include(GNUInstallDirs) + + get_target_property(CP2K_LIBS cp2k_link_libs INTERFACE_LINK_LIBRARIES) +-configure_file(cmake/cp2k.pc.in cp2k.pc @ONLY) ++configure_file(cmake/libcp2k.pc.in libcp2k.pc @ONLY) + + message( + STATUS "--------------------------------------------------------------------") +@@ -1039,6 +1053,9 @@ install(FILES "${PROJECT_BINARY_DIR}/cp2kConfig.cmake" + "${PROJECT_BINARY_DIR}/cp2kConfigVersion.cmake" + DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/cp2k") + ++install(FILES "${PROJECT_BINARY_DIR}/libcp2k.pc" ++ DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig") ++ + install( + DIRECTORY "${PROJECT_SOURCE_DIR}/cmake" + DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/cp2k" +diff --git a/cmake/FindBlas.cmake b/cmake/FindBlas.cmake +index 6e5fb7824..335cbd964 100644 +--- a/cmake/FindBlas.cmake ++++ b/cmake/FindBlas.cmake +@@ -15,104 +15,108 @@ if(NOT + OR CMAKE_Fortran_COMPILER_LOADED)) + message(FATAL_ERROR "FindBLAS requires Fortran, C, or C++ to be enabled.") + endif() ++if(NOT CP2K_CONFIG_PACKAGE) ++ set(CP2K_BLAS_VENDOR_LIST ++ "auto" ++ "MKL" ++ "OpenBLAS" ++ "SCI" ++ "GenericBLAS" ++ "Armpl" ++ "FlexiBLAS" ++ "Atlas" ++ "NVHPCBlas" ++ "CUSTOM") ++ ++ set(__BLAS_VENDOR_LIST ${CP2K_BLAS_VENDOR_LIST}) ++ list(REMOVE_ITEM __BLAS_VENDOR_LIST "auto") ++ list(REMOVE_ITEM __BLAS_VENDOR_LIST "CUSTOM") ++ ++ # set(CP2K_BLAS_VENDOR "auto" CACHE STRING "Blas library for computations on ++ # host") ++ set_property(CACHE CP2K_BLAS_VENDOR PROPERTY STRINGS ${CP2K_BLAS_VENDOR_LIST}) ++ ++ if(NOT ${CP2K_BLAS_VENDOR} IN_LIST CP2K_BLAS_VENDOR_LIST) ++ message(FATAL_ERROR "Invalid Host BLAS backend") ++ endif() + +-set(CP2K_BLAS_VENDOR_LIST +- "auto" +- "MKL" +- "OpenBLAS" +- "SCI" +- "GenericBLAS" +- "Armpl" +- "FlexiBLAS" +- "Atlas" +- "NVHPCBlas" +- "CUSTOM") +- +-set(__BLAS_VENDOR_LIST ${CP2K_BLAS_VENDOR_LIST}) +-list(REMOVE_ITEM __BLAS_VENDOR_LIST "auto") +-list(REMOVE_ITEM __BLAS_VENDOR_LIST "CUSTOM") +- +-# set(CP2K_BLAS_VENDOR "auto" CACHE STRING "Blas library for computations on +-# host") +-set_property(CACHE CP2K_BLAS_VENDOR PROPERTY STRINGS ${CP2K_BLAS_VENDOR_LIST}) +- +-if(NOT ${CP2K_BLAS_VENDOR} IN_LIST CP2K_BLAS_VENDOR_LIST) +- message(FATAL_ERROR "Invalid Host BLAS backend") +-endif() +- +-set(CP2K_BLAS_THREAD_LIST "sequential" "thread" "gnu-thread" "intel-thread" +- "tbb-thread" "openmp") +- +-set(CP2K_BLAS_THREADING +- "sequential" +- CACHE STRING "threaded blas library") +-set_property(CACHE CP2K_BLAS_THREADING PROPERTY STRINGS +- ${CP2K_BLAS_THREAD_LIST}) +- +-if(NOT ${CP2K_BLAS_THREADING} IN_LIST CP2K_BLAS_THREAD_LIST) +- message(FATAL_ERROR "Invalid threaded BLAS backend") +-endif() ++ set(CP2K_BLAS_THREAD_LIST "sequential" "thread" "gnu-thread" "intel-thread" ++ "tbb-thread" "openmp") + +-set(CP2K_BLAS_INTERFACE_BITS_LIST "32bits" "64bits") +-set(CP2K_BLAS_INTERFACE +- "32bits" +- CACHE STRING +- "32 bits integers are used for indices, matrices and vectors sizes") +-set_property(CACHE CP2K_BLAS_INTERFACE +- PROPERTY STRINGS ${CP2K_BLAS_INTERFACE_BITS_LIST}) +- +-if(NOT ${CP2K_BLAS_INTERFACE} IN_LIST CP2K_BLAS_INTERFACE_BITS_LIST) +- message( +- FATAL_ERROR +- "Invalid parameters. Blas and lapack can exist in two flavors 32 or 64 bits interfaces (relevant mostly for mkl)" +- ) +-endif() ++ set(CP2K_BLAS_THREADING ++ "sequential" ++ CACHE STRING "threaded blas library") ++ set_property(CACHE CP2K_BLAS_THREADING PROPERTY STRINGS ++ ${CP2K_BLAS_THREAD_LIST}) + +-set(CP2K_BLAS_FOUND FALSE) ++ if(NOT ${CP2K_BLAS_THREADING} IN_LIST CP2K_BLAS_THREAD_LIST) ++ message(FATAL_ERROR "Invalid threaded BLAS backend") ++ endif() + +-# first check for a specific implementation if requested ++ set(CP2K_BLAS_INTERFACE_BITS_LIST "32bits" "64bits") ++ set(CP2K_BLAS_INTERFACE ++ "32bits" ++ CACHE STRING ++ "32 bits integers are used for indices, matrices and vectors sizes") ++ set_property(CACHE CP2K_BLAS_INTERFACE ++ PROPERTY STRINGS ${CP2K_BLAS_INTERFACE_BITS_LIST}) + +-if(NOT CP2K_BLAS_VENDOR MATCHES "auto|CUSTOM") +- find_package(${CP2K_BLAS_VENDOR} REQUIRED) +- if(TARGET CP2K::BLAS::${CP2K_BLAS_VENDOR}::blas) +- get_target_property( +- CP2K_BLAS_INCLUDE_DIRS CP2K::BLAS::${CP2K_BLAS_VENDOR}::blas +- INTERFACE_INCLUDE_DIRECTORIES) +- get_target_property( +- CP2K_BLAS_LINK_LIBRARIES CP2K::BLAS::${CP2K_BLAS_VENDOR}::blas +- INTERFACE_LINK_LIBRARIES) +- set(CP2K_BLAS_FOUND TRUE) +- endif() +-else() +- if(CP2K_BLAS_VENDOR MATCHES "CUSTOM" AND NOT DEFINED CP2K_BLAS_LINK_LIBRARIES) ++ if(NOT ${CP2K_BLAS_INTERFACE} IN_LIST CP2K_BLAS_INTERFACE_BITS_LIST) + message( + FATAL_ERROR +- "Setting CP2K_BLAS_VENDOR=CUSTOM imply setting CP2K_BLAS_LINK_LIBRARIES\n and CP2K_LAPACK_LINK_LIBRARIES to the right libraries. See the README_cmake.md for more details" ++ "Invalid parameters. Blas and lapack can exist in two flavors 32 or 64 bits interfaces (relevant mostly for mkl)" + ) + endif() + +- if(DEFINED CP2K_BLAS_LINK_LIBRARIES) +- set(CP2K_BLAS_FOUND TRUE) ++ set(CP2K_BLAS_FOUND FALSE) ++ ++ # first check for a specific implementation if requested ++ ++ if(NOT CP2K_BLAS_VENDOR MATCHES "auto|CUSTOM") ++ find_package(${CP2K_BLAS_VENDOR} REQUIRED) ++ if(TARGET CP2K::BLAS::${CP2K_BLAS_VENDOR}::blas) ++ get_target_property( ++ CP2K_BLAS_INCLUDE_DIRS CP2K::BLAS::${CP2K_BLAS_VENDOR}::blas ++ INTERFACE_INCLUDE_DIRECTORIES) ++ get_target_property( ++ CP2K_BLAS_LINK_LIBRARIES CP2K::BLAS::${CP2K_BLAS_VENDOR}::blas ++ INTERFACE_LINK_LIBRARIES) ++ set(CP2K_BLAS_FOUND TRUE) ++ endif() + else() +- # search for any blas implementation and exit immediately if one is found. +- # we could also give a full list of found implementation and let the user +- # choose which implementation to use +- foreach(_libs ${__BLAS_VENDOR_LIST}) +- # I exclude the first item of the list +- find_package(${_libs}) +- if(TARGET CP2K::BLAS::${_libs}::blas) +- get_target_property(CP2K_BLAS_INCLUDE_DIRS CP2K::BLAS::${_libs}::blas +- INTERFACE_INCLUDE_DIRECTORIES) +- get_target_property(CP2K_BLAS_LINK_LIBRARIES CP2K::BLAS::${_libs}::blas +- INTERFACE_LINK_LIBRARIES) +- set(CP2K_BLAS_VENDOR "${_libs}") +- set(CP2K_BLAS_FOUND TRUE) +- break() +- endif() +- endforeach() ++ if(CP2K_BLAS_VENDOR MATCHES "CUSTOM" AND NOT DEFINED ++ CP2K_BLAS_LINK_LIBRARIES) ++ message( ++ FATAL_ERROR ++ "Setting CP2K_BLAS_VENDOR=CUSTOM imply setting CP2K_BLAS_LINK_LIBRARIES\n and CP2K_LAPACK_LINK_LIBRARIES to the right libraries. See the README_cmake.md for more details" ++ ) ++ endif() ++ ++ if(DEFINED CP2K_BLAS_LINK_LIBRARIES) ++ set(CP2K_BLAS_FOUND TRUE) ++ else() ++ # search for any blas implementation and exit immediately if one is found. ++ # we could also give a full list of found implementation and let the user ++ # choose which implementation to use ++ foreach(_libs ${__BLAS_VENDOR_LIST}) ++ # I exclude the first item of the list ++ find_package(${_libs}) ++ if(TARGET CP2K::BLAS::${_libs}::blas) ++ get_target_property(CP2K_BLAS_INCLUDE_DIRS CP2K::BLAS::${_libs}::blas ++ INTERFACE_INCLUDE_DIRECTORIES) ++ get_target_property( ++ CP2K_BLAS_LINK_LIBRARIES CP2K::BLAS::${_libs}::blas ++ INTERFACE_LINK_LIBRARIES) ++ set(CP2K_BLAS_VENDOR "${_libs}") ++ set(CP2K_BLAS_FOUND TRUE) ++ break() ++ endif() ++ endforeach() ++ endif() + endif() ++else() ++ set(CP2K_BLAS_FOUND ON) + endif() +- + # we exclude the CP2K_BLAS_INCLUDE_DIRS from the list of mandatory variables as + # having the fortran interface is usually enough. C, C++ and others languages + # might require this information though +diff --git a/cmake/FindLapack.cmake b/cmake/FindLapack.cmake +index 966e0d78d..77a1e0425 100644 +--- a/cmake/FindLapack.cmake ++++ b/cmake/FindLapack.cmake +@@ -20,33 +20,34 @@ include(FindPackageHandleStandardArgs) + find_package(PkgConfig) + find_package(Blas REQUIRED) + +-if(CP2K_BLAS_FOUND) +- # LAPACK in the Intel MKL 10+ library? +- if(CP2K_BLAS_VENDOR MATCHES "MKL|OpenBLAS|Armpl|SCI|FlexiBLAS|NVHPC") +- # we just need to create the interface that's all +- set(CP2K_LAPACK_FOUND TRUE) +- get_target_property(CP2K_LAPACK_INCLUDE_DIRS CP2K::BLAS::blas +- INTERFACE_INCLUDE_DIRECTORIES) +- get_target_property(CP2K_LAPACK_LINK_LIBRARIES CP2K::BLAS::blas +- INTERFACE_LINK_LIBRARIES) +- else() +- # we might get lucky to find a pkgconfig package for lapack (fedora provides +- # one for instance) +- if(PKG_CONFIG_FOUND) +- pkg_check_modules(CP2K_LAPACK lapack) +- endif() ++if(NOT CP2K_CONFIG_PACKAGE) ++ if(CP2K_BLAS_FOUND) ++ # LAPACK in the Intel MKL 10+ library? ++ if(CP2K_BLAS_VENDOR MATCHES "MKL|OpenBLAS|Armpl|SCI|FlexiBLAS|NVHPC") ++ # we just need to create the interface that's all ++ set(CP2K_LAPACK_FOUND TRUE) ++ get_target_property(CP2K_LAPACK_INCLUDE_DIRS CP2K::BLAS::blas ++ INTERFACE_INCLUDE_DIRECTORIES) ++ get_target_property(CP2K_LAPACK_LINK_LIBRARIES CP2K::BLAS::blas ++ INTERFACE_LINK_LIBRARIES) ++ else() ++ # we might get lucky to find a pkgconfig package for lapack (fedora ++ # provides one for instance) ++ if(PKG_CONFIG_FOUND) ++ pkg_check_modules(CP2K_LAPACK lapack) ++ endif() + +- if(NOT CP2K_LAPACK_FOUND) +- find_library( +- CP2K_LAPACK_LINK_LIBRARIES +- NAMES "lapack" "lapack64" +- PATH_SUFFIXES "openblas" "openblas64" "openblas-pthread" +- "openblas-openmp" "lib" "lib64" +- NO_DEFAULT_PATH) ++ if(NOT CP2K_LAPACK_FOUND) ++ find_library( ++ CP2K_LAPACK_LINK_LIBRARIES ++ NAMES "lapack" "lapack64" ++ PATH_SUFFIXES "openblas" "openblas64" "openblas-pthread" ++ "openblas-openmp" "lib" "lib64" ++ NO_DEFAULT_PATH) ++ endif() + endif() + endif() + endif() +- + # check if found + find_package_handle_standard_args(Lapack + REQUIRED_VARS CP2K_LAPACK_LINK_LIBRARIES) +diff --git a/cmake/cp2k.pc.in b/cmake/cp2k.pc.in +deleted file mode 100644 +index 5b4a09566..000000000 +--- a/cmake/cp2k.pc.in ++++ /dev/null +@@ -1,19 +0,0 @@ +-# this template is filled-in by CMake `configure_file(... @ONLY)` +-# the `@....@` are filled in by CMake configure_file(), +-# from variables set in your CMakeLists.txt or by CMake itself +-# +-# Good tutoral for understanding .pc files: +-# https://people.freedesktop.org/~dbn/pkg-config-guide.html +- +-prefix="@CMAKE_INSTALL_PREFIX@" +-exec_prefix="${prefix}" +-libdir="${prefix}/lib" +-includedir="${prefix}/include" +- +-Name: @PROJECT_NAME@ +-Description: @CMAKE_PROJECT_DESCRIPTION@ +-URL: @CMAKE_PROJECT_HOMEPAGE_URL@ +-Version: @PROJECT_VERSION@ +-Cflags: -I"${includedir}" +-Libs: -L"${libdir}" -lcp2k -lcp2k_dbm -lcp2k_grid -lcp2k_offload +-#Libs.private: -L"${libdir}" @CP2K_LIBS@ +\ No newline at end of file +diff --git a/cmake/cp2kConfig.cmake.in b/cmake/cp2kConfig.cmake.in +index a3acd4744..1c310e19b 100644 +--- a/cmake/cp2kConfig.cmake.in ++++ b/cmake/cp2kConfig.cmake.in +@@ -5,112 +5,121 @@ + #! SPDX-License-Identifier: GPL-2.0-or-later ! + #!-------------------------------------------------------------------------------------------------! + +- + cmake_minimum_required(VERSION 3.22) ++include(CMakeFindDependencyMacro) ++ ++if(NOT TARGET cp2k::cp2k) ++ set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/modules" ++ ${CMAKE_MODULE_PATH}) ++ ++ # store CXX compiler id. Used in MKL package. ++ set(CP2K_CXX_COMPILER_ID @CMAKE_CXX_COMPILER_ID@) ++ if(NOT ${CMAKE_CXX_COMPILER_ID}) ++ set(CMAKE_CXX_COMPILER_ID ${CP2K_CXX_COMPILER_ID}) ++ endif() ++ ++ set(CP2K_BLAS_VENDOR @CP2K_BLAS_VENDOR@) ++ set(CP2K_SCALAPACK_VENDOR @CP2K_SCALAPACK_VENDOR@) ++ set(CP2K_BLAS_LINK_LIBRARIES @CP2K_BLAS_LINK_LIBRARIES@) ++ set(CP2K_LAPACK_LINK_LIBRARIES @CP2K_LAPACK_LINK_LIBRARIES@) ++ set(CP2K_SCALAPACK_LINK_LIBRARIES @CP2K_SCALAPACK_LINK_LIBRARIES@) ++ ++ set(CP2K_CONFIG_PACKAGE ON) ++ find_dependency(Lapack REQUIRED) ++ ++ # define lapack and blas TARGETS ++ ++ if(@CP2K_USE_MPI@) ++ find_dependency(SCALAPACK REQUIRED) ++ endif() ++ unset(CP2K_CONFIG_PACKAGE) ++ ++ set(cp2k_VERSION @cp2k_VERSION@) ++ ++ find_dependency(DBCSR 2.5 REQUIRED) ++ ++ if(@CP2K_USE_LIBXSMM@) ++ find_dependency(LibXSMM REQUIRED) ++ endif() ++ ++ if(@CP2K_USE_HIP@) ++ # Find hip ++ find_dependency(hipfft REQUIRED IMPORTED CONFIG) ++ find_dependency(hipblas REQUIRED IMPORTED CONFIG) ++ endif() ++ ++ if(@CP2K_USE_CUDA@) ++ find_dependency(CUDAToolkit REQUIRED) ++ endif() ++ if(@CP2K_USE_ELPA@) ++ find_dependency(Elpa REQUIRED) ++ endif() ++ ++ if(@CP2K_USE_LIBXC@) ++ find_dependency(LibXC 6 REQUIRED EXACT) ++ endif() ++ ++ if(@CP2K_USE_COSMA@) ++ find_dependency(cosma REQUIRED) ++ endif() ++ ++ if(@CP2K_USE_MPI@) ++ find_dependency(MPI REQUIRED) ++ endif() ++ ++ if(@CP2K_USE_FFTW3@ OR @CP2K_USE_FFTW3_WITH_MKL@) ++ find_dependency(Fftw REQUIRED) ++ endif() ++ ++ # QUIP ++ if(@CP2K_USE_QUIP@) ++ find_dependency(Quip REQUIRED) ++ endif() + +-# store CXX compiler id. Used in MKL package. +-set(SIRIUS_CXX_COMPILER_ID @CMAKE_CXX_COMPILER_ID@) +-if(NOT ${CMAKE_CXX_COMPILER_ID}) +- set(CMAKE_CXX_COMPILER_ID ${SIRIUS_CXX_COMPILER_ID}) +-endif() +- +-set(CP2K_BLAS_VENDOR @CP2K_BLAS_VENDOR@) +-set(CP2K_SCALAPACK_VENDOR @CP2K_SCALAPACK_VENDOR@) +- +-if (@CP2K_BLAS_VENDOR@ MATCHES "CUSTOM") +- set(CP2K_BLAS_LINK_LIBRARIES @CP2K_BLAS_LINK_LIBRARIES@) +- set(CP2K_LAPACK_LINK_LIBRARIES @CP2K_LAPACK_LINK_LIBRARIES@) +-endif() +- +-if (@CP2K_SCALAPACK_VENDOR@ MATCHES "CUSTOM") +- set(CP2K_SCALAPACK_LINK_LIBRARIES @CP2K_SCALAPACK_LINK_LIBRARIES@) +-endif() +- +-find_package(Lapack REQUIRED) +-find_package(DBCSR 2.4 REQUIRED) +- +-if(@CP2K_USE_LIBXSMM@ +- find_package(LibXSMM REQUIRED) +-endif() +- +-if (@@CP2K_USE_HIP@) +- # Find hip +- find_package(hipfft REQUIRED IMPORTED CONFIG) +- find_package(hipblas REQUIRED IMPORTED CONFIG) +-endif() +- +-if (@@CP2K_USE_CUDA@) +- find_package(CUDAToolkit REQUIRED) +-endif() +-if(@CP2K_USE_ELPA@) +- find_package(Elpa REQUIRED) +-endif() +- +-if(@CP2K_USE_LIBXC@) +- find_package(LibXC 6 REQUIRED EXACT) +-endif() +- +-if(@CP2K_USE_COSMA@) +- find_package(cosma REQUIRED) +-endif() ++ # libint + +-if (@@CP2K_USE_MPI@) +- find_package(MPI REQUIRED) +- find_package(SCALAPACK REQUIRED) +-endif() ++ if(@CP2K_USE_LIBINT2@) ++ find_dependency(Libint2 REQUIRED) ++ endif() + +-if(@CP2K_USE_FFTW3@) +- find_package(Fftw REQUIRED) +-endif() +- # QUIP +-if(@CP2K_USE_QUIP@) +- find_package(Quip REQUIRED) +-endif() ++ # spglib + +-# libint ++ if(@CP2K_USE_SPGLIB@) ++ find_dependency(LibSPG REQUIRED) ++ endif() + +-if(@CP2K_USE_LIBINT2@) +- find_package(Libint2 REQUIRED) +-endif() ++ if(@CP2K_USE_SPLA@) ++ find_dependency(SPLA REQUIRED) ++ endif() + +-# spglib ++ if(@CP2K_USE_SIRIUS@) ++ find_dependency(sirius REQUIRED) ++ endif() + +-if(@CP2K_USE_SPGLIB@) +- find_package(LibSPG REQUIRED) +-endif() ++ if(@CP2K_USE_SUPERLU@) ++ find_dependency(SuperLU REQUIRED) ++ endif() + +-if(@CP2K_USE_SPLA@) +- find_package(SPLA REQUIRED) +-endif() ++ if(@CP2K_USE_METIS@) ++ find_dependency(Metis) ++ endif() + +-if(@CP2K_USE_SIRIUS@) +- find_package(sirius REQUIRED) +-endif() +- +-if(@CP2K_USE_SUPERLU@) +- find_package(SuperLU REQUIRED) +-endif() ++ if(@CP2K_USE_PEXSI@) ++ # PEXSI 1.2 uses cmake as build system ++ find_dependency(PEXSI REQUIRED) ++ endif() + +-if(@CP2K_USE_PARMETIS@) +- find_package(Metis) +-endif() ++ if(@CP2K_USE_PLUMED@) ++ find_dependency(Plumed REQUIRED) ++ endif() + +-if(@CP2K_USE_PTSCOTCH@) +- find_package(Ptscotch REQUIRED) +-endif() ++ if(@CP2K_USE_LIBTORCH@) ++ find_dependency(Torch REQUIRED) ++ endif() + +-if(@CP2K_USE_PEXSI@) +- # PEXSI 1.2 uses cmake as build system +- find_package(PEXSI REQUIRED) +-endif() ++ include("${CMAKE_CURRENT_LIST_DIR}/cp2kTargets.cmake") + +-if(@CP2K_USE_PLUMED@) +- find_package(Plumed REQUIRED) +-endif() ++ # Clean-up module path. ++ list(REMOVE_ITEM CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/modules") + +-if(@CP2K_USE_LIBTORCH@) +- find_package(Torch REQUIRED) + endif() +- +-# Include SIRIUS target +-include("${CMAKE_CURRENT_LIST_DIR}/cp2kTargets.cmake") +diff --git a/cmake/libcp2k.pc.in b/cmake/libcp2k.pc.in +new file mode 100644 +index 000000000..618af55e2 +--- /dev/null ++++ b/cmake/libcp2k.pc.in +@@ -0,0 +1,11 @@ ++prefix="@CMAKE_INSTALL_PREFIX@" ++exec_prefix="${prefix}" ++libdir="${prefix}/@CMAKE_INSTALL_LIBDIR@" ++includedir="${prefix}/@CMAKE_INSTALL_INCLUDEDIR@" ++ ++Name: @PROJECT_NAME@ ++Description: @CMAKE_PROJECT_DESCRIPTION@ ++URL: @CMAKE_PROJECT_HOMEPAGE_URL@ ++Version: @PROJECT_VERSION@ ++Cflags: -I"${includedir}/cp2k" -I"${includedir}/cp2k/@CMAKE_Fortran_COMPILER_ID@-@CMAKE_Fortran_COMPILER_VERSION@" ++Libs: -L"${libdir}" -lcp2k +diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt +index dbc955885..1178101ad 100644 +--- a/src/CMakeLists.txt ++++ b/src/CMakeLists.txt +@@ -1536,9 +1536,9 @@ target_link_libraries( + $<$:CP2K::LIBSPG::libspg> + $<$:CP2K::Libxc::xc> + $<$:CP2K::ELPA::elpa> +- $<$:CP2K::FFTW3::fftw3> +- $<$:CP2K::FFTW3::fftw3_threads> +- $<$:CP2K::FFTW3::fftw3_omp> ++ $<$:CP2K::FFTW3::fftw3> ++ $<$,$>:CP2K::FFTW3::fftw3_threads> ++ $<$,$>:CP2K::FFTW3::fftw3_omp> + $<$:SPLA::spla> + $<$:CP2K::Libint2::int2> + $<$:${TORCH_LIBRARIES}> +@@ -1555,7 +1555,7 @@ target_compile_definitions( + cp2k + PUBLIC $<$:__parallel> + $<$:__SCALAPACK> +- $<$:__MPI_08> ++ $<$:__MPI_F08> + __COMPILE_DATE=\"${CP2K_TIMESTAMP}\" + __COMPILE_HOST=\"${CP2K_HOST_NAME}\" + __COMPILE_REVISION=\"${CP2K_GIT_HASH}\" +@@ -1577,7 +1577,7 @@ target_compile_definitions( + $<$:__OFFLOAD_GEMM> + $<$:__ELPA> + $<$:__LIBXC> +- $<$:__FFTW3> ++ $<$:__FFTW3> + $<$:__LIBINT> + $<$:__LIBPEXSI> + $<$:__LIBTORCH> +@@ -1774,12 +1774,14 @@ install( + EXPORT cp2k_targets + FILE cp2kTargets.cmake + NAMESPACE cp2k:: +- DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/cp2k") ++ DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}") + +-install(FILES start/libcp2k.h DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/cp2k") ++install(FILES start/libcp2k.h ++ DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}") + + install( + DIRECTORY "${PROJECT_BINARY_DIR}/src/mod_files" +- DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/cp2k" ++ DESTINATION ++ "${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}/${CMAKE_Fortran_COMPILER_ID}-${CMAKE_Fortran_COMPILER_VERSION}" + FILES_MATCHING + PATTERN "*.mod") +-- +2.41.0 + diff --git a/recipes/cp2k/2024.3/mc/repo/packages/cp2k/cmake-relwithdebinfo-2024.1.patch b/recipes/cp2k/2024.3/mc/repo/packages/cp2k/cmake-relwithdebinfo-2024.1.patch new file mode 100644 index 00000000..b974527b --- /dev/null +++ b/recipes/cp2k/2024.3/mc/repo/packages/cp2k/cmake-relwithdebinfo-2024.1.patch @@ -0,0 +1,23 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index 4526160ad..8218a7a3d 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -63,6 +63,18 @@ string(REPLACE "-DNDEBUG" "" CMAKE_C_FLAGS_RELEASE ${CMAKE_C_FLAGS_RELEASE}) + string(REPLACE "-DNDEBUG" "" CMAKE_CXX_FLAGS_RELEASE ${CMAKE_CXX_FLAGS_RELEASE}) + string(REPLACE "-DNDEBUG" "" CMAKE_Fortran_FLAGS_RELEASE + ${CMAKE_Fortran_FLAGS_RELEASE}) ++string(REPLACE "-DNDEBUG" "" CMAKE_C_FLAGS_RELWITHDEBINFO ++ ${CMAKE_C_FLAGS_RELWITHDEBINFO}) ++string(REPLACE "-DNDEBUG" "" CMAKE_CXX_FLAGS_RELWITHDEBINFO ++ ${CMAKE_CXX_FLAGS_RELWITHDEBINFO}) ++string(REPLACE "-DNDEBUG" "" CMAKE_Fortran_FLAGS_RELWITHDEBINFO ++ ${CMAKE_Fortran_FLAGS_RELWITHDEBINFO}) ++string(REPLACE "-DNDEBUG" "" CMAKE_C_FLAGS_MINSIZEREL ++ ${CMAKE_C_FLAGS_MINSIZEREL}) ++string(REPLACE "-DNDEBUG" "" CMAKE_CXX_FLAGS_MINSIZEREL ++ ${CMAKE_CXX_FLAGS_MINSIZEREL}) ++string(REPLACE "-DNDEBUG" "" CMAKE_Fortran_FLAGS_MINSIZEREL ++ ${CMAKE_Fortran_FLAGS_MINSIZEREL}) + + find_package(PkgConfig) + diff --git a/recipes/cp2k/2024.3/mc/repo/packages/cp2k/package.py b/recipes/cp2k/2024.3/mc/repo/packages/cp2k/package.py new file mode 100644 index 00000000..89413c93 --- /dev/null +++ b/recipes/cp2k/2024.3/mc/repo/packages/cp2k/package.py @@ -0,0 +1,1016 @@ +# Copyright 2013-2024 Lawrence Livermore National Security, LLC and other +# Spack Project Developers. See the top-level COPYRIGHT file for details. +# +# SPDX-License-Identifier: (Apache-2.0 OR MIT) +import copy +import os +import os.path +import sys + +import spack.platforms +import spack.util.environment +import spack.util.executable +from spack.build_environment import dso_suffix +from spack.build_systems import cmake, makefile +from spack.package import * + +GPU_MAP = { + "35": "K40", + "37": "K80", + "60": "P100", + "70": "V100", + "80": "A100", + "90": "H100", + "gfx906": "Mi50", + "gfx908": "Mi100", + "gfx90a": "Mi250", + "gfx90a:xnack-": "Mi250", + "gfx90a:xnack+": "Mi250", +} + + +class Cp2k(MakefilePackage, CMakePackage, CudaPackage, ROCmPackage): + """CP2K is a quantum chemistry and solid state physics software package + that can perform atomistic simulations of solid state, liquid, molecular, + periodic, material, crystal, and biological systems + """ + + build_system(conditional("cmake", when="@2023.2:"), "makefile", default="cmake") + + homepage = "https://www.cp2k.org" + url = "https://github.com/cp2k/cp2k/releases/download/v3.0.0/cp2k-3.0.tar.bz2" + git = "https://github.com/cp2k/cp2k.git" + list_url = "https://github.com/cp2k/cp2k/releases" + + maintainers("dev-zero", "mtaillefumier") + + license("GPL-2.0-or-later") + + version("2024.3", sha256="a6eeee773b6b1fb417def576e4049a89a08a0ed5feffcd7f0b33c7d7b48f19ba") + version("2024.2", sha256="cc3e56c971dee9e89b705a1103765aba57bf41ad39a11c89d3de04c8b8cdf473") + version("2024.1", sha256="a7abf149a278dfd5283dc592a2c4ae803b37d040df25d62a5e35af5c4557668f") + version("2023.2", sha256="adbcc903c1a78cba98f49fe6905a62b49f12e3dfd7cedea00616d1a5f50550db") + version("2023.1", sha256="dff343b4a80c3a79363b805429bdb3320d3e1db48e0ff7d20a3dfd1c946a51ce") + version("2022.2", sha256="1a473dea512fe264bb45419f83de432d441f90404f829d89cbc3a03f723b8354") + version("2022.1", sha256="2c34f1a7972973c62d471cd35856f444f11ab22f2ff930f6ead20f3454fd228b") + version("9.1", sha256="fedb4c684a98ad857cd49b69a3ae51a73f85a9c36e9cb63e3b02320c74454ce6") + version("8.2", sha256="2e24768720efed1a5a4a58e83e2aca502cd8b95544c21695eb0de71ed652f20a") + version("8.1", sha256="7f37aead120730234a60b2989d0547ae5e5498d93b1e9b5eb548c041ee8e7772") + version("7.1", sha256="ccd711a09a426145440e666310dd01cc5772ab103493c4ae6a3470898cd0addb") + version("master", branch="master", submodules="True") + + variant("mpi", default=True, description="Enable MPI support") + variant("openmp", default=True, description="Enable OpenMP support") + variant( + "smm", + default="libxsmm", + values=("libxsmm", "libsmm", "blas"), + description="Library for small matrix multiplications", + ) + variant("plumed", default=False, description="Enable PLUMED support") + variant( + "libint", default=True, description="Use libint, required for HFX (and possibly others)" + ) + variant("libxc", default=True, description="Support additional functionals via libxc") + variant( + "pexsi", + default=False, + description="Enable the alternative PEXSI method for density matrix evaluation", + when="+mpi", + ) + variant( + "elpa", + default=False, + description="Enable optimised diagonalisation routines from ELPA", + when="+mpi", + ) + variant( + "dlaf", + default=False, + description="Enable DLA-Future eigensolver and Cholesky decomposition", + when="@2024.1: build_system=cmake +mpi", + ) + # sirius support was introduced in 7, but effectively usable starting from CP2K 9 + variant( + "sirius", + default=False, + description="Enable planewave electronic structure calculations via SIRIUS", + when="@9: +mpi", + ) + variant("cosma", default=False, description="Use COSMA for p?gemm", when="@8: +mpi") + variant( + "libvori", + default=False, + description="Enable support for Voronoi integration and BQB compression", + when="@8:", + ) + variant("spglib", default=False, description="Enable support for spglib") + variant( + "spla", + default=False, + description="Use SPLA off-loading functionality. Only relevant when CUDA or ROCM" + " are enabled", + ) + variant("pytorch", default=False, description="Enable libtorch support") + variant("quip", default=False, description="Enable quip support") + variant("mpi_f08", default=False, description="Use MPI F08 module") + + variant( + "enable_regtests", + default=False, + description="Configure cp2k to run the regtests afterwards." + " It build cp2k normally but put the executables in exe/cmake-build-* instead of the" + " conventional location. This option is only relevant when regtests need to be run.", + ) + + with when("+cuda"): + variant( + "cuda_arch_35_k20x", + default=False, + description=( + "CP2K (resp. DBCSR) has specific parameter sets for" + " different GPU models. Enable this when building" + " with cuda_arch=35 for a K20x instead of a K40" + ), + ) + variant( + "cuda_fft", default=False, description="Use CUDA also for FFTs in the PW part of CP2K" + ) + variant( + "cuda_blas", + default=False, + when="@:7", # req in CP2K v8+ + description="Use CUBLAS for general matrix operations in DBCSR", + ) + + HFX_LMAX_RANGE = range(4, 8) + + variant( + "lmax", + description="Maximum supported angular momentum (HFX and others)", + default="5", + values=[str(x) for x in HFX_LMAX_RANGE], + multi=False, + ) + + depends_on("python@3", type="build") + + depends_on("blas") + depends_on("lapack") + depends_on("fftw-api@3") + + # Force openmp propagation on some providers of blas / fftw-api + with when("+openmp"): + depends_on("fftw+openmp", when="^[virtuals=fftw-api] fftw") + depends_on("amdfftw+openmp", when="^[virtuals=fftw-api] amdfftw") + depends_on("cray-fftw+openmp", when="^[virtuals=fftw-api] cray-fftw") + depends_on("armpl-gcc threads=openmp", when="^[virtuals=blas] armpl-gcc") + depends_on("openblas threads=openmp", when="^[virtuals=blas] openblas") + # The Cray compiler wrappers will automatically add libsci_mp with + # -fopenmp. Since CP2K unconditionally links blas/lapack/scalapack + # we have to be consistent. + depends_on("cray-libsci+openmp", when="^[virtuals=blas] cray-libsci") + + with when("smm=libxsmm"): + depends_on("libxsmm~header-only") + # require libxsmm-1.11+ since 1.10 can leak file descriptors in Fortran + depends_on("libxsmm@1.11:") + depends_on("libxsmm@1.17:", when="@9.1:") + # build needs to be fixed for libxsmm@2 once it is released + depends_on("libxsmm@:1") + # use pkg-config (support added in libxsmm-1.10) to link to libxsmm + depends_on("pkgconfig", type="build") + + with when("+libint"): + depends_on("pkgconfig", type="build", when="@7.0:") + for lmax in HFX_LMAX_RANGE: + depends_on( + "libint@2.6.0:+fortran tune=cp2k-lmax-{0}".format(lmax), + when="@7.0: lmax={0}".format(lmax), + ) + + with when("+libxc"): + depends_on("pkgconfig", type="build", when="@7.0:") + depends_on("libxc@4.0.3:4", when="@7.0:8.1") + depends_on("libxc@5.1.3:5.1", when="@8.2:8") + depends_on("libxc@5.1.7:5.1", when="@9:2022.2") + depends_on("libxc@6.1:", when="@2023.1:") + depends_on("libxc@6.2:", when="@2023.2:") + + with when("+spla"): + depends_on("spla+cuda+fortran", when="+cuda") + depends_on("spla+rocm+fortran", when="+rocm") + + with when("+mpi"): + depends_on("mpi@2:") + depends_on("mpi@3:", when="@2023.1:") + depends_on("scalapack") + depends_on("mpich+fortran", when="^[virtuals=mpi] mpich") + conflicts("~mpi_f08", when="^mpich@4.1:") + + with when("+cosma"): + depends_on("cosma+scalapack") + depends_on("cosma@2.5.1:", when="@9:") + depends_on("cosma@2.6.3:", when="@2023.2:") + depends_on("cosma+cuda", when="+cuda") + depends_on("cosma+rocm", when="+rocm") + + with when("+elpa"): + depends_on("elpa+openmp", when="+openmp") + depends_on("elpa~openmp", when="~openmp") + depends_on("elpa+cuda", when="+cuda") + depends_on("elpa~cuda", when="~cuda") + depends_on("elpa+rocm", when="+rocm") + depends_on("elpa~rocm", when="~rocm") + depends_on("elpa@2021.05:", when="@8.3:") + depends_on("elpa@2021.11.001:", when="@9.1:") + depends_on("elpa@2023.05.001:", when="@2023.2:") + + with when("+dlaf"): + with when("@:2024.1"): + depends_on("dla-future@0.2.1: +scalapack") + depends_on("dla-future ~cuda", when="~cuda") + depends_on("dla-future ~rocm", when="~rocm") + depends_on("dla-future +cuda", when="+cuda") + depends_on("dla-future +rocm", when="+rocm") + + with when("@2024.2:"): + depends_on("dla-future-fortran@0.1.0:") + + # Use a direct dependency on dla-future so that constraints can be expressed + # WARN: In the concretizer output, dla-future will appear as dependency of CP2K + # instead of dla-future-fortran + depends_on("dla-future ~cuda", when="~cuda") + depends_on("dla-future ~rocm", when="~rocm") + depends_on("dla-future +cuda", when="+cuda") + depends_on("dla-future +rocm", when="+rocm") + + conflicts( + "+plumed", + when="@:2024.1 build_system=cmake", + msg="PLUMED support is broken in cp2k@:2024.1 with CMake", + ) + with when("+plumed"): + depends_on("plumed+shared") + depends_on("plumed+mpi", when="+mpi") + depends_on("plumed~mpi", when="~mpi") + + # while we link statically against PEXSI, its own deps may be linked in + # dynamically, therefore can't set this as pure build-type dependency. + depends_on("pexsi+fortran@0.10.0:", when="+pexsi") + + # only OpenMP should be consistently used, all other common things + # like ELPA, SCALAPACK are independent and Spack will ensure that + # a consistent/compatible combination is pulled into the dependency graph. + with when("+sirius"): + depends_on("sirius+fortran+shared") + depends_on("sirius+cuda", when="+cuda") + depends_on("sirius+rocm", when="+rocm") + depends_on("sirius+openmp", when="+openmp") + depends_on("sirius~openmp", when="~openmp") + depends_on("sirius@7.3:", when="@9.1") + depends_on("sirius@7.4:7.5", when="@2023.2") + depends_on("sirius@7.5:", when="@2024.1:") + depends_on("sirius@7.6: +pugixml", when="@2024.2:") + with when("+libvori"): + depends_on("libvori@201219:", when="@8.1") + depends_on("libvori@210412:", when="@8.2:") + depends_on("libvori@220621:", when="@2023.1:") + + # the bundled libcusmm uses numpy in the parameter prediction (v7+) + # which is written using Python 3 + depends_on("py-numpy", when="@7:+cuda") + depends_on("python@3.6:", when="@7:+cuda") + depends_on("py-fypp") + + depends_on("spglib", when="+spglib") + + with when("build_system=cmake"): + depends_on("cmake@3.22:", type="build") + + # DBCSR as external dependency + depends_on("dbcsr@2.6: ~examples") + depends_on("dbcsr+openmp", when="+openmp") + depends_on("dbcsr+mpi", when="+mpi") + depends_on("dbcsr+cuda", when="+cuda") + depends_on("dbcsr+rocm", when="+rocm") + depends_on("dbcsr smm=libxsmm", when="smm=libxsmm") + depends_on("dbcsr smm=blas", when="smm=blas") + + with when("@2022: +rocm"): + depends_on("hipblas") + depends_on("hipfft") + + # CP2K needs compiler specific compilation flags, e.g. optflags + conflicts("%apple-clang") + conflicts("%clang") + conflicts("%nag") + conflicts( + "%aocc@:3.2", + msg="Please use AOCC 4.0+ that better support modern Fortran features CP2K requires", + ) + + conflicts("~openmp", when="@8:", msg="Building without OpenMP is not supported in CP2K 8+") + + # We only support specific cuda_archs for which we have parameter files + # for optimal kernels. Note that we don't override the cuda_archs property + # from the parent class, since the parent class defines constraints for all + # versions. Instead just mark all unsupported cuda archs as conflicting. + + supported_cuda_arch_list = ("35", "37", "60", "70", "80", "90") + supported_rocm_arch_list = ("gfx906", "gfx908", "gfx90a", "gfx90a:xnack-", "gfx90a:xnack+") + cuda_msg = "cp2k only supports cuda_arch {0}".format(supported_cuda_arch_list) + rocm_msg = "cp2k only supports amdgpu_target {0}".format(supported_rocm_arch_list) + + conflicts("+cuda", when="cuda_arch=none") + + # ROCm already emits an error if +rocm amdgpu_target=none is given + + with when("+cuda"): + for arch in CudaPackage.cuda_arch_values: + if arch not in supported_cuda_arch_list: + conflicts("+cuda", when="cuda_arch={0}".format(arch), msg=cuda_msg) + + with when("+rocm"): + for arch in ROCmPackage.amdgpu_targets: + if arch not in supported_rocm_arch_list: + conflicts("+rocm", when="amdgpu_target={0}".format(arch), msg=rocm_msg) + + # Fix 2- and 3-center integral calls to libint + patch( + "https://github.com/cp2k/cp2k/commit/5eaf864ed2bd21fb1b05a9173bb77a815ad4deda.patch?full_index=1", + sha256="3617abb877812c4b933f601438c70f95e21c6161bea177277b1d4125fd1c0bf9", + when="@8.2", + ) + + # Patch for compilers with stricter C99 checks + patch("posix_c_source.patch", when="@7.1%aocc@4.0:") + patch("posix_c_source.patch", when="@7.1%gcc@13:") + + # Fix missing variable in OpenMP private clause + patch( + "https://github.com/cp2k/cp2k/commit/be86bd7f6cd6af7d68f8957dcdb67e7c3d586741.patch?full_index=1", + sha256="1bb5a8e80603684a743e7821d24d41b31b60ccbb7d4257df1d2da53a3630e5bf", + when="@2022.1:2022.2", + ) + + # Avoid using NULL() as subroutine argument as doing so breaks some versions of AOCC compiler + # These patches backport 2023.x fixes to previous versions + patch("backport_avoid_null_2022.x.patch", when="@2022.1:2022.2 %aocc@:4.0") + patch("backport_avoid_null_9.1.patch", when="@9.1 %aocc@:4.0") + patch("cmake-fixes-2023.2.patch", when="@2023.2 build_system=cmake") + + # Allow compilation with build_type=RelWithDebInfo and build_type=MinSizeRel + # after NDEBUG support was dropped in https://github.com/cp2k/cp2k/pull/3172 + # The patch applies https://github.com/cp2k/cp2k/pull/3251 to version 2024.1 + patch("cmake-relwithdebinfo-2024.1.patch", when="@2024.1 build_system=cmake") + + # Patch for an undefined constant due to incompatible changes in ELPA + @when("@9.1:2022.2 +elpa") + def patch(self): + if self.spec["elpa"].satisfies("@2022.05.001:"): + filter_file( + r"ELPA_2STAGE_REAL_INTEL_GPU", + "ELPA_2STAGE_REAL_INTEL_GPU_SYCL", + "src/fm/cp_fm_elpa.F", + ) + + def url_for_version(self, version): + url = "https://github.com/cp2k/cp2k/releases/download/v{0}/cp2k-{0}.tar.bz2" + return url.format(version) + + +class MakefileBuilder(makefile.MakefileBuilder): + def edit(self, pkg, spec, prefix): + pkgconf = which("pkg-config") + + fftw = spec["fftw-api:openmp" if "+openmp" in spec else "fftw-api"] + fftw_header_dir = fftw.headers.directories[0] + + # some providers (mainly Intel) keep the fftw headers in a subdirectory, find it + for incdir in [join_path(f, "fftw") for f in fftw.headers.directories]: + if os.path.exists(incdir): + fftw_header_dir = incdir + break + + optimization_flags = { + "gcc": ["-O2", "-funroll-loops", "-ftree-vectorize"], + "intel": ["-O2", "-pc64", "-unroll"], + "pgi": ["-fast"], + "nvhpc": ["-fast"], + "cce": ["-O2"], + "xl": ["-O3"], + "aocc": ["-O2"], + } + + dflags = ["-DNDEBUG"] if spec.satisfies("@:2023.2") else [] + if fftw.name in ("intel-mkl", "intel-parallel-studio", "intel-oneapi-mkl"): + cppflags = ["-D__FFTW3_MKL", "-I{0}".format(fftw_header_dir)] + else: + cppflags = ["-D__FFTW3", "-I{0}".format(fftw_header_dir)] + + # CP2K requires MPI 3 starting at version 2023.1 + # and __MPI_VERSION is not supported anymore. + if spec.satisfies("@:2022.2"): + if spec.satisfies("^mpi@3:"): + cppflags.append("-D__MPI_VERSION=3") + elif spec.satisfies("^mpi@2:"): + cppflags.append("-D__MPI_VERSION=2") + + cflags = optimization_flags[spec.compiler.name][:] + cxxflags = optimization_flags[spec.compiler.name][:] + fcflags = optimization_flags[spec.compiler.name][:] + nvflags = ["-O3"] + ldflags = [] + libs = [] + + # CP2K Makefile doesn't set C standard + if spec.satisfies("@2023.2:"): + # Use of DBL_DECIMAL_DIG + cflags.append(pkg.compiler.c11_flag) + else: + # C99-style for-loops with inline definition of iterating variable. + cflags.append(pkg.compiler.c99_flag) + + if spec.satisfies("%intel"): + cflags.append("-fp-model precise") + cxxflags.append("-fp-model precise") + fcflags += ["-fp-model precise", "-heap-arrays 64", "-g", "-traceback"] + elif spec.satisfies("%gcc"): + fcflags += [ + "-ffree-form", + "-ffree-line-length-none", + "-ggdb", # make sure we get proper Fortran backtraces + ] + elif spec.satisfies("%aocc"): + fcflags += ["-ffree-form", "-Mbackslash"] + elif spec.satisfies("%pgi") or spec.satisfies("%nvhpc"): + fcflags += ["-Mfreeform", "-Mextend"] + elif spec.satisfies("%cce"): + fcflags += ["-emf", "-ffree", "-hflex_mp=strict"] + elif spec.satisfies("%xl"): + fcflags += ["-qpreprocess", "-qstrict", "-q64"] + ldflags += ["-Wl,--allow-multiple-definition"] + + if "%gcc@10: +mpi" in spec and spec["mpi"].name in ["mpich", "cray-mpich"]: + fcflags += [ + "-fallow-argument-mismatch" + ] # https://github.com/pmodels/mpich/issues/4300 + if spec.satisfies("@7.1%gcc@13:"): + fcflags.append("-fallow-argument-mismatch") + + if spec.satisfies("+openmp"): + cflags.append(pkg.compiler.openmp_flag) + cxxflags.append(pkg.compiler.openmp_flag) + fcflags.append(pkg.compiler.openmp_flag) + ldflags.append(pkg.compiler.openmp_flag) + nvflags.append('-Xcompiler="{0}"'.format(pkg.compiler.openmp_flag)) + elif spec.satisfies("%cce"): # Cray enables OpenMP by default + cflags += ["-hnoomp"] + cxxflags += ["-hnoomp"] + fcflags += ["-hnoomp"] + ldflags += ["-hnoomp"] + + if spec.satisfies("@7:"): # recent versions of CP2K use C++14 CUDA code + cxxflags.append(pkg.compiler.cxx14_flag) + nvflags.append(pkg.compiler.cxx14_flag) + + ldflags.append(fftw.libs.search_flags) + + if spec.satisfies("^superlu-dist@4.3"): + ldflags.insert(0, "-Wl,--allow-multiple-definition") + + if spec.satisfies("+libint"): + cppflags += ["-D__LIBINT"] + + if spec.satisfies("@:6.9"): + cppflags += ["-D__LIBINT_MAX_AM=6", "-D__LIBDERIV_MAX_AM1=5"] + + # libint-1.x.y has to be linked statically to work around + # inconsistencies in its Fortran interface definition + # (short-int vs int) which otherwise causes segfaults at + # runtime due to wrong offsets into the shared library + # symbols. + libs.extend( + [ + join_path(spec["libint"].libs.directories[0], "libderiv.a"), + join_path(spec["libint"].libs.directories[0], "libint.a"), + ] + ) + else: + fcflags += pkgconf("--cflags", "libint2", output=str).split() + libs += pkgconf("--libs", "libint2", output=str).split() + + if spec.satisfies("+libxc"): + cppflags += ["-D__LIBXC"] + + if spec.satisfies("@:6.9"): + libxc = spec["libxc:fortran,static"] + cppflags += [libxc.headers.cpp_flags] + ldflags.append(libxc.libs.search_flags) + libs.append(str(libxc.libs)) + else: + fcflags += pkgconf("--cflags", "libxcf03", output=str).split() + # some Fortran functions seem to be direct wrappers of the + # C functions such that we get a direct dependency on them, + # requiring `-lxc` to be present in addition to `-lxcf03` + libs += pkgconf("--libs", "libxcf03", "libxc", output=str).split() + + if spec.satisfies("+pexsi"): + cppflags.append("-D__LIBPEXSI") + fcflags.append("-I" + join_path(spec["pexsi"].prefix, "fortran")) + libs.extend( + [ + join_path(spec["pexsi"].libs.directories[0], "libpexsi.a"), + join_path(spec["superlu-dist"].libs.directories[0], "libsuperlu_dist.a"), + join_path( + spec["parmetis"].libs.directories[0], "libparmetis.{0}".format(dso_suffix) + ), + join_path( + spec["metis"].libs.directories[0], "libmetis.{0}".format(dso_suffix) + ), + ] + ) + + if spec.satisfies("+elpa"): + elpa = spec["elpa"] + elpa_suffix = "_openmp" if "+openmp" in elpa else "" + elpa_incdir = elpa.headers.directories[0] + + fcflags += ["-I{0}".format(join_path(elpa_incdir, "modules"))] + + # Currently AOCC support only static libraries of ELPA + if spec.satisfies("%aocc"): + libs.append( + join_path( + elpa.prefix.lib, ("libelpa{elpa_suffix}.a".format(elpa_suffix=elpa_suffix)) + ) + ) + else: + libs.append( + join_path( + elpa.libs.directories[0], + ( + "libelpa{elpa_suffix}.{dso_suffix}".format( + elpa_suffix=elpa_suffix, dso_suffix=dso_suffix + ) + ), + ) + ) + + if spec.satisfies("@:4"): + if elpa.satisfies("@:2014.5"): + cppflags.append("-D__ELPA") + elif elpa.satisfies("@2014.6:2015.10"): + cppflags.append("-D__ELPA2") + else: + cppflags.append("-D__ELPA3") + else: + cppflags.append( + "-D__ELPA={0}{1:02d}".format(elpa.version[0], int(elpa.version[1])) + ) + fcflags += ["-I{0}".format(join_path(elpa_incdir, "elpa"))] + + if "+cuda" in spec and "+cuda" in elpa: + cppflags += ["-D__ELPA_NVIDIA_GPU"] + + if spec.satisfies("+sirius"): + sirius = spec["sirius"] + cppflags.append("-D__SIRIUS") + fcflags += ["-I{0}".format(sirius.prefix.include.sirius)] + libs += list(sirius.libs) + + if spec.satisfies("+plumed"): + dflags.extend(["-D__PLUMED2"]) + cppflags.extend(["-D__PLUMED2"]) + libs.extend([join_path(spec["plumed"].prefix.lib, "libplumed.{0}".format(dso_suffix))]) + + if spec.satisfies("+libvori"): + cppflags += ["-D__LIBVORI"] + libvori = spec["libvori"].libs + ldflags += [libvori.search_flags] + libs += libvori + libs += ["-lstdc++"] + + if spec.satisfies("+spglib"): + cppflags += ["-D__SPGLIB"] + spglib = spec["spglib"].libs + ldflags += [spglib.search_flags] + libs += spglib + + cc = spack_cc if "~mpi" in spec else spec["mpi"].mpicc + cxx = spack_cxx if "~mpi" in spec else spec["mpi"].mpicxx + fc = spack_fc if "~mpi" in spec else spec["mpi"].mpifc + + # Intel + if spec.satisfies("%intel"): + cppflags.extend(["-D__INTEL", "-D__HAS_ISO_C_BINDING", "-D__USE_CP2K_TRACE"]) + fcflags.extend(["-diag-disable 8290,8291,10010,10212,11060", "-free", "-fpp"]) + + # FFTW, LAPACK, BLAS + lapack = spec["lapack"].libs + blas = spec["blas"].libs + ldflags.append((lapack + blas).search_flags) + libs.extend([str(x) for x in (fftw.libs, lapack, blas)]) + + if spec.satisfies("platform=darwin"): + cppflags.extend(["-D__NO_STATM_ACCESS"]) + + if spec["blas"].name in ("intel-mkl", "intel-parallel-studio", "intel-oneapi-mkl"): + cppflags += ["-D__MKL"] + elif spec["blas"].name == "accelerate": + cppflags += ["-D__ACCELERATE"] + + if spec.satisfies("+cosma"): + # add before ScaLAPACK to override the p?gemm symbols + cosma = spec["cosma"].libs + ldflags.append(cosma.search_flags) + libs.extend(cosma) + + # MPI + if spec.satisfies("+mpi"): + cppflags.extend(["-D__parallel", "-D__SCALAPACK"]) + + if spec["mpi"].name == "intel-oneapi-mpi": + mpi = [join_path(spec["intel-oneapi-mpi"].libs.directories[0], "libmpi.so")] + else: + mpi = spec["mpi:cxx"].libs + + # while intel-mkl has a mpi variant and adds the scalapack + # libs to its libs, intel-oneapi-mkl does not. + if spec["scalapack"].name == "intel-oneapi-mkl": + mpi_impl = "openmpi" if spec["mpi"].name in ["openmpi", "hpcx-mpi"] else "intelmpi" + scalapack = [ + join_path( + spec["intel-oneapi-mkl"].libs.directories[0], "libmkl_scalapack_lp64.so" + ), + join_path( + spec["intel-oneapi-mkl"].libs.directories[0], + "libmkl_blacs_{0}_lp64.so".format(mpi_impl), + ), + ] + else: + scalapack = spec["scalapack"].libs + ldflags.append(scalapack.search_flags) + + libs.extend(scalapack) + libs.extend(mpi) + libs.extend(pkg.compiler.stdcxx_libs) + + if spec.satisfies("+mpi_f08"): + cppflags.append("-D__MPI_F08") + + if spec.satisfies("^wannier90"): + cppflags.append("-D__WANNIER90") + wannier = join_path(spec["wannier90"].libs.directories[0], "libwannier.a") + libs.append(wannier) + + gpuver = "" + if spec.satisfies("+cuda"): + libs += [ + "-L{}".format(spec["cuda"].libs.directories[0]), + "-L{}/stubs".format(spec["cuda"].libs.directories[0]), + "-lcuda", + "-lcudart", + "-lnvrtc", + "-lstdc++", + ] + + if spec.satisfies("@9:"): + if spec.satisfies("@2022:"): + cppflags += ["-D__OFFLOAD_CUDA"] + + acc_compiler_var = "OFFLOAD_CC" + acc_flags_var = "OFFLOAD_FLAGS" + cppflags += ["-D__DBCSR_ACC", "-D__GRID_CUDA", "-DOFFLOAD_TARGET=cuda"] + libs += ["-lcublas"] + + if spec.satisfies("+cuda_fft"): + if spec.satisfies("@:9"): + cppflags += ["-D__PW_CUDA"] + + libs += ["-lcufft"] + else: + if spec.satisfies("@2022:"): + cppflags += ["-D__NO_OFFLOAD_PW"] + else: + acc_compiler_var = "NVCC" + acc_flags_var = "NVFLAGS" + cppflags += ["-D__ACC"] + if spec.satisfies("+cuda_blas"): + cppflags += ["-D__DBCSR_ACC=2"] + libs += ["-lcublas"] + else: + cppflags += ["-D__DBCSR_ACC"] + + if spec.satisfies("+cuda_fft"): + cppflags += ["-D__PW_CUDA"] + libs += ["-lcufft", "-lcublas"] + + cuda_arch = spec.variants["cuda_arch"].value[0] + gpuver = GPU_MAP[cuda_arch] + if cuda_arch == "35" and spec.satisfies("+cuda_arch_35_k20x"): + gpuver = "K20X" + + if spec.satisfies("@2022: +rocm"): + libs += [ + "-L{}".format(spec["rocm"].libs.directories[0]), + "-L{}/stubs".format(spec["rocm"].libs.directories[0]), + "-lhipblas", + "-lhipfft", + "-lstdc++", + ] + + cppflags += ["-D__OFFLOAD_HIP"] + acc_compiler_var = "hipcc" + acc_flags_var = "NVFLAGS" + cppflags += ["-D__ACC"] + cppflags += ["-D__DBCSR_ACC"] + gpuver = GPU_MAP[spec.variants["amdgpu_target"].value[0]] + + if spec.satisfies("smm=libsmm"): + lib_dir = join_path("lib", self.makefile_architecture, self.makefile_version) + mkdirp(lib_dir) + try: + copy(env["LIBSMM_PATH"], join_path(lib_dir, "libsmm.a")) + except KeyError: + raise KeyError( + "Point environment variable LIBSMM_PATH to " + "the absolute path of the libsmm.a file" + ) + except IOError: + raise IOError( + "The file LIBSMM_PATH pointed to does not " + "exist. Note that it must be absolute path." + ) + cppflags.extend(["-D__HAS_smm_dnn", "-D__HAS_smm_vec"]) + libs.append("-lsmm") + + elif spec.satisfies("smm=libxsmm"): + cppflags += ["-D__LIBXSMM"] + cppflags += pkgconf("--cflags-only-other", "libxsmmf", output=str).split() + fcflags += pkgconf("--cflags-only-I", "libxsmmf", output=str).split() + libs += pkgconf("--libs", "libxsmmf", output=str).split() + + dflags.extend(cppflags) + cflags.extend(cppflags) + cxxflags.extend(cppflags) + fcflags.extend(cppflags) + nvflags.extend(cppflags) + + with open(self.makefile, "w") as mkf: + if spec.satisfies("+plumed"): + mkf.write( + "# include Plumed.inc as recommended by" + "PLUMED to include libraries and flags" + ) + mkf.write("include {0}\n".format(spec["plumed"].package.plumed_inc)) + + mkf.write("\n# COMPILER, LINKER, TOOLS\n\n") + mkf.write( + "FC = {0}\n" "CC = {1}\n" "CXX = {2}\n" "LD = {3}\n".format(fc, cc, cxx, fc) + ) + + if spec.satisfies("%intel"): + intel_bin_dir = ancestor(pkg.compiler.cc) + # CPP is a commented command in Intel arch of CP2K + # This is the hack through which cp2k developers avoid doing : + # + # ${CPP} .F > .f90 + # + # and use `-fpp` instead + mkf.write("CPP = # {0} -P\n".format(spack_cc)) + mkf.write("AR = {0}/xiar -qs\n".format(intel_bin_dir)) + else: + mkf.write("CPP = # {0} -E\n".format(spack_cc)) + mkf.write("AR = ar -qs\n") # r = qs is a GNU extension + + if spec.satisfies("+cuda"): + mkf.write( + "{0} = {1}\n".format( + acc_compiler_var, join_path(spec["cuda"].prefix, "bin", "nvcc") + ) + ) + + # Write compiler flags to file + def fflags(var, lst): + return "{0} = {1}\n\n".format(var, " \\\n\t".join(lst)) + + mkf.write("\n# FLAGS & LIBRARIES\n") + mkf.write(fflags("DFLAGS", dflags)) + mkf.write(fflags("CPPFLAGS", cppflags)) + mkf.write(fflags("CFLAGS", cflags)) + mkf.write(fflags("CXXFLAGS", cxxflags)) + if spec.satisfies("+cuda"): + mkf.write(fflags(acc_flags_var, nvflags)) + mkf.write(fflags("FCFLAGS", fcflags)) + mkf.write(fflags("LDFLAGS", ldflags)) + mkf.write(fflags("LIBS", libs)) + + if spec.satisfies("%intel"): + mkf.write(fflags("LDFLAGS_C", ldflags + ["-nofor-main"])) + + mkf.write("# CP2K-specific flags\n\n") + mkf.write("GPUVER = {0}\n".format(gpuver)) + mkf.write("DATA_DIR = {0}\n".format(prefix.share.data)) + + def build(self, pkg, spec, prefix): + if "+cuda" in spec and len(spec.variants["cuda_arch"].value) > 1: + raise InstallError("cp2k supports only one cuda_arch at a time") + + # Apparently the Makefile bases its paths on PWD + # so we need to set PWD = self.build_directory + with spack.util.environment.set_env(PWD=self.build_directory): + super().build(pkg, spec, prefix) + + with working_dir(self.build_directory): + make("libcp2k", *self.build_targets) + + def install(self, pkg, spec, prefix): + exe_dir = join_path("exe", self.makefile_architecture) + lib_dir = join_path("lib", self.makefile_architecture, self.makefile_version) + + install_tree(exe_dir, self.prefix.bin) + install_tree("data", self.prefix.share.data) + install_tree(lib_dir, self.prefix.lib) + + mkdirp(self.prefix.include) + install("src/start/libcp2k.h", join_path(self.prefix.include, "libcp2k.h")) + + @property + def build_directory(self): + build_dir = self.pkg.stage.source_path + + if self.spec.satisfies("@:6"): + # prior to version 7.1 was the Makefile located in makefiles/ + build_dir = join_path(build_dir, "makefiles") + + return build_dir + + @property + def build_targets(self): + return [ + "ARCH={0}".format(self.makefile_architecture), + "VERSION={0}".format(self.makefile_version), + ] + + @property + def makefile(self): + makefile_basename = ".".join([self.makefile_architecture, self.makefile_version]) + return join_path("arch", makefile_basename) + + @property + def makefile_architecture(self): + return "{0.architecture}-{0.compiler.name}".format(self.spec) + + @property + def makefile_version(self): + return "{prefix}{suffix}".format( + prefix="p" if "+mpi" in self.spec else "s", + suffix="smp" if "+openmp" in self.spec else "opt", + ) + + @property + def archive_files(self): + return [join_path(self.pkg.stage.source_path, self.makefile)] + + def check(self): + data_dir = join_path(self.pkg.stage.source_path, "data") + + # CP2K < 7 still uses $PWD to detect the current working dir + # and Makefile is in a subdir, account for both facts here: + with spack.util.environment.set_env(CP2K_DATA_DIR=data_dir, PWD=self.build_directory): + with working_dir(self.build_directory): + make("test", *self.build_targets) + + @run_after("install", when="@9.1:") + def fix_package_config(self): + """ + Default build procedure generates libcp2k.pc with invalid paths, + because they are collected from temporary directory. + + Ignoring invalid paths, most library-related switches are correct + except for fftw and openblas. + + This procedure is appending two missing switches (tested with GROMACS 2022.2 + CP2K). + + In case such approach causes issues in the future, it might be necessary + to generate and override entire libcp2k.pc. + """ + pkgconfig_file = join_path(self.prefix.lib.pkgconfig, "libcp2k.pc") + filter_file(r"(^includedir=).*", r"\1{0}".format(self.prefix.include), pkgconfig_file) + filter_file(r"(^libdir=).*", r"\1{0}".format(self.prefix.lib), pkgconfig_file) + + with open(pkgconfig_file, "r+") as handle: + content = handle.read().rstrip() + + content += " " + self.spec["blas"].libs.ld_flags + content += " " + self.spec["lapack"].libs.ld_flags + content += " " + self.spec["fftw-api"].libs.ld_flags + + fftw = self.spec["fftw-api"] + if fftw.name in ["fftw", "amdfftw"] and fftw.satisfies("+openmp"): + content += " -lfftw3_omp" + + content += "\n" + + handle.seek(0) + handle.write(content) + + +class CMakeBuilder(cmake.CMakeBuilder): + def cmake_args(self): + spec = self.spec + args = [] + + if spec.satisfies("+cuda"): + if (len(spec.variants["cuda_arch"].value) > 1) or spec.satisfies("cuda_arch=none"): + raise InstallError("CP2K supports only one cuda_arch at a time.") + else: + gpu_ver = GPU_MAP[spec.variants["cuda_arch"].value[0]] + args += [ + self.define("CP2K_USE_ACCEL", "CUDA"), + self.define("CP2K_WITH_GPU", gpu_ver), + ] + + if spec.satisfies("+rocm"): + if len(spec.variants["amdgpu_target"].value) > 1: + raise InstallError("CP2K supports only one amdgpu_target at a time.") + else: + gpu_ver = GPU_MAP[spec.variants["amdgpu_target"].value[0]] + args += [ + self.define("CP2K_USE_ACCEL", "HIP"), + self.define("CP2K_WITH_GPU", gpu_ver), + ] + + args += [ + self.define_from_variant("CP2K_ENABLE_REGTESTS", "enable_regtests"), + self.define_from_variant("CP2K_USE_ELPA", "elpa"), + self.define_from_variant("CP2K_USE_DLAF", "dlaf"), + self.define_from_variant("CP2K_USE_LIBINT2", "libint"), + self.define_from_variant("CP2K_USE_SIRIUS", "sirius"), + self.define_from_variant("CP2K_USE_SPLA", "spla"), + self.define_from_variant("CP2K_USE_COSMA", "cosma"), + self.define_from_variant("CP2K_USE_LIBXC", "libxc"), + self.define_from_variant("CP2K_USE_LIBTORCH", "pytorch"), + self.define_from_variant("CP2K_USE_METIS", "pexsi"), + self.define_from_variant("CP2K_USE_SUPERLU", "pexsi"), + self.define_from_variant("CP2K_USE_PLUMED", "plumed"), + self.define_from_variant("CP2K_USE_SPGLIB", "spglib"), + self.define_from_variant("CP2K_USE_VORI", "libvori"), + self.define_from_variant("CP2K_USE_SPLA", "spla"), + self.define_from_variant("CP2K_USE_QUIP", "quip"), + self.define_from_variant("CP2K_USE_MPI_F08", "mpi_f08"), + ] + + # we force the use elpa openmp threading support. might need to be revisited though + args += [ + self.define( + "CP2K_ENABLE_ELPA_OPENMP_SUPPORT", + ("+elpa +openmp" in spec) or ("^elpa +openmp" in spec), + ) + ] + + if "spla" in spec and (spec.satisfies("+cuda") or spec.satisfies("+rocm")): + args += ["-DCP2K_USE_SPLA_GEMM_OFFLOADING=ON"] + + args += ["-DCP2K_USE_FFTW3=ON"] + + if spec.satisfies("smm=libxsmm"): + args += ["-DCP2K_USE_LIBXSMM=ON"] + else: + args += ["-DCP2K_USE_LIBXSMM=OFF"] + + lapack = spec["lapack"] + blas = spec["blas"] + + if blas.name in ["intel-mkl", "intel-parallel-studio", "intel-oneapi-mkl"]: + args += ["-DCP2K_BLAS_VENDOR=MKL"] + if sys.platform == "darwin": + args += [ + self.define("CP2K_BLAS_VENDOR", "CUSTOM"), + self.define("CP2K_SCALAPACK_VENDOR", "GENERIC"), + self.define( + "CP2K_SCALAPACK_LINK_LIBRARIES", spec["scalapack"].libs.joined(";") + ), + ] + else: + args += ["-DCP2K_SCALAPACK_VENDOR=MKL"] + else: + args.extend( + [ + self.define("CP2K_LAPACK_FOUND", True), + self.define("CP2K_LAPACK_LINK_LIBRARIES", lapack.libs.joined(";")), + self.define("CP2K_BLAS_FOUND", True), + self.define("CP2K_BLAS_LINK_LIBRARIES", blas.libs.joined(";")), + self.define("CP2K_SCALAPACK_FOUND", True), + self.define("CP2K_SCALAPACK_INCLUDE_DIRS", spec["scalapack"].prefix.include), + self.define("CP2K_BLAS_VENDOR", "CUSTOM"), + self.define("CP2K_SCALAPACK_VENDOR", "GENERIC"), + self.define( + "CP2K_SCALAPACK_LINK_LIBRARIES", spec["scalapack"].libs.joined(";") + ), + ] + ) + + return args diff --git a/recipes/cp2k/2024.3/mc/repo/packages/cp2k/posix_c_source.patch b/recipes/cp2k/2024.3/mc/repo/packages/cp2k/posix_c_source.patch new file mode 100644 index 00000000..87a544a7 --- /dev/null +++ b/recipes/cp2k/2024.3/mc/repo/packages/cp2k/posix_c_source.patch @@ -0,0 +1,12 @@ +--- a/src/sockets.c 2019-12-24 01:41:57.000000000 +0530 ++++ b/src/sockets.c 2023-05-15 18:35:33.941236292 +0530 +@@ -35,6 +35,7 @@ + */ + #ifndef __NO_IPI_DRIVER + ++#define _POSIX_C_SOURCE 200112L + #include + #include + #include + + diff --git a/recipes/cp2k/2024.3/mc/repo/packages/dbcsr/package.py b/recipes/cp2k/2024.3/mc/repo/packages/dbcsr/package.py new file mode 100644 index 00000000..112c4293 --- /dev/null +++ b/recipes/cp2k/2024.3/mc/repo/packages/dbcsr/package.py @@ -0,0 +1,184 @@ +# Copyright 2013-2024 Lawrence Livermore National Security, LLC and other +# Spack Project Developers. See the top-level COPYRIGHT file for details. +# +# SPDX-License-Identifier: (Apache-2.0 OR MIT) + +from spack.package import * + + +class Dbcsr(CMakePackage, CudaPackage, ROCmPackage): + """Distributed Block Compressed Sparse Row matrix library.""" + + homepage = "https://github.com/cp2k/dbcsr" + git = "https://github.com/cp2k/dbcsr.git" + url = "https://github.com/cp2k/dbcsr/releases/download/v2.2.0/dbcsr-2.2.0.tar.gz" + list_url = "https://github.com/cp2k/dbcsr/releases" + + maintainers("dev-zero", "mtaillefumier") + + license("GPL-2.0-or-later") + + version("develop", branch="develop") + version("2.7.0", sha256="25c367b49fb108c5230bcfb127f05fc16deff2bb467f437023dfa6045aff66f6") + version("2.6.0", sha256="c67b02ff9abc7c1f529af446a9f01f3ef9e5b0574f220259128da8d5ca7e9dc6") + version("2.5.0", sha256="91fda9b2502e5d0a2a6cdd5a73ef096253cc7e75bd01ba5189a4726ad86aef08") + version("2.4.1", sha256="b3d5ae62ca582b72707a2c932e8074a4f2f61d61085d97bd374213c70b8dbdcf") + version("2.4.0", sha256="cf2b774328c9a30677501f49b79955841bd08915a7ca53c8533bfdf14a8f9bd4") + version("2.3.0", sha256="f750de586cffa66852b646f7f85eb831eeb64fa2d25ce50ed10e1df016dd3364") + version("2.2.0", sha256="245b0382ddc7b80f85af8288f75bd03d56ec51cdfb6968acb4931529b35173ec") + version("2.1.0", sha256="9e58fd998f224632f356e479d18b5032570d00d87b86736b6a6ac2d03f8d4b3c") + version("2.0.1", sha256="61d5531b661e1dab043353a1d67939ddcde3893d3dc7b0ab3d05074d448b485c") + + variant("mpi", default=True, description="Compile with MPI") + variant("openmp", default=False, description="Build with OpenMP support") + variant("shared", default=True, description="Build shared library") + variant( + "smm", + default="libxsmm", + values=("libxsmm", "blas"), + description="Library for small matrix multiplications", + ) + variant( + "cuda_arch_35_k20x", + default=False, + description=( + "CP2K (resp. DBCSR) has specific parameter sets for" + " different GPU models. Enable this when building" + " with cuda_arch=35 for a K20x instead of a K40" + ), + ) + variant("examples", default=True, description="Build examples") + + variant("opencl", default=False, description="Enable OpenCL backend") + variant("mpi_f08", default=False, when="@2.6:", description="Use mpi F08 module") + + depends_on("blas") + depends_on("lapack") + depends_on("mpi", when="+mpi") + + with when("smm=libxsmm"): + depends_on("libxsmm~header-only") + depends_on("libxsmm@1.11:1") + + depends_on("cmake@3.10:", type="build") + depends_on("cmake@3.12:", type="build", when="@2.1:") + depends_on("cmake@3.17:", type="build", when="@2.2:") + depends_on("cmake@3.22:", type="build", when="@2.3:") + + depends_on("py-fypp", type="build") + depends_on("py-fypp@3.1:", type="build", when="@2.6:") + depends_on("pkgconfig", type="build") + depends_on("python@3.6:", type="build", when="+cuda") + + depends_on("hipblas", when="+rocm") + + depends_on("opencl", when="+opencl") + + # All examples require MPI + conflicts("+examples", when="~mpi", msg="Examples require MPI") + + # We only support specific gpu archs for which we have parameter files + # for optimal kernels. Note that we don't override the parent class arch + # properties, since the parent class defines constraints for different archs + # Instead just mark all unsupported cuda archs as conflicting. + dbcsr_cuda_archs = ("35", "37", "60", "70", "80", "90") + cuda_msg = "dbcsr only supports cuda_arch {0}".format(dbcsr_cuda_archs) + + for arch in CudaPackage.cuda_arch_values: + if arch not in dbcsr_cuda_archs: + conflicts("+cuda", when="cuda_arch={0}".format(arch), msg=cuda_msg) + + conflicts("+cuda", when="cuda_arch=none", msg=cuda_msg) + + dbcsr_amdgpu_targets = {"gfx906", "gfx910", "gfx90a", "gfx90a:xnack-", "gfx90a:xnack+"} + amd_msg = "DBCSR only supports amdgpu_target {0}".format(dbcsr_amdgpu_targets) + + for arch in ROCmPackage.amdgpu_targets: + if arch not in dbcsr_amdgpu_targets: + conflicts("+rocm", when="amdgpu_target={0}".format(arch), msg=amd_msg) + + accel_msg = "CUDA, ROCm and OpenCL support are mutually exlusive" + conflicts("+cuda", when="+rocm", msg=accel_msg) + conflicts("+cuda", when="+opencl", msg=accel_msg) + conflicts("+rocm", when="+opencl", msg=accel_msg) + + # Require openmp threading for OpenBLAS by making other options conflict + conflicts("^openblas threads=pthreads", when="+openmp") + conflicts("^openblas threads=none", when="+openmp") + + conflicts("smm=blas", when="+opencl") + + with when("+mpi"): + # When using mpich 4.1 or higher, mpi_f08 has to be used, otherwise: + # Error: Type mismatch in argument 'baseptr' at (1); passed TYPE(c_ptr) + # to INTEGER(8) + conflicts("^mpich@4.1:", when="@:2.5") + conflicts("~mpi_f08", when="^mpich@4.1:") + depends_on("mpich+fortran", when="^[virtuals=mpi] mpich") + + generator("ninja") + depends_on("ninja@1.10:", type="build") + + def cmake_args(self): + spec = self.spec + + if "+cuda" in spec and len(spec.variants["cuda_arch"].value) > 1: + raise InstallError("dbcsr supports only one cuda_arch at a time") + + if "+rocm" in spec and len(spec.variants["amdgpu_target"].value) > 1: + raise InstallError("DBCSR supports only one amdgpu_arch at a time") + + args = [ + "-DUSE_SMM=%s" % ("libxsmm" if "smm=libxsmm" in spec else "blas"), + self.define_from_variant("USE_MPI", "mpi"), + self.define_from_variant("USE_OPENMP", "openmp"), + # C API needs MPI + self.define_from_variant("WITH_C_API", "mpi"), + "-DBLAS_FOUND=true", + "-DBLAS_LIBRARIES=%s" % (spec["blas"].libs.joined(";")), + "-DLAPACK_FOUND=true", + "-DLAPACK_LIBRARIES=%s" % (spec["lapack"].libs.joined(";")), + self.define_from_variant("BUILD_SHARED_LIBS", "shared"), + self.define_from_variant("WITH_EXAMPLES", "examples"), + ] + + # Switch necessary as a result of a bug. + if "@2.1:2.2" in spec: + args += ["-DBUILD_TESTING=ON"] + + if self.spec.satisfies("+cuda"): + cuda_arch = self.spec.variants["cuda_arch"].value[0] + + gpu_map = {"35": "K40", "37": "K80", "60": "P100", "70": "V100", "80": "A100", "90": "H100"} + + gpuver = gpu_map[cuda_arch] + if cuda_arch == "35" and self.spec.satisfies("+cuda_arch_35_k20x"): + gpuver = "K20X" + + args += ["-DWITH_GPU=%s" % gpuver, "-DUSE_ACCEL=cuda"] + + if self.spec.satisfies("+rocm"): + amd_arch = self.spec.variants["amdgpu_target"].value[0] + gpuver = { + "gfx906": "Mi50", + "gfx908": "Mi100", + "gfx90a": "Mi250", + "gfx90a:xnack-": "Mi250", + "gfx90a:xnack+": "Mi250", + }[amd_arch] + + args += ["-DWITH_GPU={0}".format(gpuver), "-DUSE_ACCEL=hip"] + + if self.spec.satisfies("+opencl"): + args += ["-DUSE_ACCEL=opencl"] + + if self.spec.satisfies("+mpi_f08"): + args += ["-DUSE_MPI_F08=ON"] + + return args + + def check(self): + """Override CMakePackage's check() to enforce seralized test runs + since they are already parallelized""" + with working_dir(self.build_directory): + self._if_ninja_target_execute("test", parallel=False) diff --git a/recipes/cp2k/2024.3/mc/repo/packages/dla-future-fortran/package.py b/recipes/cp2k/2024.3/mc/repo/packages/dla-future-fortran/package.py new file mode 100644 index 00000000..ea6a50c7 --- /dev/null +++ b/recipes/cp2k/2024.3/mc/repo/packages/dla-future-fortran/package.py @@ -0,0 +1,52 @@ +# Copyright 2013-2024 Lawrence Livermore National Security, LLC and other +# Spack Project Developers. See the top-level COPYRIGHT file for details. +# +# SPDX-License-Identifier: (Apache-2.0 OR MIT) + +# dlaf-no-license-check +from spack.package import * + + +class DlaFutureFortran(CMakePackage): + """ + Fortran interface to the DLA-Future library. + """ + + homepage = "https://github.com/eth-cscs/DLA-Future-Fortran" + url = "https://github.com/eth-cscs/DLA-Future-Fortran/archive/v0.0.0.tar.gz" + git = "https://github.com/eth-cscs/DLA-Future-Fortran.git" + + maintainers("RMeli", "rasolca", "aurianer") + + license("BSD-3-Clause") + + version("main", branch="main") + version("0.2.0", sha256="7fd3e1779c111b35f0d2701a024398b4f6e8dea4af523b6c8617d28c0b7ae61a") + version("0.1.0", sha256="9fd8a105cbb2f3e1daf8a49910f98fce68ca0b954773dba98a91464cf2e7c1da") + + depends_on("fortran", type="build") # generated + + variant("shared", default=True, description="Build shared libraries.") + variant("test", default=False, description="Build tests.") + + generator("ninja") + depends_on("cmake@3.22:", type="build") + + depends_on("dla-future@0.4.1:0.5 +scalapack", when="@0.1.0") + depends_on("dla-future@0.6.0: +scalapack", when="@0.2.0:") + depends_on("dla-future +shared", when="+shared") + + depends_on("mpi", when="+test") + depends_on("py-fypp", when="+test", type="build") + + def cmake_args(self): + args = [] + + args.append(self.define_from_variant("BUILD_SHARED_LIBS", "shared")) + + if self.spec.satisfies("+test"): + args.append(self.define("DLAF_FORTRAN_BUILD_TESTING", True)) + # Tests run with 6 MPI ranks + args.append(self.define("MPIEXEC_MAX_NUMPROCS", 6)) + + return args diff --git a/recipes/cp2k/2024.3/mc/repo/packages/elpa/fujitsu.patch b/recipes/cp2k/2024.3/mc/repo/packages/elpa/fujitsu.patch new file mode 100644 index 00000000..d3600cf6 --- /dev/null +++ b/recipes/cp2k/2024.3/mc/repo/packages/elpa/fujitsu.patch @@ -0,0 +1,65 @@ +From 8bda2149e4398bb6e6b66e601151966c91f9ec78 Mon Sep 17 00:00:00 2001 +From: m-shunji +Date: Wed, 13 Sep 2023 17:58:26 +0900 +Subject: [PATCH] Fix compile error in disabling openmp + +--- + src/elpa_impl_math_template.F90 | 6 +++--- + test/Fortran/test_autotune.F90 | 4 ++-- + 2 files changed, 5 insertions(+), 5 deletions(-) + +diff --git a/src/elpa_impl_math_template.F90 b/src/elpa_impl_math_template.F90 +index f87a0ad..b41c0c3 100644 +--- a/src/elpa_impl_math_template.F90 ++++ b/src/elpa_impl_math_template.F90 +@@ -888,10 +888,10 @@ + #endif + #ifdef COMPLEXCASE + #ifdef DOUBLE_PRECISION_COMPLEX +- & !bind(C, name="elpa_solve_tridiagonal_dc") ++ bind(C, name="elpa_solve_tridiagonal_dc") + #endif + #ifdef SINGLE_PRECISION_COMPLEX +- & !bind(C, name="elpa_solve_tridiagonal_fc") ++ bind(C, name="elpa_solve_tridiagonal_fc") + #endif + #endif + +@@ -913,4 +913,4 @@ + &ELPA_IMPL_SUFFIX& + & (self, d, e, q, error) + end subroutine +- +\ No newline at end of file ++ +diff --git a/test/Fortran/test_autotune.F90 b/test/Fortran/test_autotune.F90 +index 4662564..5355ab3 100644 +--- a/test/Fortran/test_autotune.F90 ++++ b/test/Fortran/test_autotune.F90 +@@ -312,8 +312,8 @@ program test + status = check_correctness_analytic(na, nev, ev, z, nblk, myid, np_rows, np_cols, my_prow, my_pcol, & + .true., .true., print_times=.false.) + a(:,:) = as(:,:) +- call e%autotune_print_state(tune_state) +- call e%autotune_save_state(tune_state, "saved_state_"//trim(iter_string)//".txt") ++ call e%autotune_print_state(tune_state, error_elpa) ++ call e%autotune_save_state(tune_state, "saved_state_"//trim(iter_string)//".txt", error_elpa) + end do + + !! set and print the autotuned-settings +-- +1.8.3.1 +diff --git a/manual_cpp b/manual_cpp +index 6f74a79..dbdfc65 100755 +--- a/manual_cpp ++++ b/manual_cpp +@@ -46,7 +46,7 @@ elif len(files) == 0: + elif len(files) == 1: + file, = files + +-tmp_filename = "manually_preprocessed_" + file.replace("/", "_") ++tmp_filename = "manually_preprocessed_" + file.replace("/", "_").replace("-", "_") + + try: + output = args.index("-o") + diff --git a/recipes/cp2k/2024.3/mc/repo/packages/elpa/package.py b/recipes/cp2k/2024.3/mc/repo/packages/elpa/package.py new file mode 100644 index 00000000..eb5b8dd2 --- /dev/null +++ b/recipes/cp2k/2024.3/mc/repo/packages/elpa/package.py @@ -0,0 +1,238 @@ +# Copyright 2013-2024 Lawrence Livermore National Security, LLC and other +# Spack Project Developers. See the top-level COPYRIGHT file for details. +# +# SPDX-License-Identifier: (Apache-2.0 OR MIT) + +import os + +from spack.package import * + +# +# Please note that you can open issues on the github page of ELPA: +# https://github.com/marekandreas/elpa/issues +# + + +class Elpa(AutotoolsPackage, CudaPackage, ROCmPackage): + """Eigenvalue solvers for Petaflop-Applications (ELPA)""" + + homepage = "https://elpa.mpcdf.mpg.de/" + url = "https://elpa.mpcdf.mpg.de/software/tarball-archive/Releases/2015.11.001/elpa-2015.11.001.tar.gz" + git = "https://gitlab.mpcdf.mpg.de/elpa/elpa.git" + + license("LGPL-3.0-only") + + version("master", branch="master") + + version( + "2024.03.001", sha256="41c6cbf56d2dac26443faaba8a77307d261bf511682a64b96e24def77c813622" + ) + version( + "2023.11.001-patched", + sha256="62ee109afc06539507f459c08b958dc4db65b757dbd77f927678c77f7687415e", + url="https://elpa.mpcdf.mpg.de/software/tarball-archive/Releases/2023.11.001/elpa-2023.11.001-patched.tar.gz", + ) + version( + "2023.05.001", sha256="ec64be5d6522810d601a3b8e6a31720e3c3eb4af33a434d8a64570d76e6462b6" + ) + version( + "2022.11.001", sha256="75db3ac146f9a6a1598e3418ddcab2be2f40a30ef9ec4c00a3b5d3808c99c430" + ) + version( + "2021.11.001", sha256="fb361da6c59946661b73e51538d419028f763d7cb9dacf9d8cd5c9cd3fb7802f" + ) + version( + "2021.05.002_bugfix", + sha256="deabc48de5b9e4b2f073d749d335c8f354a7ce4245b643a23b7951cd6c90224b", + ) + version( + "2021.05.001", sha256="a4f1a4e3964f2473a5f8177f2091a9da5c6b5ef9280b8272dfefcbc3aad44d41" + ) + +# depends_on("c", type="build") # generated +# depends_on("cxx", type="build") # generated +# depends_on("fortran", type="build") # generated + + variant("openmp", default=True, description="Activates OpenMP support") + variant("mpi", default=True, description="Activates MPI support") + + with when("@2021.11.001:"): + variant( + "autotune", default=False, description="Enables autotuning for matrix restribution" + ) + variant( + "gpu_streams", default=True, when="+cuda", description="Activates GPU streams support" + ) + + patch("fujitsu.patch", when="%fj") + + depends_on("autoconf@2.71:", type="build", when="@master") + depends_on("automake", type="build", when="@master") + + depends_on("blas") + depends_on("lapack") + depends_on("mpi", when="+mpi") + depends_on("scalapack", when="+mpi") + depends_on("rocblas", when="+rocm") + depends_on("libtool", type="build") + depends_on("python@3:", type="build") + depends_on("scalapack", when="+autotune") + + # Force openmp propagation on some providers of blas/lapack, as adviced by docs + # https://gitlab.mpcdf.mpg.de/elpa/elpa/-/blob/master/documentation/PERFORMANCE_TUNING.md?ref_type=heads#builds-with-openmp-enabled + with when("+openmp"): + requires("^openblas threads=openmp", when="^[virtuals=blas,lapack] openblas") + requires("^intel-mkl threads=openmp", when="^[virtuals=blas,lapack] intel-mkl") + requires( + "^intel-oneapi-mkl threads=openmp", when="^[virtuals=blas,lapack] intel-oneapi-mkl" + ) + requires( + "^intel-parallel-studio threads=openmp", + when="^[virtuals=blas,lapack] intel-parallel-studio", + ) + + # fails to build due to broken type-bound procedures in OMP parallel regions + conflicts( + "+openmp", + when="@2021.05.001: %gcc@:7", + msg="ELPA-2021.05.001+ requires GCC-8+ for OpenMP support", + ) + conflicts("+mpi", when="+rocm", msg="ROCm support and MPI are not yet compatible") + conflicts( + "+gpu_streams", + when="@:2023.11.001-patched +openmp", + msg="GPU streams currently not supported in combination with OpenMP", + ) + + def url_for_version(self, version): + return "https://elpa.mpcdf.mpg.de/software/tarball-archive/Releases/{0}/elpa-{0}.tar.gz".format( + str(version) + ) + + # override default implementation which returns static lib + @property + def libs(self): + libname = "libelpa_openmp" if "+openmp" in self.spec else "libelpa" + return find_libraries(libname, root=self.prefix, shared=True, recursive=True) + + @property + def headers(self): + suffix = "_openmp" if self.spec.satisfies("+openmp") else "" + + # upstream sometimes adds tarball suffixes not part of the internal version + elpa_version = str(self.spec.version) + for vsuffix in ("_bugfix", "-patched"): + if elpa_version.endswith(vsuffix): # implementation of py3.9 removesuffix + elpa_version = elpa_version[: -len(vsuffix)] + + incdir = os.path.join( + self.spec.prefix.include, + "elpa{suffix}-{version}".format(suffix=suffix, version=elpa_version), + ) + + hlist = find_all_headers(incdir) + hlist.directories = [incdir] + return hlist + + build_directory = "spack-build" + parallel = False + + def configure_args(self): + spec = self.spec + options = [] + + options += self.with_or_without("mpi") + + # New options use the "-kernels" suffix + kernels = "-kernels" if spec.satisfies("@2023.11:") else "" + + # TODO: --disable-sse-assembly, --enable-sparc64, --enable-neon-arch64 + # Don't include vsx; as of 2022.05 it fails (reported upstream). + # Altivec SSE intrinsics are used anyway. + simd_features = ["sse", "avx", "avx2", "avx512", "sve128", "sve256", "sve512"] + + for feature in simd_features: + msg = "--enable-{0}" if feature in spec.target else "--disable-{0}" + options.append(msg.format(feature + kernels)) + + if spec.target.family != "x86_64": + options.append("--disable-sse-assembly") + + if "%aocc" in spec or "%fj" in spec: + options.append("--disable-shared") + options.append("--enable-static") + + # If no features are found, enable the generic ones + if not any(f in spec.target for f in simd_features): + options.append("--enable-generic" + kernels) + + if self.compiler.name == "gcc": + options.extend(["CFLAGS=-O3", "FCFLAGS=-O3 -ffree-line-length-none"]) + + if "%aocc" in spec: + options.extend(["FCFLAGS=-O3", "CFLAGS=-O3"]) + + if "%fj" in spec: + options.append("--disable-Fortran2008-features") + options.append("--enable-FUGAKU") + if "+openmp" in spec: + options.extend(["FCFLAGS=-Kparallel"]) + + cuda_flag = "nvidia-gpu" + if "+cuda" in spec: + prefix = spec["cuda"].prefix + # Can't yet be changed to the new option --enable-nvidia-gpu-kernels + # https://github.com/marekandreas/elpa/issues/55 + options.append(f"--enable-{cuda_flag}") + options.append("--with-cuda-path={0}".format(prefix)) + options.append("--with-cuda-sdk-path={0}".format(prefix)) + + if spec.satisfies("+gpu_streams"): + options.append("--enable-gpu-streams=nvidia") + + cuda_arch = spec.variants["cuda_arch"].value[0] + + if cuda_arch != "none": + options.append( + "--with-{0}-compute-capability=sm_{1}".format(cuda_flag.upper(), cuda_arch) + ) + else: + options.append(f"--disable-{cuda_flag}" + kernels) + + if "+rocm" in spec: + # Can't yet be changed to the new option --enable-amd-gpu-kernels + # https://github.com/marekandreas/elpa/issues/55 + options.append("--enable-amd-gpu") + options.append("CXX={0}".format(self.spec["hip"].hipcc)) + + if spec.satisfies("+gpu_streams"): + options.append("--enable-gpu-streams=amd") + + elif "@2021.05.001:" in self.spec: + options.append("--disable-amd-gpu" + kernels) + + options += self.enable_or_disable("openmp") + + # Additional linker search paths and link libs + ldflags = [spec["blas"].libs.search_flags, spec["lapack"].libs.search_flags, "-lstdc++"] + libs = [spec["lapack"].libs.link_flags, spec["blas"].libs.link_flags] + + options += [f'LDFLAGS={" ".join(ldflags)}', f'LIBS={" ".join(libs)}'] + + if "+mpi" in self.spec: + options += [ + "CC={0}".format(spec["mpi"].mpicc), + "CXX={0}".format(spec["mpi"].mpicxx), + "FC={0}".format(spec["mpi"].mpifc), + "SCALAPACK_LDFLAGS={0}".format(spec["scalapack"].libs.joined()), + ] + + if "+autotune" in self.spec: + options.append("--enable-autotune-redistribute-matrix") + # --enable-autotune-redistribute-matrix requires --enable-scalapack-tests as well + options.append("--enable-scalapack-tests") + + options.append("--disable-silent-rules") + options.append("--without-threading-support-check-during-build") + + return options diff --git a/recipes/cp2k/2024.3/mc/repo/packages/intel-oneapi-mkl/package.py b/recipes/cp2k/2024.3/mc/repo/packages/intel-oneapi-mkl/package.py new file mode 100644 index 00000000..986b5847 --- /dev/null +++ b/recipes/cp2k/2024.3/mc/repo/packages/intel-oneapi-mkl/package.py @@ -0,0 +1,287 @@ +# Copyright 2013-2024 Lawrence Livermore National Security, LLC and other +# Spack Project Developers. See the top-level COPYRIGHT file for details. +# +# SPDX-License-Identifier: (Apache-2.0 OR MIT) + +from os.path import dirname, isdir + +from spack.package import * + + +@IntelOneApiPackage.update_description +class IntelOneapiMkl(IntelOneApiLibraryPackage): + """Intel oneAPI Math Kernel Library (Intel oneMKL; formerly Intel Math + Kernel Library or Intel MKL), is a library of optimized math + routines for science, engineering, and financial + applications. Core math functions include BLAS, LAPACK, + ScaLAPACK, sparse solvers, fast Fourier transforms, and vector + math. + + """ + + maintainers("rscohn2") + + homepage = ( + "https://software.intel.com/content/www/us/en/develop/tools/oneapi/components/onemkl.html" + ) + + version( + "2024.2.0", + url="https://registrationcenter-download.intel.com/akdlm/IRC_NAS/cdff21a5-6ac7-4b41-a7ec-351b5f9ce8fd/l_onemkl_p_2024.2.0.664_offline.sh", + sha256="f1f46f5352c197a9840e08fc191a879dad79ebf742fe782e386ba8006f262f7a", + expand=False, + ) + version( + "2024.1.0", + url="https://registrationcenter-download.intel.com/akdlm/IRC_NAS/2f3a5785-1c41-4f65-a2f9-ddf9e0db3ea0/l_onemkl_p_2024.1.0.695_offline.sh", + sha256="b121bc70d3493ef1fbd05f077b1cd27ac4eb2fd1099f44e9f4b8a1366995fb92", + expand=False, + ) + version( + "2024.0.0", + url="https://registrationcenter-download.intel.com/akdlm//IRC_NAS/86d6a4c1-c998-4c6b-9fff-ca004e9f7455/l_onemkl_p_2024.0.0.49673_offline.sh", + sha256="2a3be7d01d75ba8cc3059f9a32ae72e5bfc93e68e72e94e79d7fa6ea2f7814de", + expand=False, + ) + version( + "2023.2.0", + url="https://registrationcenter-download.intel.com/akdlm/IRC_NAS/adb8a02c-4ee7-4882-97d6-a524150da358/l_onemkl_p_2023.2.0.49497_offline.sh", + sha256="4a0d93da85a94d92e0ad35dc0fc3b3ab7f040bd55ad374c4d5ec81a57a2b872b", + expand=False, + ) + version( + "2023.1.0", + url="https://registrationcenter-download.intel.com/akdlm/IRC_NAS/cd17b7fe-500e-4305-a89b-bd5b42bfd9f8/l_onemkl_p_2023.1.0.46342_offline.sh", + sha256="cc28c94cab23c185520b93c5a04f3979d8da6b4c90cee8c0681dd89819d76167", + expand=False, + ) + version( + "2023.0.0", + url="https://registrationcenter-download.intel.com/akdlm/IRC_NAS/19138/l_onemkl_p_2023.0.0.25398_offline.sh", + sha256="0d61188e91a57bdb575782eb47a05ae99ea8eebefee6b2dfe20c6708e16e9927", + expand=False, + ) + version( + "2022.2.1", + url="https://registrationcenter-download.intel.com/akdlm/IRC_NAS/19038/l_onemkl_p_2022.2.1.16993_offline.sh", + sha256="eedd4b795720de776b1fc5f542ae0fac37ec235cdb567f7c2ee3182e73e3e59d", + expand=False, + ) + version( + "2022.2.0", + url="https://registrationcenter-download.intel.com/akdlm/IRC_NAS/18898/l_onemkl_p_2022.2.0.8748_offline.sh", + sha256="07d7caedd4b9f025c6fd439a0d2c2f279b18ecbbb63cadb864f6c63c1ed942db", + expand=False, + ) + version( + "2022.1.0", + url="https://registrationcenter-download.intel.com/akdlm/IRC_NAS/18721/l_onemkl_p_2022.1.0.223_offline.sh", + sha256="4b325a3c4c56e52f4ce6c8fbb55d7684adc16425000afc860464c0f29ea4563e", + expand=False, + ) + version( + "2022.0.2", + url="https://registrationcenter-download.intel.com/akdlm/IRC_NAS/18483/l_onemkl_p_2022.0.2.136_offline.sh", + sha256="134b748825a474acc862bb4a7fada99741a15b7627cfaa6ba0fb05ec0b902b5e", + expand=False, + ) + version( + "2022.0.1", + url="https://registrationcenter-download.intel.com/akdlm/IRC_NAS/18444/l_onemkl_p_2022.0.1.117_offline.sh", + sha256="22afafbe2f3762eca052ac21ec40b845ff2f3646077295c88c2f37f80a0cc160", + expand=False, + ) + version( + "2021.4.0", + url="https://registrationcenter-download.intel.com/akdlm/IRC_NAS/18222/l_onemkl_p_2021.4.0.640_offline.sh", + sha256="9ad546f05a421b4f439e8557fd0f2d83d5e299b0d9bd84bdd86be6feba0c3915", + expand=False, + ) + version( + "2021.3.0", + url="https://registrationcenter-download.intel.com/akdlm/IRC_NAS/17901/l_onemkl_p_2021.3.0.520_offline.sh", + sha256="a06e1cdbfd8becc63440b473b153659885f25a6e3c4dcb2907ad9cd0c3ad59ce", + expand=False, + ) + version( + "2021.2.0", + url="https://registrationcenter-download.intel.com/akdlm/IRC_NAS/17757/l_onemkl_p_2021.2.0.296_offline.sh", + sha256="816e9df26ff331d6c0751b86ed5f7d243f9f172e76f14e83b32bf4d1d619dbae", + expand=False, + ) + version( + "2021.1.1", + url="https://registrationcenter-download.intel.com/akdlm/IRC_NAS/17402/l_onemkl_p_2021.1.1.52_offline.sh", + sha256="818b6bd9a6c116f4578cda3151da0612ec9c3ce8b2c8a64730d625ce5b13cc0c", + expand=False, + ) + + variant("gfortran", default=False, description="Compatibility with GNU Fortran") + + variant("shared", default=True, description="Builds shared library") + variant("ilp64", default=False, description="Build with ILP64 support") + variant( + "cluster", default=False, description="Build with cluster support: scalapack, blacs, etc" + ) + variant( + "mpi_family", + default="none", + values=("none", "mpich", "openmpi"), + description="MPI family", + multi=False, + ) + + variant( + "threads", + default="none", + description="Multithreading support", + values=("openmp", "tbb", "none"), + multi=False, + ) + + requires( + "%clang", + "%gcc", + "%intel", + "%oneapi", + policy="one_of", + when="threads=openmp", + msg="MKL with OpenMP threading requires GCC, clang, or Intel compilers", + ) + + depends_on("tbb") + # cluster libraries need mpi + depends_on("mpi", when="+cluster") + + # If a +cluster then mpi_family must be set + with when("+cluster"): + conflicts("mpi_family=none") + requires("mpi_family=mpich", when="^intel-oneapi-mpi") + requires("mpi_family=mpich", when="^intel-mpi") + requires("mpi_family=mpich", when="^mpich") + requires("mpi_family=mpich", when="^mvapich") + requires("mpi_family=mpich", when="^mvapich2") + requires("mpi_family=mpich", when="^cray-mpich") + requires("mpi_family=openmpi", when="^openmpi") + requires("mpi_family=openmpi", when="^hpcx-mpi") + + provides("fftw-api@3") + provides("scalapack", when="+cluster") + provides("mkl") + provides("lapack", "blas") + + @run_after("install") + def fixup_installation(self): + # fixup missing path in mkl cmake files. This issue was new in + # 2024.0.0 and expected to be fixed in the next release. + if self.spec.satisfies("@2024.0.0"): + # cannot use spack patch because this is applied to the + # installed mkl, not sources + filter_file( + 'PATH_SUFFIXES "lib"', + 'PATH_SUFFIXES "lib" "../../compiler/latest/lib"', + self.component_prefix.lib.cmake.mkl.join("MKLConfig.cmake"), + backup=False, + ) + + @property + def v2_layout_versions(self): + return "@2024:" + + @property + def component_dir(self): + return "mkl" + + @property + def libs(self): + shared = self.spec.satisfies("+shared") + + libs = self._find_mkl_libs(shared) + + system_libs = find_system_libraries(["libpthread", "libm", "libdl"]) + if shared: + return libs + system_libs + else: + return IntelOneApiStaticLibraryList(libs, system_libs) + + def setup_dependent_build_environment(self, env, dependent_spec): + # Only if environment modifications are desired (default is +envmods) + if self.spec.satisfies("+envmods"): + env.set("MKLROOT", self.component_prefix) + # 2023.1.0 has the pkgconfig files in lib/pkgconfig, 2021.3.0 has them in + # tools/pkgconfig, just including both in PKG_CONFIG_PATH + env.append_path("PKG_CONFIG_PATH", self.component_prefix.lib.pkgconfig) + env.append_path("PKG_CONFIG_PATH", self.component_prefix.tools.pkgconfig) + + def _find_mkl_libs(self, shared): + libs = [] + + if self.spec.satisfies("+cluster"): + libs.extend([self._xlp64_lib("libmkl_scalapack"), "libmkl_cdft_core"]) + + # Explicit variant for compatibility with gfortran, otherwise + # support intel fortran. Be aware that some dependencies may + # be using this logic and other dependencies might be using + # cmake for the library list and they have to be consistent. + # https://github.com/spack/spack/pull/43673 for discussion + if self.spec.satisfies("+gfortran"): + depends_on("fortran", type="build") + libs.append(self._xlp64_lib("libmkl_gf")) + else: + libs.append(self._xlp64_lib("libmkl_intel")) + + if self.spec.satisfies("threads=tbb"): + libs.append("libmkl_tbb_thread") + elif self.spec.satisfies("threads=openmp"): + if self.spec.satisfies("%oneapi") or self.spec.satisfies("%intel"): + libs.append("libmkl_intel_thread") + else: + libs.append("libmkl_gnu_thread") + else: + libs.append("libmkl_sequential") + + libs.append("libmkl_core") + + if self.spec.satisfies("+cluster"): + if self.spec.satisfies("mpi_family=mpich"): + libs.append(self._xlp64_lib("libmkl_blacs_intelmpi")) + elif self.spec.satisfies("mpi_family=openmpi"): + libs.append(self._xlp64_lib("libmkl_blacs_openmpi")) + + lib_path = ( + self.component_prefix.lib if self.v2_layout else self.component_prefix.lib.intel64 + ) + lib_path = lib_path if isdir(lib_path) else dirname(lib_path) + + # resolved_libs is populated as follows + # MKL-related + MPI-related + threading-related + resolved_libs = find_libraries(libs, lib_path, shared=shared) + + # Add MPI libraries for cluster support. If MPI is not in the + # spec, then MKL is externally installed and application must + # link with MPI libaries. If MPI is in spec, but there are no + # libraries, then the package (e.g. hpcx-mpi) relies on the + # compiler wrapper to add the libraries. + try: + if self.spec.satisfies("+cluster ^mpi"): + resolved_libs = resolved_libs + self.spec["mpi"].libs + except spack.error.NoLibrariesError: + pass + + if self.spec.satisfies("threads=openmp"): + resolved_libs += self.openmp_libs() + return resolved_libs + + def _xlp64_lib(self, lib): + return lib + ("_ilp64" if self.spec.satisfies("+ilp64") else "_lp64") + + @run_after("install") + def fixup_prefix(self): + # The motivation was to provide a more standard layout so mkl + # would be more likely to work as a virtual dependence. I am + # not sure if this mechanism is useful and it became a problem + # for mpi so disabling for v2_layout. + if self.v2_layout: + return + self.symlink_dir(self.component_prefix.include, self.prefix.include) + self.symlink_dir(self.component_prefix.lib, self.prefix.lib)