From 6d081b2f3609f5a76be8b62a1ae1fdacad74cf6d Mon Sep 17 00:00:00 2001 From: Jose Gracia Date: Thu, 16 Nov 2023 16:48:49 +0100 Subject: [PATCH] Add template files --- .../repo/packages/extrae/package.py | 175 ++++++++++++++++ .../repo/packages/papi/crayftn-fixes.patch | 57 ++++++ .../papi/intel-oneapi-compiler-fixes.patch | 37 ++++ .../repo/packages/papi/package.py | 188 ++++++++++++++++++ ChEESE_templates/repo/repo.yaml | 2 + ChEESE_templates/spack.yaml | 18 ++ 6 files changed, 477 insertions(+) create mode 100644 ChEESE_templates/repo/packages/extrae/package.py create mode 100644 ChEESE_templates/repo/packages/papi/crayftn-fixes.patch create mode 100644 ChEESE_templates/repo/packages/papi/intel-oneapi-compiler-fixes.patch create mode 100644 ChEESE_templates/repo/packages/papi/package.py create mode 100644 ChEESE_templates/repo/repo.yaml create mode 100644 ChEESE_templates/spack.yaml diff --git a/ChEESE_templates/repo/packages/extrae/package.py b/ChEESE_templates/repo/packages/extrae/package.py new file mode 100644 index 0000000..12630de --- /dev/null +++ b/ChEESE_templates/repo/packages/extrae/package.py @@ -0,0 +1,175 @@ +# Copyright 2013-2023 Lawrence Livermore National Security, LLC and other +# Spack Project Developers. See the top-level COPYRIGHT file for details. +# +# SPDX-License-Identifier: (Apache-2.0 OR MIT) + +import os + +from spack.package import * +from spack.pkg.builtin.boost import Boost + +# typical working line with extrae 3.0.1 +# ./configure +# --prefix=/usr/local +# --with-mpi=/usr/lib64/mpi/gcc/openmpi +# --with-unwind=/usr/local +# --with-papi=/usr +# --with-dwarf=/usr +# --with-elf=/usr +# --with-dyninst=/usr +# --with-binutils=/usr +# --with-xml-prefix=/usr +# --enable-openmp +# --enable-nanos +# --enable-pthread +# --disable-parallel-merge +# +# LDFLAGS=-pthread + + +class Extrae(AutotoolsPackage): + """Extrae is the package devoted to generate tracefiles which can + be analyzed later by Paraver. Extrae is a tool that uses + different interposition mechanisms to inject probes into the + target application so as to gather information regarding the + application performance. The Extrae instrumentation package can + instrument the MPI programin model, and the following parallel + programming models either alone or in conjunction with MPI : + OpenMP, CUDA, OpenCL, pthread, OmpSs""" + + homepage = "https://tools.bsc.es/extrae" + url = "https://ftp.tools.bsc.es/extrae/extrae-3.4.1-src.tar.bz2" + + version("4.0.6", sha256="b5060336cac57f1345faa09009b1940edf1e6991aae05cc10d0b714d31360a92") + version("4.0.4", sha256="b867d395c344020c04e6630e9bfc10bf126e093df989d5563a2f3a6bc7568224") + version("4.0.3", sha256="b5139a07dbb1f4aa9758c1d62d54e42c01125bcfa9aa0cb9ee4f863afae93db1") + version("3.8.3", sha256="c3bf27fb6f18e66200e40a0b4c35bc257766e5c1a525dc5725f561879e88bf32") + version("3.7.1", sha256="c83ddd18a380c9414d64ee5de263efc6f7bac5fe362d5b8374170c7f18360378") + version("3.4.1", sha256="77bfec16d6b5eee061fbaa879949dcef4cad28395d6a546b1ae1b9246f142725") + + depends_on("autoconf", type="build") + depends_on("automake", type="build") + depends_on("libtool", type="build") + depends_on("m4", type="build") + + depends_on("mpi") + depends_on("libunwind") + + # TODO: replace this with an explicit list of components of Boost, + # for instance depends_on('boost +filesystem') + # See https://github.com/spack/spack/pull/22303 for reference + # it seems to prevent boost reuse and force using older boost version#depends_on(Boost.with_default_variants) + depends_on("boost") + depends_on("libdwarf") + depends_on("papi") + depends_on("elf", type="link") + depends_on("libxml2") + depends_on("numactl") + depends_on("binutils+libiberty@:2.33", when="@:4.0.1") + depends_on("binutils+libiberty", when="@4.0.2:") + depends_on("gettext") + # gettext dependency added to find -lintl + # https://www.gnu.org/software/gettext/FAQ.html#integrating_undefined + + build_directory = "spack-build" + + variant("dyninst", default=False, description="Use dyninst for dynamic code installation") + depends_on("dyninst@:9", when="+dyninst") + + variant("papi", default=True, description="Use PAPI to collect performance counters") + depends_on("papi", when="+papi") + + variant("cuda", default=False, description="Enable support for tracing CUDA") + depends_on("cuda", when="+cuda") + + variant("cupti", default=False, description="Enable CUPTI support") + depends_on("cuda", when="+cupti") + conflicts("+cupti", when="~cuda", msg="CUPTI requires CUDA") + + variant("openacc", default=False, description="Enable OpenACC support") + depends_on("cuda", when="+openacc") + conflicts("+openacc", when="~cuda", msg="OpenACC requires CUDA") + + + def configure_args(self): + spec = self.spec + if "^intel-oneapi-mpi" in spec: + mpiroot = spec["mpi"].component_prefix + else: + mpiroot = spec["mpi"].prefix + + args = [ + "--with-mpi=%s" % mpiroot, + "--with-unwind=%s" % spec["libunwind"].prefix, + "--with-boost=%s" % spec["boost"].prefix, + "--with-dwarf=%s" % spec["libdwarf"].prefix, + "--with-elf=%s" % spec["elf"].prefix, + "--with-xml-prefix=%s" % spec["libxml2"].prefix, + "--with-binutils=%s" % spec["binutils"].prefix, + ] + + args += ( + ["--with-papi=%s" % spec["papi"].prefix] + if "+papi" in self.spec + else ["--without-papi"] + ) + + args += ( + ["--with-dyninst=%s" % spec["dyninst"].prefix] + if "+dyninst" in self.spec + else ["--without-dyninst"] + ) + + args += ( + ["--with-cuda=%s" % spec["cuda"].prefix] + if "+cuda" in self.spec + else ["--without-cuda"] + ) + + if "+cupti" in self.spec: + cupti_h = find_headers("cupti", spec["cuda"].prefix, recursive=True) + cupti_dir = os.path.dirname(os.path.dirname(cupti_h[0])) + + args += ["--with-cupti=%s" % cupti_dir] if "+cupti" in self.spec else ["--without-cupti"] + + args += ( + ["--with-openacc=%s" % spec["cuda"].prefix] + if "+openacc" in self.spec + else ["--without-openacc"] + ) + + if spec.satisfies("^dyninst@9.3.0:"): + make.add_default_arg("CXXFLAGS=%s" % self.compiler.cxx11_flag) + args.append("CXXFLAGS=%s" % self.compiler.cxx11_flag) + + return args + + def flag_handler(self, name, flags): + # This was added due to: + # - configure failure + # https://www.gnu.org/software/gettext/FAQ.html#integrating_undefined + # - linking error + # https://github.com/bsc-performance-tools/extrae/issues/57 + if name == "ldlibs": + if "intl" in self.spec["gettext"].libs.names: + flags.append("-lintl") + elif name == "ldflags": + flags.append("-pthread") + return self.build_system_flags(name, flags) + + def install(self, spec, prefix): + with working_dir(self.build_directory): + # parallel installs are buggy prior to 3.7 + # see https://github.com/bsc-performance-tools/extrae/issues/18 + if spec.satisfies("@3.7:"): + make("install", parallel=True) + else: + make("install", parallel=False) + + def setup_run_environment(self, env): + # set EXTRAE_HOME in the module file + env.set("EXTRAE_HOME", self.prefix) + + def setup_dependent_build_environment(self, env, dependent_spec): + # set EXTRAE_HOME for everyone using the Extrae package + env.set("EXTRAE_HOME", self.prefix) diff --git a/ChEESE_templates/repo/packages/papi/crayftn-fixes.patch b/ChEESE_templates/repo/packages/papi/crayftn-fixes.patch new file mode 100644 index 0000000..bd4aa65 --- /dev/null +++ b/ChEESE_templates/repo/packages/papi/crayftn-fixes.patch @@ -0,0 +1,57 @@ +From ddfa53f3e20218dceaed6e0bfbe307e531ae879f Mon Sep 17 00:00:00 2001 +From: Howard Pritchard +Date: Thu, 10 Dec 2020 15:05:33 -0700 +Subject: [PATCH] fix fixed form ftn argument for crayftn patch openmp.F + +Signed-off-by: Howard Pritchard + +diff --git a/src/ftests/Makefile b/src/ftests/Makefile +index 315e1e76..d45fbb6d 100644 +--- a/src/ftests/Makefile ++++ b/src/ftests/Makefile +@@ -3,7 +3,7 @@ + include Makefile.target + + INCLUDE = -I../testlib -I. -I.. +-FFLAGS = $(CFLAGS) -ffixed-line-length-132 ++FFLAGS = $(CFLAGS) -N132 + testlibdir=../testlib + TESTLIB= $(testlibdir)/libtestlib.a + DOLOOPS= $(testlibdir)/do_loops.o +diff --git a/src/ftests/openmp.F b/src/ftests/openmp.F +index 6cd5af23..ccf9030a 100644 +--- a/src/ftests/openmp.F ++++ b/src/ftests/openmp.F +@@ -18,7 +18,7 @@ + tests_quiet = get_quiet() + es = PAPI_NULL + +- call PAPIF_thread_init(omp_get_thread_num, retval) ++ call PAPIF_thread_init(my_thread_num, retval) + + + retval = PAPI_VER_CURRENT +@@ -64,7 +64,6 @@ + + !$OMP END PARALLEL + +- + call PAPIf_stop(es, values(1), retval) + if ( retval .NE. PAPI_OK ) then + call ftest_fail(__FILE__, __LINE__, +@@ -80,3 +79,12 @@ + call ftests_pass(__FILE__) + end + ++ function my_thread_num() ++ use omp_lib ++ integer::my_thread_num ++ ++ my_thread_num = omp_get_thread_num() ++ ++ end function my_thread_num ++ ++ +-- +2.26.2 + diff --git a/ChEESE_templates/repo/packages/papi/intel-oneapi-compiler-fixes.patch b/ChEESE_templates/repo/packages/papi/intel-oneapi-compiler-fixes.patch new file mode 100644 index 0000000..5973d24 --- /dev/null +++ b/ChEESE_templates/repo/packages/papi/intel-oneapi-compiler-fixes.patch @@ -0,0 +1,37 @@ +diff --git a/src/configure.in b/src/configure.in +index 3cf47edc..ef5463ff 100644 +--- a/src/configure.in ++++ b/src/configure.in +@@ -566,7 +566,7 @@ AC_ARG_WITH(tls, + #include + extern __thread int i; + static int res1, res2; +- void thread_main (void *arg) { ++ void *thread_main (void *arg) { + i = (int)arg; + sleep (1); + if ((int)arg == 1) +diff --git a/src/libpfm4/lib/pfmlib_common.c b/src/libpfm4/lib/pfmlib_common.c +index 335155e2..38f3f957 100644 +--- a/src/libpfm4/lib/pfmlib_common.c ++++ b/src/libpfm4/lib/pfmlib_common.c +@@ -1749,7 +1749,7 @@ pfmlib_pmu_validate_encoding(pfmlib_pmu_t *pmu, FILE *fp) + pfmlib_event_attr_info_t ainfo; + char *buf; + size_t maxlen = 0, len; +- int i, u, n = 0, um; ++ int i, u, um; + int ret, retval = PFM_SUCCESS; + + pfmlib_for_each_pmu_event(pmu, i) { +@@ -1838,7 +1838,6 @@ pfmlib_pmu_validate_encoding(pfmlib_pmu_t *pmu, FILE *fp) + continue; + } + } +- n++; + } + free(buf); + +-- +2.27.0 + diff --git a/ChEESE_templates/repo/packages/papi/package.py b/ChEESE_templates/repo/packages/papi/package.py new file mode 100644 index 0000000..0ae13e4 --- /dev/null +++ b/ChEESE_templates/repo/packages/papi/package.py @@ -0,0 +1,188 @@ +# Copyright 2013-2023 Lawrence Livermore National Security, LLC and other +# Spack Project Developers. See the top-level COPYRIGHT file for details. +# +# SPDX-License-Identifier: (Apache-2.0 OR MIT) + +import glob +import os +import sys + +import llnl.util.filesystem as fs + +from spack.package import * + + +class Papi(AutotoolsPackage, ROCmPackage): + """PAPI provides the tool designer and application engineer with a + consistent interface and methodology for use of the performance + counter hardware found in most major microprocessors. PAPI + enables software engineers to see, in near real time, the + relation between software performance and processor events. In + addition Component PAPI provides access to a collection of + components that expose performance measurement opportunities + across the hardware and software stack.""" + + homepage = "https://icl.cs.utk.edu/papi/index.html" + maintainers("G-Ragghianti") + + tags = ["e4s"] + + url = "https://icl.cs.utk.edu/projects/papi/downloads/papi-5.4.1.tar.gz" + git = "https://bitbucket.org/icl/papi/src/master/" + + version("master", branch="master") + version("7.0.1", sha256="c105da5d8fea7b113b0741a943d467a06c98db959ce71bdd9a50b9f03eecc43e") + version("6.0.0.1", sha256="3cd7ed50c65b0d21d66e46d0ba34cd171178af4bbf9d94e693915c1aca1e287f") + version("6.0.0", sha256="3442709dae3405c2845b304c06a8b15395ecf4f3899a89ceb4d715103cb4055f") + version("5.7.0", sha256="d1a3bb848e292c805bc9f29e09c27870e2ff4cda6c2fba3b7da8b4bba6547589") + version("5.6.0", sha256="49b7293f9ca2d74d6d80bd06b5c4be303663123267b4ac0884cbcae4c914dc47") + version("5.5.1", sha256="49dc2c2323f6164c4a7e81b799ed690ee73158671205e71501f849391dd2c2d4") + version("5.5.0", sha256="3ea15e6cc2354017335b659c1635409ddab1414e70573aa4df91fd892e99f98d") + version("5.4.3", sha256="3aefd581e274f0a103f001f1ffd1009019b297c637e97f4b8c5fc13fa5a1e675") + version("5.4.1", sha256="e131c1449786fe870322a949e44f974a5963824f683232e653fb570cc65d4e87") + version("5.3.0", sha256="99f2f36398b370e75d100b4a189d5bc0ac4f5dd66df44d441f88fd32e1421524") + + variant("example", default=True, description="Install the example files") + variant("infiniband", default=False, description="Enable Infiniband support") + variant("powercap", default=False, description="Enable powercap interface support") + variant("rapl", default=False, description="Enable RAPL support") + variant("lmsensors", default=False, description="Enable lm_sensors support") + variant("sde", default=False, description="Enable software defined events") + variant("cuda", default=False, description="Enable CUDA support") + variant("nvml", default=False, description="Enable NVML support") + variant("rocm_smi", default=False, description="Enable ROCm SMI support") + + variant("shared", default=True, description="Build shared libraries") + # PAPI requires building static libraries, so there is no "static" variant + variant("static_tools", default=False, description="Statically link the PAPI tools") + # The PAPI configure option "--with-shlib-tools" is deprecated + # and therefore not implemented here + + depends_on("lm-sensors", when="+lmsensors") + depends_on("cuda", when="+cuda") + depends_on("cuda", when="+nvml") + depends_on("hsa-rocr-dev", when="+rocm") + depends_on("rocprofiler-dev", when="+rocm") + depends_on("rocm-smi-lib", when="+rocm_smi") + + conflicts("%gcc@8:", when="@5.3.0", msg="Requires GCC version less than 8.0") + conflicts("+sde", when="@:5", msg="Software defined events (SDE) added in 6.0.0") + conflicts("^cuda", when="@:5", msg="CUDA support for versions < 6.0.0 not implemented") + + # This is the only way to match exactly version 6.0.0 without also + # including version 6.0.0.1 due to spack version matching logic + conflicts( + "@6.0:6.0.0.a", when="+static_tools", msg="Static tools cannot build on version 6.0.0" + ) + + # Does not build with newer versions of gcc, see + # https://bitbucket.org/icl/papi/issues/46/cannot-compile-on-arch-linux + patch( + "https://bitbucket.org/icl/papi/commits/53de184a162b8a7edff48fed01a15980664e15b1/raw", + sha256="64c57b3ad4026255238cc495df6abfacc41de391a0af497c27d0ac819444a1f8", + when="@5.4.0:5.6%gcc@8:", + ) + patch("crayftn-fixes.patch", when="@6.0.0:%cce@9:") + patch("intel-oneapi-compiler-fixes.patch", when="@6.0.0:%oneapi") + + configure_directory = "src" + + def setup_build_environment(self, env): + spec = self.spec + if "+lmsensors" in spec and self.version >= Version("6"): + env.set("PAPI_LMSENSORS_ROOT", spec["lm-sensors"].prefix) + if "^cuda" in spec: + env.set("PAPI_CUDA_ROOT", spec["cuda"].prefix) + if "+rocm" in spec: + env.set("PAPI_ROCM_ROOT", spec["hsa-rocr-dev"].prefix) + env.append_flags("CFLAGS", "-I%s/rocprofiler/include" % spec["rocprofiler-dev"].prefix) + env.set( + "ROCP_METRICS", "%s/rocprofiler/lib/metrics.xml" % spec["rocprofiler-dev"].prefix + ) + env.set("ROCPROFILER_LOG", "1") + env.set("HSA_VEN_AMD_AQLPROFILE_LOG", "1") + env.set("AQLPROFILE_READ_API", "1") + # Setting HSA_TOOLS_LIB=librocprofiler64.so (as recommended) doesn't work + # due to a conflict between the spack and system-installed versions. + env.set("HSA_TOOLS_LIB", "unset") + if "+rocm_smi" in spec: + env.append_flags("CFLAGS", "-I%s/rocm_smi" % spec["rocm-smi-lib"].prefix.include) + # + # Intel OneAPI LLVM cannot compile papi unless the DBG enviroment variable is cleared + # + if spec.satisfies("%oneapi"): + env.set("DBG", "") + + setup_run_environment = setup_build_environment + + @when("@6.0.0:%oneapi") + def autoreconf(self, spec, prefix): + bash = which("bash") + bash("-c", "cd src && autoreconf -ivf") + + def configure_args(self): + spec = self.spec + # PAPI uses MPI if MPI is present; since we don't require + # an MPI package, we ensure that all attempts to use MPI + # fail, so that PAPI does not get confused + options = ["MPICC=:"] + # Build a list of PAPI components + components = filter( + lambda x: spec.variants[x].value, + [ + "example", + "infiniband", + "powercap", + "rapl", + "lmsensors", + "sde", + "cuda", + "nvml", + "rocm", + "rocm_smi", + ], + ) + if components: + options.append("--with-components=" + " ".join(components)) + + build_shared = "yes" if "+shared" in spec else "no" + options.append("--with-shared-lib=" + build_shared) + + if "+static_tools" in spec: + options.append("--with-static-tools") + + return options + + @run_before("configure") + def fortran_check(self): + if not self.compiler.fc: + msg = "PAPI requires a Fortran compiler to build" + raise RuntimeError(msg) + + @run_before("configure") + def component_configure(self): + configure_script = Executable("./configure") + if "+lmsensors" in self.spec and self.version < Version("6"): + with working_dir("src/components/lmsensors"): + configure_script( + "--with-sensors_incdir=%s/sensors" + % self.spec["lm-sensors"].headers.directories[0], + "--with-sensors_libdir=%s" % self.spec["lm-sensors"].libs.directories[0], + ) + + @run_before("build") + def fix_build(self): + # Don't use + for level in [".", "*", "*/*"]: + files = glob.iglob(join_path(level, "*.[ch]")) + filter_file(r"\", "", *files) + + @run_after("install") + def fix_darwin_install(self): + # The shared library is not installed correctly on Darwin + if sys.platform == "darwin": + os.rename( + join_path(self.prefix.lib, "libpapi.so"), + join_path(self.prefix.lib, "libpapi.dylib"), + ) + fs.fix_darwin_install_name(self.prefix.lib) diff --git a/ChEESE_templates/repo/repo.yaml b/ChEESE_templates/repo/repo.yaml new file mode 100644 index 0000000..bb8a1c7 --- /dev/null +++ b/ChEESE_templates/repo/repo.yaml @@ -0,0 +1,2 @@ +repo: + namespace: 'cheese' diff --git a/ChEESE_templates/spack.yaml b/ChEESE_templates/spack.yaml new file mode 100644 index 0000000..63da57a --- /dev/null +++ b/ChEESE_templates/spack.yaml @@ -0,0 +1,18 @@ +spack: + concretizer: + unify: true + repos: + - $SPACK_USER_PREFIX/repo + modules: + default: + tcl: + projections: + all: '{name}/{version}-{compiler.name}' + cray-mpich: '{name}/{version}' + hash_length: 0 + packages: + cray-mpich: + externals: + - spec: cray-mpich@8.1.27 + modules: + - cray-mpich/8.1.27