Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 57 additions & 6 deletions easybuild/easyblocks/l/llvm.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@

GENERAL_OPTS = {
'CMAKE_VERBOSE_MAKEFILE': 'ON',
'LLVM_INCLUDE_BENCHMARKS': 'OFF',
'LLVM_INSTALL_UTILS': 'ON',
# If EB is launched from a venv, avoid giving priority to the venv's python
'Python3_FIND_VIRTUALENV': 'STANDARD',
Expand Down Expand Up @@ -231,6 +230,7 @@ def extra_options():
'skip_sanitizer_tests': [True, "Do not run the sanitizer tests", CUSTOM],
'test_suite_ignore_patterns': [None, "List of test to ignore (if the string matches)", CUSTOM],
'test_suite_ignore_timeouts': [False, "Do not treat timedoud tests as failures", CUSTOM],
'test_suite_include_benchmarks': [False, "Include benchmarks in the LLVM tests (default False)", CUSTOM],
'test_suite_max_failed': [0, "Maximum number of failing tests (does not count allowed failures)", CUSTOM],
'test_suite_timeout_single': [None, "Timeout for each individual test in the test suite", CUSTOM],
'test_suite_timeout_total': [None, "Timeout for total running time of the testsuite", CUSTOM],
Expand Down Expand Up @@ -279,6 +279,7 @@ def __init__(self, *args, **kwargs):
}
self.offload_targets = ['host']
self.host_triple = None
self.sysroot = None
self.dynamic_linker = None

# Shared
Expand Down Expand Up @@ -567,6 +568,32 @@ def _configure_intermediate_build(self):
self._cmakeopts['LLVM_ENABLE_PROJECTS'] = self.list_to_cmake_arg(self.intermediate_projects)
self._cmakeopts['LLVM_ENABLE_RUNTIMES'] = self.list_to_cmake_arg(self.intermediate_runtimes)

def _remove_iterable_from_envvar(self, varname, to_remove, sep=' '):
"""Remove items in to_remove from environment variable varname."""
flags = os.getenv(varname, '')
flags = set(filter(None, flags.split(sep)))
torm = flags & set(to_remove)
if torm:
self.log.info(
"Removing unsupported options from %s for flang %s: `%s`", varname, self.version, ', '.join(torm)
)
setvar(varname, sep.join(flags - torm))

def remove_unsupported_flang_opts(self):
"""For version of LLVM where `flang` is invoked at build time to build modules, ensure that unsupported
options are removed from F90FLAGS and FFLAGS."""
unsupported_flang_opts = set()
if self.version >= '21':
if self.version < '22':
Comment on lines +586 to +587

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about LLVM 20?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LLVM 20 does not need knowledge of the flags here since it does not compile fortran stuff at build time (atleast not in a way that it uses our flags from EB causing failures)

unsupported_flang_opts.update([
'-fmath-errno', '-fno-math-errno',
'-fno-unsafe-math-optimizations',
])

if unsupported_flang_opts:
self._remove_iterable_from_envvar('F90FLAGS', unsupported_flang_opts)
self._remove_iterable_from_envvar('FFLAGS', unsupported_flang_opts)
Comment thread
Crivella marked this conversation as resolved.

def _configure_final_build(self):
"""Configure the final stage of the build."""
self._cmakeopts['LLVM_ENABLE_PROJECTS'] = self.list_to_cmake_arg(self.final_projects)
Expand Down Expand Up @@ -609,6 +636,14 @@ def _configure_final_build(self):
else:
self._cmakeopts['LIBCXX_INSTALL_MODULES'] = 'OFF'

if 'flang' in self.final_projects:
self.remove_unsupported_flang_opts()

include_benchmarks = 'ON' if self.cfg['test_suite_include_benchmarks'] else 'OFF'
for cmake_flag in ['LIBCXX_INCLUDE_BENCHMARKS', 'LIBC_INCLUDE_BENCHMARKS', 'LLVM_INCLUDE_BENCHMARKS']:
self._cmakeopts[cmake_flag] = include_benchmarks
self.runtimes_cmake_args[cmake_flag] = include_benchmarks

# Make sure tests are not running with more than 'parallel' tasks
parallel = self.cfg.parallel
if not build_option('mpi_tests'):
Expand Down Expand Up @@ -1101,6 +1136,7 @@ def configure_step3(self):
self._cmakeopts = {}
self._configure_general_build()
self._configure_final_build()

# Update runtime CMake arguments, as they might have
# changed when configuring the final build arguments
self._add_cmake_runtime_args()
Expand All @@ -1118,7 +1154,7 @@ def _create_compiler_config_file(self, installdir):
opts = [f'--gcc-install-dir={self.gcc_prefix}']

if self.dynamic_linker:
opts.append(f'-Wl,-dynamic-linker,{self.dynamic_linker}')
opts.append(f'-Wl,-dynamic-linker={self.dynamic_linker}')
# The --dyld-prefix flag exists, but beside being poorly documented it is also not supported by flang
# https://reviews.llvm.org/D851
# prefix = self.sysroot.rstrip('/')
Expand Down Expand Up @@ -1582,6 +1618,11 @@ def sanity_check_step(self, custom_paths=None, custom_commands=None, *args, **kw
lib_dir_runtime = self.get_runtime_lib_path(self.installdir)
shlib_ext = '.' + get_shared_lib_ext()

if not hasattr(self, 'nvptx_target_cond'):
# Need to perform the target configuration if not done already e.g. when running in `--module-only`
# or `--sanity-check-only` modes
self._configure_build_targets()

resdir_version = self.version.split('.')[0]
version = LooseVersion(self.version)

Expand Down Expand Up @@ -1653,10 +1694,14 @@ def sanity_check_step(self, custom_paths=None, custom_commands=None, *args, **kw
else:
check_bin_files += ['bbc', 'flang-new', 'f18-parse-demo', 'fir-opt', 'tco']
check_lib_files += [
'libFortranRuntime.a', 'libFortranSemantics.a', 'libFortranLower.a', 'libFortranParser.a',
'libFIRCodeGen.a', 'libflangFrontend.a', 'libFortranCommon.a', 'libFortranDecimal.a',
'libFortranSemantics.a', 'libFortranLower.a', 'libFortranParser.a',
'libFIRCodeGen.a', 'libflangFrontend.a', 'libFortranDecimal.a',
'libHLFIRDialect.a'
]
if version < '21':
check_lib_files += [
'libFortranRuntime.a', 'libFortranCommon.a'
]
check_dirs += ['lib/cmake/flang', 'include/flang']
custom_commands += ['bbc --help', 'mlir-tblgen --help', 'flang-new --help']
gcc_prefix_compilers += ['flang-new']
Expand Down Expand Up @@ -1722,15 +1767,21 @@ def sanity_check_step(self, custom_paths=None, custom_commands=None, *args, **kw
omp_lib_files += ['libomptarget.rtl.cuda.so']
if version < '20':
omp_lib_files += [f'libomptarget-nvptx-sm_{cc}.bc' for cc in self.cuda_cc]
else:
elif version < '21':
omp_lib_files += ['libomptarget-nvptx.bc']
else:
# In LLVM 21 the location has changed to lib/nvptx64-nvidia-cuda/libomptarget-nvptx.bc
check_lib_files += [os.path.join('nvptx64-nvidia-cuda', 'libomptarget-nvptx.bc')]
if self.amdgpu_target_cond:
if version < '19':
omp_lib_files += ['libomptarget.rtl.amdgpu.so']
if version < '20':
omp_lib_files += [f'libomptarget-amdgpu-{gfx}.bc' for gfx in self.amd_gfx]
else:
elif version < '21':
omp_lib_files += ['libomptarget-amdgpu.bc']
else:
# In LLVM 21 the location has changed to lib/amdgcn-amd-amdhsa/libomptarget-amdgpu.bc
check_lib_files += [os.path.join('amdgcn-amd-amdhsa', 'libomptarget-amdgpu.bc')]
check_bin_files += ['llvm-omp-kernel-replay']
if version < '20':
check_bin_files += ['llvm-omp-device-info']
Expand Down