amg2023 package: cmake build (#39618)

Switch from makefile to CMake-based build. CMake support is currently
in a specific branch of the amg2023 repo, so add this branch as a
version in the package.
This commit is contained in:
Dewi 2023-08-29 15:47:36 -07:00 committed by GitHub
parent f3c6d892b1
commit f4f396745e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -6,7 +6,7 @@
from spack.package import *
class Amg2023(MakefilePackage):
class Amg2023(CMakePackage, CudaPackage, ROCmPackage):
"""AMG2023 is a parallel algebraic multigrid solver for linear systems
arising from problems on unstructured grids. The driver provided here
builds linear systems for various 3-dimensional problems. It requires
@ -18,66 +18,34 @@ class Amg2023(MakefilePackage):
git = "https://github.com/LLNL/AMG2023.git"
version("develop", branch="main")
version("cmake-build", git="https://github.com/dyokelson/AMG2023.git", branch="cmake")
variant("mpi", default=True, description="Enable MPI support")
variant("openmp", default=False, description="Enable OpenMP support")
variant("caliper", default=False, description="Enable Caliper monitoring")
variant("adiak", default=False, description="Enable Adiak metadata gathering")
depends_on("mpi", when="+mpi")
depends_on("hypre+mpi", when="+mpi")
requires("+mpi", when="^hypre+mpi")
depends_on("caliper", when="+caliper")
depends_on("adiak", when="+adiak")
depends_on("adiak", when="+caliper")
depends_on("hypre+caliper", when="+caliper")
depends_on("hypre@2.27.0:")
depends_on("mpi", when="+mpi")
depends_on("hypre+cuda", when="+cuda")
requires("+cuda", when="^hypre+cuda")
depends_on("hypre+rocm", when="+rocm")
requires("+rocm", when="^hypre+rocm")
def flag_handler(self, name, flags):
if name == "ldlibs":
if self.spec.satisfies("+caliper"):
flags.append("-lcaliper")
if self.spec.satisfies("+adiak"):
flags.append("-ladiak")
return (flags, None, None)
def cmake_args(self):
cmake_options = []
cmake_options.append(self.define_from_variant("AMG_WITH_CALIPER", "caliper"))
cmake_options.append(self.define_from_variant("AMG_WITH_OMP", "openmp"))
cmake_options.append("-DHYPRE_PREFIX={0}".format(self.spec["hypre"].prefix))
if self.spec["hypre"].satisfies("+cuda"):
cmake_options.append("-DAMG_WITH_CUDA=ON")
if self.spec["hypre"].satisfies("+rocm"):
cmake_options.append("-DAMG_WITH_HIP=ON")
if self.spec["hypre"].satisfies("+mpi"):
cmake_options.append("-DAMG_WITH_MPI=ON")
def edit(self, spec, prefix):
makefile = FileFilter("Makefile")
if "+mpi" in spec:
makefile.filter(r"CC\s*=.*", f"CC = {spec['mpi'].mpicc}")
makefile.filter(r"CXX\s*=.*", f"CXX = {spec['mpi'].mpicxx}")
makefile.filter(r"#MPIPATH = .*", f"MPIPATH = {spec['mpi'].prefix}")
makefile.filter(r"#MPIINCLUDE", "MPIINCLUDE")
if spec["mpi"].extra_attributes and "ldflags" in spec["mpi"].extra_attributes:
makefile.filter(
"#MPILIBS = .*",
"MPILIBS = {0}".format(spec["mpi"].extra_attributes["ldflags"]),
)
else:
makefile.filter("#MPILIBDIRS", "MPILIBDIRS")
makefile.filter("#MPILIBS", "MPILIBS")
makefile.filter("#MPIFLAGS", "MPIFLAGS")
else:
makefile.filter(r"CC\s*=.*", "CC = {0}".format(spack_cc))
makefile.filter(r"CXX\s*=.*", "CXX = {0}".format(spack_cxx))
makefile.filter(r"HYPRE_DIR = .*", f'HYPRE_DIR = {spec["hypre"].prefix}')
if spec["hypre"].satisfies("+cuda"):
makefile.filter(
"HYPRE_CUDA_PATH = .*", "HYPRE_CUDA_PATH = %s" % (spec["cuda"].prefix)
)
makefile.filter("HYPRE_CUDA_INCLUDE = #", "HYPRE_CUDA_INCLUDE = ")
makefile.filter("HYPRE_CUDA_LIBS = #", "HYPRE_CUDA_LIBS = ")
makefile.filter("HYPRE_HIP_PATH =", "#HYPRE_HIP_PATH =")
makefile.filter("HYPRE_HIP_INCLUDE =", "#HYPRE_HIP_INCLUDE =")
makefile.filter("HYPRE_HIP_LIBS =", "#HYPRE_HIP_LIBS =")
if spec["hypre"].satisfies("+rocm"):
makefile.filter("HYPRE_HIP_PATH = .*", "HYPRE_HIP_PATH = ${ROCM_PATH}")
else:
makefile.filter("HYPRE_HIP_PATH =", "#HYPRE_HIP_PATH =")
makefile.filter("HYPRE_HIP_INCLUDE =", "#HYPRE_HIP_INCLUDE =")
makefile.filter("HYPRE_HIP_LIBS =", "#HYPRE_HIP_LIBS =")
def install(self, spec, prefix):
make()
mkdirp(prefix.bin)
install("amg", prefix.bin)
return cmake_options