Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add dashes directly in compiler optimization flags #4698

Open
wants to merge 23 commits into
base: 5.0.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
949ec95
Add dashes in front of compiler flags
Micket Nov 7, 2024
8270137
Drop adding - for compiler options in toolchain tests
Micket Nov 7, 2024
e6b9b07
Drop extra dashes in front of compiler flags in tests
Micket Nov 8, 2024
24cfdc6
Stop adding - in front of option flags
Micket Nov 8, 2024
8fdbd6e
Add - in front of compiler flags for yet more tests
Micket Nov 8, 2024
651b625
Remove unnecessary list conversion
Micket Nov 8, 2024
784563f
Drop now pointless test since get_flag is trivial
Micket Nov 8, 2024
d7ca466
Add - in front of another mcpu flag
Micket Nov 8, 2024
d1b098c
Use StrList instead of *FlagList
Micket Nov 12, 2024
e8a4edb
Adjusts test to not expect appending of - for flags
Micket Nov 12, 2024
47d824e
Add dashes for shared compiler flags
Micket Nov 12, 2024
6462cc2
Add test to check for old and new optarch syntax. Add deprecation war…
Micket Nov 12, 2024
65fcfc5
Add missing - in front of mt_mpi
Micket Nov 12, 2024
f9fba39
Rename several _FLAGS to _OPTIONS as that is what they actually are.
Micket Nov 12, 2024
7b5ec13
Fix typo
Micket Nov 13, 2024
d92343d
Fix typo
Micket Nov 13, 2024
f19f0bc
Correctly put dash in front of gencode instead of arch for CUDA
Micket Nov 13, 2024
748d4f5
Exclude cray when using optarch as a flag since it has it's own hacks.
Micket Nov 13, 2024
23093b6
Stop removing - from flags, use log.deprecated
Micket Nov 13, 2024
1601165
Add warnings for non EB 5.0 compliant compilers
Micket Nov 13, 2024
dded2ea
Allow deprecated behaviour for "test" optarch flag
Micket Nov 13, 2024
37c4af7
Allow deprecation warnings when testing intelflag/gccflag
Micket Nov 15, 2024
8640288
Fix typo that broke test
Micket Nov 22, 2024
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
34 changes: 17 additions & 17 deletions easybuild/toolchains/compiler/clang.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ class Clang(Compiler):
'basic-block-vectorize': (False, "Basic block vectorization"),
}
COMPILER_UNIQUE_OPTION_MAP = {
'unroll': 'funroll-loops',
'loop-vectorize': ['fvectorize'],
'basic-block-vectorize': ['fslp-vectorize'],
'optarch': 'march=native',
'unroll': '-funroll-loops',
'loop-vectorize': ['-fvectorize'],
'basic-block-vectorize': ['-fslp-vectorize'],
'optarch': '-march=native',
# Clang's options do not map well onto these precision modes. The flags enable and disable certain classes of
# optimizations.
#
Expand All @@ -80,31 +80,31 @@ class Clang(Compiler):
#
# 'strict', 'precise' and 'defaultprec' are all ISO C++ and IEEE complaint, but we explicitly specify details
# flags for strict and precise for robustness against future changes.
'strict': ['fno-fast-math'],
'precise': ['fno-unsafe-math-optimizations'],
'strict': ['-fno-fast-math'],
'precise': ['-fno-unsafe-math-optimizations'],
'defaultprec': [],
'loose': ['ffast-math', 'fno-unsafe-math-optimizations'],
'veryloose': ['ffast-math'],
'vectorize': {False: 'fno-vectorize', True: 'fvectorize'},
'loose': ['-ffast-math', '-fno-unsafe-math-optimizations'],
'veryloose': ['-ffast-math'],
'vectorize': {False: '-fno-vectorize', True: '-fvectorize'},
}

# used when 'optarch' toolchain option is enabled (and --optarch is not specified)
COMPILER_OPTIMAL_ARCHITECTURE_OPTION = {
(systemtools.POWER, systemtools.POWER): 'mcpu=native', # no support for march=native on POWER
(systemtools.POWER, systemtools.POWER_LE): 'mcpu=native', # no support for march=native on POWER
(systemtools.X86_64, systemtools.AMD): 'march=native',
(systemtools.X86_64, systemtools.INTEL): 'march=native',
(systemtools.POWER, systemtools.POWER): '-mcpu=native', # no support for march=native on POWER
(systemtools.POWER, systemtools.POWER_LE): '-mcpu=native', # no support for march=native on POWER
(systemtools.X86_64, systemtools.AMD): '-march=native',
(systemtools.X86_64, systemtools.INTEL): '-march=native',
}
# used with --optarch=GENERIC
COMPILER_GENERIC_OPTION = {
(systemtools.RISCV64, systemtools.RISCV): 'march=rv64gc -mabi=lp64d', # default for -mabi is system-dependent
(systemtools.X86_64, systemtools.AMD): 'march=x86-64 -mtune=generic',
(systemtools.X86_64, systemtools.INTEL): 'march=x86-64 -mtune=generic',
(systemtools.RISCV64, systemtools.RISCV): '-march=rv64gc -mabi=lp64d', # default for -mabi is system-dependent
(systemtools.X86_64, systemtools.AMD): '-march=x86-64 -mtune=generic',
(systemtools.X86_64, systemtools.INTEL): '-march=x86-64 -mtune=generic',
}

COMPILER_CC = 'clang'
COMPILER_CXX = 'clang++'
COMPILER_C_UNIQUE_FLAGS = []
COMPILER_C_UNIQUE_OPTIONS = []
Copy link
Member

Choose a reason for hiding this comment

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

Hmm, do we really need to change this?

We have to take into account that people may have their own/custom implementations of classes that derive from Compiler, they will need to be adjusted accordingly (and we have no easy way to produce a clean error message there, I think)...


LIB_MULTITHREAD = ['pthread']
LIB_MATH = ['m']
18 changes: 9 additions & 9 deletions easybuild/toolchains/compiler/craype.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ class CrayPECompiler(Compiler):
# handle shared and dynamic always via $CRAYPE_LINK_TYPE environment variable, don't pass flags to wrapper
'shared': '',
'dynamic': '',
'verbose': 'craype-verbose',
'mpich-mt': 'craympich-mt',
'verbose': '-craype-verbose',
'mpich-mt': '-craympich-mt',
}

COMPILER_CC = 'cc'
Expand All @@ -98,7 +98,7 @@ def __init__(self, *args, **kwargs):
"""Constructor."""
super(CrayPECompiler, self).__init__(*args, **kwargs)
# 'register' additional toolchain options that correspond to a compiler flag
self.COMPILER_FLAGS.extend(['dynamic', 'mpich-mt'])
self.COMPILER_OPTIONS.extend(['dynamic', 'mpich-mt'])

# use name of PrgEnv module as name of module that provides compiler
self.COMPILER_MODULE_NAME = ['PrgEnv-%s' % self.PRGENV_MODULE_NAME_SUFFIX]
Expand Down Expand Up @@ -139,7 +139,7 @@ class CrayPEGCC(CrayPECompiler):
def __init__(self, *args, **kwargs):
"""CrayPEGCC constructor."""
super(CrayPEGCC, self).__init__(*args, **kwargs)
for precflag in self.COMPILER_PREC_FLAGS:
for precflag in self.COMPILER_PREC_OPTIONS:
self.COMPILER_UNIQUE_OPTION_MAP[precflag] = Gcc.COMPILER_UNIQUE_OPTION_MAP[precflag]


Expand All @@ -151,7 +151,7 @@ class CrayPEIntel(CrayPECompiler):
def __init__(self, *args, **kwargs):
"""CrayPEIntel constructor."""
super(CrayPEIntel, self).__init__(*args, **kwargs)
for precflag in self.COMPILER_PREC_FLAGS:
for precflag in self.COMPILER_PREC_OPTIONS:
self.COMPILER_UNIQUE_OPTION_MAP[precflag] = IntelIccIfort.COMPILER_UNIQUE_OPTION_MAP[precflag]


Expand All @@ -163,8 +163,8 @@ class CrayPEPGI(CrayPECompiler):
def __init__(self, *args, **kwargs):
"""CrayPEPGI constructor."""
super(CrayPEPGI, self).__init__(*args, **kwargs)
self.COMPILER_UNIQUE_OPTION_MAP['openmp'] = 'mp'
for precflag in self.COMPILER_PREC_FLAGS:
self.COMPILER_UNIQUE_OPTION_MAP['openmp'] = '-mp'
for precflag in self.COMPILER_PREC_OPTIONS:
self.COMPILER_UNIQUE_OPTION_MAP[precflag] = Pgi.COMPILER_UNIQUE_OPTION_MAP[precflag]


Expand All @@ -176,6 +176,6 @@ class CrayPECray(CrayPECompiler):
def __init__(self, *args, **kwargs):
"""CrayPEIntel constructor."""
super(CrayPECray, self).__init__(*args, **kwargs)
self.COMPILER_UNIQUE_OPTION_MAP['openmp'] = 'homp'
for precflag in self.COMPILER_PREC_FLAGS:
self.COMPILER_UNIQUE_OPTION_MAP['openmp'] = '-homp'
for precflag in self.COMPILER_PREC_OPTIONS:
self.COMPILER_UNIQUE_OPTION_MAP[precflag] = []
10 changes: 5 additions & 5 deletions easybuild/toolchains/compiler/cuda.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ class Cuda(Compiler):

# always C++ compiler command, even for C!
COMPILER_CUDA_UNIQUE_OPTION_MAP = {
'_opt_CUDA_CC': 'ccbin="%(CXX_base)s"',
'_opt_CUDA_CXX': 'ccbin="%(CXX_base)s"',
'_opt_CUDA_CC': '-ccbin="%(CXX_base)s"',
'_opt_CUDA_CXX': '-ccbin="%(CXX_base)s"',
}

COMPILER_CUDA_CC = 'nvcc'
Expand Down Expand Up @@ -90,14 +90,14 @@ def _set_compiler_flags(self):
# note: using $LIBS will yield the use of -lcudart in Xlinker, which is silly, but fine

cuda_flags = [
'Xcompiler="%s"' % str(self.variables['CXXFLAGS']),
'Xlinker="%s %s"' % (str(self.variables['LDFLAGS']), str(self.variables['LIBS'])),
'-Xcompiler="%s"' % str(self.variables['CXXFLAGS']),
'-Xlinker="%s %s"' % (str(self.variables['LDFLAGS']), str(self.variables['LIBS'])),
]
self.variables.nextend('CUDA_CFLAGS', cuda_flags)
self.variables.nextend('CUDA_CXXFLAGS', cuda_flags)

# add gencode compiler flags to list of flags for compiler variables
for gencode_val in self.options.get('cuda_gencode', []):
gencode_option = 'gencode %s' % gencode_val
gencode_option = '-gencode %s' % gencode_val
self.variables.nappend('CUDA_CFLAGS', gencode_option)
self.variables.nappend('CUDA_CXXFLAGS', gencode_option)
26 changes: 13 additions & 13 deletions easybuild/toolchains/compiler/fujitsu.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,23 +58,23 @@ class FujitsuCompiler(Compiler):
COMPILER_FC = 'frt'

COMPILER_UNIQUE_OPTION_MAP = {
DEFAULT_OPT_LEVEL: 'O2',
'lowopt': 'O1',
'noopt': 'O0',
'opt': 'Kfast', # -O3 -Keval,fast_matmul,fp_contract,fp_relaxed,fz,ilfunc,mfunc,omitfp,simd_packed_promotion
DEFAULT_OPT_LEVEL: '-O2',
'lowopt': '-O1',
'noopt': '-O0',
'opt': '-Kfast', # -O3 -Keval,fast_matmul,fp_contract,fp_relaxed,fz,ilfunc,mfunc,omitfp,simd_packed_promotion
'optarch': '', # Fujitsu compiler by default generates code for the arch it is running on
'openmp': 'Kopenmp',
'unroll': 'funroll-loops',
'openmp': '-Kopenmp',
'unroll': '-funroll-loops',
# apparently the -Kfp_precision flag doesn't work in clang mode, will need to look into these later
# also at strict vs precise and loose vs veryloose
'strict': ['Knoeval,nofast_matmul,nofp_contract,nofp_relaxed,noilfunc'], # ['Kfp_precision'],
'precise': ['Knoeval,nofast_matmul,nofp_contract,nofp_relaxed,noilfunc'], # ['Kfp_precision'],
'strict': ['-Knoeval,nofast_matmul,nofp_contract,nofp_relaxed,noilfunc'], # ['-Kfp_precision'],
'precise': ['-Knoeval,nofast_matmul,nofp_contract,nofp_relaxed,noilfunc'], # ['-Kfp_precision'],
'defaultprec': [],
'loose': ['Kfp_relaxed'],
'veryloose': ['Kfp_relaxed'],
'loose': ['-Kfp_relaxed'],
'veryloose': ['-Kfp_relaxed'],
# apparently the -K[NO]SVE flags don't work in clang mode
# SVE is enabled by default, -Knosimd seems to disable it
'vectorize': {False: 'Knosimd', True: ''},
'vectorize': {False: '-Knosimd', True: ''},
}

# used when 'optarch' toolchain option is enabled (and --optarch is not specified)
Expand Down Expand Up @@ -109,8 +109,8 @@ def _set_compiler_vars(self):
super(FujitsuCompiler, self)._set_compiler_vars()

# enable clang compatibility mode
self.variables.nappend('CFLAGS', ['Nclang'])
self.variables.nappend('CXXFLAGS', ['Nclang'])
self.variables.nappend('CFLAGS', ['-Nclang'])
self.variables.nappend('CXXFLAGS', ['-Nclang'])

# also add fujitsu module library path to LDFLAGS
libdir = os.path.join(os.getenv(TC_CONSTANT_MODULE_VAR), 'lib64')
Expand Down
68 changes: 34 additions & 34 deletions easybuild/toolchains/compiler/gcc.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,26 +55,26 @@ class Gcc(Compiler):
'lto': (False, "Enable Link Time Optimization"),
}
COMPILER_UNIQUE_OPTION_MAP = {
'i8': 'fdefault-integer-8',
'r8': ['fdefault-real-8', 'fdefault-double-8'],
'unroll': 'funroll-loops',
'f2c': 'ff2c',
'loop': ['ftree-switch-conversion', 'floop-interchange', 'floop-strip-mine', 'floop-block'],
'lto': 'flto',
'ieee': ['mieee-fp', 'fno-trapping-math'],
'strict': ['mieee-fp', 'mno-recip'],
'precise': ['mno-recip'],
'defaultprec': ['fno-math-errno'],
'loose': ['fno-math-errno', 'mrecip', 'mno-ieee-fp'],
'veryloose': ['fno-math-errno', 'mrecip=all', 'mno-ieee-fp'],
'vectorize': {False: 'fno-tree-vectorize', True: 'ftree-vectorize'},
DEFAULT_OPT_LEVEL: ['O2', 'ftree-vectorize'],
'i8': '-fdefault-integer-8',
'r8': ['-fdefault-real-8', '-fdefault-double-8'],
'unroll': '-funroll-loops',
'f2c': '-ff2c',
'loop': ['-ftree-switch-conversion', '-floop-interchange', '-floop-strip-mine', '-floop-block'],
'lto': '-flto',
'ieee': ['-mieee-fp', '-fno-trapping-math'],
'strict': ['-mieee-fp', '-mno-recip'],
'precise': ['-mno-recip'],
'defaultprec': ['-fno-math-errno'],
'loose': ['-fno-math-errno', '-mrecip', '-mno-ieee-fp'],
'veryloose': ['-fno-math-errno', '-mrecip=all', '-mno-ieee-fp'],
'vectorize': {False: '-fno-tree-vectorize', True: '-ftree-vectorize'},
DEFAULT_OPT_LEVEL: ['-O2', '-ftree-vectorize'],
}

# gcc on aarch64 does not support -mno-recip, -mieee-fp, -mfno-math-errno...
# https://gcc.gnu.org/onlinedocs/gcc/AArch64-Options.html
if systemtools.get_cpu_architecture() == systemtools.AARCH64:
no_recip_alternative = ['mno-low-precision-recip-sqrt', 'mno-low-precision-sqrt', 'mno-low-precision-div']
no_recip_alternative = ['-mno-low-precision-recip-sqrt', '-mno-low-precision-sqrt', '-mno-low-precision-div']
COMPILER_UNIQUE_OPTION_MAP['strict'] = no_recip_alternative
COMPILER_UNIQUE_OPTION_MAP['precise'] = no_recip_alternative

Expand All @@ -84,38 +84,38 @@ class Gcc(Compiler):
if systemtools.get_cpu_family() == systemtools.RISCV:
COMPILER_UNIQUE_OPTION_MAP['strict'] = []
COMPILER_UNIQUE_OPTION_MAP['precise'] = []
COMPILER_UNIQUE_OPTION_MAP['loose'] = ['fno-math-errno']
COMPILER_UNIQUE_OPTION_MAP['veryloose'] = ['fno-math-errno']
COMPILER_UNIQUE_OPTION_MAP['loose'] = ['-fno-math-errno']
COMPILER_UNIQUE_OPTION_MAP['veryloose'] = ['-fno-math-errno']

# used when 'optarch' toolchain option is enabled (and --optarch is not specified)
COMPILER_OPTIMAL_ARCHITECTURE_OPTION = {
(systemtools.AARCH32, systemtools.ARM): 'mcpu=native', # implies -march=native and -mtune=native
(systemtools.AARCH64, systemtools.ARM): 'mcpu=native', # since GCC 6; implies -march=native and -mtune=native
(systemtools.AARCH32, systemtools.ARM): '-mcpu=native', # implies -march=native and -mtune=native
(systemtools.AARCH64, systemtools.ARM): '-mcpu=native', # since GCC 6; implies -march=native and -mtune=native
# no support for -march on POWER; implies -mtune=native
(systemtools.POWER, systemtools.POWER): 'mcpu=native',
(systemtools.POWER, systemtools.POWER_LE): 'mcpu=native',
(systemtools.X86_64, systemtools.AMD): 'march=native', # implies -mtune=native
(systemtools.X86_64, systemtools.INTEL): 'march=native', # implies -mtune=native
(systemtools.POWER, systemtools.POWER): '-mcpu=native',
(systemtools.POWER, systemtools.POWER_LE): '-mcpu=native',
(systemtools.X86_64, systemtools.AMD): '-march=native', # implies -mtune=native
(systemtools.X86_64, systemtools.INTEL): '-march=native', # implies -mtune=native
}
# used with --optarch=GENERIC
COMPILER_GENERIC_OPTION = {
(systemtools.AARCH32, systemtools.ARM): 'mcpu=generic-armv7', # implies -march=armv7 and -mtune=generic-armv7
(systemtools.AARCH64, systemtools.ARM): 'mcpu=generic', # implies -march=armv8-a and -mtune=generic
(systemtools.POWER, systemtools.POWER): 'mcpu=powerpc64', # no support for -march on POWER
(systemtools.POWER, systemtools.POWER_LE): 'mcpu=powerpc64le', # no support for -march on POWER
(systemtools.RISCV64, systemtools.RISCV): 'march=rv64gc -mabi=lp64d', # default for -mabi is system-dependent
(systemtools.X86_64, systemtools.AMD): 'march=x86-64 -mtune=generic',
(systemtools.X86_64, systemtools.INTEL): 'march=x86-64 -mtune=generic',
(systemtools.AARCH32, systemtools.ARM): '-mcpu=generic-armv7', # implies -march=armv7 and -mtune=generic-armv7
(systemtools.AARCH64, systemtools.ARM): '-mcpu=generic', # implies -march=armv8-a and -mtune=generic
(systemtools.POWER, systemtools.POWER): '-mcpu=powerpc64', # no support for -march on POWER
(systemtools.POWER, systemtools.POWER_LE): '-mcpu=powerpc64le', # no support for -march on POWER
(systemtools.RISCV64, systemtools.RISCV): '-march=rv64gc -mabi=lp64d', # default for -mabi is system-dependent
(systemtools.X86_64, systemtools.AMD): '-march=x86-64 -mtune=generic',
(systemtools.X86_64, systemtools.INTEL): '-march=x86-64 -mtune=generic',
}

COMPILER_CC = 'gcc'
COMPILER_CXX = 'g++'
COMPILER_C_UNIQUE_FLAGS = []
COMPILER_C_UNIQUE_OPTIONS = []

COMPILER_F77 = 'gfortran'
COMPILER_F90 = 'gfortran'
COMPILER_FC = 'gfortran'
COMPILER_F_UNIQUE_FLAGS = ['f2c']
COMPILER_F_UNIQUE_OPTIONS = ['f2c']

LIB_MULTITHREAD = ['pthread']
LIB_MATH = ['m']
Expand Down Expand Up @@ -186,8 +186,8 @@ def _guess_aarch64_default_optarch(self):
break
if core_types:
# On big.LITTLE setups, sort core types to have big core (higher model number) first.
# Example: 'mcpu=cortex-a72.cortex-a53' for "ARM Cortex-A53 + Cortex-A72"
default_optarch = 'mcpu=%s' % '.'.join([ct[1] for ct in sorted(core_types, reverse=True)])
# Example: '-mcpu=cortex-a72.cortex-a53' for "ARM Cortex-A53 + Cortex-A72"
default_optarch = '-mcpu=%s' % '.'.join([ct[1] for ct in sorted(core_types, reverse=True)])
self.log.debug("Using architecture-specific compiler optimization flag '%s'", default_optarch)

return default_optarch
14 changes: 7 additions & 7 deletions easybuild/toolchains/compiler/intel_compilers.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,22 +106,22 @@ def set_variables(self):

if oneapi:
# fp-model source is not supported by icx but is equivalent to precise
self.options.options_map['defaultprec'] = ['fp-speculation=safe', 'fp-model precise']
self.options.options_map['defaultprec'] = ['-fp-speculation=safe', '-fp-model precise']
if LooseVersion(comp_ver) >= LooseVersion('2022'):
self.options.options_map['defaultprec'].insert(0, 'ftz')
self.options.options_map['defaultprec'].insert(0, '-ftz')
# icx doesn't like -fp-model fast=1; fp-model fast is equivalent
self.options.options_map['loose'] = ['fp-model fast']
self.options.options_map['loose'] = ['-fp-model fast']
# fp-model fast=2 gives "warning: overriding '-ffp-model=fast=2' option with '-ffp-model=fast'"
self.options.options_map['veryloose'] = ['fp-model fast']
self.options.options_map['veryloose'] = ['-fp-model fast']
# recommended in porting guide: qopenmp, unlike fiopenmp, works for both classic and oneapi compilers
# https://www.intel.com/content/www/us/en/developer/articles/guide/porting-guide-for-ifort-to-ifx.html
self.options.options_map['openmp'] = ['qopenmp']
self.options.options_map['openmp'] = ['-qopenmp']

# -xSSE2 is not supported by Intel oneAPI compilers,
# so use -march=x86-64 -mtune=generic when using optarch=GENERIC
self.COMPILER_GENERIC_OPTION = {
(systemtools.X86_64, systemtools.AMD): 'march=x86-64 -mtune=generic',
(systemtools.X86_64, systemtools.INTEL): 'march=x86-64 -mtune=generic',
(systemtools.X86_64, systemtools.AMD): '-march=x86-64 -mtune=generic',
(systemtools.X86_64, systemtools.INTEL): '-march=x86-64 -mtune=generic',
}

# skip IntelIccIfort.set_variables (no longer relevant for recent versions)
Expand Down
Loading
Loading