Unverified Commit 539ef5aa authored by Markus Kowalewski's avatar Markus Kowalewski Committed by GitHub
Browse files

cp2k: cleanup, format, move to pkgs/by-name (#344847)

parents 6f3ec147 4fc83956
Loading
Loading
Loading
Loading
+144 −113
Original line number Diff line number Diff line
{ lib
, stdenv
, fetchFromGitHub
, mpiCheckPhaseHook
, python3
, gfortran
, blas
, lapack
, fftw
, libint
, libvori
, libxc
, dftd4
, mctc-lib
, mstore
, multicharge
, mpi
, gsl
, scalapack
, openssh
, makeWrapper
, libxsmm
, spglib
, which
, pkg-config
, plumed
, zlib
, hdf5-fortran
, sirius
, libvdwxc
, spla
, spfft
, enableElpa ? false
, elpa
, cudaPackages
, rocmPackages
, config
, gpuBackend ? (
  if config.cudaSupport
  then "cuda"
  else if config.rocmSupport
  then "rocm"
  else "none"
)
{
  lib,
  stdenv,
  fetchFromGitHub,
  mpiCheckPhaseHook,
  python3,
  gfortran,
  blas,
  lapack,
  fftw,
  libint,
  libvori,
  libxc,
  dftd4,
  mctc-lib,
  mstore,
  multicharge,
  mpi,
  gsl,
  scalapack,
  openssh,
  makeWrapper,
  libxsmm,
  spglib,
  which,
  pkg-config,
  plumed,
  zlib,
  hdf5-fortran,
  sirius,
  libvdwxc,
  spla,
  spfft,
  enableElpa ? false,
  elpa,
  cudaPackages,
  rocmPackages,
  config,
  gpuBackend ? (
    if config.cudaSupport then
      "cuda"
    else if config.rocmSupport then
      "rocm"
    else
      "none"
  ),
  # Change to a value suitable for your target GPU.
  # For AMD values see https://github.com/cp2k/cp2k/blob/master/INSTALL.md#2v-rocmhip-support-for-amd-gpu
  # and for Nvidia see https://github.com/cp2k/cp2k/blob/master/INSTALL.md#2i-cuda-optional-improved-performance-on-gpu-systems
, gpuVersion ? ( if gpuBackend == "cuda" then "A100" else "Mi100" )
, gpuArch ? ( if gpuBackend == "cuda" then "sm_80" else "gfx908" )
  gpuVersion ? (if gpuBackend == "cuda" then "A100" else "Mi100"),
  gpuArch ? (if gpuBackend == "cuda" then "sm_80" else "gfx908"),
}:

assert builtins.elem gpuBackend [ "none" "cuda" "rocm" ];
assert builtins.elem gpuBackend [
  "none"
  "cuda"
  "rocm"
];

let
  cp2kVersion = "psmp";
@@ -74,10 +80,16 @@ stdenv.mkDerivation rec {
    ./remove-compiler-options.patch
  ];

  nativeBuildInputs = [ python3 which openssh makeWrapper pkg-config ]
    ++ lib.optional (gpuBackend == "cuda") cudaPackages.cuda_nvcc;
  nativeBuildInputs = [
    python3
    which
    openssh
    makeWrapper
    pkg-config
  ] ++ lib.optional (gpuBackend == "cuda") cudaPackages.cuda_nvcc;

  buildInputs = [
  buildInputs =
    [
      gfortran
      fftw
      gsl
@@ -107,14 +119,14 @@ stdenv.mkDerivation rec {
      cudaPackages.cuda_cudart
      cudaPackages.libcublas
      cudaPackages.cuda_nvrtc
  ] ++ lib.optionals (gpuBackend == "rocm") [
    ]
    ++ lib.optionals (gpuBackend == "rocm") [
      rocmPackages.clr
      rocmPackages.rocm-core
      rocmPackages.hipblas
      rocmPackages.hipfft
      rocmPackages.rocblas
  ]
  ;
    ];

  propagatedBuildInputs = [ (lib.getBin mpi) ];
  propagatedUserEnvPkgs = [ mpi ];
@@ -136,6 +148,8 @@ stdenv.mkDerivation rec {
  '';

  configurePhase = ''
    runHook preConfigure

    cat > arch/${arch}.${cp2kVersion} << EOF
    CC         = mpicc
    CPP        =
@@ -163,8 +177,14 @@ stdenv.mkDerivation rec {
                 -D__MAX_CONTR=4 -D__LIBVORI ${lib.optionalString enableElpa "-D__ELPA"} \
                 -D__PLUMED2 -D__HDF5 -D__GSL -D__SIRIUS -D__LIBVDWXC -D__SPFFT -D__SPLA \
                 -D__DFTD4 \
                 ${lib.strings.optionalString (gpuBackend == "cuda") "-D__OFFLOAD_CUDA -D__ACC -D__DBCSR_ACC -D__NO_OFFLOAD_PW"} \
                 ${lib.strings.optionalString (gpuBackend == "rocm") "-D__OFFLOAD_HIP -D__DBCSR_ACC -D__NO_OFFLOAD_PW"}
                 ${
                   lib.strings.optionalString (
                     gpuBackend == "cuda"
                   ) "-D__OFFLOAD_CUDA -D__ACC -D__DBCSR_ACC -D__NO_OFFLOAD_PW"
                 } \
                 ${
                   lib.strings.optionalString (gpuBackend == "rocm") "-D__OFFLOAD_HIP -D__DBCSR_ACC -D__NO_OFFLOAD_PW"
                 }
    CFLAGS    = -fopenmp
    FCFLAGS    = \$(DFLAGS) -O2 -ffree-form -ffree-line-length-none \
                 -ftree-vectorize -funroll-loops -msse2 \
@@ -187,15 +207,20 @@ stdenv.mkDerivation rec {
                 -lz -ldl ${lib.optionalString (mpi.pname == "openmpi") "$(mpicxx --showme:link)"} \
                 -lplumed -lhdf5_fortran -lhdf5_hl -lhdf5 -lgsl -lsirius -lspla -lspfft -lvdwxc \
                 -ldftd4 -lmstore -lmulticharge -lmctc-lib \
                 ${lib.strings.optionalString (gpuBackend == "cuda") ''
                 ${
                   lib.strings.optionalString (gpuBackend == "cuda") ''
                     -L${cudaPackages.cuda_cudart}/lib/stubs/ \
                     -lcudart -lnvrtc -lcuda -lcublas
                   ''
                 } \
                 ${lib.strings.optionalString (gpuBackend == "rocm") "-lamdhip64 -lhipfft -lhipblas -lrocblas"}
                 ${
                   lib.strings.optionalString (gpuBackend == "rocm") "-lamdhip64 -lhipfft -lhipblas -lrocblas"
                 }
    LDFLAGS    = \$(FCFLAGS) \$(LIBS)
    include ${plumed}/lib/plumed/src/lib/Plumed.inc
    EOF

    runHook postConfigure
  '';

  nativeCheckInputs = [
@@ -213,6 +238,8 @@ stdenv.mkDerivation rec {
  '';

  installPhase = ''
    runHook preInstall

    mkdir -p $out/bin $out/share/cp2k

    cp exe/${arch}/* $out/bin
@@ -228,15 +255,19 @@ stdenv.mkDerivation rec {
      --set OMP_NUM_THREADS 1

    cp -r data/* $out/share/cp2k

    runHook postInstall
  '';

  passthru = { inherit mpi; };
  passthru = {
    inherit mpi;
  };

  meta = with lib; {
  meta = {
    description = "Quantum chemistry and solid state physics program";
    homepage = "https://www.cp2k.org";
    license = licenses.gpl2Plus;
    maintainers = [ maintainers.sheepforce ];
    license = lib.licenses.gpl2Plus;
    maintainers = [ lib.maintainers.sheepforce ];
    platforms = [ "x86_64-linux" ];
  };
}
+0 −2
Original line number Diff line number Diff line
@@ -36024,8 +36024,6 @@ with pkgs;
  avogadro2 = libsForQt5.callPackage ../applications/science/chemistry/avogadro2 { };
  cp2k = callPackage ../applications/science/chemistry/cp2k { };
  d-seams = callPackage ../applications/science/chemistry/d-seams { };
  ergoscf = callPackage ../applications/science/chemistry/ergoscf { };