vtk-h: use cmake base pkg, overhaul recipe (#28898)

Co-authored-by: Massimiliano Culpo <massimiliano.culpo@gmail.com>
This commit is contained in:
Cyrus Harrison 2022-06-17 00:59:57 -07:00 committed by GitHub
parent 6ac3186132
commit f35d8c4102
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 99 additions and 112 deletions

View File

@ -27,7 +27,7 @@ def cmake_cache_entry(name, value, vtype=None):
return 'set({0} "{1}" CACHE {2} "")\n\n'.format(name, value, vtype)
class VtkH(Package, CudaPackage):
class VtkH(CMakePackage, CudaPackage):
"""VTK-h is a toolkit of scientific visualization algorithms for emerging
processor architectures. VTK-h brings together several projects like VTK-m
and DIY2 to provide a toolkit with hybrid parallel capabilities."""
@ -62,6 +62,8 @@ class VtkH(Package, CudaPackage):
variant("shared", default=True, description="Build vtk-h as shared libs")
variant("mpi", default=True, description="build mpi support")
# set to false for systems that implicitly link mpi
variant('blt_find_mpi', default=True, description='Use BLT CMake Find MPI logic')
variant("serial", default=True, description="build serial (non-mpi) libraries")
variant("openmp", default=(sys.platform != 'darwin'),
description="build openmp support")
@ -69,95 +71,63 @@ class VtkH(Package, CudaPackage):
variant("contourtree", default=False, description="Enable contour tree support")
# Certain CMake versions have been found to break for our use cases
depends_on("cmake@3.14.1:3.14,3.18.2:", type='build')
depends_on("cmake@3.14.1:3.14.99,3.18.2:", type='build')
depends_on("mpi", when="+mpi")
depends_on("cuda", when="+cuda")
depends_on("vtk-m+fpic")
depends_on("vtk-m~tbb")
depends_on("vtk-m@:1.6", when="@:0.7")
# use vtk-m 1.7 or newer for vtk-h 0.8 or newer
depends_on("vtk-m@1.7:", when="@0.8:")
# use vtk-m 1.6 or lower for vtk-h 0.7 or lower
depends_on("vtk-m@:1.6", when="@:0.7")
depends_on("vtk-m~tbb")
depends_on("vtk-m+openmp", when="+openmp")
depends_on("vtk-m~openmp", when="~openmp")
depends_on("vtk-m+openmp", when="+openmp")
depends_on("vtk-m~openmp", when="~openmp")
depends_on("vtk-m~cuda", when="~cuda")
depends_on("vtk-m+cuda", when="+cuda")
for _arch in CudaPackage.cuda_arch_values:
depends_on("vtk-m cuda_arch={0}".format(_arch), when="+cuda cuda_arch={0}".format(_arch))
depends_on("vtk-m+cuda cuda_arch={0}".format(_arch), when="+cuda+openmp cuda_arch={0}".format(_arch))
depends_on("vtk-m+shared", when="+shared")
depends_on("vtk-m~shared", when="~shared")
patch('vtk-h-shared-cuda.patch', when='@0.8.0,0.8.1 +cuda')
# provide cmake args (pass host config as cmake cache file)
def cmake_args(self):
host_config = self._get_host_config_path(self.spec)
options = []
options.extend(['-C', host_config, "../spack-src/src/"])
return options
def install(self, spec, prefix):
with working_dir('spack-build', create=True):
cmake_args = ["../src",
"-DVTKM_DIR={0}".format(spec["vtk-m"].prefix),
"-DENABLE_TESTS=OFF",
"-DBUILD_TESTING=OFF"]
def _get_host_config_path(self, spec):
sys_type = spec.architecture
# if on llnl systems, we can use the SYS_TYPE
if "SYS_TYPE" in env:
sys_type = env["SYS_TYPE"]
host_config_path = "{0}-{1}-{2}-vtkh-{3}.cmake".format(socket.gethostname(),
sys_type,
spec.compiler,
spec.dag_hash())
dest_dir = spec.prefix
host_config_path = os.path.abspath(join_path(dest_dir,
host_config_path))
return host_config_path
# shared vs static libs logic
# force static when building with CUDA <= 1.6
if "+cuda" in spec and spec["vtk-m"].satisfies('@:1.6'):
cmake_args.append('-DBUILD_SHARED_LIBS=OFF')
else:
if "+shared" in spec:
cmake_args.append('-DBUILD_SHARED_LIBS=ON')
else:
cmake_args.append('-DBUILD_SHARED_LIBS=OFF')
# mpi support
if "+mpi" in spec:
mpicc = spec['mpi'].mpicc
mpicxx = spec['mpi'].mpicxx
cmake_args.extend(["-DMPI_C_COMPILER={0}".format(mpicc),
"-DMPI_CXX_COMPILER={0}".format(mpicxx)])
mpiexe_bin = join_path(spec['mpi'].prefix.bin, 'mpiexec')
if os.path.isfile(mpiexe_bin):
cmake_args.append("-DMPIEXEC={0}".format(mpiexe_bin))
# openmp support
if "+openmp" in spec:
cmake_args.append("-DENABLE_OPENMP=ON")
# build with logging
if "+logging" in spec:
cmake_args.append("-DENABLE_LOGGING=ON")
if "+contourtree" in spec:
cmake_args.append("-DENABLE_FILTER_CONTOUR_TREE=ON")
# cuda support
if "+cuda" in spec:
cmake_args.append("-DVTKm_ENABLE_CUDA:BOOL=ON")
cmake_args.append("-DENABLE_CUDA:BOOL=ON")
cmake_args.append("-DCMAKE_CUDA_HOST_COMPILER={0}".format(
env["SPACK_CXX"]))
else:
cmake_args.append("-DVTKm_ENABLE_CUDA:BOOL=OFF")
cmake_args.append("-DENABLE_CUDA:BOOL=OFF")
# use release, instead of release with debug symbols b/c vtkh libs
# can overwhelm compilers with too many symbols
for arg in std_cmake_args:
if arg.count("CMAKE_BUILD_TYPE") == 0:
cmake_args.extend(std_cmake_args)
cmake_args.append("-DCMAKE_BUILD_TYPE=Release")
cmake(*cmake_args)
make()
make("install")
host_cfg_fname = self.create_host_config(spec,
prefix)
install(host_cfg_fname, prefix)
def create_host_config(self, spec, prefix, py_site_pkgs_dir=None):
@run_before('cmake')
def hostconfig(self):
spec = self.spec
"""
This method creates a 'host-config' file that specifies
all of the options used to configure and build vtkh.
"""
if not os.path.isdir(spec.prefix):
os.mkdir(spec.prefix)
#######################
# Compiler Info
#######################
@ -181,9 +151,8 @@ def create_host_config(self, spec, prefix, py_site_pkgs_dir=None):
cmake_exe = spec['cmake'].command.path
host_cfg_fname = "%s-%s-%s-vtkh.cmake" % (socket.gethostname(),
sys_type,
spec.compiler)
# get hostconfig name
host_cfg_fname = self._get_host_config_path(spec)
cfg = open(host_cfg_fname, "w")
cfg.write("##################################\n")
@ -214,43 +183,8 @@ def create_host_config(self, spec, prefix, py_site_pkgs_dir=None):
else:
cfg.write(cmake_cache_entry("BUILD_SHARED_LIBS", "OFF"))
#######################################################################
# Core Dependencies
#######################################################################
#######################
# VTK-h (and deps)
#######################
cfg.write("# vtk-m support \n")
if "+openmp" in spec:
cfg.write("# enable openmp support\n")
cfg.write(cmake_cache_entry("ENABLE_OPENMP", "ON"))
cfg.write("# vtk-m from spack\n")
cfg.write(cmake_cache_entry("VTKM_DIR", spec['vtk-m'].prefix))
#######################################################################
# Optional Dependencies
#######################################################################
#######################
# Serial
#######################
if "+serial" in spec:
cfg.write(cmake_cache_entry("ENABLE_SERIAL", "ON"))
else:
cfg.write(cmake_cache_entry("ENABLE_SERIAL", "OFF"))
#######################
# Logging
#######################
if "+logging" in spec:
cfg.write(cmake_cache_entry("ENABLE_LOGGING", "ON"))
else:
cfg.write(cmake_cache_entry("ENABLE_LOGGING", "OFF"))
cfg.write(cmake_cache_entry("ENABLE_TESTS", "OFF"))
cfg.write(cmake_cache_entry("BUILD_TESTING", "OFF"))
#######################
# MPI
@ -284,19 +218,68 @@ def create_host_config(self, spec, prefix, py_site_pkgs_dir=None):
else:
cfg.write(cmake_cache_entry("MPIEXEC",
mpiexe_bin))
if "+blt_find_mpi" in spec:
cfg.write(cmake_cache_entry("ENABLE_FIND_MPI", "ON"))
else:
cfg.write(cmake_cache_entry("ENABLE_FIND_MPI", "OFF"))
else:
cfg.write(cmake_cache_entry("ENABLE_MPI", "OFF"))
#######################
# CUDA
#######################
cfg.write("# CUDA Support\n")
if "+cuda" in spec:
cfg.write(cmake_cache_entry("ENABLE_CUDA", "ON"))
cfg.write(cmake_cache_entry("VTKm_ENABLE_CUDA", "ON"))
cfg.write(cmake_cache_entry("CMAKE_CUDA_HOST_COMPILER", env["SPACK_CXX"]))
else:
cfg.write(cmake_cache_entry("ENABLE_CUDA", "OFF"))
cfg.write(cmake_cache_entry("VTKm_ENABLE_CUDA", "OFF"))
#######################################################################
# Core Dependencies
#######################################################################
#######################
# VTK-h (and deps)
#######################
cfg.write("# vtk-m support \n")
if "+openmp" in spec:
cfg.write("# enable openmp support\n")
cfg.write(cmake_cache_entry("ENABLE_OPENMP", "ON"))
cfg.write("# vtk-m from spack\n")
cfg.write(cmake_cache_entry("VTKM_DIR", spec['vtk-m'].prefix))
#######################################################################
# Optional Dependencies
#######################################################################
#######################
# Serial
#######################
if "+serial" in spec:
cfg.write(cmake_cache_entry("ENABLE_SERIAL", "ON"))
else:
cfg.write(cmake_cache_entry("ENABLE_SERIAL", "OFF"))
#######################
# Logging
#######################
if "+logging" in spec:
cfg.write(cmake_cache_entry("ENABLE_LOGGING", "ON"))
else:
cfg.write(cmake_cache_entry("ENABLE_LOGGING", "OFF"))
# contour tree
if "+contourtree" in spec:
cfg.write(cmake_cache_entry("ENABLE_FILTER_CONTOUR_TREE", "ON"))
else:
cfg.write(cmake_cache_entry("ENABLE_FILTER_CONTOUR_TREE", "ON"))
cfg.write("##################################\n")
cfg.write("# end spack generated host-config\n")
@ -304,5 +287,4 @@ def create_host_config(self, spec, prefix, py_site_pkgs_dir=None):
cfg.close()
host_cfg_fname = os.path.abspath(host_cfg_fname)
tty.info("spack generated conduit host-config file: " + host_cfg_fname)
return host_cfg_fname
tty.info("spack generated host-config file: " + host_cfg_fname)

View File

@ -58,6 +58,7 @@ class VtkM(CMakePackage, CudaPackage, ROCmPackage):
variant("64bitids", default=False,
description="enable 64 bits ids")
variant("testlib", default=False, description="build test library")
variant("fpic", default=False, description="build fpic support")
# Device variants
# CudaPackage provides cuda variant
@ -183,6 +184,10 @@ def cmake_args(self):
if spec.variants["build_type"].value != 'Release':
options.append("-DVTKm_NO_ASSERT:BOOL=ON")
# Support for relocatable code
if "~shared" in spec and "+fpic" in spec:
options.append("-DCMAKE_POSITION_INDEPENDENT_CODE:BOOL=ON")
# cuda support
if "+cuda_native" in spec:
options.append("-DVTKm_ENABLE_CUDA:BOOL=ON")