diff --git a/config.yaml b/config.yaml index fd0561bbc..6bdc596a5 100644 --- a/config.yaml +++ b/config.yaml @@ -70,6 +70,16 @@ clusters: F7T_TOKEN_URL: "https://auth-tds.cscs.ch/auth/realms/firecrest-clients/protocol/openid-connect/token" SLURM_TIMELIMIT: '500' SLURM_CPUS_PER_TASK: '64' + - + uarch: 'mi300' + partition: 'mi300' + variables: + F7T_CLIENT_ID: $F7T_TDS_CLIENT_ID + F7T_CLIENT_SECRET: $F7T_TDS_CLIENT_SECRET + F7T_URL: "https://api.tds.cscs.ch/stp/firecrest/v2" + F7T_TOKEN_URL: "https://auth-tds.cscs.ch/auth/realms/firecrest-clients/protocol/openid-connect/token" + SLURM_TIMELIMIT: '500' + SLURM_CPUS_PER_TASK: '64' runner: f7t uenvs: climana: @@ -148,9 +158,16 @@ uenvs: recipes: gh200: 2025.1/gh200 zen2: 2025.1/mc + mi300: 2025.1/mi300 deploy: daint: [gh200] eiger: [zen2] + beverin: [mi300] + "2025.2": + recipes: + mi300: 2025.2/mi300 + deploy: + beverin: [mi300] icon-wcp: "v1": recipes: diff --git a/recipes/cp2k/2025.2/mi300/compilers.yaml b/recipes/cp2k/2025.2/mi300/compilers.yaml new file mode 100755 index 000000000..4d9296449 --- /dev/null +++ b/recipes/cp2k/2025.2/mi300/compilers.yaml @@ -0,0 +1,2 @@ +gcc: + version: "12.3" diff --git a/recipes/cp2k/2025.2/mi300/config.yaml b/recipes/cp2k/2025.2/mi300/config.yaml new file mode 100755 index 000000000..799b4fc67 --- /dev/null +++ b/recipes/cp2k/2025.2/mi300/config.yaml @@ -0,0 +1,10 @@ +name: cp2k-uenv +version: 2 +spack: + commit: releases/v1.0 + repo: https://github.com/spack/spack.git + packages: + repo: https://github.com/spack/spack-packages.git + commit: 4568e82f27a390c46b0fc710aa68e534ae54277b +store: /user-environment +description: CP2K Beverin uenv diff --git a/recipes/cp2k/2025.2/mi300/environments.yaml b/recipes/cp2k/2025.2/mi300/environments.yaml new file mode 100755 index 000000000..a5c001c84 --- /dev/null +++ b/recipes/cp2k/2025.2/mi300/environments.yaml @@ -0,0 +1,28 @@ +gcc-env: + compiler: [gcc] + network: + mpi: cray-mpich@8.1.32+rocm + unify: true + specs: + #- sirius@7.8 +fortran +pugixml +magma + - libunwind@1.7-stable + - hip@6.3.3 ^mesa@23.3.6 + - llvm-amdgpu + - cosma +gpu_direct ^netlib-scalapack + - dbcsr@develop #develop branch for mi300 support + - spla +fortran + - cp2k@2025.2 +cosma +spla ~sirius ~dlaf #+sirius + variants: + - amdgpu_target=gfx942 + - amdgpu_target_sram_ecc=gfx942 + - +mpi + - +rocm + - +openmp + - build_type=Release + views: + cp2k: + link: roots + uenv: + add_compilers: true + prefix_paths: + LD_LIBRARY_PATH: [lib, lib64] diff --git a/recipes/cp2k/2025.2/mi300/modules.yaml b/recipes/cp2k/2025.2/mi300/modules.yaml new file mode 100755 index 000000000..623307b09 --- /dev/null +++ b/recipes/cp2k/2025.2/mi300/modules.yaml @@ -0,0 +1,23 @@ +modules: + # Paths to check when creating modules for all module sets + prefix_inspections: + bin: + - PATH + lib: + - LD_LIBRARY_PATH + lib64: + - LD_LIBRARY_PATH + + default: + arch_folder: false + # Where to install modules + 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/2025.2/mi300/repo/packages/cp2k/backport_avoid_null_2022.x.patch b/recipes/cp2k/2025.2/mi300/repo/packages/cp2k/backport_avoid_null_2022.x.patch new file mode 100644 index 000000000..ecd3db979 --- /dev/null +++ b/recipes/cp2k/2025.2/mi300/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/2025.2/mi300/repo/packages/cp2k/backport_avoid_null_9.1.patch b/recipes/cp2k/2025.2/mi300/repo/packages/cp2k/backport_avoid_null_9.1.patch new file mode 100644 index 000000000..7f580a043 --- /dev/null +++ b/recipes/cp2k/2025.2/mi300/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/2025.2/mi300/repo/packages/cp2k/cmake-fixes-2023.2.patch b/recipes/cp2k/2025.2/mi300/repo/packages/cp2k/cmake-fixes-2023.2.patch new file mode 100644 index 000000000..985edad3a --- /dev/null +++ b/recipes/cp2k/2025.2/mi300/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/2025.2/mi300/repo/packages/cp2k/cmake-relwithdebinfo-2024.1.patch b/recipes/cp2k/2025.2/mi300/repo/packages/cp2k/cmake-relwithdebinfo-2024.1.patch new file mode 100644 index 000000000..b974527b8 --- /dev/null +++ b/recipes/cp2k/2025.2/mi300/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/2025.2/mi300/repo/packages/cp2k/d4-dispersion-bugfix-2024.3.patch b/recipes/cp2k/2025.2/mi300/repo/packages/cp2k/d4-dispersion-bugfix-2024.3.patch new file mode 100644 index 000000000..36613ab6d --- /dev/null +++ b/recipes/cp2k/2025.2/mi300/repo/packages/cp2k/d4-dispersion-bugfix-2024.3.patch @@ -0,0 +1,56 @@ +diff --git a/src/qs_dispersion_d4.F b/src/qs_dispersion_d4.F +index 74df989b4..e513ed435 100644 +--- a/src/qs_dispersion_d4.F ++++ b/src/qs_dispersion_d4.F +@@ -26,6 +26,7 @@ MODULE qs_dispersion_d4 + #endif + USE kinds, ONLY: dp + USE particle_types, ONLY: particle_type ++ USE periodic_table, ONLY: get_ptable_info, ptable + USE qs_dispersion_types, ONLY: qs_dispersion_type + USE qs_force_types, ONLY: qs_force_type + USE message_passing, ONLY: mp_para_env_type +@@ -76,7 +77,8 @@ CONTAINS + TYPE(structure_type) :: mol + TYPE(realspace_cutoff) :: cutoff + +- INTEGER :: iatom, natom, ind_atom ++ LOGICAL :: found ++ INTEGER :: iatom, natom, ind_atom, zatom + INTEGER, ALLOCATABLE, DIMENSION(:) :: el_num + REAL(KIND=dp), ALLOCATABLE, DIMENSION(:, :) :: gradient, xyz + REAL(KIND=dp), DIMENSION(3, 3) :: stress +@@ -94,7 +96,9 @@ CONTAINS + DO iatom = 1, natom + xyz(:, iatom) = particle_set(iatom)%r(:) + CALL get_atomic_kind(particle_set(iatom)%atomic_kind, kind_number=ikind) +- el_num(iatom) = ikind ++ CALL get_ptable_info(particle_set(iatom)%atomic_kind%element_symbol, & ++ ielement=zatom, found=found) ++ el_num(iatom) = zatom + END DO + + !get information about cell / lattice +@@ -125,7 +129,7 @@ CONTAINS + IF (para_env%num_pe > 1 .AND. para_env%mepos > 0) virial = 0.00_dp + END IF + DO iatom = 1, natom +- ikind = el_num(iatom) ++ CALL get_atomic_kind(particle_set(iatom)%atomic_kind, kind_number=ikind) + ind_atom = atom_of_kind(iatom) + force(ikind)%dispersion(:, ind_atom) = force(ikind)%dispersion(:, ind_atom) + gradient(:, iatom) + END DO +diff --git a/tests/QS/regtest-dft-vdw-corr-4/TEST_FILES b/tests/QS/regtest-dft-vdw-corr-4/TEST_FILES +index 047421204..c817677df 100644 +--- a/tests/QS/regtest-dft-vdw-corr-4/TEST_FILES ++++ b/tests/QS/regtest-dft-vdw-corr-4/TEST_FILES +@@ -3,7 +3,7 @@ + # e.g. 0 means do not compare anything, running is enough + # 1 compares the last total energy in the file + # for details see cp2k/tools/do_regtest +-pbe_dftd4.inp 33 1.0E-14 -0.00141644869634 ++pbe_dftd4.inp 33 1.0E-14 -0.00283102230260 + pbe_dftd4_force.inp 72 1.0E-07 0.00007217 +-pbe_dftd4_stress.inp 31 1.0E-07 -5.16289312880E-03 ++pbe_dftd4_stress.inp 31 1.0E-07 -2.14003785359E-02 + #EOF diff --git a/recipes/cp2k/2025.2/mi300/repo/packages/cp2k/gcc_linker.patch b/recipes/cp2k/2025.2/mi300/repo/packages/cp2k/gcc_linker.patch new file mode 100644 index 000000000..0539abea2 --- /dev/null +++ b/recipes/cp2k/2025.2/mi300/repo/packages/cp2k/gcc_linker.patch @@ -0,0 +1,12 @@ +diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt +index 1334bb6da5..028c9ab03a 100644 +--- a/src/CMakeLists.txt ++++ b/src/CMakeLists.txt +@@ -1647,6 +1647,7 @@ else() + add_library(cp2k STATIC "${CP2K_SRCS};${CP2K_SRCS_C};${CP2K_SRCS_GPU}") + endif() + endif() ++set_target_properties(cp2k PROPERTIES LINKER_LANGUAGE CXX) + + target_compile_features(cp2k PUBLIC cuda_std_11) + target_include_directories(cp2k PUBLIC $) diff --git a/recipes/cp2k/2025.2/mi300/repo/packages/cp2k/package.py b/recipes/cp2k/2025.2/mi300/repo/packages/cp2k/package.py new file mode 100644 index 000000000..e10fd6736 --- /dev/null +++ b/recipes/cp2k/2025.2/mi300/repo/packages/cp2k/package.py @@ -0,0 +1,1240 @@ +# Copyright Spack Project Developers. See COPYRIGHT file for details. +# +# SPDX-License-Identifier: (Apache-2.0 OR MIT) +import os +import sys + +from spack_repo.builtin.build_systems import cmake, makefile +from spack_repo.builtin.build_systems.cmake import CMakePackage, generator +from spack_repo.builtin.build_systems.cuda import CudaPackage +from spack_repo.builtin.build_systems.makefile import MakefilePackage +from spack_repo.builtin.build_systems.rocm import ROCmPackage + +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", + "gfx942": "Mi300", +} + + +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/v2025.2/cp2k-2025.2.tar.bz2" + git = "https://github.com/cp2k/cp2k.git" + list_url = "https://github.com/cp2k/cp2k/releases" + + maintainers("dev-zero", "mtaillefumier", "RMeli", "abussy", "hfp") + + tags = ["e4s"] + + license("GPL-2.0-or-later") + + version("2025.2", sha256="c8392a4e123304644ec8d241443796277c6ed7ae977452317e779f3c387c2e19") + version("2025.1", sha256="65c8ad5488897b0f995919b9fa77f2aba4b61677ba1e3c19bb093d5c08a8ce1d") + 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") + + generator("ninja") + + 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("opencl", default=False, description="Enable OpenCL backend") + 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( + "openpmd-api", + default=False, + description="Enable openPMD support", + when="@2026.1: build_system=cmake", + ) + variant("quip", default=False, description="Enable quip support") + variant("dftd4", when="@2024.2:", default=False, description="Enable DFT-D4 support") + variant("mpi_f08", default=False, description="Use MPI F08 module", when="+mpi") + variant("smeagol", default=False, description="Enable libsmeagol support", when="@2025.2:") + variant("dbm_gpu", default=True, description="Enable DBM GPU backend", when="@2025.2:") + variant("grid_gpu", default=True, description="Enable grid GPU backend", when="@2025.2:") + variant( + "grid_gpu", default=False, description="Enable grid GPU backend", when="@2025.2: +opencl" + ) + variant( + "pw_gpu", default=True, description="Enable FFT calculations on GPU", when="@2025.2: +cuda" + ) + variant( + "pw_gpu", + default=False, + description="Enable FFT calculations on GPU", + when="@2025.2: +rocm", + ) + variant( + "pw_gpu", + default=False, + description="Enable FFT calculations on GPU", + when="@2025.2: +opencl", + ) + variant( + "hip_backend_cuda", + default=False, + description="Enable HIP backend on Nvidia GPU", + when="@2025.2: +cuda", + ) + 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.", + ) + variant( + "grpp", + default=False, + description="Enable GRPP psuedo potentials", + when="@2025.2: build_system=cmake", + ) + variant( + "hdf5", + default=False, + description="Enable HDF5 support", + when="@2025.2: build_system=cmake", + ) + variant( + "trexio", + default=False, + description="Enable TrexIO support", + when="@2025.2: build_system=cmake", + ) + variant( + "greenx", + default=False, + description="Enable green X support", + when="@2025.2: build_system=cmake", + ) + + variant("vdwxc", default=False, description="Enable VDW support in SIRIUS.", when="+sirius") + variant("deepmd", default=False, description="Enable DeepMD-kit support") + variant("tblite", default=False, description="Enable tblite support", when="@2025.2:") + variant("nlcg", default=False, description="Enable nlcg support in sirius", when="+sirius") + variant("vcsqnm", default=False, description="Enable VCSQNM support in sirius", when="+sirius") + + conflicts("+deepmd", msg="DeepMD-kit is not yet available in Spack") + + 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", + ) + + with when("+hip_backend_cuda"): + depends_on("hipcc") + depends_on("hip+cuda") + depends_on("hipfft+cuda") + depends_on("hipblas+cuda") + + 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("c", type="build") + depends_on("cxx", type="build") + depends_on("fortran", type="build") + + depends_on("python@3", type="build") + depends_on("pkgconfig", type="build", when="build_system=cmake") + + depends_on("blas") + depends_on("lapack") + depends_on("fftw-api@3") + depends_on("greenx", when="+greenx") + depends_on("hdf5+hl+fortran", when="+hdf5") + depends_on("trexio", when="+trexio") + + depends_on("tblite build_system=cmake", when="+tblite") + # 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") + depends_on("intel-oneapi-mkl threads=openmp", when="^[virtuals=fftw-api] intel-oneapi-mkl") + depends_on( + "intel-oneapi-mkl+gfortran threads=openmp", + when="^[virtuals=blas] intel-oneapi-mkl %gcc", + ) + depends_on("intel-oneapi-mkl threads=openmp", when="^[virtuals=blas] intel-oneapi-mkl") + # 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"): + # 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:") + # use pkg-config (support added in libxsmm-1.10) to link to libxsmm + depends_on("pkgconfig", type="build") + + # Several packages provide "opencl" (incl. ICD/loader), e.g., "cuda" + with when("+opencl"): + depends_on("opencl", when="+opencl") + opencl_loader_header_version = "2022.10.24" + depends_on(f"opencl-c-headers@{opencl_loader_header_version}:") + requires(f"%opencl=opencl-icd-loader@{opencl_loader_header_version}:") + # OpenCL backend implementation relies on LIBXSMM + requires("smm=libxsmm") + + with when("+libint"): + depends_on("pkgconfig", type="build", when="@7.0:") + for lmax in HFX_LMAX_RANGE: + depends_on(f"libint@2.6.0:+fortran tune=cp2k-lmax-{lmax}", when=f"@7.0: lmax={lmax}") + # AOCC only works with libint@2.6.0 + depends_on( + f"libint@=2.6.0+fortran tune=cp2k-lmax-{lmax}", when=f"@7.0: lmax={lmax} %aocc" + ) + + with when("+libxc"): + depends_on("pkgconfig", type="build", when="@7.0: ^libxc@:6") + 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:") + depends_on("libxc@:6", when="@:2024.3") + depends_on("libxc@7 build_system=cmake", when="@2025.2:") + + # Force SPLA dependence + depends_on("spla+rocm+fortran") + #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") + depends_on("intel-oneapi-mkl +cluster", when="^[virtuals=scalapack] intel-oneapi-mkl") + 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:") + depends_on("dla-future-fortran@0.2.0:", when="@2025.1:") + + # 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") + + depends_on("libsmeagol", when="+smeagol") + + # 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+scalapack") + 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:", when="@2023.2") + depends_on("sirius@7.5:", when="@2024.1:") + depends_on("sirius@7.6:+pugixml", when="@2024.2:") + depends_on("sirius@7.7:+pugixml", when="@2025.2:") + depends_on("sirius+vdwxc", when="+vdwxc") + depends_on("sirius+nlcglib", when="@2025.2:+nlcg") + depends_on("sirius+vcsqnm", when="@2025.2:+vcsqnm") + depends_on("sirius@7.8.1:+dftd3+dftd4", when="@2025.2:+dftd4") + depends_on("sirius@7.5.0:+dlaf", when="+dlaf") + + with when("+libvori"): + depends_on("libvori@201219:", when="@8.1") + depends_on("libvori@210412:", when="@8.2:") + depends_on("libvori@220621:", when="@2023.1:") + + with when("+openpmd-api"): + depends_on("openpmd-api@0.16.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") + + depends_on("dftd4@3.6.0: build_system=cmake", when="+dftd4") + + 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@2.8:", when="@2025.1:") + depends_on("dbcsr+openmp", when="+openmp") + depends_on("dbcsr+opencl", when="+opencl") + depends_on("dbcsr+mpi", when="+mpi") + depends_on("dbcsr+rocm", when="+rocm") + depends_on("dbcsr+cuda", when="+cuda") + + 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") + + # The CMake build system and AOCC are not compatible as of AOCC 5 + requires("build_system=makefile", when="%aocc") + + # 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+", + "gfx942", + ) + 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") + + # Bugfix for D4 dispersion correction in CP2K 2024.3 + # https://github.com/cp2k/cp2k/issues/3688 + patch("d4-dispersion-bugfix-2024.3.patch", when="@2024.3") + + # Fix segmentation faults caused by accessing unallocated arrays + # https://github.com/cp2k/cp2k/pull/3733 + patch( + "https://github.com/cp2k/cp2k/commit/7a99649828ecf7d5dc53d952a1bf7be6970deabe.patch?full_index=1", + sha256="37f4f1a76634ff4a5617fe0c670e6acfe2afa2b2cfc5b2875e438a54baa4525e", + when="@2024.2:2024.3", + ) + # Follow api change of sirius, deleted unrelated tools part. + # https://github.com/cp2k/cp2k/commit/9ae0441d1aa760e247a8a389793207ec65a35775 + # https://github.com/electronic-structure/SIRIUS/pull/1048 + patch("sirius-api-7.7.0.patch", when="@2024.2:2025.1 ^sirius@7.7.0") + + # Fix missing S in data/BASIS_MOLOPT_UZH + # https://github.com/cp2k/cp2k/pull/4140 + patch( + "https://github.com/cp2k/cp2k/commit/da03128481adf8f78a8a04ebeae0490480c03b89.patch?full_index=1", + sha256="0d542c414216866953c95e642d2590b3d313717dfaebbf12cfafedbdd3bf54a3", + when="@=2025.1", + ) + + # Ensure gcc is used as the linker (as opposed to clang) + patch("gcc_linker.patch") + + def patch(self): + # Patch for an undefined constant due to incompatible changes in ELPA + if self.spec.satisfies("@9.1:2022.2 +elpa"): + 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", + ) + + # Patch for resolving .mod file conflicts in ROCm by implementing 'USE, INTRINSIC' + # This patch triggers compilation errors on some systems as rocm install these + # modules files in rocm/include/llvm and this directory is given to gcc + + #if self.spec.satisfies("+rocm"): + # for directory, subdirectory, files in os.walk(os.getcwd()): + # for i in files: + # file_path = os.path.join(directory, i) + # filter_file("USE ISO_C_BINDING", "USE,INTRINSIC :: ISO_C_BINDING", file_path) + # filter_file( + # "USE ISO_FORTRAN_ENV", "USE,INTRINSIC :: ISO_FORTRAN_ENV", file_path + # ) + # filter_file("USE omp_lib", "USE,INTRINSIC :: omp_lib", file_path) + # filter_file("USE OMP_LIB", "USE,INTRINSIC :: OMP_LIB", file_path) + # filter_file("USE iso_c_binding", "USE,INTRINSIC :: iso_c_binding", file_path) + # filter_file( + # "USE iso_fortran_env", "USE,INTRINSIC :: iso_fortran_env", file_path + # ) + + 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-oneapi-compilers": ["-O2", "-fp-model precise"], + "intel": ["-g", "-O2", "-fp-model precise"], + "nvhpc": ["-fast"], + "cce": ["-O2"], + "xl": ["-O3"], + "aocc": ["-O2"], + "rocmcc": ["-O1"], + } + + dflags = ["-DNDEBUG"] if spec.satisfies("@:2023.2") else [] + if fftw.name == "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 = [] + dso_suffix = shared_library_suffix(spec) + + # 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") or spec.satisfies("%intel-oneapi-compilers"): + fcflags += ["-traceback"] # -heap-arrays 64 + elif spec.satisfies("%gcc"): + fcflags += [ + "-ffree-form", + "-ffree-line-length-none", + "-ggdb", # make sure we get proper Fortran backtraces + ] + elif spec.satisfies("%aocc") or spec.satisfies("%rocmcc"): + fcflags += ["-ffree-form", "-Mbackslash"] + elif 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 "+mpi %gcc@10:" 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 += [ + 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 += [ + 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], f"libparmetis.{dso_suffix}"), + join_path(spec["metis"].libs.directories[0], f"libmetis.{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(elpa.libs.ld_flags) + 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 += [join_path(spec["plumed"].prefix.lib, f"libplumed.{dso_suffix}")] + + if spec.satisfies("+libvori"): + cppflags += ["-D__LIBVORI"] + libvori = spec["libvori"].libs + ldflags += [libvori.search_flags] + libs.append(libvori.ld_flags) + libs += ["-lstdc++"] + + if spec.satisfies("+spglib"): + cppflags += ["-D__SPGLIB"] + spglib = spec["spglib"].libs + ldflags += [spglib.search_flags] + libs.append(spglib.ld_flags) + + if spec.satisfies("+dftd4"): + cppflags += ["-D__DFTD4"] + dftd4 = spec["dftd4"].libs + ldflags += [dftd4.search_flags] + libs.append(dftd4.ld_flags) + + if spec.satisfies("+smeagol"): + cppflags += ["-D__SMEAGOL"] + smeagol = spec["libsmeagol"].libs + ldflags += [smeagol.search_flags] + libs.append(smeagol.ld_flags) + + 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") or spec.satisfies("%intel-oneapi-compilers"): + cppflags.extend( + [ + "-D__INTEL", + "-D__HAS_IEEE_EXCEPTIONS", + "-D__HAS_ISO_C_BINDING", + "-D__USE_CP2K_TRACE", + ] + ) + fcflags.extend(["-free", "-fpp", "-diag-disable 8290,8291,10010,10212,11060"]) + + # FFTW, LAPACK, BLAS + lapack = spec["lapack"].libs + blas = spec["blas"].libs + ldflags.append((lapack + blas).search_flags) + libs += [str(x) for x in (fftw.libs, lapack, blas)] + + if spec.satisfies("platform=darwin"): + cppflags.extend(["-D__NO_STATM_ACCESS"]) + + if spec["blas"].name == "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 += 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 + + 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 += scalapack + libs += mpi + libs += 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["hip"].prefix.lib), + "-lamdhip64", + "-lhipblas", + "-lhipfft", + "-lstdc++", + ] + + acc_compiler_var = "hipcc" + acc_flags_var = "NVFLAGS" + cppflags += ["-D__ACC"] + cppflags += ["-D__DBCSR_ACC"] + cppflags += ["-D__HIP_PLATFORM_AMD__"] + cppflags += ["-D__GRID_HIP"] + + 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 OSError: + raise OSError( + "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(self.pkg["plumed"].plumed_inc)) + + mkf.write("\n# COMPILER, LINKER, TOOLS\n\n") + mkf.write("FC = {0}\nCC = {1}\nCXX = {2}\nLD = {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: # incl. spec.satisfies("%intel-oneapi-compilers") + 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)) + if "+rocm" in spec: + mkf.write("OFFLOAD_TARGET = hip\n") + + mkf.write(fflags("FCFLAGS", fcflags)) + mkf.write(fflags("LDFLAGS", ldflags)) + mkf.write(fflags("LIBS", libs)) + + if spec.satisfies("%intel") or spec.satisfies("%intel-oneapi-compilers"): + mkf.write(fflags("LDFLAGS_C", ldflags + ["-nofor-main"])) + + if spec.satisfies("%aocc@5:"): + # ensure C based applications can be build properly + mkf.write(fflags("LDFLAGS_C", ldflags + ["-fno-fortran-main"])) + # This flag is required for the correct runtime behaviour of the code with aocc@5.0 + mkf.write(fflags("FCFLAGS", fcflags + ["-mllvm -enable-newgvn=true"])) + + 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 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 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", "cray-fftw"] 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("+opencl"): + args += [self.define("CP2K_USE_ACCEL", "OPENCL")] + + 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]] + if spec.satisfies("+hip_backend_cuda"): + args += [ + self.define("CP2K_USE_ACCEL", "HIP"), + self.define("CMAKE_HIP_PLATFORM", "nvidia"), + ] + else: + args += [self.define("CP2K_USE_ACCEL", "CUDA")] + + args += [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 += [ + "-DCP2K_USE_FFTW3=ON", + self.define_from_variant("CP2K_USE_MPI", "mpi"), + 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_OPENPMD", "openpmd-api"), + 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_DFTD4", "dftd4"), + self.define_from_variant("CP2K_USE_MPI_F08", "mpi_f08"), + self.define_from_variant("CP2K_USE_LIBSMEAGOL", "smeagol"), + self.define_from_variant("CP2K_ENABLE_GRID_GPU", "grid_gpu"), + self.define_from_variant("CP2K_ENABLE_DBM_GPU", "dbm_gpu"), + self.define_from_variant("CP2K_ENABLE_PW_GPU", "pw_gpu"), + self.define_from_variant("CP2K_USE_GRPP", "grpp"), + self.define_from_variant("CP2K_USE_HDF5", "hdf5"), + self.define_from_variant("CP2K_USE_DEEPMD", "deepmd"), + self.define_from_variant("CP2K_USE_TREXIO", "trexio"), + self.define_from_variant("CP2K_USE_GREENX", "greenx"), + self.define_from_variant("CP2K_USE_LIBVDWXC", "vdwxc"), + self.define_from_variant("CP2K_USE_TBLITE", "tblite"), + ] + + if spec.satisfies("+sirius"): + args += [ + self.define_from_variant("CP2K_USE_SIRIUS_DFTD4", "dftd4"), + self.define_from_variant("CP2K_USE_SIRIUS_VCSQNM", "vcsqnm"), + self.define_from_variant("CP2K_USE_SIRIUS_NLCG", "nlcg"), + ] + if spec.satisfies("^[virtuals=fftw-api] fftw+openmp"): + args += ["-DCP2K_USE_FFTW3_WITH_OPENMP=ON"] + + # 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"] + + 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 == "intel-oneapi-mkl": + args += ["-DCP2K_BLAS_VENDOR=MKL"] + + if spec.satisfies("+openmp"): + mkl_thread = "thread" if spec.satisfies("%gcc") else "intel-thread" + args += [f"-DCP2K_BLAS_THREADING={mkl_thread}"] + else: + args += ["-DCP2K_BLAS_THREADING=sequential"] + + 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/2025.2/mi300/repo/packages/cp2k/posix_c_source.patch b/recipes/cp2k/2025.2/mi300/repo/packages/cp2k/posix_c_source.patch new file mode 100644 index 000000000..87a544a77 --- /dev/null +++ b/recipes/cp2k/2025.2/mi300/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/2025.2/mi300/repo/packages/cp2k/sirius-api-7.7.0.patch b/recipes/cp2k/2025.2/mi300/repo/packages/cp2k/sirius-api-7.7.0.patch new file mode 100644 index 000000000..f63b880cc --- /dev/null +++ b/recipes/cp2k/2025.2/mi300/repo/packages/cp2k/sirius-api-7.7.0.patch @@ -0,0 +1,44 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index b9e660fbfd2..06ccb802a9b 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -692,7 +692,7 @@ endif() + + # SIRIUS + if(CP2K_USE_SIRIUS) +- find_package(sirius REQUIRED) ++ find_package(sirius 7.7.0 REQUIRED) + endif() + + if(CP2K_USE_PLUMED) +diff --git a/src/sirius_interface.F b/src/sirius_interface.F +index f6dc257c5d4..a84223d2433 100644 +--- a/src/sirius_interface.F ++++ b/src/sirius_interface.F +@@ -145,7 +145,7 @@ SUBROUTINE cp_sirius_create_env(pwdft_env) + magnetization, mass, pf, rl, zeff, alpha_u, beta_u, & + J0_u, J_u, U_u, occ_u, u_minus_J + REAL(KIND=dp), ALLOCATABLE, DIMENSION(:) :: beta, corden, ef, fe, locpot, rc, rp +- REAL(KIND=dp), DIMENSION(3) :: vr, vs ++ REAL(KIND=dp), DIMENSION(3) :: vr, vs, j_t + REAL(KIND=dp), DIMENSION(:), POINTER :: density + REAL(KIND=dp), DIMENSION(:, :), POINTER :: wavefunction, wfninfo + TYPE(atom_gthpot_type), POINTER :: gth_atompot +@@ -464,12 +464,14 @@ SUBROUTINE cp_sirius_create_env(pwdft_env) + CPABORT("CP2K/SIRIUS (hubbard): the occupation number can not be negative.") + END IF + ++ j_t(:) = 0.0 + IF (ABS(u_minus_j) < 1e-8) THEN ++ j_t(1) = J_u + CALL sirius_set_atom_type_hubbard(sctx, label, lu, nu, & +- occ_u, U_u, J_u, alpha_u, beta_u, J0_u) ++ occ_u, U_u, j_t, alpha_u, beta_u, J0_u) + ELSE + CALL sirius_set_atom_type_hubbard(sctx, label, lu, nu, & +- occ_u, u_minus_j, 0.0_dp, alpha_u, beta_u, J0_u) ++ occ_u, u_minus_j, j_t, alpha_u, beta_u, J0_u) + END IF + END IF + + diff --git a/recipes/cp2k/2025.2/mi300/repo/packages/cp2k/sirius_dftd4.patch b/recipes/cp2k/2025.2/mi300/repo/packages/cp2k/sirius_dftd4.patch new file mode 100644 index 000000000..40c0753c8 --- /dev/null +++ b/recipes/cp2k/2025.2/mi300/repo/packages/cp2k/sirius_dftd4.patch @@ -0,0 +1,416 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index 8ba3d8c857..15d1b79b77 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -23,7 +23,6 @@ endif() + # ================================================================================================= + # PROJECT AND VERSION + include(CMakeDependentOption) +-include(GitSubmodule) + include(CustomTargets) + + cmake_policy(SET CMP0048 NEW) +@@ -55,7 +54,7 @@ if(NOT DEFINED CMAKE_CUDA_STANDARD) + endif() + + if(NOT DEFINED CMAKE_CXX_STANDARD) +- set(CMAKE_CXX_STANDARD 14) ++ set(CMAKE_CXX_STANDARD 17) + set(CMAKE_CXX_STANDARD_REQUIRED ON) + endif() + +@@ -185,18 +184,18 @@ cmake_dependent_option(CP2K_USE_SIRIUS_NLCG "Enable nlcg method in SIRIUS" OFF + + cmake_dependent_option( + CP2K_DBCSR_USE_CPU_ONLY "Disable the DBCSR accelerated backend" OFF +- "NOT CP2K_USE_ACCEL MATCHES \"OPENCL\"" OFF) ++ "NOT CP2K_USE_ACCEL MATCHES \"OPENCL|HIP|CUDA\"" OFF) + + cmake_dependent_option( +- CP2K_ENABLE_DBM_GPU "Disable the dbm accelerated backend (mostly GPU)." ON ++ CP2K_ENABLE_DBM_GPU "Enable the dbm accelerated backend (mostly GPU)." ON + "CP2K_USE_ACCEL" OFF) + + cmake_dependent_option( +- CP2K_ENABLE_GRID_GPU "Disable acceleration for grid related functions." ON ++ CP2K_ENABLE_GRID_GPU "Enable acceleration for grid related functions." ON + "CP2K_USE_ACCEL MATCHES \"HIP|CUDA\"" OFF) + + cmake_dependent_option( +- CP2K_ENABLE_PW_GPU "Disable the ffts accelerated backend (mostly GPU)." ON ++ CP2K_ENABLE_PW_GPU "Enable the ffts accelerated backend (mostly GPU)." ON + "CP2K_USE_ACCEL MATCHES \"HIP|CUDA\"" OFF) + + cmake_dependent_option( +@@ -230,7 +229,21 @@ cmake_dependent_option( + + set(CP2K_BLAS_VENDOR + "auto" +- CACHE STRING "BLAS library for computations on host") ++ CACHE STRING "blas vendor/generic libraries") ++ ++set_property( ++ CACHE CP2K_BLAS_VENDOR ++ PROPERTY STRINGS ++ "auto" ++ "MKL" ++ "OpenBLAS" ++ "SCI" ++ "GenericBLAS" ++ "Armpl" ++ "FlexiBLAS" ++ "Atlas" ++ "NVHPCBlas" ++ "CUSTOM") + + set(CP2K_SCALAPACK_VENDOR_LIST "MKL" "SCI" "GENERIC" "auto") + set(CP2K_SCALAPACK_VENDOR +@@ -761,14 +774,10 @@ endif() + + if(CP2K_USE_ACE) + find_package(ACE REQUIRED) +- get_target_property(CP2K_ACE_INCLUDE_DIRS ACE::pace ++ get_target_property(CP2K_ACE_INCLUDE_DIRS cp2k::ACE + INTERFACE_INCLUDE_DIRECTORIES) +- get_target_property(CP2K_ACE_LINK_LIBRARIES ACE::pace ++ get_target_property(CP2K_ACE_LINK_LIBRARIES cp2k::ACE + INTERFACE_LINK_LIBRARIES) +- get_target_property(LIB_PATH ACE::yaml-cpp-pace INTERFACE_LINK_LIBRARIES) +- list(APPEND CP2K_ACE_LINK_LIBRARIES ${LIB_PATH}) +- get_target_property(LIB_PATH ACE::cnpy INTERFACE_LINK_LIBRARIES) +- list(APPEND CP2K_ACE_LINK_LIBRARIES ${LIB_PATH}) + endif() + + if(CP2K_USE_TBLITE) +@@ -776,9 +785,10 @@ if(CP2K_USE_TBLITE) + find_package(toml-f REQUIRED) + find_package(s-dftd3 REQUIRED) + find_package(tblite REQUIRED) ++ add_library(cp2k::tblite INTERFACE IMPORTED) + target_link_libraries( +- tblite::tblite INTERFACE mctc-lib::mctc-lib dftd4::dftd4 toml-f::toml-f +- s-dftd3::s-dftd3) ++ cp2k::tblite INTERFACE tblite::tblite mctc-lib::mctc-lib dftd4::dftd4 ++ toml-f::toml-f s-dftd3::s-dftd3) + endif() + + # SIRIUS +@@ -825,6 +835,9 @@ if(CP2K_USE_GREENX) + set(CMAKE_EXE_LINKER_FLAGS ${CMAKE_EXE_LINKER_FLAGS} "-L${GMP_LIBRARY_PATH}") + set(CMAKE_SHARED_LINKER_FLAGS ${CMAKE_SHARED_LINKER_FLAGS} + "-L${GMP_LIBRARY_PATH}") ++ ++ add_library(cp2k::greenx INTERFACE greenX::GXCommon greenX::LibGXAC ++ greenX::LibGXMiniMax cp2k::trexio::trexio) + endif() + + # OPTION HANDLING +diff --git a/cmake/CompilerConfiguration.cmake b/cmake/CompilerConfiguration.cmake +index 6469558f56..93b946fa58 100644 +--- a/cmake/CompilerConfiguration.cmake ++++ b/cmake/CompilerConfiguration.cmake +@@ -37,16 +37,14 @@ endif() + add_compile_options( + "$<$:-std=f2008;-ffree-form;-ffree-line-length-none;-fimplicit-none>" + "$<$:-g;-fno-omit-frame-pointer;-fbacktrace>" +- "$<$:$<$:-fallow-argument-mismatch>>" ++ "$<$:$<$,10>:-fallow-argument-mismatch>>" + "$<$:-Wno-deprecated-declarations;-Wno-maybe-uninitialized;-Wuninitialized;-Wuse-without-only>" + ) + add_compile_options( +- "$<$:--std=c++17>" + "$<$:-g;-fno-omit-frame-pointer>" + "$<$:-Wno-deprecated-declarations;-Wno-vla-parameter>" + ) + add_compile_options( +- "$<$:-std=c11>" + "$<$:-g;-fno-omit-frame-pointer>" + "$<$:-Wno-deprecated-declarations;-Wno-vla-parameter>" + ) +diff --git a/cmake/GitSubmodule.cmake b/cmake/GitSubmodule.cmake +deleted file mode 100644 +index b9ca6a2fe1..0000000000 +--- a/cmake/GitSubmodule.cmake ++++ /dev/null +@@ -1,30 +0,0 @@ +-#!-------------------------------------------------------------------------------------------------! +-#! CP2K: A general program to perform molecular dynamics simulations ! +-#! Copyright 2000-2025 CP2K developers group ! +-#! ! +-#! SPDX-License-Identifier: GPL-2.0-or-later ! +-#!-------------------------------------------------------------------------------------------------! +- +-# Call to ensure that the git submodule in location `path` is loaded. If the +-# submodule is not loaded, an error message that describes how to update the +-# submodules is printed. Sets the variable name_avail to `ON` if the submodule +-# is available, or `OFF` otherwise. copyright github.com/arbor-sim +- +-function(check_git_submodule name path) +- set(success_var "${name}_avail") +- set(${success_var} +- ON +- PARENT_SCOPE) +- +- get_filename_component(dotgit "${path}/.git" ABSOLUTE) +- if(NOT EXISTS ${dotgit}) +- message( +- FATAL_ERROR +- "\nThe git submodule for ${name} is not available.\n" +- "To check out all submodules use the following commands:\n" +- " git submodule init\n" +- " git submodule update\n" +- "Or download submodules recursively when checking out:\n" +- " git clone --recursive https://github.com/cp2k/cp2k.git\n") +- endif() +-endfunction() +diff --git a/cmake/modules/FindACE.cmake b/cmake/modules/FindACE.cmake +index 4dfabcae18..9b69ea9109 100644 +--- a/cmake/modules/FindACE.cmake ++++ b/cmake/modules/FindACE.cmake +@@ -24,30 +24,18 @@ cp2k_find_libraries(ACE_CNPY "cnpy") + find_package_handle_standard_args(ACE DEFAULT_MSG CP2K_ACE_CNPY_LINK_LIBRARIES) + + if(CP2K_ACE_FOUND) +- if(NOT TARGET ACE::pace) +- add_library(ACE::pace INTERFACE IMPORTED) ++ if(NOT TARGET cp2k::ACE) ++ add_library(cp2k::ACE INTERFACE IMPORTED) + endif() + set_target_properties( +- ACE::pace ++ cp2k::ACE + PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${CP2K_ACE_INCLUDE_DIRS}" + INTERFACE_LINK_LIBRARIES "${CP2K_ACE_LINK_LIBRARIES}") +-endif() +- +-if(CP2K_ACE_YAML_FOUND) +- if(NOT TARGET ACE::yaml-cpp-pace) +- add_library(ACE::yaml-cpp-pace INTERFACE IMPORTED) +- endif() +- set_target_properties( +- ACE::yaml-cpp-pace PROPERTIES INTERFACE_LINK_LIBRARIES +- "${CP2K_ACE_YAML_LINK_LIBRARIES}") +-endif() + +-if(CP2K_ACE_CNPY_FOUND) +- if(NOT TARGET ACE::cnpy) +- add_library(ACE::cnpy INTERFACE IMPORTED) +- endif() +- set_target_properties(ACE::cnpy PROPERTIES INTERFACE_LINK_LIBRARIES +- "${CP2K_ACE_CNPY_LINK_LIBRARIES}") ++ target_link_libraries( ++ cp2k::ACE PROPERTIES INTERFACE_LINK_LIBRARIES ++ "$:${CP2K_ACE_YAML_LINK_LIBRARIES}>" ++ "$:${CP2K_ACE_CNPY_LINK_LIBRARIES}>") + endif() + + mark_as_advanced(CP2K_ACE_FOUND CP2K_ACE_INCLUDE_DIRS CP2K_ACE_LINK_LIBRARIES +diff --git a/cmake/modules/FindBlas.cmake b/cmake/modules/FindBlas.cmake +index deb67cff96..369233cae3 100644 +--- a/cmake/modules/FindBlas.cmake ++++ b/cmake/modules/FindBlas.cmake +@@ -9,13 +9,6 @@ + # + # authors : Mathieu Taillefumier + +-if(NOT +- (CMAKE_C_COMPILER_LOADED +- OR CMAKE_CXX_COMPILER_LOADED +- 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 + # cmake-format: sortable +@@ -34,8 +27,6 @@ if(NOT CP2K_CONFIG_PACKAGE) + 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) +@@ -152,3 +143,4 @@ mark_as_advanced(CP2K_BLAS_INCLUDE_DIRS) + mark_as_advanced(CP2K_BLAS_LINK_LIBRARIES) + mark_as_advanced(CP2K_BLAS_VENDOR) + mark_as_advanced(CP2K_BLAS_FOUND) ++mark_as_advanced(CP2K_BLAS_VENDOR_LIST) +diff --git a/cmake/modules/FindLibXSMM.cmake b/cmake/modules/FindLibXSMM.cmake +index 60fe8c836d..4d0fe8f2eb 100644 +--- a/cmake/modules/FindLibXSMM.cmake ++++ b/cmake/modules/FindLibXSMM.cmake +@@ -75,26 +75,28 @@ else() + CP2K_LIBXSMM_LINK_LIBRARIES) + endif() + +-if(NOT TARGET cp2k::LibXSMM::libxsmm) +- foreach(__lib libxsmm libxsmmf libxsmmext libxsmmnoblas) ++if(NOT TARGET cp2k::LibXSMM) ++ add_library(cp2k::LibXSMM INTERFACE IMPORTED) ++ foreach(__lib libxsmmf libxsmmext libxsmm libxsmmnoblas) + string(TOUPPER "CP2K_${__lib}" __lib_search_up) + + if(${__lib_search_up}_FOUND AND NOT TARGET cp2k::LibXSMM::${__lib}) + add_library(cp2k::LibXSMM::${__lib} INTERFACE IMPORTED) + target_link_directories(cp2k::LibXSMM::${__lib} INTERFACE + ${${__lib_search_up}_LIBRARY_DIRS}) +- endif() +- +- set_target_properties( +- cp2k::LibXSMM::${__lib} PROPERTIES INTERFACE_LINK_LIBRARIES +- "${${__lib_search_up}_LINK_LIBRARIES}") +- +- if(CP2K_LIBXSMM_INCLUDE_DIRS) + set_target_properties( + cp2k::LibXSMM::${__lib} +- PROPERTIES INTERFACE_INCLUDE_DIRECTORIES +- "${CP2K_LIBXSMM_INCLUDE_DIRS};${CP2K_LIBXSMM_PREFIX}/include" +- ) ++ PROPERTIES INTERFACE_LINK_LIBRARIES ++ "${${__lib_search_up}_LINK_LIBRARIES}") ++ ++ if(CP2K_LIBXSMM_INCLUDE_DIRS) ++ set_target_properties( ++ cp2k::LibXSMM::${__lib} ++ PROPERTIES ++ INTERFACE_INCLUDE_DIRECTORIES ++ "${CP2K_LIBXSMM_INCLUDE_DIRS};${CP2K_LIBXSMM_PREFIX}/include") ++ endif() ++ target_link_libraries(cp2k::LibXSMM INTERFACE cp2k::LibXSMM::${__lib}) + endif() + endforeach() + endif() +diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt +index d2baf2a32b..ab2e674807 100644 +--- a/src/CMakeLists.txt ++++ b/src/CMakeLists.txt +@@ -1635,14 +1635,13 @@ set(CP2K_GPU_DFLAGS + # ############################################################################## + + add_fypp_sources(CP2K_SRCS ${CP2K_SRCS_F}) +- +-# TODO Add __SHORT_FILE__ also to program files, e.g. metadyn_tools/graph.F ++add_fypp_sources(CP2K_PROGS_F_FYPP ${CP2K_PROGS_F}) + + # set the __SHORT_FILE__ per file for CP2K sources +-foreach(cp2k_src ${CP2K_SRCS}) +- # add_fypp_sources returns a path in the current binary dir +- file(RELATIVE_PATH short_file "${CMAKE_BINARY_DIR}/src" "${cp2k_src}") +- set_source_files_properties( ++foreach(cp2k_src ${CP2K_SRCS} ${CP2K_PROGS_F_FYPP}) ++# add_fypp_sources returns a path in the current binary dir ++file(RELATIVE_PATH short_file "${CMAKE_BINARY_DIR}/src" "${cp2k_src}") ++set_source_files_properties( + ${cp2k_src} PROPERTIES COMPILE_DEFINITIONS __SHORT_FILE__="${short_file}") + endforeach() + +diff --git a/src/input_cp2k_pwdft.F b/src/input_cp2k_pwdft.F +index 0a86c14b9f..507c89efa5 100644 +--- a/src/input_cp2k_pwdft.F ++++ b/src/input_cp2k_pwdft.F +@@ -18,7 +18,7 @@ MODULE input_cp2k_pwdft + USE SIRIUS, ONLY: & + sirius_option_get, & + sirius_option_get_section_length, sirius_option_get_info, & +- SIRIUS_INTEGER_TYPE, SIRIUS_NUMBER_TYPE, SIRIUS_STRING_TYPE, & ++ SIRIUS_INTEGER_TYPE, SIRIUS_NUMBER_TYPE, SIRIUS_STRING_TYPE, SIRIUS_OBJECT_TYPE, & + SIRIUS_LOGICAL_TYPE, SIRIUS_ARRAY_TYPE, SIRIUS_INTEGER_ARRAY_TYPE, SIRIUS_LOGICAL_ARRAY_TYPE, & + SIRIUS_NUMBER_ARRAY_TYPE, SIRIUS_STRING_ARRAY_TYPE, string_f2c + #endif +@@ -186,13 +186,13 @@ CONTAINS + CHARACTER(len=*), INTENT(in) :: section_name + + CHARACTER(len=128) :: name +- CHARACTER(len=128), TARGET :: possible_values(1:16) ++ CHARACTER(len=128), TARGET :: possible_values(1:256) + CHARACTER(len=4096) :: description, usage +- INTEGER :: ctype, enum_i_val(1:16), enum_length, i, & +- j, length, num_possible_values +- INTEGER, ALLOCATABLE, DIMENSION(:), TARGET :: ivec ++ INTEGER :: ctype, enum_length, i, j, length, & ++ num_possible_values ++ INTEGER, ALLOCATABLE, DIMENSION(:), TARGET :: enum_i_val, ivec + INTEGER, TARGET :: dummy_i +- LOGICAL :: lvecl(1:16) ++ LOGICAL :: jump_dft_parameters, lvecl(1:16) + LOGICAL(4), ALLOCATABLE, DIMENSION(:), TARGET :: lvec + LOGICAL(4), TARGET :: dummy_l + REAL(kind=dp), ALLOCATABLE, DIMENSION(:), TARGET :: rvec +@@ -202,7 +202,8 @@ CONTAINS + ALLOCATE (ivec(1:16)) + ALLOCATE (rvec(1:16)) + ALLOCATE (lvec(1:16)) +- ++ ALLOCATE (enum_i_val(1:256)) ++ jump_dft_parameters = .FALSE. + #ifdef __LIBVDWXC + IF (section_name == "parameters") THEN + NULLIFY (keyword) +@@ -238,10 +239,18 @@ CONTAINS + 4096, & + usage, & + 4096) ++ + ! description and usage are ignored here + ! it is a minor inconvenience from the api. +- + name = TRIM(ADJUSTL(name)) ++ ++#if defined(__SIRIUS_DFTD4) ++ ! need to implement the object case within a section ++ IF (((section_name == 'dftd3') .OR. (section_name == 'dftd4')) .AND. (name == 'parameters')) THEN ++ CYCLE ++ END IF ++#endif ++ + ! I exclude these three keywords because one of them is for debugging + ! purpose the other are replaced by a dedicated call in cp2k + ! +@@ -403,10 +412,19 @@ CONTAINS + END IF + CALL section_add_keyword(section, keyword) + CALL keyword_release(keyword) ++ !CASE (SIRIUS_OBJECT_TYPE) ++ ! create a subsection for the dftd3/dftd4 parameters ++ !CALL create_sirius_section(sub_section, sub_section_name) ++ !CALL section_add_subsection(section, sub_section) ++ !CALL section_release(sub_section) + CASE default + END SELECT + END IF + END DO ++ DEALLOCATE (ivec) ++ DEALLOCATE (rvec) ++ DEALLOCATE (lvec) ++ DEALLOCATE (enum_i_val) + END SUBROUTINE fill_in_section + + ! ************************************************************************************************** +diff --git a/src/sirius_interface.F b/src/sirius_interface.F +index 120998477f..f3b18804df 100644 +--- a/src/sirius_interface.F ++++ b/src/sirius_interface.F +@@ -229,7 +229,7 @@ CONTAINS + CASE (SIRIUS_FUNC_VDWDF2) + CALL sirius_add_xc_functional(sctx, "XC_FUNC_VDWDF2") + CASE (SIRIUS_FUNC_VDWDFCX) +- CALL sirius_add_xc_functional(sctx, "XC_FUNC_VDWDF2") ++ CALL sirius_add_xc_functional(sctx, "XC_FUNC_VDWDFCX") + CASE default + END SELECT + #endif +@@ -671,6 +671,12 @@ CONTAINS + 4096, & + usage, & + 4096) ++ ++ ! ignore the keyword parametes for sections dftd3 and dftd4. ++ IF (((section_name == 'dftd3') .OR. (section_name == 'dftd4')) .AND. (option_name == 'parameters')) THEN ++ CYCLE ++ END IF ++ + IF ((option_name /= 'memory_usage') .AND. (option_name /= 'xc_functionals') .AND. (option_name /= 'vk')) THEN + CALL section_vals_val_get(section, option_name, explicit=found) + IF (found) THEN diff --git a/recipes/cp2k/2025.2/mi300/repo/packages/cp2k/vdwxc.patch b/recipes/cp2k/2025.2/mi300/repo/packages/cp2k/vdwxc.patch new file mode 100644 index 000000000..e69de29bb diff --git a/recipes/cp2k/2025.2/mi300/repo/packages/dbcsr/package.py b/recipes/cp2k/2025.2/mi300/repo/packages/dbcsr/package.py new file mode 100644 index 000000000..cb54efff7 --- /dev/null +++ b/recipes/cp2k/2025.2/mi300/repo/packages/dbcsr/package.py @@ -0,0 +1,271 @@ +# Copyright Spack Project Developers. See COPYRIGHT file for details. +# +# SPDX-License-Identifier: (Apache-2.0 OR MIT) + +import os + +from spack_repo.builtin.build_systems.cmake import CMakePackage, generator +from spack_repo.builtin.build_systems.cuda import CudaPackage +from spack_repo.builtin.build_systems.rocm import ROCmPackage + +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", "RMeli", "hfp") + + license("GPL-2.0-or-later") + + version("develop", branch="develop") + version( + "2.8.0", + sha256="d55e4f052f28d1ed0faeaa07557241439243287a184d1fd27f875c8b9ca6bd96", + ) + 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("tests", default=False, description="Build DBCSR unit tests") + variant( + "tests", default=True, description="Build DBCSR unit tests", when="@2.1:2.2" + ) + variant("mpi", default=True, description="Compile with MPI") + variant("openmp", default=True, 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") + + variant("g2g", default=False, description="GPU-aware MPI with CUDA/HIP") + conflicts("+g2g", when="~cuda ~rocm", msg="GPU-aware MPI requires +cuda or +rocm") + + depends_on("c", type="build") # generated + depends_on("cxx", type="build") # generated + depends_on("fortran", type="build") # generated + + depends_on("blas") + depends_on("lapack") + depends_on("mpi", when="+mpi") + + with when("smm=libxsmm"): + depends_on("libxsmm@1.11:") + + 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") + + # Several packages provide "opencl" (incl. ICD/loader), e.g., "cuda" + depends_on("opencl", when="+opencl") + opencl_loader_header_version = "2022.10.24" + depends_on(f"opencl-c-headers@{opencl_loader_header_version}:", when="+opencl") + requires( + f"%opencl=opencl-icd-loader@{opencl_loader_header_version}:", 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 = f"dbcsr only supports cuda_arch {dbcsr_cuda_archs}" + + for arch in CudaPackage.cuda_arch_values: + if arch not in dbcsr_cuda_archs: + conflicts("+cuda", when=f"cuda_arch={arch}", msg=cuda_msg) + + conflicts("+cuda", when="cuda_arch=none", msg=cuda_msg) + + dbcsr_amdgpu_targets = ( + "gfx906", + "gfx910", + "gfx90a", + "gfx90a:xnack-", + "gfx90a:xnack+", + "gfx942", + ) + amd_msg = f"""DBCSR supports these AMD gpu targets: {', '.join(dbcsr_amdgpu_targets)}. + Set amdgpu_target explicitly to one of the supported targets""" + + for arch in ROCmPackage.amdgpu_targets: + if arch not in dbcsr_amdgpu_targets: + conflicts("+rocm", when=f"amdgpu_target={arch}", msg=amd_msg) + + # GPU runtimes are usually mutually exclusive + accel_msg = "CUDA and ROCm 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 by making other options conflict + conflicts("^intel-oneapi-mkl threads=none", when="+openmp") + conflicts("^intel-oneapi-mkl threads=tbb", when="+openmp") + conflicts("^openblas threads=pthreads", when="+openmp") + conflicts("^openblas threads=none", when="+openmp") + + # OpenCL backend implementation relies on LIBXSMM + requires("smm=libxsmm", 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") + + # @when("+rocm") + # def patch(self): + # for directory, subdirectory, files in os.walk(os.getcwd()): + # for i in files: + # file_path = os.path.join(directory, i) + # filter_file("USE ISO_C_BINDING", "USE,INTRINSIC :: ISO_C_BINDING", file_path) + # filter_file("USE ISO_FORTRAN_ENV", "USE,INTRINSIC :: ISO_FORTRAN_ENV", file_path) + # filter_file("USE omp_lib", "USE,INTRINSIC :: omp_lib", file_path) + # filter_file("USE OMP_LIB", "USE,INTRINSIC :: OMP_LIB", file_path) + # filter_file("USE iso_c_binding", "USE,INTRINSIC :: iso_c_binding", file_path) + # filter_file("USE iso_fortran_env", "USE,INTRINSIC :: iso_fortran_env", file_path) + + 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"), + self.define_from_variant("BUILD_SHARED_LIBS", "shared"), + self.define_from_variant("WITH_EXAMPLES", "examples"), + self.define_from_variant("WITH_G2G", "g2g"), + self.define_from_variant("BUILD_TESTING", "tests"), + ] + + lapack, blas = spec["lapack"], spec["blas"] + if blas.name != "intel-oneapi-mkl": + args = [ + "-DBLAS_FOUND=true", + "-DBLAS_LIBRARIES=%s" % (blas.libs.joined(";")), + "-DLAPACK_FOUND=true", + "-DLAPACK_LIBRARIES=%s" % (lapack.libs.joined(";")), + ] + + 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", + "gfx942": "Mi250", + }[amd_arch] + + args += [f"-DWITH_GPU={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/2025.2/mi300/repo/packages/libvdwxc/fftw-detection.patch b/recipes/cp2k/2025.2/mi300/repo/packages/libvdwxc/fftw-detection.patch new file mode 100644 index 000000000..f009188f5 --- /dev/null +++ b/recipes/cp2k/2025.2/mi300/repo/packages/libvdwxc/fftw-detection.patch @@ -0,0 +1,13 @@ +diff --git a/configure b/configure +index 494ea9f..1ca6516 100755 +--- a/configure ++++ b/configure +@@ -17006,7 +17006,7 @@ int + main () + { + +- fftw_plan *plan; ++ fftw_plan plan; + fftw_complex *a1, *a2; + fftw_execute_dft(plan, a1, a2); + diff --git a/recipes/cp2k/2025.2/mi300/repo/packages/libvdwxc/package.py b/recipes/cp2k/2025.2/mi300/repo/packages/libvdwxc/package.py new file mode 100644 index 000000000..e1cda7175 --- /dev/null +++ b/recipes/cp2k/2025.2/mi300/repo/packages/libvdwxc/package.py @@ -0,0 +1,68 @@ +# Copyright Spack Project Developers. See COPYRIGHT file for details. +# +# SPDX-License-Identifier: (Apache-2.0 OR MIT) + + +from spack_repo.builtin.build_systems.autotools import AutotoolsPackage + +from spack.package import * + + +class Libvdwxc(AutotoolsPackage): + """Portable C library of density functionals with van der Waals + interactions for density functional theory""" + + homepage = "https://libvdwxc.gitlab.io/libvdwxc/" + url = "https://launchpad.net/libvdwxc/stable/0.5.0/+download/libvdwxc-0.5.0.tar.gz" + git = "https://gitlab.com/libvdwxc/libvdwxc" + + license("GPL-3.0-or-later") + + version("master", branch="master", submodules="False") + version("0.5.0", sha256="29fb70efd58aff51524d2172a87e8f88e760b696b0ddb9aa5878432bdffa3c2f") + version("0.4.0", sha256="3524feb5bb2be86b4688f71653502146b181e66f3f75b8bdaf23dd1ae4a56b33") + + variant("mpi", default=True, description="Enable MPI support") + variant("pfft", default=False, description="Enable support for PFFT") + + depends_on("c", type="build") # generated + depends_on("fortran", type="build") # generated + + depends_on("fftw-api@3") + depends_on("mpi@2:", when="+mpi") + depends_on("pfft", when="+pfft") + + # pfft needs MPI + conflicts("~mpi", "+pfft") + conflicts("^fftw~mpi", "+mpi") + + def configure_args(self): + spec = self.spec + + args = [ + "--with-fftw3={0}".format(self["fftw"].prefix), # make sure that fftw path is given + "--{0}-pfft".format("with" if self.spec.satisfies("+pfft") else "without"), + "MPICC=", # make sure both variables are always unset + "MPIFC=", # otherwise the configure scripts complains + ] + + if spec.satisfies("+mpi"): + # work around b0rken MPI detection: the MPI detection tests are + # run with CC instead of MPICC, triggering an error. So, setting + # CC/FC to the MPI compiler wrappers. + args += [ + "--with-mpi", + "CC={0}".format(spec["mpi"].mpicc), + "FC={0}".format(spec["mpi"].mpifc), + ] + else: + args += ["--without-mpi"] + + return args + + # misuse of fftw_plan in m4 for fftw detection (configure fails with gcc 14) + # Only the configure script is patched, NOT the m4 macro (to avoid depending on aclocal), + # so running autoreconf is not supported. + # The relevant upstream fix for the m4 would be: + # https://gitlab.com/libvdwxc/libvdwxc/-/commit/9340f857515c4a2e56d2aa7cf3a21c41ba8559c3.diff + patch("fftw-detection.patch", when="@:0.4.0")