|
| 1 | +# Copyright Spack Project Developers. See COPYRIGHT file for details. |
| 2 | +# |
| 3 | +# SPDX-License-Identifier: (Apache-2.0 OR MIT) |
| 4 | + |
| 5 | +from spack_repo.builtin.build_systems.cuda import CudaPackage |
| 6 | +from spack_repo.builtin.build_systems.makefile import MakefilePackage |
| 7 | +from spack_repo.builtin.build_systems.rocm import ROCmPackage |
| 8 | + |
| 9 | +from spack.package import * |
| 10 | + |
| 11 | + |
| 12 | +class Libceed(MakefilePackage, CudaPackage, ROCmPackage): |
| 13 | + """The CEED API Library: Code for Efficient Extensible Discretizations.""" |
| 14 | + |
| 15 | + homepage = "https://github.com/CEED/libCEED" |
| 16 | + git = "https://github.com/CEED/libCEED.git" |
| 17 | + |
| 18 | + maintainers("jedbrown", "v-dobrev", "tzanio", "jeremylt") |
| 19 | + |
| 20 | + license("BSD-2-Clause") |
| 21 | + |
| 22 | + version("develop", branch="main") |
| 23 | + version("0.12.0", tag="v0.12.0", commit="4018a20a98d451fac24765d3ddb936861647ce8d") |
| 24 | + version("0.11.0", tag="v0.11.0", commit="8ec64e9ae9d5df169dba8c8ee61d8ec8907b8f80") |
| 25 | + version("0.10.1", tag="v0.10.1", commit="74532b27052d94e943eb8bc76257fbd710103614") |
| 26 | + version("0.9", tag="v0.9.0", commit="d66340f5aae79e564186ab7514a1cd08b3a1b06b") |
| 27 | + version("0.8", tag="v0.8", commit="e8f234590eddcce2220edb1d6e979af7a3c35f82") |
| 28 | + version("0.7", tag="v0.7", commit="0bc92be5158efcbeb80d3d59240233bf5b2f748c") |
| 29 | + version( |
| 30 | + "0.6", commit="c7f533e01e2f3f6720fbf37aac2af2ffed225f60" |
| 31 | + ) # tag v0.6 + small portability fixes |
| 32 | + version("0.5", tag="v0.5", commit="12804ff7ea2ac608ae5494437379e4f626cf5cb7") |
| 33 | + version("0.4", tag="v0.4", commit="40b9dad77dea06a1608fa8b93a0d8b9c993ee43d") |
| 34 | + version("0.2", tag="v0.2", commit="113004cb41757b819325a4b3a8a7dfcea5156531") |
| 35 | + version("0.1", tag="v0.1", commit="74e0540e2478136394f75869675056eb6aba67cc") |
| 36 | + |
| 37 | + variant("occa", default=False, description="Enable OCCA backends") |
| 38 | + variant("debug", default=False, description="Enable debug build") |
| 39 | + variant("libxsmm", default=False, description="Enable LIBXSMM backend", when="@0.3:") |
| 40 | + variant("magma", default=False, description="Enable MAGMA backend", when="@0.6:") |
| 41 | + |
| 42 | + variant("openmp", default=False, description="Enable OpenMP support") |
| 43 | + |
| 44 | + conflicts("+rocm", when="@:0.7") |
| 45 | + |
| 46 | + depends_on("c", type="build") # generated |
| 47 | + depends_on("cxx", type="build") # generated |
| 48 | + depends_on("fortran", type="build") # generated |
| 49 | + |
| 50 | + with when("+rocm"): |
| 51 | + depends_on( "[email protected]:", when="@0.8:") |
| 52 | + depends_on( "[email protected]:", when="@0.8:") |
| 53 | + |
| 54 | + conflicts("+occa", when="@0.9:") |
| 55 | + |
| 56 | + with when("+occa"): |
| 57 | + depends_on( "[email protected]", when="@0.7:") |
| 58 | + depends_on( "[email protected]:", when="@0.4") |
| 59 | + depends_on( "[email protected],develop", when="@:0.2") |
| 60 | + depends_on("occa+cuda", when="+cuda") |
| 61 | + depends_on("occa~cuda", when="~cuda") |
| 62 | + |
| 63 | + depends_on("libxsmm", when="+libxsmm") |
| 64 | + depends_on("blas", when="+libxsmm", type="link") |
| 65 | + |
| 66 | + depends_on("magma", when="+magma") |
| 67 | + |
| 68 | + patch("libceed-v0.8-hip.patch", when="@0.8+rocm") |
| 69 | + patch("pkgconfig-version-0.4.diff", when="@0.4") |
| 70 | + |
| 71 | + # occa: do not occaFree kernels |
| 72 | + # Repeated creation and freeing of kernels appears to expose a caching |
| 73 | + # bug in Occa. |
| 74 | + patch("occaFree-0.2.diff", when="@0.2") |
| 75 | + |
| 76 | + @property |
| 77 | + def common_make_opts(self): |
| 78 | + spec = self.spec |
| 79 | + compiler = self.compiler |
| 80 | + # Note: The occa package exports OCCA_DIR in the environment |
| 81 | + |
| 82 | + # Use verbose building output |
| 83 | + makeopts = ["V=1"] |
| 84 | + |
| 85 | + if spec.satisfies("@:0.2"): |
| 86 | + makeopts += ["NDEBUG=%s" % ("" if spec.satisfies("+debug") else "1")] |
| 87 | + |
| 88 | + elif spec.satisfies("@0.4:"): |
| 89 | + # Determine options based on the compiler: |
| 90 | + if spec.satisfies("+debug"): |
| 91 | + opt = "-g" |
| 92 | + elif compiler.name == "gcc": |
| 93 | + opt = "-O3 -g -ffp-contract=fast" |
| 94 | + if compiler.version >= ver(4.9): |
| 95 | + opt += " -fopenmp-simd" |
| 96 | + if self.spec.target.family in ["x86_64", "aarch64"]: |
| 97 | + opt += " -march=native" |
| 98 | + elif compiler.name == "apple-clang": |
| 99 | + opt = "-O3 -g -march=native -ffp-contract=fast" |
| 100 | + if compiler.version >= ver(10): |
| 101 | + opt += " -fopenmp-simd" |
| 102 | + elif compiler.name == "clang": |
| 103 | + opt = "-O3 -g -march=native -ffp-contract=fast" |
| 104 | + if compiler.version >= ver(6): |
| 105 | + opt += " -fopenmp-simd" |
| 106 | + elif compiler.name in ["xl", "xl_r"]: |
| 107 | + opt = "-O -g -qsimd=auto" |
| 108 | + elif compiler.name == "intel": |
| 109 | + opt = "-O3 -g" |
| 110 | + makeopts += ["CC_VENDOR=icc"] |
| 111 | + else: |
| 112 | + opt = "-O -g" |
| 113 | + # Note: spack will inject additional target-specific flags through |
| 114 | + # the compiler wrapper. |
| 115 | + makeopts += ["OPT=%s" % opt] |
| 116 | + |
| 117 | + if spec.satisfies("@0.7") and compiler.name in ["xl", "xl_r"]: |
| 118 | + makeopts += ["CXXFLAGS.XL=-qpic -std=c++11 -MMD"] |
| 119 | + |
| 120 | + if spec.satisfies("@:0.7") and "avx" in self.spec.target: |
| 121 | + makeopts.append("AVX=1") |
| 122 | + |
| 123 | + if spec.satisfies("+cuda"): |
| 124 | + makeopts += ["CUDA_DIR=%s" % spec["cuda"].prefix] |
| 125 | + makeopts += ["CUDA_ARCH=sm_%s" % spec.variants["cuda_arch"].value] |
| 126 | + if spec.satisfies("@:0.4"): |
| 127 | + nvccflags = [ |
| 128 | + '-ccbin %s -Xcompiler "%s" -Xcompiler %s' |
| 129 | + % (compiler.cxx, opt, compiler.cc_pic_flag) |
| 130 | + ] |
| 131 | + nvccflags = " ".join(nvccflags) |
| 132 | + makeopts += ["NVCCFLAGS=%s" % nvccflags] |
| 133 | + else: |
| 134 | + # Disable CUDA auto-detection: |
| 135 | + makeopts += ["CUDA_DIR=/disable-cuda"] |
| 136 | + |
| 137 | + if spec.satisfies("+rocm"): |
| 138 | + makeopts += ["HIP_DIR=%s" % spec["hip"].prefix] |
| 139 | + amdgpu_target = ",".join(spec.variants["amdgpu_target"].value) |
| 140 | + makeopts += ["HIP_ARCH=%s" % amdgpu_target] |
| 141 | + if spec.satisfies("@0.8"): |
| 142 | + makeopts += ["HIPBLAS_DIR=%s" % spec["hipblas"].prefix] |
| 143 | + |
| 144 | + if spec.satisfies("+libxsmm"): |
| 145 | + makeopts += ["XSMM_DIR=%s" % spec["libxsmm"].prefix] |
| 146 | + makeopts += ["BLAS_LIB=%s" % spec["blas"].libs] |
| 147 | + |
| 148 | + if spec.satisfies("+magma"): |
| 149 | + makeopts += ["MAGMA_DIR=%s" % spec["magma"].prefix] |
| 150 | + |
| 151 | + if spec.satisfies("+openmp"): |
| 152 | + makeopts += ["OPENMP=1"] |
| 153 | + |
| 154 | + return makeopts |
| 155 | + |
| 156 | + def edit(self, spec, prefix): |
| 157 | + make("info", *self.common_make_opts) |
| 158 | + |
| 159 | + @property |
| 160 | + def build_targets(self): |
| 161 | + return self.common_make_opts |
| 162 | + |
| 163 | + @property |
| 164 | + def install_targets(self): |
| 165 | + return ["install", "prefix={0}".format(self.prefix)] + self.common_make_opts |
| 166 | + |
| 167 | + def check(self): |
| 168 | + make("prove", *self.common_make_opts, parallel=False) |
| 169 | + |
| 170 | + @when("@0.1") |
| 171 | + def install(self, spec, prefix): |
| 172 | + mkdirp(prefix.include) |
| 173 | + install("ceed.h", prefix.include) |
| 174 | + mkdirp(prefix.lib) |
| 175 | + install("libceed.%s" % dso_suffix, prefix.lib) |
| 176 | + filter_file(r"^prefix=.*$", "prefix=%s" % prefix, "ceed.pc") |
| 177 | + filter_file(r"^includedir=\$\{prefix\}$", "includedir=${prefix}/include", "ceed.pc") |
| 178 | + filter_file(r"^libdir=\$\{prefix\}$", "libdir=${prefix}/lib", "ceed.pc") |
| 179 | + filter_file(r"Version:.*$", "Version: 0.1", "ceed.pc") |
| 180 | + mkdirp(prefix.lib.pkgconfig) |
| 181 | + install("ceed.pc", prefix.lib.pkgconfig) |
0 commit comments