From bd415ec8417320f42213ebf4a4b5088f753eed0b Mon Sep 17 00:00:00 2001 From: Cyrus Harrison Date: Fri, 17 Sep 2021 10:37:16 -0700 Subject: improve ascent package to use stages and cmake base (#25720) * improve ascent package to use stages and cmake base * style * more style --- var/spack/repos/builtin/packages/ascent/package.py | 143 ++++++++++----------- 1 file changed, 70 insertions(+), 73 deletions(-) diff --git a/var/spack/repos/builtin/packages/ascent/package.py b/var/spack/repos/builtin/packages/ascent/package.py index 49affd7365..2974ca8f36 100644 --- a/var/spack/repos/builtin/packages/ascent/package.py +++ b/var/spack/repos/builtin/packages/ascent/package.py @@ -28,7 +28,7 @@ def cmake_cache_entry(name, value, vtype=None): return 'set({0} "{1}" CACHE {2} "")\n\n'.format(name, value, vtype) -class Ascent(Package, CudaPackage): +class Ascent(CMakePackage, CudaPackage): """Ascent is an open source many-core capable lightweight in situ visualization and analysis infrastructure for multi-physics HPC simulations.""" @@ -79,6 +79,8 @@ class Ascent(Package, CudaPackage): variant("mfem", default=False, description="Build MFEM filter support") variant("adios", default=False, description="Build Adios filter support") variant("dray", default=False, description="Build with Devil Ray support") + variant("adios2", default=False, description="Build Adios2 filter support") + variant("fides", default=False, description="Build Fides filter support") # variants for dev-tools (docs, etc) variant("doc", default=False, description="Build Ascent's documentation") @@ -102,10 +104,11 @@ class Ascent(Package, CudaPackage): ####################### # we need a shared version of python b/c linking with static python lib # causes duplicate state issues when running compiled python modules. - depends_on("python+shared", when="+python") - extends("python", when="+python") - depends_on("py-numpy", when="+python", type=('build', 'run')) - depends_on("py-pip", when="+python", type=('build', 'run')) + with when('+python'): + depends_on("python+shared") + extends("python") + depends_on("py-numpy", type=('build', 'run')) + depends_on("py-pip", type=('build', 'run')) ####################### # MPI @@ -140,7 +143,8 @@ class Ascent(Package, CudaPackage): depends_on("mfem~threadsafe~openmp+shared~mpi+conduit", when="+shared+mfem~mpi") depends_on("mfem~threadsafe~openmp~shared~mpi+conduit", when="~shared+mfem~mpi") - depends_on("adios", when="+adios") + # fides + depends_on("fides", when="+fides") # devil ray variants with mpi # we have to specify both because mfem makes us @@ -173,50 +177,24 @@ class Ascent(Package, CudaPackage): conflicts("+shared", when="+cuda", msg="Ascent needs to be built with ~shared for CUDA builds.") + ################################### + # build phases used by this package + ################################### + phases = ['hostconfig', 'cmake', 'build', 'install'] + def setup_build_environment(self, env): env.set('CTEST_OUTPUT_ON_FAILURE', '1') - def install(self, spec, prefix): - """ - Build and install Ascent. - """ - with working_dir('spack-build', create=True): - py_site_pkgs_dir = None - if "+python" in spec: - try: - py_site_pkgs_dir = site_packages_dir - except NameError: - # spack's site_packages_dir won't exist in a subclass - pass - - host_cfg_fname = self.create_host_config(spec, - prefix, - py_site_pkgs_dir) - cmake_args = [] - # if we have a static build, we need to avoid any of - # spack's default cmake settings related to rpaths - # (see: https://github.com/LLNL/spack/issues/2658) - if "+shared" in spec: - cmake_args.extend(std_cmake_args) - else: - for arg in std_cmake_args: - if arg.count("RPATH") == 0: - cmake_args.append(arg) - if self.spec.satisfies('%cce'): - cmake_args.extend(["-DCMAKE_Fortran_FLAGS=-ef"]) - cmake_args.extend(["-C", host_cfg_fname, "../src"]) - print("Configuring Ascent...") - cmake(*cmake_args) - print("Building Ascent...") - make() - # run unit tests if requested - if "+test" in spec and self.run_tests: - print("Running Ascent Unit Tests...") - make("test") - print("Installing Ascent...") - make("install") - # install copy of host config for provenance - install(host_cfg_fname, prefix) + #################################################################### + # Note: cmake, build, and install stages are handled by CMakePackage + #################################################################### + + # 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 @run_after('install') @on_package_attributes(run_tests=True) @@ -258,7 +236,21 @@ class Ascent(Package, CudaPackage): example = Executable('./ascent_render_example') example() - def create_host_config(self, spec, prefix, py_site_pkgs_dir=None): + 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}-ascent-{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 + + def hostconfig(self, spec, prefix): """ This method creates a 'host-config' file that specifies all of the options used to configure and build ascent. @@ -266,16 +258,9 @@ class Ascent(Package, CudaPackage): For more details about 'host-config' files see: https://ascent.readthedocs.io/en/latest/BuildingAscent.html - Note: - The `py_site_pkgs_dir` arg exists to allow a package that - subclasses this package provide a specific site packages - dir when calling this function. `py_site_pkgs_dir` should - be an absolute path or `None`. - - This is necessary because the spack `site_packages_dir` - var will not exist in the base class. For more details - on this issue see: https://github.com/spack/spack/issues/6261 """ + if not os.path.isdir(spec.prefix): + os.mkdir(spec.prefix) ####################### # Compiler Info @@ -289,11 +274,9 @@ class Ascent(Package, CudaPackage): f_compiler = env["SPACK_FC"] ####################################################################### - # By directly fetching the names of the actual compilers we appear - # to doing something evil here, but this is necessary to create a + # Directly fetch the names of the actual compilers to create a # 'host config' file that works outside of the spack install env. ####################################################################### - sys_type = spec.architecture # if on llnl systems, we can use the SYS_TYPE if "SYS_TYPE" in env: @@ -312,9 +295,8 @@ class Ascent(Package, CudaPackage): raise RuntimeError(msg) cmake_exe = cmake_exe.path - host_cfg_fname = "%s-%s-%s-ascent.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") @@ -405,10 +387,13 @@ class Ascent(Package, CudaPackage): cfg.write("# python from spack \n") cfg.write(cmake_cache_entry("PYTHON_EXECUTABLE", spec['python'].command.path)) - # only set dest python site packages dir if passed - if py_site_pkgs_dir: + try: + cfg.write("# python module install dir\n") cfg.write(cmake_cache_entry("PYTHON_MODULE_INSTALL_PREFIX", - py_site_pkgs_dir)) + site_packages_dir)) + except NameError: + # spack's won't exist in a subclass + pass else: cfg.write(cmake_cache_entry("ENABLE_PYTHON", "OFF")) @@ -534,15 +519,28 @@ class Ascent(Package, CudaPackage): cfg.write("# devil ray not built by spack \n") ####################### - # Adios + # Adios2 ####################### + cfg.write("# adios2 support\n") + + if "+adios2" in spec: + cfg.write(cmake_cache_entry("ADIOS2_DIR", spec['adios2'].prefix)) + else: + cfg.write("# adios2 not built by spack \n") - cfg.write("# adios support\n") + ####################### + # Fides + ####################### + cfg.write("# Fides support\n") - if "+adios" in spec: - cfg.write(cmake_cache_entry("ADIOS_DIR", spec['adios'].prefix)) + if "+fides" in spec: + cfg.write(cmake_cache_entry("FIDES_DIR", spec['fides'].prefix)) else: - cfg.write("# adios not built by spack \n") + cfg.write("# fides not built by spack \n") + + ####################### + # Finish host-config + ####################### cfg.write("##################################\n") cfg.write("# end spack generated host-config\n") @@ -550,5 +548,4 @@ class Ascent(Package, CudaPackage): 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 ascent host-config file: " + host_cfg_fname) -- cgit v1.2.3-70-g09d2