Skip to content

Commit

Permalink
Merge pull request easybuilders#4698 from Micket/optarchdash
Browse files Browse the repository at this point in the history
change `Toolchain.get_flag` so it doesn't automatically prepend a dash (`-`) to compiler flags, add deprecation warning for `optarch` value without leading dash, rename `Compiler.COMPILER*_FLAGS` to `Compiler.COMPILER*_OPTIONS`
  • Loading branch information
boegel authored Dec 18, 2024
2 parents 66f8df3 + a94f2b3 commit a470089
Show file tree
Hide file tree
Showing 17 changed files with 272 additions and 250 deletions.
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 = []

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

0 comments on commit a470089

Please sign in to comment.