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

Allow user to define the default compiler optimsation level #1565

Merged
merged 6 commits into from
Jan 23, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions easybuild/tools/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,9 @@ def mk_full_default_path(name, prefix=DEFAULT_PREFIX):
GENERAL_CLASS: [
'suffix_modules_path',
],
'defaultopt': [
'default_opt_level',
]
}
# build option that do not have a perfectly matching command line option
BUILD_OPTIONS_OTHER = {
Expand Down
3 changes: 3 additions & 0 deletions easybuild/tools/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
from easybuild.tools.ordereddict import OrderedDict
from easybuild.tools.run import run_cmd
from easybuild.tools.package.utilities import avail_package_naming_schemes
from easybuild.tools.toolchain.compiler import DEFAULT_OPT_LEVEL, Compiler
from easybuild.tools.toolchain.utilities import search_toolchain
from easybuild.tools.repository.repository import avail_repositories
from easybuild.tools.version import this_is_easybuild
Expand Down Expand Up @@ -213,6 +214,8 @@ def override_options(self):
'cleanup-builddir': ("Cleanup build dir after successful installation.", None, 'store_true', True),
'cleanup-tmpdir': ("Cleanup tmp dir after successful run.", None, 'store_true', True),
'color': ("Allow color output", None, 'store_true', True),
'default-opt-level': ("Specify default optimisation level", 'choice', 'store', DEFAULT_OPT_LEVEL,
Compiler.COMPILER_OPT_FLAGS),
'deprecated': ("Run pretending to be (future) version, to test removal of deprecated code.",
None, 'store', None),
'download-timeout': ("Timeout for initiating downloads (in seconds)", float, 'store', None),
Expand Down
18 changes: 13 additions & 5 deletions easybuild/tools/toolchain/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@
from easybuild.tools.toolchain.constants import COMPILER_VARIABLES
from easybuild.tools.toolchain.toolchain import Toolchain

# default optimization 'level' (see COMPILER_SHARED_OPTION_MAP/COMPILER_OPT_FLAGS)
DEFAULT_OPT_LEVEL = 'defaultopt'

# 'GENERIC' can beused to enable generic compilation instead of optimized compilation (which is the default)
# 'GENERIC' can be used to enable generic compilation instead of optimized compilation (which is the default)
# by doing eb --optarch=GENERIC
OPTARCH_GENERIC = 'GENERIC'

Expand Down Expand Up @@ -63,7 +65,7 @@ class Compiler(Toolchain):
'pic': (False, "Use PIC"), # also FFTW
'noopt': (False, "Disable compiler optimizations"),
'lowopt': (False, "Low compiler optimizations"),
'defaultopt': (False, "Default compiler optimizations"), # not set, but default
DEFAULT_OPT_LEVEL: (False, "Default compiler optimizations"), # not set, but default
'opt': (False, "High compiler optimizations"),
'optarch': (True, "Enable architecture optimizations"),
'strict': (False, "Strict (highest) precision"),
Expand Down Expand Up @@ -94,7 +96,7 @@ class Compiler(Toolchain):
'shared': 'shared',
'noopt': 'O0',
'lowopt': 'O1',
'defaultopt': 'O2',
DEFAULT_OPT_LEVEL: 'O2',
'opt': 'O3',
'32bit' : 'm32',
'cstd': 'std=%(value)s',
Expand All @@ -104,7 +106,7 @@ class Compiler(Toolchain):
COMPILER_GENERIC_OPTION = None

COMPILER_FLAGS = ['debug', 'verbose', 'static', 'shared', 'openmp', 'pic', 'unroll'] # any compiler
COMPILER_OPT_FLAGS = ['noopt', 'lowopt', 'defaultopt', 'opt'] # optimisation args, ordered !
COMPILER_OPT_FLAGS = ['noopt', 'lowopt', DEFAULT_OPT_LEVEL, 'opt'] # optimisation args, ordered !
COMPILER_PREC_FLAGS = ['strict', 'precise', 'defaultprec', 'loose', 'veryloose'] # precision flags, ordered !

COMPILER_CC = None
Expand Down Expand Up @@ -231,9 +233,15 @@ def _set_compiler_flags(self):
fflags = [self.options.option(x) for x in self.COMPILER_F_FLAGS + self.COMPILER_F_UNIQUE_FLAGS \
if self.options.get(x, False)]

# Allow a user-defined default optimisation
default_opt_level = build_option('default_opt_level')
if default_opt_level not in self.COMPILER_OPT_FLAGS:
raise EasyBuildError("Unknown value for default optimisation: %s (possibilities are %s)" %
(default_opt_level, self.COMPILER_OPT_FLAGS))
Copy link
Member

Choose a reason for hiding this comment

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

how about

default_opt_level = build_option('default_opt_level')
if default_opt_level not in self.COMPILER_OPT_FLAGS:
    raise ...

and then also use default_opt_level below


Copy link
Member Author

Choose a reason for hiding this comment

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

Invalid option already picked up by the option parser...could remove the if/else?

Copy link
Member

Choose a reason for hiding this comment

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

Hmm, leave it there, it's pretty cheap, and we may change things later such that default_opt_level comes from somewhere else

# 1st one is the one to use. add default at the end so len is at least 1
optflags = [self.options.option(x) for x in self.COMPILER_OPT_FLAGS if self.options.get(x, False)] + \
[self.options.option('defaultopt')]
[self.options.option(default_opt_level)]

optarchflags = []
if build_option('optarch') == OPTARCH_GENERIC:
Expand Down