Build OpenMP in LLVM via LLVM_ENABLE_RUNTIMES. (#26870)

This commit is contained in:
Ye Luo 2021-10-26 18:43:28 -05:00 committed by GitHub
parent 02bea6d2d2
commit 7dc94b6683
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -145,6 +145,11 @@ class Llvm(CMakePackage, CudaPackage):
default=False, default=False,
description="Build with OpenMP capable thread sanitizer", description="Build with OpenMP capable thread sanitizer",
) )
variant(
"omp_as_runtime",
default=True,
description="Build OpenMP runtime via ENABLE_RUNTIME by just-built Clang",
)
variant('code_signing', default=False, variant('code_signing', default=False,
description="Enable code-signing on macOS") description="Enable code-signing on macOS")
variant("python", default=False, description="Install python bindings") variant("python", default=False, description="Install python bindings")
@ -210,6 +215,10 @@ class Llvm(CMakePackage, CudaPackage):
# OMP TSAN exists in > 5.x # OMP TSAN exists in > 5.x
conflicts("+omp_tsan", when="@:5") conflicts("+omp_tsan", when="@:5")
# OpenMP via ENABLE_RUNTIME restrictions
conflicts("+omp_as_runtime", when="~clang", msg="omp_as_runtime requires clang being built.")
conflicts("+omp_as_runtime", when="@:11.1", msg="omp_as_runtime works since LLVM 12.")
# cuda_arch value must be specified # cuda_arch value must be specified
conflicts("cuda_arch=none", when="+cuda", msg="A value for cuda_arch must be specified.") conflicts("cuda_arch=none", when="+cuda", msg="A value for cuda_arch must be specified.")
@ -461,6 +470,7 @@ def cmake_args(self):
python.command.path)) python.command.path))
projects = [] projects = []
runtimes = []
if "+cuda" in spec: if "+cuda" in spec:
cmake_args.extend( cmake_args.extend(
@ -474,6 +484,17 @@ def cmake_args(self):
), ),
] ]
) )
if "+omp_as_runtime" in spec:
cmake_args.append(
"-DLIBOMPTARGET_NVPTX_ENABLE_BCLIB:BOOL=TRUE"
)
# work around bad libelf detection in libomptarget
cmake_args.append(
"-DLIBOMPTARGET_DEP_LIBELF_INCLUDE_DIR:String={0}".format(
spec["libelf"].prefix.include
)
)
else: else:
# still build libomptarget but disable cuda # still build libomptarget but disable cuda
cmake_args.extend( cmake_args.extend(
@ -506,7 +527,11 @@ def cmake_args(self):
if "+clang" in spec: if "+clang" in spec:
projects.append("clang") projects.append("clang")
projects.append("clang-tools-extra") projects.append("clang-tools-extra")
projects.append("openmp") if "+omp_as_runtime" in spec:
runtimes.append("openmp")
else:
projects.append("openmp")
if "+flang" in spec: if "+flang" in spec:
projects.append("flang") projects.append("flang")
if "+lldb" in spec: if "+lldb" in spec:
@ -530,8 +555,6 @@ def cmake_args(self):
cmake_args.append("-DBUILD_SHARED_LIBS:Bool=ON") cmake_args.append("-DBUILD_SHARED_LIBS:Bool=ON")
if "+llvm_dylib" in spec: if "+llvm_dylib" in spec:
cmake_args.append("-DLLVM_BUILD_LLVM_DYLIB:Bool=ON") cmake_args.append("-DLLVM_BUILD_LLVM_DYLIB:Bool=ON")
if "+omp_debug" in spec:
cmake_args.append("-DLIBOMPTARGET_ENABLE_DEBUG:Bool=ON")
if "+split_dwarf" in spec: if "+split_dwarf" in spec:
cmake_args.append("-DLLVM_USE_SPLIT_DWARF:Bool=ON") cmake_args.append("-DLLVM_USE_SPLIT_DWARF:Bool=ON")
@ -598,6 +621,12 @@ def cmake_args(self):
"-DLLVM_ENABLE_PROJECTS:STRING={0}".format(";".join(projects)) "-DLLVM_ENABLE_PROJECTS:STRING={0}".format(";".join(projects))
) )
# Semicolon seperated list of runtimes to enable
if runtimes:
cmake_args.append(
"-DLLVM_ENABLE_RUNTIMES:STRING={0}".format(";".join(runtimes))
)
return cmake_args return cmake_args
@run_before("build") @run_before("build")
@ -614,8 +643,8 @@ def pre_install(self):
def post_install(self): def post_install(self):
spec = self.spec spec = self.spec
# unnecessary if we get bootstrap builds in here # unnecessary if we build openmp via LLVM_ENABLE_RUNTIMES
if "+cuda" in self.spec: if "+cuda" in self.spec and "+omp_as_runtime" not in self.spec:
ompdir = "build-bootstrapped-omp" ompdir = "build-bootstrapped-omp"
# rebuild libomptarget to get bytecode runtime library files # rebuild libomptarget to get bytecode runtime library files
with working_dir(ompdir, create=True): with working_dir(ompdir, create=True):