Merge pull request #258863 from sheepforce/cp2k

cp2k: enable SIRIUS planewave code and optimisations

authored by markuskowa and committed by GitHub b7129e44 55b51adc

+375 -13
+85 -13
pkgs/applications/science/chemistry/cp2k/default.nix
··· 1 - { lib, stdenv, fetchFromGitHub, mpiCheckPhaseHook, python3, gfortran, blas, lapack 2 - , fftw, libint, libvori, libxc, mpi, gsl, scalapack, openssh, makeWrapper 3 - , libxsmm, spglib, which, pkg-config, plumed, zlib 1 + { lib 2 + , stdenv 3 + , fetchFromGitHub 4 + , mpiCheckPhaseHook 5 + , python3 6 + , gfortran 7 + , blas 8 + , lapack 9 + , fftw 10 + , libint 11 + , libvori 12 + , libxc 13 + , mpi 14 + , gsl 15 + , scalapack 16 + , openssh 17 + , makeWrapper 18 + , libxsmm 19 + , spglib 20 + , which 21 + , pkg-config 22 + , plumed 23 + , zlib 24 + , hdf5-fortran 25 + , sirius 26 + , libvdwxc 27 + , spla 28 + , spfft 4 29 , enableElpa ? false 5 30 , elpa 6 - } : 31 + , gpuBackend ? "none" 32 + , cudaPackages 33 + # gpuVersion needs to be set for both CUDA as well as ROCM hardware. 34 + # gpuArch is only required for the ROCM stack. 35 + # Change to a value suitable for your target GPU. 36 + # For AMD values see https://github.com/cp2k/cp2k/blob/master/INSTALL.md#2v-rocmhip-support-for-amd-gpu 37 + # and for Nvidia see https://github.com/cp2k/cp2k/blob/master/INSTALL.md#2i-cuda-optional-improved-performance-on-gpu-systems 38 + , gpuVersion ? "Mi100" 39 + , gpuArch ? "gfx908" 40 + , rocm-core 41 + , hip 42 + , hipblas 43 + , hipfft 44 + , rocblas 45 + }: 46 + 47 + assert builtins.elem gpuBackend [ "none" "cuda" "rocm" ]; 7 48 8 49 let 9 50 cp2kVersion = "psmp"; 10 51 arch = "Linux-x86-64-gfortran"; 11 52 12 - in stdenv.mkDerivation rec { 53 + in 54 + stdenv.mkDerivation rec { 13 55 pname = "cp2k"; 14 56 version = "2023.2"; 15 57 ··· 36 78 lapack 37 79 plumed 38 80 zlib 39 - ] ++ lib.optional enableElpa elpa; 81 + hdf5-fortran 82 + sirius 83 + spla 84 + spfft 85 + libvdwxc 86 + ] 87 + ++ lib.optional enableElpa elpa 88 + ++ lib.optional (gpuBackend == "cuda") cudaPackages.cudatoolkit 89 + ++ lib.optional (gpuBackend == "rocm") [hip rocm-core hipblas hipfft rocblas] 90 + ; 40 91 41 92 propagatedBuildInputs = [ mpi ]; 42 93 propagatedUserEnvPkgs = [ mpi ]; ··· 46 97 "VERSION=${cp2kVersion}" 47 98 ]; 48 99 49 - doCheck = true; 100 + doCheck = gpuBackend == "none"; 50 101 51 102 enableParallelBuilding = true; 52 103 ··· 64 115 FC = mpif90 65 116 LD = mpif90 66 117 AR = ar -r 118 + ${lib.strings.optionalString (gpuBackend == "cuda") '' 119 + OFFLOAD_CC = nvcc 120 + OFFLOAD_FLAGS = -O3 -g -w --std=c++11 121 + OFFLOAD_TARGET = cuda 122 + GPUVER = ${gpuVersion} 123 + CXX = mpicxx 124 + CXXFLAGS = -std=c++11 -fopenmp 125 + ''} 126 + ${lib.strings.optionalString (gpuBackend == "rocm") '' 127 + GPUVER = ${gpuVersion} 128 + OFFLOAD_CC = hipcc 129 + OFFLOAD_FLAGS = -fopenmp -m64 -pthread -fPIC -D__GRID_HIP -O2 --offload-arch=${gpuArch} --rocm-path=${rocm-core} 130 + OFFLOAD_TARGET = hip 131 + CXX = mpicxx 132 + CXXFLAGS = -std=c++11 -fopenmp -D__HIP_PLATFORM_AMD__ 133 + ''} 67 134 DFLAGS = -D__FFTW3 -D__LIBXC -D__LIBINT -D__parallel -D__SCALAPACK \ 68 135 -D__MPI_VERSION=3 -D__F2008 -D__LIBXSMM -D__SPGLIB \ 69 136 -D__MAX_CONTR=4 -D__LIBVORI ${lib.optionalString enableElpa "-D__ELPA"} \ 70 - -D__PLUMED2 71 - CFLAGS = -fopenmp 137 + -D__PLUMED2 -D__HDF5 -D__GSL -D__SIRIUS -D__LIBVDWXC -D__SPFFT -D__SPLA \ 138 + ${lib.strings.optionalString (gpuBackend == "cuda") "-D__OFFLOAD_CUDA -D__DBCSR_ACC"} \ 139 + ${lib.strings.optionalString (gpuBackend == "rocm") "-D__OFFLOAD_HIP -D__DBCSR_ACC -D__NO_OFFLOAD_PW"} 140 + CFLAGS = -fopenmp -I${lib.getDev hdf5-fortran}/include -I${lib.getDev gsl}/include 72 141 FCFLAGS = \$(DFLAGS) -O2 -ffree-form -ffree-line-length-none \ 73 142 -ftree-vectorize -funroll-loops -msse2 \ 74 143 -std=f2008 \ 75 144 -fopenmp -ftree-vectorize -funroll-loops \ 76 - -I${lib.getDev libxc}/include -I${lib.getDev libxsmm}/include \ 77 - -I${libint}/include ${lib.optionalString enableElpa "$(pkg-config --variable=fcflags elpa)"} 145 + -I${lib.getDev libint}/include ${lib.optionalString enableElpa "$(pkg-config --variable=fcflags elpa)"} \ 146 + -I${lib.getDev sirius}/include/sirius \ 147 + -I${lib.getDev libxc}/include -I${lib.getDev libxsmm}/include 78 148 LIBS = -lfftw3 -lfftw3_threads \ 79 149 -lscalapack -lblas -llapack \ 80 150 -lxcf03 -lxc -lxsmmf -lxsmm -lsymspg \ 81 151 -lint2 -lstdc++ -lvori \ 82 152 -lgomp -lpthread -lm \ 83 153 -fopenmp ${lib.optionalString enableElpa "$(pkg-config --libs elpa)"} \ 84 - -lz -ldl -lstdc++ ${lib.optionalString (mpi.pname == "openmpi") "$(mpicxx --showme:link)"} \ 85 - -lplumed 154 + -lz -ldl ${lib.optionalString (mpi.pname == "openmpi") "$(mpicxx --showme:link)"} \ 155 + -lplumed -lhdf5_fortran -lhdf5_hl -lhdf5 -lgsl -lsirius -lspla -lspfft -lvdwxc \ 156 + ${lib.strings.optionalString (gpuBackend == "cuda") "-lcudart -lnvrtc -lcuda -lcublas"} \ 157 + ${lib.strings.optionalString (gpuBackend == "rocm") "-lamdhip64 -lhipfft -lhipblas -lrocblas"} 86 158 LDFLAGS = \$(FCFLAGS) \$(LIBS) 87 159 include ${plumed}/lib/plumed/src/lib/Plumed.inc 88 160 EOF
+40
pkgs/by-name/co/costa/package.nix
··· 1 + { stdenv 2 + , lib 3 + , fetchFromGitHub 4 + , cmake 5 + , mpi 6 + , scalapack 7 + , llvmPackages 8 + }: 9 + 10 + stdenv.mkDerivation rec { 11 + pname = "COSTA"; 12 + version = "2.2.2"; 13 + 14 + src = fetchFromGitHub { 15 + owner = "eth-cscs"; 16 + repo = pname; 17 + rev = "v${version}"; 18 + hash = "sha256-jiAyZXC7wiuEnOLsQFFLxhN3AsGXN09q/gHC2Hrb2gg="; 19 + }; 20 + 21 + nativeBuildInputs = [ cmake ]; 22 + 23 + buildInputs = [ scalapack ] ++ lib.optional stdenv.isDarwin llvmPackages.openmp; 24 + 25 + propagatedBuildInputs = [ mpi ]; 26 + 27 + cmakeFlags = [ 28 + "-DCOSTA_SCALAPACK=CUSTOM" 29 + "-DSCALAPACK_ROOT=${scalapack}" 30 + ]; 31 + 32 + 33 + meta = with lib; { 34 + description = "Distributed Communication-Optimal Shuffle and Transpose Algorithm"; 35 + homepage = "https://github.com/eth-cscs/COSTA"; 36 + license = licenses.bsd3; 37 + platforms = platforms.linux; 38 + maintainers = [ maintainers.sheepforce ]; 39 + }; 40 + }
+117
pkgs/by-name/si/sirius/package.nix
··· 1 + { stdenv 2 + , lib 3 + , fetchFromGitHub 4 + , cmake 5 + , pkg-config 6 + , mpi 7 + , mpiCheckPhaseHook 8 + , openssh 9 + , gfortran 10 + , blas 11 + , lapack 12 + , gsl 13 + , libxc 14 + , hdf5 15 + , spglib 16 + , spfft 17 + , spla 18 + , costa 19 + , scalapack 20 + , boost 21 + , eigen 22 + , libvdwxc 23 + , llvmPackages 24 + , gpuBackend ? "none" 25 + , cudaPackages 26 + , hip 27 + , rocblas 28 + }: 29 + 30 + assert builtins.elem gpuBackend [ "none" "cuda" "rocm" ]; 31 + 32 + stdenv.mkDerivation rec { 33 + pname = "SIRIUS"; 34 + version = "7.4.3"; 35 + 36 + src = fetchFromGitHub { 37 + owner = "electronic-structure"; 38 + repo = pname; 39 + rev = "v${version}"; 40 + hash = "sha256-s4rO+dePvtvn41wxCvbqgQGrEckWmfng7sPX2M8OPB0="; 41 + }; 42 + 43 + postPatch = '' 44 + substituteInPlace src/gpu/acc_blas_api.hpp \ 45 + --replace '#include <rocblas.h>' '#include <rocblas/rocblas.h>' 46 + ''; 47 + 48 + nativeBuildInputs = [ 49 + cmake 50 + gfortran 51 + pkg-config 52 + ]; 53 + 54 + buildInputs = [ 55 + blas 56 + lapack 57 + gsl 58 + libxc 59 + hdf5 60 + spglib 61 + spfft 62 + spla 63 + costa 64 + scalapack 65 + boost 66 + eigen 67 + libvdwxc 68 + ] 69 + ++ lib.optional (gpuBackend == "cuda") cudaPackages.cudatoolkit 70 + ++ lib.optionals (gpuBackend == "rocm") [ hip rocblas ] 71 + ++ lib.optional stdenv.isDarwin llvmPackages.openmp 72 + ; 73 + 74 + propagatedBuildInputs = [ mpi ]; 75 + 76 + cmakeFlags = [ 77 + "-DUSE_SCALAPACK=ON" 78 + "-DBUILD_TESTING=ON" 79 + "-DUSE_VDWXC=ON" 80 + "-DCREATE_FORTRAN_BINDINGS=ON" 81 + "-DUSE_OPENMP=ON" 82 + "-DBUILD_TESTING=ON" 83 + ] 84 + ++ lib.optionals (gpuBackend == "cuda") [ 85 + "-DUSE_CUDA=ON" 86 + "-DCUDA_TOOLKIT_ROOT_DIR=${cudaPackages.cudatoolkit}" 87 + ] 88 + ++ lib.optionals (gpuBackend == "rocm") [ 89 + "-DUSE_ROCM=ON" 90 + "-DHIP_ROOT_DIR=${hip}" 91 + ]; 92 + 93 + doCheck = true; 94 + 95 + # Can not run parallel checks generally as it requires exactly multiples of 4 MPI ranks 96 + checkPhase = '' 97 + runHook preCheck 98 + 99 + ctest --output-on-failure --label-exclude integration_test 100 + ctest --output-on-failure -L cpu_serial 101 + 102 + runHook postCheck 103 + ''; 104 + 105 + nativeCheckInputs = [ 106 + mpiCheckPhaseHook 107 + openssh 108 + ]; 109 + 110 + meta = with lib; { 111 + description = "Domain specific library for electronic structure calculations"; 112 + homepage = "https://github.com/electronic-structure/SIRIUS"; 113 + license = licenses.bsd2; 114 + platforms = platforms.linux; 115 + maintainers = [ maintainers.sheepforce ]; 116 + }; 117 + }
+67
pkgs/by-name/sp/spfft/package.nix
··· 1 + { stdenv 2 + , lib 3 + , fetchFromGitHub 4 + , fftw 5 + , cmake 6 + , mpi 7 + , gfortran 8 + , llvmPackages 9 + , gpuBackend ? "none" 10 + , cudaPackages 11 + , hip 12 + , rocfft 13 + , hipfft 14 + }: 15 + 16 + assert builtins.elem gpuBackend [ "none" "cuda" "rocm" ]; 17 + 18 + stdenv.mkDerivation rec { 19 + pname = "SpFFT"; 20 + version = "1.0.6"; 21 + 22 + src = fetchFromGitHub { 23 + owner = "eth-cscs"; 24 + repo = pname; 25 + rev = "v${version}"; 26 + hash = "sha256-70fPbIYbW50CoMdRS93hZKSbMEIQvZGFNE+eiRvuw0o="; 27 + }; 28 + 29 + nativeBuildInputs = [ 30 + cmake 31 + gfortran 32 + ]; 33 + 34 + buildInputs = [ 35 + fftw 36 + ] 37 + ++ lib.optional (gpuBackend == "cuda") cudaPackages.cudatoolkit 38 + ++ lib.optionals (gpuBackend == "rocm") [ hip rocfft hipfft ] 39 + ++ lib.optional stdenv.isDarwin llvmPackages.openmp 40 + ; 41 + 42 + propagatedBuildInputs = [ mpi ]; 43 + 44 + cmakeFlags = [ 45 + "-DSPFFT_OMP=ON" 46 + "-DSPFFT_MPI=ON" 47 + "-DSPFFT_SINGLE_PRECISION=OFF" 48 + "-DSPFFT_FORTRAN=ON" 49 + # Required due to broken CMake files 50 + "-DCMAKE_INSTALL_LIBDIR=lib" 51 + "-DCMAKE_INSTALL_INCLUDEDIR=include" 52 + ] 53 + ++ lib.optional (gpuBackend == "cuda") "-DSPFFT_GPU_BACKEND=CUDA" 54 + ++ lib.optionals (gpuBackend == "rocm") [ 55 + "-DSPFFT_GPU_BACKEND=ROCM" 56 + "-DHIP_ROOT_DIR=${hip}" 57 + ]; 58 + 59 + 60 + meta = with lib; { 61 + description = "Sparse 3D FFT library with MPI, OpenMP, CUDA and ROCm support"; 62 + homepage = "https://github.com/eth-cscs/SpFFT"; 63 + license = licenses.bsd3; 64 + maintainers = [ maintainers.sheepforce ]; 65 + platforms = platforms.linux; 66 + }; 67 + }
+66
pkgs/by-name/sp/spla/package.nix
··· 1 + { stdenv 2 + , lib 3 + , fetchFromGitHub 4 + , cmake 5 + , mpi 6 + , blas 7 + , gfortran 8 + , llvmPackages 9 + , gpuBackend ? "none" 10 + , cudaPackages 11 + , hip 12 + , rocblas 13 + }: 14 + 15 + assert builtins.elem gpuBackend [ "none" "cuda" "rocm" ]; 16 + 17 + stdenv.mkDerivation rec { 18 + pname = "spla"; 19 + version = "1.5.5"; 20 + 21 + src = fetchFromGitHub { 22 + owner = "eth-cscs"; 23 + repo = pname; 24 + rev = "v${version}"; 25 + hash = "sha256-71QpwTsRogH+6Bik9DKwezl9SqwoLxQt4SZ7zw5X6DE="; 26 + }; 27 + 28 + postPatch = '' 29 + substituteInPlace src/gpu_util/gpu_blas_api.hpp \ 30 + --replace '#include <rocblas.h>' '#include <rocblas/rocblas.h>' 31 + ''; 32 + 33 + nativeBuildInputs = [ 34 + cmake 35 + gfortran 36 + ]; 37 + 38 + buildInputs = [ 39 + blas 40 + ] 41 + ++ lib.optional (gpuBackend == "cuda") cudaPackages.cudatoolkit 42 + ++ lib.optionals (gpuBackend == "rocm") [ hip rocblas rocblas ] 43 + ++ lib.optional stdenv.isDarwin llvmPackages.openmp 44 + ; 45 + 46 + propagatedBuildInputs = [ mpi ]; 47 + 48 + cmakeFlags = [ 49 + "-DSPLA_OMP=ON" 50 + "-DSPLA_FORTRAN=ON" 51 + "-DSPLA_INSTALL=ON" 52 + # Required due to broken CMake files 53 + "-DCMAKE_INSTALL_LIBDIR=lib" 54 + "-DCMAKE_INSTALL_INCLUDEDIR=include" 55 + ] 56 + ++ lib.optional (gpuBackend == "cuda") "-DSPLA_GPU_BACKEND=CUDA" 57 + ++ lib.optional (gpuBackend == "rocm") [ "-DSPLA_GPU_BACKEND=ROCM" ] 58 + ; 59 + 60 + meta = with lib; { 61 + description = "Specialized Parallel Linear Algebra, providing distributed GEMM functionality for specific matrix distributions with optional GPU acceleration"; 62 + homepage = "https://github.com/eth-cscs/spla"; 63 + license = licenses.bsd3; 64 + maintainers = [ maintainers.sheepforce ];# 65 + }; 66 + }