diff --git a/examples/python/hello-loopy.py b/examples/python/hello-loopy.py index e7ab13c1649ef42241fdb2826ab88655b307f969..da1273d2b3a0665c31bfa04520d351b2330b79fd 100644 --- a/examples/python/hello-loopy.py +++ b/examples/python/hello-loopy.py @@ -8,6 +8,9 @@ import pyopencl.array 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) @@ -15,8 +18,7 @@ a = cl.array.arange(queue, n, dtype=np.float32) # ------ knl = lp.make_kernel( "{ [i]: 0<=i<n }", - "out[i] = 2*a[i]", - lang_version=(2018, 1)) + "out[i] = 2*a[i]") # transform # --------- diff --git a/loopy/frontend/fortran/translator.py b/loopy/frontend/fortran/translator.py index e801d09dcf10750ce09af647e0b14f4641fa1fb2..bcbe41874d8613eaabd84ae71dd65317558f0185 100644 --- a/loopy/frontend/fortran/translator.py +++ b/loopy/frontend/fortran/translator.py @@ -708,6 +708,7 @@ class F2LoopyTranslator(FTreeWalkerBase): # }}} + from loopy.version import MOST_RECENT_LANGUAGE_VERSION knl = lp.make_kernel( sub.index_sets, sub.instructions, @@ -717,6 +718,7 @@ class F2LoopyTranslator(FTreeWalkerBase): index_dtype=self.index_dtype, target=self.target, seq_dependencies=seq_dependencies, + lang_version=MOST_RECENT_LANGUAGE_VERSION ) from loopy.loop import fuse_loop_domains diff --git a/loopy/kernel/creation.py b/loopy/kernel/creation.py index 15cb29c22eb85d321893cd235f600001ae12ff1a..f43bf849052bd410dd1159def4023a8417af577c 100644 --- a/loopy/kernel/creation.py +++ b/loopy/kernel/creation.py @@ -1920,6 +1920,11 @@ 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. + See also :ref:`language-versioning`. .. versionchanged:: 2017.2.1 @@ -1972,18 +1977,32 @@ def make_kernel(domains, instructions, kernel_data=["..."], **kwargs): lang_version = kwargs.pop("lang_version", None) if lang_version is None: - from warnings import warn - from loopy.diagnostic import LoopyWarning - from loopy.version import ( - MOST_RECENT_LANGUAGE_VERSION, - FALLBACK_LANGUAGE_VERSION) - warn("'lang_version' was not passed to make_kernel(). " - "To avoid this warning, pass " - "lang_version=%r in this invocation." - % (MOST_RECENT_LANGUAGE_VERSION,), - LoopyWarning, stacklevel=2) - - lang_version = FALLBACK_LANGUAGE_VERSION + # {{{ peek into caller's module to look for LOOPY_KERNEL_LANGUAGE_VERSION + + # 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 + + # }}} + + if lang_version is None: + from warnings import warn + from loopy.diagnostic import LoopyWarning + from loopy.version import ( + MOST_RECENT_LANGUAGE_VERSION, + FALLBACK_LANGUAGE_VERSION) + warn("'lang_version' was not passed to make_kernel(). " + "To avoid this warning, pass " + "lang_version=%r in this invocation." + % (MOST_RECENT_LANGUAGE_VERSION,), + LoopyWarning, stacklevel=2) + + lang_version = FALLBACK_LANGUAGE_VERSION if lang_version >= (2018, 1): options = options.copy(enforce_check_variable_access_ordered=True) diff --git a/loopy/version.py b/loopy/version.py index 21c920ce49074573a8597a09ee8f2407dfdd7b8b..49dca90fee59f2280df621d893163d4b3829b131 100644 --- a/loopy/version.py +++ b/loopy/version.py @@ -62,8 +62,12 @@ break existing programs, kernels now have to declare support for a given 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. +: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, that its value will be used. Language versions will generally reflect the version number of :mod:`loopy` in which they were introduced, though it is possible that some versions of diff --git a/test/test_apps.py b/test/test_apps.py index c4844d3a3c5d88e0c4eeccf0d67e9b4284fd744f..55eecdf2baa59d7a0477f4e6bba801d52610ae6e 100644 --- a/test/test_apps.py +++ b/test/test_apps.py @@ -49,6 +49,9 @@ __all__ = [ ] +LOOPY_KERNEL_LANGUAGE_VERSION = (2018, 1) + + # {{{ convolutions def test_convolution(ctx_factory): diff --git a/test/test_c_execution.py b/test/test_c_execution.py index d1b3c95caa034191b4b29c49076fc101cd318950..582f3a105207c799d7e4f0fc88d2f0a5c367cc7e 100644 --- a/test/test_c_execution.py +++ b/test/test_c_execution.py @@ -40,6 +40,9 @@ else: faulthandler.enable() +LOOPY_KERNEL_LANGUAGE_VERSION = (2018, 1) + + def test_c_target(): from loopy.target.c import ExecutableCTarget diff --git a/test/test_dg.py b/test/test_dg.py index ef4a3137324f012d8ad64939d0bf1ab8f00040fb..6688362aa679a1ea0aec7bbfdcb01386a1e640c7 100644 --- a/test/test_dg.py +++ b/test/test_dg.py @@ -34,6 +34,9 @@ from pyopencl.tools import ( # noqa pytest_generate_tests_for_pyopencl as pytest_generate_tests) +LOOPY_KERNEL_LANGUAGE_VERSION = (2018, 1) + + def test_dg_volume(ctx_factory): #logging.basicConfig(level=logging.DEBUG) diff --git a/test/test_diff.py b/test/test_diff.py index 95471f9b126fd6b763530d115c21509d14d2ba47..8a4fe9587e9397084ee943b21c8304f764458922 100644 --- a/test/test_diff.py +++ b/test/test_diff.py @@ -48,6 +48,9 @@ __all__ = [ ] +LOOPY_KERNEL_LANGUAGE_VERSION = (2018, 1) + + def test_diff(ctx_factory): ctx = ctx_factory() queue = cl.CommandQueue(ctx) diff --git a/test/test_domain.py b/test/test_domain.py index 9d0379a50af188cc84de8e01f8278030b6cc04e2..d8a83007ad7c9bb85952c546db1c106145352416 100644 --- a/test/test_domain.py +++ b/test/test_domain.py @@ -52,6 +52,9 @@ __all__ = [ ] +LOOPY_KERNEL_LANGUAGE_VERSION = (2018, 1) + + def test_assume(ctx_factory): ctx = ctx_factory() diff --git a/test/test_linalg.py b/test/test_linalg.py index 3d422f1d8b5a847d4445468978ee529db95c481f..7eba5facbec91e9116f597b651813a9746e64fb9 100644 --- a/test/test_linalg.py +++ b/test/test_linalg.py @@ -62,6 +62,9 @@ def check_float4(result, ref_result): ref_result[comp], result[comp], rtol=1e-3, atol=1e-3), None +LOOPY_KERNEL_LANGUAGE_VERSION = (2018, 1) + + def test_axpy(ctx_factory): logging.basicConfig(level="INFO") ctx = ctx_factory() diff --git a/test/test_loopy.py b/test/test_loopy.py index 02002c5cd844131ee82812c12763e37269373bd9..d9bc3d271cb7a3de8e2d56f1dc267e1c90e9e3db 100644 --- a/test/test_loopy.py +++ b/test/test_loopy.py @@ -52,6 +52,9 @@ __all__ = [ ] +LOOPY_KERNEL_LANGUAGE_VERSION = (2018, 1) + + def test_globals_decl_once_with_multi_subprogram(ctx_factory): ctx = ctx_factory() queue = cl.CommandQueue(ctx) @@ -67,8 +70,7 @@ def test_globals_decl_once_with_multi_subprogram(ctx_factory): [lp.TemporaryVariable( 'cnst', shape=('n'), initializer=cnst, scope=lp.temp_var_scope.GLOBAL, - read_only=True), '...'], - lang_version=(2018, 1)) + read_only=True), '...']) knl = lp.fix_parameters(knl, n=16) knl = lp.add_barrier(knl, "id:first", "id:second") @@ -89,8 +91,7 @@ def test_complicated_subst(ctx_factory): h(x) := 1 + g(x) + 20*g$two(x) a[i] = h$one(i) * h$two(i) - """, - lang_version=(2018, 1)) + """) knl = lp.expand_subst(knl, "... > id:h and tag:two > id:g and tag:two") @@ -121,8 +122,7 @@ def test_type_inference_no_artificial_doubles(ctx_factory): lp.GlobalArg("c", np.float32, shape=("n",)), lp.ValueArg("n", np.int32), ], - assumptions="n>=1", - lang_version=(2018, 1)) + assumptions="n>=1") knl = lp.preprocess_kernel(knl, ctx.devices[0]) for k in lp.generate_loop_schedules(knl): @@ -142,9 +142,7 @@ def test_type_inference_with_type_dependencies(): c = b + c <>d = b + 2 + 1j """, - "...", - lang_version=(2018, 1)) - + "...") knl = lp.infer_unknown_types(knl) from loopy.types import to_loopy_type diff --git a/test/test_misc.py b/test/test_misc.py index 0273948b38b28b85e42a600bffb65fbf86dcc554..c1ae6c5329eb963164bca089139e70879b8e6654 100644 --- a/test/test_misc.py +++ b/test/test_misc.py @@ -32,6 +32,9 @@ import logging logger = logging.getLogger(__name__) +LOOPY_KERNEL_LANGUAGE_VERSION = (2018, 1) + + def test_compute_sccs(): from loopy.tools import compute_sccs import random diff --git a/test/test_nbody.py b/test/test_nbody.py index e118b04b997020943d79ec1ba566eff85d56199a..f231dfd5b6c58ebeb69ebecd215b33899f93f446 100644 --- a/test/test_nbody.py +++ b/test/test_nbody.py @@ -34,6 +34,9 @@ import logging logger = logging.getLogger(__name__) +LOOPY_KERNEL_LANGUAGE_VERSION = (2018, 1) + + def test_nbody(ctx_factory): logging.basicConfig(level=logging.INFO) diff --git a/test/test_numa_diff.py b/test/test_numa_diff.py index eff3dbd0e07439bbec399479183a7e9ddb69b9ff..a5c69020af58926846545e64f3550e7b6953c671 100644 --- a/test/test_numa_diff.py +++ b/test/test_numa_diff.py @@ -44,6 +44,9 @@ __all__ = [ ] +LOOPY_KERNEL_LANGUAGE_VERSION = (2018, 1) + + @pytest.mark.parametrize("Nq", [7]) @pytest.mark.parametrize("ilp_multiple", [1, 2]) @pytest.mark.parametrize("opt_level", [11]) diff --git a/test/test_reduction.py b/test/test_reduction.py index 909a800b29c75b13fad494b5a859186b9cd5587c..1ddbbfebf91e3f82c0d317db525a2033bfb97d81 100644 --- a/test/test_reduction.py +++ b/test/test_reduction.py @@ -49,6 +49,9 @@ __all__ = [ ] +LOOPY_KERNEL_LANGUAGE_VERSION = (2018, 1) + + def test_nonsense_reduction(ctx_factory): ctx = ctx_factory() diff --git a/test/test_scan.py b/test/test_scan.py index 08754819c9a156403aba689cb3e9c238144e7905..228453fd855b5e55e0b748d4eb9d2a67ed8e9fdb 100644 --- a/test/test_scan.py +++ b/test/test_scan.py @@ -56,6 +56,9 @@ __all__ = [ # - scan(a) + scan(b) # - test for badly tagged inames +LOOPY_KERNEL_LANGUAGE_VERSION = (2018, 1) + + @pytest.mark.parametrize("n", [1, 2, 3, 16]) @pytest.mark.parametrize("stride", [1, 2]) def test_sequential_scan(ctx_factory, n, stride): diff --git a/test/test_sem_reagan.py b/test/test_sem_reagan.py index 0571e41910020aa0a60cd911a63b6ce2984ed939..a92f2b2abb109a33a78b2fa8eeb45748b0090377 100644 --- a/test/test_sem_reagan.py +++ b/test/test_sem_reagan.py @@ -31,6 +31,9 @@ from pyopencl.tools import ( # noqa pytest_generate_tests_for_pyopencl as pytest_generate_tests) +LOOPY_KERNEL_LANGUAGE_VERSION = (2018, 1) + + def test_tim2d(ctx_factory): dtype = np.float32 ctx = ctx_factory() diff --git a/test/test_statistics.py b/test/test_statistics.py index eeb4a5a288afdd5b9295b0b681abb61b5f021d97..9427a4edf79e4183a8c9436d7a56320a408dddc6 100644 --- a/test/test_statistics.py +++ b/test/test_statistics.py @@ -34,6 +34,9 @@ import numpy as np from pymbolic.primitives import Variable +LOOPY_KERNEL_LANGUAGE_VERSION = (2018, 1) + + def test_op_counter_basic(): knl = lp.make_kernel( diff --git a/test/test_target.py b/test/test_target.py index d3cf2670cb0db0eb5d0046ce1d816b679d4a1ed8..8fd565a8158db988039aae94babd8b865e495077 100644 --- a/test/test_target.py +++ b/test/test_target.py @@ -52,6 +52,9 @@ __all__ = [ ] +LOOPY_KERNEL_LANGUAGE_VERSION = (2018, 1) + + def test_ispc_target(occa_mode=False): from loopy.target.ispc import ISPCTarget diff --git a/test/test_transform.py b/test/test_transform.py index 0e10db362f36b7fc258059c2ec7ed1a344b97212..feb8bf9df5e31a1017efc1eca3fdf872f0e9ab96 100644 --- a/test/test_transform.py +++ b/test/test_transform.py @@ -49,6 +49,9 @@ __all__ = [ ] +LOOPY_KERNEL_LANGUAGE_VERSION = (2018, 1) + + def test_chunk_iname(ctx_factory): ctx = ctx_factory()