From b49bfe25af85e1197ba7de892fcab19e29387498 Mon Sep 17 00:00:00 2001 From: Simon Pintarelli <1237199+simonpintarelli@users.noreply.github.com> Date: Wed, 24 May 2023 11:17:15 +0200 Subject: [PATCH] update nlcglib package (#37578) --- .../repos/builtin/packages/nlcglib/package.py | 90 +++++++++++++------ .../repos/builtin/packages/sirius/package.py | 4 +- 2 files changed, 66 insertions(+), 28 deletions(-) diff --git a/var/spack/repos/builtin/packages/nlcglib/package.py b/var/spack/repos/builtin/packages/nlcglib/package.py index 5d470c68dc..b8869ed0ab 100644 --- a/var/spack/repos/builtin/packages/nlcglib/package.py +++ b/var/spack/repos/builtin/packages/nlcglib/package.py @@ -6,22 +6,23 @@ from spack.package import * -class Nlcglib(CMakePackage, CudaPackage): +class Nlcglib(CMakePackage, CudaPackage, ROCmPackage): """Nonlinear CG methods for wave-function optimization in DFT.""" homepage = "https://github.com/simonpintarelli/nlcglib" git = "https://github.com/simonpintarelli/nlcglib.git" url = "https://github.com/simonpintarelli/nlcglib/archive/v0.9.tar.gz" - maintainers("simonpintarelli") + maintainers = ["simonpintarelli"] - version("master", branch="master") version("develop", branch="develop") + version("master", branch="master") + version("1.0b", sha256="086c46f06a117f267cbdf1df4ad42a8512689a9610885763f463469fb15e82dc") version("0.9", sha256="8d5bc6b85ee714fb3d6480f767e7f43e5e7d569116cf60e48f533a7f50a37a08") - variant("wrapper", default=False, description="Use nvcc-wrapper for CUDA build") - variant("openmp", default=False) + variant("openmp", default=True) + variant("tests", default=False) variant( "build_type", default="Release", @@ -29,38 +30,73 @@ class Nlcglib(CMakePackage, CudaPackage): values=("Debug", "Release", "RelWithDebInfo"), ) + depends_on("cmake@3.21:", type="build") + depends_on("mpi") depends_on("lapack") - depends_on("kokkos +cuda~cuda_relocatable_device_code+cuda_lambda") - depends_on("kokkos-nvcc-wrapper", when="+wrapper") - depends_on("kokkos +cuda~cuda_relocatable_device_code+cuda_lambda+wrapper", when="+wrapper") - depends_on("cmake@3.15:", type="build") - depends_on( - "kokkos+cuda~cuda_relocatable_device_code+cuda_lambda+openmp+wrapper", - when="+openmp+wrapper", - ) + depends_on("kokkos~cuda~rocm", when="~cuda~rocm") + depends_on("kokkos+openmp", when="+openmp") + depends_on("googletest", type="build", when="+tests") + depends_on("nlohmann-json") + + with when("@:0.9"): + conflicts("+rocm") + conflicts("^kokkos@4:") + + with when("+rocm"): + variant("magma", default=True, description="Use magma eigenvalue solver (AMDGPU)") + depends_on("magma+rocm", when="+magma") + depends_on("kokkos+rocm") + depends_on("rocblas") + depends_on("rocsolver") + + with when("+cuda"): + depends_on("kokkos+cuda+cuda_lambda+wrapper", when="%gcc") + depends_on("kokkos+cuda") def cmake_args(self): - options = [] + options = [ + self.define_from_variant("USE_OPENMP", "openmp"), + self.define_from_variant("BUILD_TESTS", "tests"), + self.define_from_variant("USE_ROCM", "rocm"), + self.define_from_variant("USE_MAGMA", "magma"), + self.define_from_variant("USE_CUDA", "cuda"), + ] - if "+openmp" in self.spec: - options.append("-DUSE_OPENMP=On") - else: - options.append("-DUSE_OPENMP=Off") if self.spec["blas"].name in ["intel-mkl", "intel-parallel-studio"]: - options.append("-DLAPACK_VENDOR=MKL") + options += [self.define("LAPACK_VENDOR", "MKL")] + elif self.spec["blas"].name in ["intel-oneapi-mkl"]: + options += [self.define("LAPACK_VENDOR", "MKLONEAPI")] elif self.spec["blas"].name in ["openblas"]: - options.append("-DLAPACK_VENDOR=OpenBLAS") + options += [self.define("LAPACK_VENDOR", "OpenBLAS")] else: raise Exception("blas/lapack must be either openblas or mkl.") - options.append("-DBUILD_TESTS=OFF") - - if "+wrapper" in self.spec: - options.append("-DCMAKE_CXX_COMPILER=%s" % self.spec["kokkos-nvcc-wrapper"].kokkos_cxx) + if "+cuda%gcc" in self.spec: + options += [ + self.define( + "CMAKE_CXX_COMPILER", "{0}".format(self.spec["kokkos-nvcc-wrapper"].kokkos_cxx) + ) + ] if "+cuda" in self.spec: - cuda_arch = self.spec.variants["cuda_arch"].value - if cuda_arch[0] != "none": - options += ["-DCMAKE_CUDA_FLAGS=-arch=sm_{0}".format(cuda_arch[0])] + cuda_archs = self.spec.variants["cuda_arch"].value + if "@:0.9" in self.spec: + cuda_flags = " ".join( + ["-gencode arch=compute_{0},code=sm_{0}".format(x) for x in cuda_archs] + ) + options += [self.define("CMAKE_CUDA_FLAGS", cuda_flags)] + else: + options += [self.define("CMAKE_CUDA_ARCHITECTURES", cuda_archs)] + + if "^cuda+allow-unsupported-compilers" in self.spec: + options += [self.define("CMAKE_CUDA_FLAGS", "--allow-unsupported-compiler")] + + if "+rocm" in self.spec: + options.append(self.define("CMAKE_CXX_COMPILER", self.spec["hip"].hipcc)) + archs = ",".join(self.spec.variants["amdgpu_target"].value) + options.append("-DHIP_HCC_FLAGS=--amdgpu-target={0}".format(archs)) + options.append( + "-DCMAKE_CXX_FLAGS=--amdgpu-target={0} --offload-arch={0}".format(archs) + ) return options diff --git a/var/spack/repos/builtin/packages/sirius/package.py b/var/spack/repos/builtin/packages/sirius/package.py index 41dbdf9703..641a908377 100644 --- a/var/spack/repos/builtin/packages/sirius/package.py +++ b/var/spack/repos/builtin/packages/sirius/package.py @@ -203,6 +203,8 @@ class Sirius(CMakePackage, CudaPackage, ROCmPackage): depends_on("spla+openmp", when="+openmp ^spla") depends_on("nlcglib", when="+nlcglib") + depends_on("nlcglib+rocm", when="+nlcglib+rocm") + depends_on("nlcglib+cuda", when="+nlcglib+cuda") depends_on("libvdwxc@0.3.0:+mpi", when="+vdwxc") @@ -309,7 +311,7 @@ def cmake_args(self): if "^cray-libsci" in spec: args.append(self.define("USE_CRAY_LIBSCI", "ON")) - if spec["blas"].name in ["intel-mkl", "intel-parallel-studio"]: + if spec["blas"].name in ["intel-mkl", "intel-parallel-studio", "intel-oneapi-mkl"]: args.append(self.define("USE_MKL", "ON")) if "+elpa" in spec: