From ae55c3b88dd6c45e8dd4bc35420e0df758848694 Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Wed, 16 Nov 2016 16:28:41 -0600 Subject: [PATCH 1/2] Remove some CL terminology from options --- loopy/options.py | 73 ++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 59 insertions(+), 14 deletions(-) diff --git a/loopy/options.py b/loopy/options.py index 5db1be646..ef225b98b 100644 --- a/loopy/options.py +++ b/loopy/options.py @@ -95,26 +95,25 @@ class Options(Record): 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 @@ -142,12 +141,38 @@ class Options(Record): 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=[], + write_code=None, disable_code_highlight=None, + edit_code=None, build_options=None, allow_terminal_colors=None, disable_global_barriers=False, + + # legacy + write_cl=None, + highlight_cl=None, + cl_build_options=None, + edit_cl=None, ): + if build_options is None: + build_options = cl_build_options + if build_options is None: + build_options = [] + + if write_code is None: + write_code = write_cl + if write_code is None: + write_code = False + + if disable_code_highlight is None and highlight_cl is not None: + disable_code_highlight = not highlight_cl + if disable_code_highlight is None: + disable_code_highlight = False + + if edit_code is None: + edit_code = edit_cl + if edit_code is None: + edit_code = False + if allow_terminal_colors is None: try: import colorama # noqa @@ -167,12 +192,32 @@ class Options(Record): 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, + write_code=write_code, disable_code_highlight=disable_code_highlight, + edit_code=edit_code, build_options=build_options, allow_terminal_colors=allow_terminal_colors, disable_global_barriers=disable_global_barriers, ) + # {{{ 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)) -- GitLab From 062fbcf89cb4be65de094b2db2ee1ec20951f035 Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Wed, 16 Nov 2016 17:57:38 -0600 Subject: [PATCH 2/2] Unify legacy option handling --- loopy/__init__.py | 3 ++ loopy/options.py | 120 +++++++++++++++++++++++----------------------- loopy/version.py | 2 +- 3 files changed, 63 insertions(+), 62 deletions(-) diff --git a/loopy/__init__.py b/loopy/__init__.py index 73a02479d..b6c2d15c2 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 ef225b98b..a19afdaca 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,7 +113,7 @@ 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`. @@ -125,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. @@ -132,70 +162,38 @@ 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_code=None, disable_code_highlight=None, - edit_code=None, build_options=None, - allow_terminal_colors=None, - disable_global_barriers=False, - - # legacy - write_cl=None, - highlight_cl=None, - cl_build_options=None, - edit_cl=None, - ): - - if build_options is None: - build_options = cl_build_options - if build_options is None: - build_options = [] - - if write_code is None: - write_code = write_cl - if write_code is None: - write_code = False - - if disable_code_highlight is None and highlight_cl is not None: - disable_code_highlight = not highlight_cl - if disable_code_highlight is None: - disable_code_highlight = False - - if edit_code is None: - edit_code = edit_cl - if edit_code is None: - edit_code = 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_code=write_code, disable_code_highlight=disable_code_highlight, - edit_code=edit_code, build_options=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 diff --git a/loopy/version.py b/loopy/version.py index aa3e7abee..0b56284bb 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 -- GitLab