Skip to content

Commit

Permalink
Merge pull request #2454 from nordmoen/clang_nvptx_output_check
Browse files Browse the repository at this point in the history
enhance sanity check for Clang to verify if CUDA offload library was produced
  • Loading branch information
boegel authored Jun 3, 2021
2 parents 3fdc207 + f78d4eb commit 30dcfb2
Showing 1 changed file with 50 additions and 23 deletions.
73 changes: 50 additions & 23 deletions easybuild/easyblocks/c/clang.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,39 @@ def find_source_dir(globpatterns, targetdir):
src['finalpath'] = new_path
break

def prepare_step(self, *args, **kwargs):
"""Prepare build environment."""
super(EB_Clang, self).prepare_step(*args, **kwargs)

build_targets = self.cfg['build_targets']
if build_targets is None:
arch = get_cpu_architecture()
default_targets = DEFAULT_TARGETS_MAP.get(arch, None)
if default_targets:
# If CUDA is included as a dep, add NVPTX as a target (could also support AMDGPU if we knew how)
if get_software_root("CUDA"):
default_targets += ["NVPTX"]
self.cfg['build_targets'] = build_targets = default_targets
self.log.debug("Using %s as default build targets for CPU/GPU architecture %s.", default_targets, arch)
else:
raise EasyBuildError("No default build targets defined for CPU architecture %s.", arch)

# carry on with empty list from this point forward if no build targets are specified
if build_targets is None:
self.cfg['build_targets'] = build_targets = []

unknown_targets = [target for target in build_targets if target not in CLANG_TARGETS]

if unknown_targets:
raise EasyBuildError("Some of the chosen build targets (%s) are not in %s.",
', '.join(unknown_targets), ', '.join(CLANG_TARGETS))

if LooseVersion(self.version) < LooseVersion('3.4') and "R600" in build_targets:
raise EasyBuildError("Build target R600 not supported in < Clang-3.4")

if LooseVersion(self.version) > LooseVersion('3.3') and "MBlaze" in build_targets:
raise EasyBuildError("Build target MBlaze is not supported anymore in > Clang-3.3")

def configure_step(self):
"""Run CMake for stage 1 Clang."""

Expand Down Expand Up @@ -264,29 +297,6 @@ def configure_step(self):
self.cfg.update('configopts', "-DLLVM_Z3_INSTALL_DIR=%s" % z3_root)

build_targets = self.cfg['build_targets']
if build_targets is None:
arch = get_cpu_architecture()
default_targets = DEFAULT_TARGETS_MAP.get(arch, None)
if default_targets:
# If CUDA is included as a dep, add NVPTX as a target (could also support AMDGPU if we knew how)
if get_software_root("CUDA"):
default_targets += ["NVPTX"]
self.cfg['build_targets'] = build_targets = default_targets
self.log.debug("Using %s as default build targets for CPU/GPU architecture %s.", default_targets, arch)
else:
raise EasyBuildError("No default build targets defined for CPU architecture %s.", arch)

unknown_targets = [target for target in build_targets if target not in CLANG_TARGETS]

if unknown_targets:
raise EasyBuildError("Some of the chosen build targets (%s) are not in %s.",
', '.join(unknown_targets), ', '.join(CLANG_TARGETS))

if LooseVersion(self.version) < LooseVersion('3.4') and "R600" in build_targets:
raise EasyBuildError("Build target R600 not supported in < Clang-3.4")

if LooseVersion(self.version) > LooseVersion('3.3') and "MBlaze" in build_targets:
raise EasyBuildError("Build target MBlaze is not supported anymore in > Clang-3.3")

if self.cfg["usepolly"] and "NVPTX" in build_targets:
self.cfg.update('configopts', "-DPOLLY_ENABLE_GPGPU_CODEGEN=ON")
Expand Down Expand Up @@ -478,6 +488,23 @@ def sanity_check_step(self):
if LooseVersion(self.version) >= LooseVersion('3.8'):
custom_paths['files'].extend(["lib/libomp.%s" % shlib_ext, "lib/clang/%s/include/omp.h" % self.version])

if 'NVPTX' in self.cfg['build_targets']:
arch = get_cpu_architecture()
# Check architecture explicitly since Clang uses potentially
# different names
if arch == X86_64:
arch = 'x86_64'
elif arch == POWER:
arch = 'ppc64'
elif arch == AARCH64:
arch = 'aarch64'
else:
print_warning("Unknown CPU architecture (%s) for OpenMP offloading!" % arch)
custom_paths['files'].extend(["lib/libomptarget.%s" % shlib_ext,
"lib/libomptarget-nvptx.a",
"lib/libomptarget.rtl.cuda.%s" % shlib_ext,
"lib/libomptarget.rtl.%s.%s" % (arch, shlib_ext)])

custom_commands = ['clang --help', 'clang++ --help', 'llvm-config --cxxflags']
super(EB_Clang, self).sanity_check_step(custom_paths=custom_paths, custom_commands=custom_commands)

Expand Down

0 comments on commit 30dcfb2

Please sign in to comment.