diff --git a/doc/tutorial.rst b/doc/tutorial.rst index 7196dad863474d9b6ea9df9d9d0ae90b3e14986d..7ac506806d3c0b416298c22592cfc5e055754fb9 100644 --- a/doc/tutorial.rst +++ b/doc/tutorial.rst @@ -25,6 +25,7 @@ import a few modules and set up a :class:`pyopencl.Context` and a >>> import loopy as lp >>> lp.set_caching_enabled(False) + >>> from loopy.version import LOOPY_USE_LANGUAGE_VERSION_2018_1 >>> from warnings import filterwarnings, catch_warnings >>> filterwarnings('error', category=lp.LoopyWarning) diff --git a/examples/python/hello-loopy.py b/examples/python/hello-loopy.py index da1273d2b3a0665c31bfa04520d351b2330b79fd..6fa9b5fd30b350a07e2d1d27fa36c930c9afb892 100644 --- a/examples/python/hello-loopy.py +++ b/examples/python/hello-loopy.py @@ -2,15 +2,13 @@ import numpy as np import loopy as lp import pyopencl as cl import pyopencl.array +from loopy.version import LOOPY_USE_LANGUAGE_VERSION_2018_1 # setup # ----- ctx = cl.create_some_context() queue = cl.CommandQueue(ctx) -# for make_kernel calls from this file -LOOPY_KERNEL_LANGUAGE_VERSION = (2018, 1) - n = 15 * 10**6 a = cl.array.arange(queue, n, dtype=np.float32) diff --git a/loopy/kernel/creation.py b/loopy/kernel/creation.py index c351aa5a03196111cdcbd56eb605fb28ab95da80..0daf327f441031662b46a4a83b4fc40e73eb5688 100644 --- a/loopy/kernel/creation.py +++ b/loopy/kernel/creation.py @@ -1922,10 +1922,12 @@ def make_kernel(domains, instructions, kernel_data=["..."], **kwargs): If not given, this value defaults to version **(2017, 2, 1)** and a warning will be issued. - If this is impractical, you may also place a global variable - ``LOOPY_KERNEL_LANGUAGE_VERSION`` in the global namespace of the - function calling :func:`make_kernel`. If *lang_version* is not - explicitly given, that its value will be used. + To set the kernel version for all :mod:`loopy` kernels in a (Python) source + file, you may simply say:: + + from loopy.version import LOOPY_USE_LANGUAGE_VERSION_2018_1 + + If *lang_version* is not explicitly given, that version value will be used. See also :ref:`language-versioning`. @@ -1981,17 +1983,26 @@ def make_kernel(domains, instructions, kernel_data=["..."], **kwargs): if lang_version is None: # {{{ peek into caller's module to look for LOOPY_KERNEL_LANGUAGE_VERSION + from loopy.version import LANGUAGE_VERSION_SYMBOLS + # This *is* gross. But it seems like the right thing interface-wise. import inspect caller_globals = inspect.currentframe().f_back.f_globals - try: - lang_version = caller_globals["LOOPY_KERNEL_LANGUAGE_VERSION"] - except KeyError: - pass + for ver_sym in LANGUAGE_VERSION_SYMBOLS: + try: + lang_version = caller_globals[ver_sym] + break + except KeyError: + pass # }}} + import loopy.version + version_to_symbol = dict( + (getattr(loopy.version, lvs), lvs) + for lvs in LANGUAGE_VERSION_SYMBOLS) + if lang_version is None: from warnings import warn from loopy.diagnostic import LoopyWarning @@ -2001,13 +2012,20 @@ def make_kernel(domains, instructions, kernel_data=["..."], **kwargs): warn("'lang_version' was not passed to make_kernel(). " "To avoid this warning, pass " "lang_version={ver} in this invocation. " - "(Or set LOOPY_KERNEL_LANGUAGE_VERSION = {ver} in " + "(Or say 'from loopy.version import " + "{sym_ver}' in " "the global scope of the calling frame.)" - .format(ver=MOST_RECENT_LANGUAGE_VERSION), + .format( + ver=MOST_RECENT_LANGUAGE_VERSION, + sym_ver=version_to_symbol[MOST_RECENT_LANGUAGE_VERSION] + ), LoopyWarning, stacklevel=2) lang_version = FALLBACK_LANGUAGE_VERSION + if lang_version not in version_to_symbol: + raise LoopyError("Language version '%s' is not known." % lang_version) + if lang_version >= (2018, 1): options = options.copy(enforce_variable_access_ordered=True) diff --git a/loopy/version.py b/loopy/version.py index d7b0ebc45bdc25c8adcdd1aa6aa1dabb83a5e135..aeb0b277a6c4de8a6db346aee97014699d591d03 100644 --- a/loopy/version.py +++ b/loopy/version.py @@ -38,6 +38,14 @@ DATA_MODEL_VERSION = "v77-islpy%s" % _islpy_version FALLBACK_LANGUAGE_VERSION = (2017, 2, 1) MOST_RECENT_LANGUAGE_VERSION = (2018, 1) +LOOPY_USE_LANGUAGE_VERSION_2018_1 = (2018, 1) +LOOPY_USE_LANGUAGE_VERSION_2017_2_1 = (2017, 2, 1) + +LANGUAGE_VERSION_SYMBOLS = [ + "LOOPY_USE_LANGUAGE_VERSION_2018_1", + "LOOPY_USE_LANGUAGE_VERSION_2017_2_1", + ] + __doc__ = """ .. currentmodule:: loopy @@ -64,10 +72,13 @@ language version to let them take advantage of this check. As a result, :mod:`loopy` will now issue a warning when a call to :func:`loopy.make_kernel` does not declare a language version. Such kernels will (indefinitely) default to language version 2017.2.1. If passing a -language version to :func:`make_kernel` is impractical, you may also place a -global variable ``LOOPY_KERNEL_LANGUAGE_VERSION`` in the global namespace of -the function calling :func:`make_kernel`. If *lang_version* is not explicitly -given, this value will be used. +language version to :func:`make_kernel` is impractical, you may also import +one of the ``LOOPY_USE_LANGUAGE_VERSION_...`` symbols given below using:: + + from loopy.version import LOOPY_USE_LANGUAGE_VERSION_2018_1 + +in the global namespace of the function calling :func:`make_kernel`. If +*lang_version* in that call is not explicitly given, this value will be used. Language versions will generally reflect the version number of :mod:`loopy` in which they were introduced, though it is likely that most versions of @@ -81,11 +92,16 @@ will work hard to avoid backward-incompatible language changes.) example **(2018, 1)**. Direct comparison of these tuples will always yield valid version comparisons. + History of Language Versions ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -* ``(2018, 1)``: :attr:`loopy.Options.enforce_variable_access_ordered` +.. data:: LOOPY_USE_LANGUAGE_VERSION_2018_1 + + :attr:`loopy.Options.enforce_variable_access_ordered` is turned on by default. -* ``(2017, 2, 1)``: Initial legacy language version. +.. data:: LOOPY_USE_LANGUAGE_VERSION_2017_2_1 + + Initial legacy language version. """ diff --git a/test/test_apps.py b/test/test_apps.py index 4707b7f07253ff0079c65634da00b50d0bf46d23..1be7edec1ff48c06da784ba0cf771075c13bf35c 100644 --- a/test/test_apps.py +++ b/test/test_apps.py @@ -49,7 +49,7 @@ __all__ = [ ] -LOOPY_KERNEL_LANGUAGE_VERSION = (2018, 1) +from loopy.version import LOOPY_USE_LANGUAGE_VERSION_2018_1 # noqa # {{{ convolutions diff --git a/test/test_c_execution.py b/test/test_c_execution.py index 582f3a105207c799d7e4f0fc88d2f0a5c367cc7e..f653eb0dc2b5edeec421c58a56d07d07472305f1 100644 --- a/test/test_c_execution.py +++ b/test/test_c_execution.py @@ -40,7 +40,7 @@ else: faulthandler.enable() -LOOPY_KERNEL_LANGUAGE_VERSION = (2018, 1) +from loopy.version import LOOPY_USE_LANGUAGE_VERSION_2018_1 # noqa def test_c_target(): diff --git a/test/test_dg.py b/test/test_dg.py index 6688362aa679a1ea0aec7bbfdcb01386a1e640c7..ae725ab491b950031038dae7bff3f4c6af9e90ec 100644 --- a/test/test_dg.py +++ b/test/test_dg.py @@ -34,7 +34,7 @@ from pyopencl.tools import ( # noqa pytest_generate_tests_for_pyopencl as pytest_generate_tests) -LOOPY_KERNEL_LANGUAGE_VERSION = (2018, 1) +from loopy.version import LOOPY_USE_LANGUAGE_VERSION_2018_1 # noqa def test_dg_volume(ctx_factory): diff --git a/test/test_diff.py b/test/test_diff.py index 8a4fe9587e9397084ee943b21c8304f764458922..3d19721ac030ceccf819f4135b4e734594384e53 100644 --- a/test/test_diff.py +++ b/test/test_diff.py @@ -48,7 +48,7 @@ __all__ = [ ] -LOOPY_KERNEL_LANGUAGE_VERSION = (2018, 1) +from loopy.version import LOOPY_USE_LANGUAGE_VERSION_2018_1 # noqa def test_diff(ctx_factory): diff --git a/test/test_domain.py b/test/test_domain.py index d8a83007ad7c9bb85952c546db1c106145352416..680ff299292e928c6286a168c3e71a23c60aac9b 100644 --- a/test/test_domain.py +++ b/test/test_domain.py @@ -52,7 +52,7 @@ __all__ = [ ] -LOOPY_KERNEL_LANGUAGE_VERSION = (2018, 1) +from loopy.version import LOOPY_USE_LANGUAGE_VERSION_2018_1 # noqa def test_assume(ctx_factory): diff --git a/test/test_linalg.py b/test/test_linalg.py index 7eba5facbec91e9116f597b651813a9746e64fb9..accdebc1237c70f4227adc5bfcba6fa9cf88d190 100644 --- a/test/test_linalg.py +++ b/test/test_linalg.py @@ -62,7 +62,7 @@ def check_float4(result, ref_result): ref_result[comp], result[comp], rtol=1e-3, atol=1e-3), None -LOOPY_KERNEL_LANGUAGE_VERSION = (2018, 1) +from loopy.version import LOOPY_USE_LANGUAGE_VERSION_2018_1 # noqa def test_axpy(ctx_factory): diff --git a/test/test_loopy.py b/test/test_loopy.py index 3e1d2a631c4566250f112c6a000844d663c9c190..b876cdb55d8c802a0d7691248074561d923c7ed8 100644 --- a/test/test_loopy.py +++ b/test/test_loopy.py @@ -52,7 +52,7 @@ __all__ = [ ] -LOOPY_KERNEL_LANGUAGE_VERSION = (2018, 1) +from loopy.version import LOOPY_USE_LANGUAGE_VERSION_2018_1 # noqa def test_globals_decl_once_with_multi_subprogram(ctx_factory): diff --git a/test/test_misc.py b/test/test_misc.py index c1ae6c5329eb963164bca089139e70879b8e6654..ec14770a912af978fbc6651110529a86b307df83 100644 --- a/test/test_misc.py +++ b/test/test_misc.py @@ -32,7 +32,7 @@ import logging logger = logging.getLogger(__name__) -LOOPY_KERNEL_LANGUAGE_VERSION = (2018, 1) +from loopy.version import LOOPY_USE_LANGUAGE_VERSION_2018_1 # noqa def test_compute_sccs(): diff --git a/test/test_nbody.py b/test/test_nbody.py index f231dfd5b6c58ebeb69ebecd215b33899f93f446..f2a8fc1981ddc2066ff52a2b712df95b5d36ccd2 100644 --- a/test/test_nbody.py +++ b/test/test_nbody.py @@ -34,7 +34,7 @@ import logging logger = logging.getLogger(__name__) -LOOPY_KERNEL_LANGUAGE_VERSION = (2018, 1) +from loopy.version import LOOPY_USE_LANGUAGE_VERSION_2018_1 # noqa def test_nbody(ctx_factory): diff --git a/test/test_numa_diff.py b/test/test_numa_diff.py index 7bacad75f5653b99d0111752dbcbfd27d6795127..a287ad59d7697eef79336678afa831e73b81784b 100644 --- a/test/test_numa_diff.py +++ b/test/test_numa_diff.py @@ -44,7 +44,7 @@ __all__ = [ ] -LOOPY_KERNEL_LANGUAGE_VERSION = (2018, 1) +from loopy.version import LOOPY_USE_LANGUAGE_VERSION_2018_1 # noqa @pytest.mark.parametrize("Nq", [7]) diff --git a/test/test_reduction.py b/test/test_reduction.py index 1ddbbfebf91e3f82c0d317db525a2033bfb97d81..6b62bad5b50952a3d29beec49cfce4369d5a4acf 100644 --- a/test/test_reduction.py +++ b/test/test_reduction.py @@ -49,7 +49,7 @@ __all__ = [ ] -LOOPY_KERNEL_LANGUAGE_VERSION = (2018, 1) +from loopy.version import LOOPY_USE_LANGUAGE_VERSION_2018_1 # noqa def test_nonsense_reduction(ctx_factory): diff --git a/test/test_scan.py b/test/test_scan.py index 228453fd855b5e55e0b748d4eb9d2a67ed8e9fdb..44903611d27e14e502c0c8459be9378dbc77a9a4 100644 --- a/test/test_scan.py +++ b/test/test_scan.py @@ -56,7 +56,7 @@ __all__ = [ # - scan(a) + scan(b) # - test for badly tagged inames -LOOPY_KERNEL_LANGUAGE_VERSION = (2018, 1) +from loopy.version import LOOPY_USE_LANGUAGE_VERSION_2018_1 # noqa @pytest.mark.parametrize("n", [1, 2, 3, 16]) diff --git a/test/test_sem_reagan.py b/test/test_sem_reagan.py index a92f2b2abb109a33a78b2fa8eeb45748b0090377..ecb2352ae277bd0677af09801d7bf24ee30da6b9 100644 --- a/test/test_sem_reagan.py +++ b/test/test_sem_reagan.py @@ -31,7 +31,7 @@ from pyopencl.tools import ( # noqa pytest_generate_tests_for_pyopencl as pytest_generate_tests) -LOOPY_KERNEL_LANGUAGE_VERSION = (2018, 1) +from loopy.version import LOOPY_USE_LANGUAGE_VERSION_2018_1 # noqa def test_tim2d(ctx_factory): diff --git a/test/test_target.py b/test/test_target.py index 71a2548c1f20e4d1277b96568649acda4a78aa21..c143fbbd2193d2ca34b911185bb3a6578dd953bc 100644 --- a/test/test_target.py +++ b/test/test_target.py @@ -52,7 +52,7 @@ __all__ = [ ] -LOOPY_KERNEL_LANGUAGE_VERSION = (2018, 1) +from loopy.version import LOOPY_USE_LANGUAGE_VERSION_2018_1 # noqa def test_ispc_target(occa_mode=False): diff --git a/test/test_transform.py b/test/test_transform.py index a234d7ac5777d42ac79e15a6f059b24887aaec3f..e1a58e30286141b4d0592debcd308552f32ff632 100644 --- a/test/test_transform.py +++ b/test/test_transform.py @@ -49,7 +49,7 @@ __all__ = [ ] -LOOPY_KERNEL_LANGUAGE_VERSION = (2018, 1) +from loopy.version import LOOPY_USE_LANGUAGE_VERSION_2018_1 # noqa def test_chunk_iname(ctx_factory):