Skip to content

Commit a470089

Browse files
authored
Merge pull request #4698 from Micket/optarchdash
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`
2 parents 66f8df3 + a94f2b3 commit a470089

File tree

17 files changed

+272
-250
lines changed

17 files changed

+272
-250
lines changed

easybuild/toolchains/compiler/clang.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,10 @@ class Clang(Compiler):
5555
'basic-block-vectorize': (False, "Basic block vectorization"),
5656
}
5757
COMPILER_UNIQUE_OPTION_MAP = {
58-
'unroll': 'funroll-loops',
59-
'loop-vectorize': ['fvectorize'],
60-
'basic-block-vectorize': ['fslp-vectorize'],
61-
'optarch': 'march=native',
58+
'unroll': '-funroll-loops',
59+
'loop-vectorize': ['-fvectorize'],
60+
'basic-block-vectorize': ['-fslp-vectorize'],
61+
'optarch': '-march=native',
6262
# Clang's options do not map well onto these precision modes. The flags enable and disable certain classes of
6363
# optimizations.
6464
#
@@ -80,31 +80,31 @@ class Clang(Compiler):
8080
#
8181
# 'strict', 'precise' and 'defaultprec' are all ISO C++ and IEEE complaint, but we explicitly specify details
8282
# flags for strict and precise for robustness against future changes.
83-
'strict': ['fno-fast-math'],
84-
'precise': ['fno-unsafe-math-optimizations'],
83+
'strict': ['-fno-fast-math'],
84+
'precise': ['-fno-unsafe-math-optimizations'],
8585
'defaultprec': [],
86-
'loose': ['ffast-math', 'fno-unsafe-math-optimizations'],
87-
'veryloose': ['ffast-math'],
88-
'vectorize': {False: 'fno-vectorize', True: 'fvectorize'},
86+
'loose': ['-ffast-math', '-fno-unsafe-math-optimizations'],
87+
'veryloose': ['-ffast-math'],
88+
'vectorize': {False: '-fno-vectorize', True: '-fvectorize'},
8989
}
9090

9191
# used when 'optarch' toolchain option is enabled (and --optarch is not specified)
9292
COMPILER_OPTIMAL_ARCHITECTURE_OPTION = {
93-
(systemtools.POWER, systemtools.POWER): 'mcpu=native', # no support for march=native on POWER
94-
(systemtools.POWER, systemtools.POWER_LE): 'mcpu=native', # no support for march=native on POWER
95-
(systemtools.X86_64, systemtools.AMD): 'march=native',
96-
(systemtools.X86_64, systemtools.INTEL): 'march=native',
93+
(systemtools.POWER, systemtools.POWER): '-mcpu=native', # no support for march=native on POWER
94+
(systemtools.POWER, systemtools.POWER_LE): '-mcpu=native', # no support for march=native on POWER
95+
(systemtools.X86_64, systemtools.AMD): '-march=native',
96+
(systemtools.X86_64, systemtools.INTEL): '-march=native',
9797
}
9898
# used with --optarch=GENERIC
9999
COMPILER_GENERIC_OPTION = {
100-
(systemtools.RISCV64, systemtools.RISCV): 'march=rv64gc -mabi=lp64d', # default for -mabi is system-dependent
101-
(systemtools.X86_64, systemtools.AMD): 'march=x86-64 -mtune=generic',
102-
(systemtools.X86_64, systemtools.INTEL): 'march=x86-64 -mtune=generic',
100+
(systemtools.RISCV64, systemtools.RISCV): '-march=rv64gc -mabi=lp64d', # default for -mabi is system-dependent
101+
(systemtools.X86_64, systemtools.AMD): '-march=x86-64 -mtune=generic',
102+
(systemtools.X86_64, systemtools.INTEL): '-march=x86-64 -mtune=generic',
103103
}
104104

105105
COMPILER_CC = 'clang'
106106
COMPILER_CXX = 'clang++'
107-
COMPILER_C_UNIQUE_FLAGS = []
107+
COMPILER_C_UNIQUE_OPTIONS = []
108108

109109
LIB_MULTITHREAD = ['pthread']
110110
LIB_MATH = ['m']

easybuild/toolchains/compiler/craype.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ class CrayPECompiler(Compiler):
7676
# handle shared and dynamic always via $CRAYPE_LINK_TYPE environment variable, don't pass flags to wrapper
7777
'shared': '',
7878
'dynamic': '',
79-
'verbose': 'craype-verbose',
80-
'mpich-mt': 'craympich-mt',
79+
'verbose': '-craype-verbose',
80+
'mpich-mt': '-craympich-mt',
8181
}
8282

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

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

145145

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

157157

@@ -163,8 +163,8 @@ class CrayPEPGI(CrayPECompiler):
163163
def __init__(self, *args, **kwargs):
164164
"""CrayPEPGI constructor."""
165165
super(CrayPEPGI, self).__init__(*args, **kwargs)
166-
self.COMPILER_UNIQUE_OPTION_MAP['openmp'] = 'mp'
167-
for precflag in self.COMPILER_PREC_FLAGS:
166+
self.COMPILER_UNIQUE_OPTION_MAP['openmp'] = '-mp'
167+
for precflag in self.COMPILER_PREC_OPTIONS:
168168
self.COMPILER_UNIQUE_OPTION_MAP[precflag] = Pgi.COMPILER_UNIQUE_OPTION_MAP[precflag]
169169

170170

@@ -176,6 +176,6 @@ class CrayPECray(CrayPECompiler):
176176
def __init__(self, *args, **kwargs):
177177
"""CrayPEIntel constructor."""
178178
super(CrayPECray, self).__init__(*args, **kwargs)
179-
self.COMPILER_UNIQUE_OPTION_MAP['openmp'] = 'homp'
180-
for precflag in self.COMPILER_PREC_FLAGS:
179+
self.COMPILER_UNIQUE_OPTION_MAP['openmp'] = '-homp'
180+
for precflag in self.COMPILER_PREC_OPTIONS:
181181
self.COMPILER_UNIQUE_OPTION_MAP[precflag] = []

easybuild/toolchains/compiler/cuda.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ class Cuda(Compiler):
6060

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

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

9292
cuda_flags = [
93-
'Xcompiler="%s"' % str(self.variables['CXXFLAGS']),
94-
'Xlinker="%s %s"' % (str(self.variables['LDFLAGS']), str(self.variables['LIBS'])),
93+
'-Xcompiler="%s"' % str(self.variables['CXXFLAGS']),
94+
'-Xlinker="%s %s"' % (str(self.variables['LDFLAGS']), str(self.variables['LIBS'])),
9595
]
9696
self.variables.nextend('CUDA_CFLAGS', cuda_flags)
9797
self.variables.nextend('CUDA_CXXFLAGS', cuda_flags)
9898

9999
# add gencode compiler flags to list of flags for compiler variables
100100
for gencode_val in self.options.get('cuda_gencode', []):
101-
gencode_option = 'gencode %s' % gencode_val
101+
gencode_option = '-gencode %s' % gencode_val
102102
self.variables.nappend('CUDA_CFLAGS', gencode_option)
103103
self.variables.nappend('CUDA_CXXFLAGS', gencode_option)

easybuild/toolchains/compiler/fujitsu.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -58,23 +58,23 @@ class FujitsuCompiler(Compiler):
5858
COMPILER_FC = 'frt'
5959

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

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

111111
# enable clang compatibility mode
112-
self.variables.nappend('CFLAGS', ['Nclang'])
113-
self.variables.nappend('CXXFLAGS', ['Nclang'])
112+
self.variables.nappend('CFLAGS', ['-Nclang'])
113+
self.variables.nappend('CXXFLAGS', ['-Nclang'])
114114

115115
# also add fujitsu module library path to LDFLAGS
116116
libdir = os.path.join(os.getenv(TC_CONSTANT_MODULE_VAR), 'lib64')

easybuild/toolchains/compiler/gcc.py

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -55,26 +55,26 @@ class Gcc(Compiler):
5555
'lto': (False, "Enable Link Time Optimization"),
5656
}
5757
COMPILER_UNIQUE_OPTION_MAP = {
58-
'i8': 'fdefault-integer-8',
59-
'r8': ['fdefault-real-8', 'fdefault-double-8'],
60-
'unroll': 'funroll-loops',
61-
'f2c': 'ff2c',
62-
'loop': ['ftree-switch-conversion', 'floop-interchange', 'floop-strip-mine', 'floop-block'],
63-
'lto': 'flto',
64-
'ieee': ['mieee-fp', 'fno-trapping-math'],
65-
'strict': ['mieee-fp', 'mno-recip'],
66-
'precise': ['mno-recip'],
67-
'defaultprec': ['fno-math-errno'],
68-
'loose': ['fno-math-errno', 'mrecip', 'mno-ieee-fp'],
69-
'veryloose': ['fno-math-errno', 'mrecip=all', 'mno-ieee-fp'],
70-
'vectorize': {False: 'fno-tree-vectorize', True: 'ftree-vectorize'},
71-
DEFAULT_OPT_LEVEL: ['O2', 'ftree-vectorize'],
58+
'i8': '-fdefault-integer-8',
59+
'r8': ['-fdefault-real-8', '-fdefault-double-8'],
60+
'unroll': '-funroll-loops',
61+
'f2c': '-ff2c',
62+
'loop': ['-ftree-switch-conversion', '-floop-interchange', '-floop-strip-mine', '-floop-block'],
63+
'lto': '-flto',
64+
'ieee': ['-mieee-fp', '-fno-trapping-math'],
65+
'strict': ['-mieee-fp', '-mno-recip'],
66+
'precise': ['-mno-recip'],
67+
'defaultprec': ['-fno-math-errno'],
68+
'loose': ['-fno-math-errno', '-mrecip', '-mno-ieee-fp'],
69+
'veryloose': ['-fno-math-errno', '-mrecip=all', '-mno-ieee-fp'],
70+
'vectorize': {False: '-fno-tree-vectorize', True: '-ftree-vectorize'},
71+
DEFAULT_OPT_LEVEL: ['-O2', '-ftree-vectorize'],
7272
}
7373

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

@@ -84,38 +84,38 @@ class Gcc(Compiler):
8484
if systemtools.get_cpu_family() == systemtools.RISCV:
8585
COMPILER_UNIQUE_OPTION_MAP['strict'] = []
8686
COMPILER_UNIQUE_OPTION_MAP['precise'] = []
87-
COMPILER_UNIQUE_OPTION_MAP['loose'] = ['fno-math-errno']
88-
COMPILER_UNIQUE_OPTION_MAP['veryloose'] = ['fno-math-errno']
87+
COMPILER_UNIQUE_OPTION_MAP['loose'] = ['-fno-math-errno']
88+
COMPILER_UNIQUE_OPTION_MAP['veryloose'] = ['-fno-math-errno']
8989

9090
# used when 'optarch' toolchain option is enabled (and --optarch is not specified)
9191
COMPILER_OPTIMAL_ARCHITECTURE_OPTION = {
92-
(systemtools.AARCH32, systemtools.ARM): 'mcpu=native', # implies -march=native and -mtune=native
93-
(systemtools.AARCH64, systemtools.ARM): 'mcpu=native', # since GCC 6; implies -march=native and -mtune=native
92+
(systemtools.AARCH32, systemtools.ARM): '-mcpu=native', # implies -march=native and -mtune=native
93+
(systemtools.AARCH64, systemtools.ARM): '-mcpu=native', # since GCC 6; implies -march=native and -mtune=native
9494
# no support for -march on POWER; implies -mtune=native
95-
(systemtools.POWER, systemtools.POWER): 'mcpu=native',
96-
(systemtools.POWER, systemtools.POWER_LE): 'mcpu=native',
97-
(systemtools.X86_64, systemtools.AMD): 'march=native', # implies -mtune=native
98-
(systemtools.X86_64, systemtools.INTEL): 'march=native', # implies -mtune=native
95+
(systemtools.POWER, systemtools.POWER): '-mcpu=native',
96+
(systemtools.POWER, systemtools.POWER_LE): '-mcpu=native',
97+
(systemtools.X86_64, systemtools.AMD): '-march=native', # implies -mtune=native
98+
(systemtools.X86_64, systemtools.INTEL): '-march=native', # implies -mtune=native
9999
}
100100
# used with --optarch=GENERIC
101101
COMPILER_GENERIC_OPTION = {
102-
(systemtools.AARCH32, systemtools.ARM): 'mcpu=generic-armv7', # implies -march=armv7 and -mtune=generic-armv7
103-
(systemtools.AARCH64, systemtools.ARM): 'mcpu=generic', # implies -march=armv8-a and -mtune=generic
104-
(systemtools.POWER, systemtools.POWER): 'mcpu=powerpc64', # no support for -march on POWER
105-
(systemtools.POWER, systemtools.POWER_LE): 'mcpu=powerpc64le', # no support for -march on POWER
106-
(systemtools.RISCV64, systemtools.RISCV): 'march=rv64gc -mabi=lp64d', # default for -mabi is system-dependent
107-
(systemtools.X86_64, systemtools.AMD): 'march=x86-64 -mtune=generic',
108-
(systemtools.X86_64, systemtools.INTEL): 'march=x86-64 -mtune=generic',
102+
(systemtools.AARCH32, systemtools.ARM): '-mcpu=generic-armv7', # implies -march=armv7 and -mtune=generic-armv7
103+
(systemtools.AARCH64, systemtools.ARM): '-mcpu=generic', # implies -march=armv8-a and -mtune=generic
104+
(systemtools.POWER, systemtools.POWER): '-mcpu=powerpc64', # no support for -march on POWER
105+
(systemtools.POWER, systemtools.POWER_LE): '-mcpu=powerpc64le', # no support for -march on POWER
106+
(systemtools.RISCV64, systemtools.RISCV): '-march=rv64gc -mabi=lp64d', # default for -mabi is system-dependent
107+
(systemtools.X86_64, systemtools.AMD): '-march=x86-64 -mtune=generic',
108+
(systemtools.X86_64, systemtools.INTEL): '-march=x86-64 -mtune=generic',
109109
}
110110

111111
COMPILER_CC = 'gcc'
112112
COMPILER_CXX = 'g++'
113-
COMPILER_C_UNIQUE_FLAGS = []
113+
COMPILER_C_UNIQUE_OPTIONS = []
114114

115115
COMPILER_F77 = 'gfortran'
116116
COMPILER_F90 = 'gfortran'
117117
COMPILER_FC = 'gfortran'
118-
COMPILER_F_UNIQUE_FLAGS = ['f2c']
118+
COMPILER_F_UNIQUE_OPTIONS = ['f2c']
119119

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

193193
return default_optarch

easybuild/toolchains/compiler/intel_compilers.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -106,22 +106,22 @@ def set_variables(self):
106106

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

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

127127
# skip IntelIccIfort.set_variables (no longer relevant for recent versions)

0 commit comments

Comments
 (0)