diff --git a/loopy/__init__.py b/loopy/__init__.py index 73a02479d705b74936097a87746baa83e5495de9..b6c2d15c26b47b8b667ffd8dc74ec10945cc802f 100644 --- a/loopy/__init__.py +++ b/loopy/__init__.py @@ -276,6 +276,9 @@ def set_options(kernel, *args, **kwargs): new_opt = kernel.options.copy() if kwargs: + from loopy.options import _apply_legacy_map, Options + kwargs = _apply_legacy_map(Options._legacy_options_map, kwargs) + for key, val in six.iteritems(kwargs): if not hasattr(new_opt, key): raise ValueError("unknown option '%s'" % key) diff --git a/loopy/options.py b/loopy/options.py index 5db1be64624c027a6579f28c99db1bb4e78e3bc3..a19afdaca8a4d14bcdf21397d1ea2d7fdd5a1a82 100644 --- a/loopy/options.py +++ b/loopy/options.py @@ -23,6 +23,7 @@ THE SOFTWARE. """ +import six from pytools import Record import re @@ -32,6 +33,27 @@ class _ColoramaStub(object): return "" +def _apply_legacy_map(lmap, kwargs): + result = {} + + for name, val in six.iteritems(kwargs): + try: + new_name, translator = lmap[name] + except KeyError: + new_name = name + else: + if name in result: + raise TypeError("may not pass a value for both '%s' and '%s'" + % (name, new_name)) + + if translator is not None: + val = translator(val) + + result[new_name] = val + + return result + + class Options(Record): """ Unless otherwise specified, these options are Boolean-valued @@ -91,30 +113,29 @@ class Options(Record): Accepts a file name as a value. Writes to ``sys.stdout`` if none is given. - .. attribute:: highlight_wrapper + .. attribute:: disable_wrapper_highlight Use syntax highlighting in :attr:`write_wrapper`. - .. attribute:: write_cl + .. attribute:: write_code - Print the generated OpenCL kernel. - Accepts a file name as a value. Writes to - ``sys.stdout`` if none is given. + Print the generated code. Accepts a file name or a boolean as a value. + Writes to ``sys.stdout`` if set to *True*. - .. attribute:: highlight_cl + .. attribute:: disable_code_highlight - Use syntax highlighting in :attr:`write_cl`. + Use syntax highlighting in :attr:`write_code`. - .. attribute:: edit_cl + .. attribute:: edit_code Invoke an editor (given by the environment variable :envvar:`EDITOR`) on the generated kernel code, allowing for tweaks before the code is passed on to - the OpenCL implementation for compilation. + the target for compilation. - .. attribute:: cl_build_options + .. attribute:: build_options - Options to pass to the OpenCL compiler when building the kernel. + Options to pass to the target compiler when building the kernel. A list of strings. .. attribute:: allow_terminal_colors @@ -126,6 +147,14 @@ class Options(Record): .. attribute:: disable_global_barriers """ + _legacy_options_map = { + "cl_build_options": ("build_options", None), + "write_cl": ("write_code", None), + "highlight_cl": ("disable_code_highlight", lambda val: not val), + "highlight_wrapper": ("disable_wrapper_highlight", lambda val: not val), + "edit_cl": ("edit_code", None), + } + def __init__( # All Boolean flags in here should default to False for the # string-based interface of make_options (below) to make sense. @@ -133,46 +162,60 @@ class Options(Record): # All defaults are further required to be False when cast to bool # for the update() functionality to work. - self, - - annotate_inames=False, - trace_assignments=False, - trace_assignment_values=False, - ignore_boostable_into=False, - - skip_arg_checks=False, no_numpy=False, return_dict=False, - write_wrapper=False, highlight_wrapper=False, - write_cl=False, highlight_cl=False, - edit_cl=False, cl_build_options=[], - allow_terminal_colors=None, - disable_global_barriers=False, - ): - - if allow_terminal_colors is None: - try: - import colorama # noqa - except ImportError: - allow_terminal_colors = False - else: - allow_terminal_colors = True + self, **kwargs): + + kwargs = _apply_legacy_map(self._legacy_options_map, kwargs) + + try: + import colorama # noqa + except ImportError: + allow_terminal_colors_def = False + else: + allow_terminal_colors_def = True Record.__init__( self, - annotate_inames=annotate_inames, - trace_assignments=trace_assignments, - trace_assignment_values=trace_assignment_values, - ignore_boostable_into=ignore_boostable_into, - - skip_arg_checks=skip_arg_checks, no_numpy=no_numpy, - return_dict=return_dict, - write_wrapper=write_wrapper, highlight_wrapper=highlight_wrapper, - write_cl=write_cl, highlight_cl=highlight_cl, - edit_cl=edit_cl, cl_build_options=cl_build_options, - allow_terminal_colors=allow_terminal_colors, - disable_global_barriers=disable_global_barriers, + annotate_inames=kwargs.get("annotate_inames", False), + trace_assignments=kwargs.get("trace_assignments", False), + trace_assignment_values=kwargs.get("trace_assignment_values", False), + ignore_boostable_into=kwargs.get("ignore_boostable_into", False), + + skip_arg_checks=kwargs.get("skip_arg_checks", False), + no_numpy=kwargs.get("no_numpy", False), + return_dict=kwargs.get("return_dict", False), + write_wrapper=kwargs.get("write_wrapper", False), + highlight_wrapper=kwargs.get("highlight_wrapper", False), + write_code=kwargs.get("write_code", False), + disable_code_highlight=kwargs.get("disable_code_highlight", False), + edit_code=kwargs.get("edit_code", False), + build_options=kwargs.get("build_options", []), + allow_terminal_colors=kwargs.get("allow_terminal_colors", + allow_terminal_colors_def), + disable_global_barriers=kwargs.get("disable_global_barriers", + False), ) + # {{{ legacy compatibility + + @property + def edit_cl(self): + return self.edit_code + + @property + def cl_build_options(self): + return self.build_options + + @property + def highlight_cl(self): + return not self.disable_code_highlight + + @property + def write_cl(self): + return self.write_code + + # }}} + def update(self, other): for f in self.__class__.fields: setattr(self, f, getattr(self, f) or getattr(other, f)) diff --git a/loopy/version.py b/loopy/version.py index aa3e7abee41a05595985df574da52c024b52dcb5..0b56284bbbf68b92bbab368de3c30a997724b29e 100644 --- a/loopy/version.py +++ b/loopy/version.py @@ -32,4 +32,4 @@ except ImportError: else: _islpy_version = islpy.version.VERSION_TEXT -DATA_MODEL_VERSION = "v44-islpy%s" % _islpy_version +DATA_MODEL_VERSION = "v48-islpy%s" % _islpy_version