From c9b14cf7b68acbf444a4dd323bd1857376739ee6 Mon Sep 17 00:00:00 2001 From: Matt Wala Date: Fri, 1 Sep 2017 16:59:06 -0500 Subject: [PATCH 1/2] Allow parameters to be fixed at kernel creation time. Among other things, passing fixed parameters can improve the accuracy of temp shape inference, so that fallback can occur less often. The motivation for this is to remove the temp_shape_fallback warnings when constructing sumpy kernels. --- loopy/kernel/creation.py | 11 +++++++++++ loopy/version.py | 2 +- test/test_loopy.py | 15 +++++++++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/loopy/kernel/creation.py b/loopy/kernel/creation.py index 89cb5f26a..a66ef99a9 100644 --- a/loopy/kernel/creation.py +++ b/loopy/kernel/creation.py @@ -1859,6 +1859,13 @@ def make_kernel(domains, instructions, kernel_data=["..."], **kwargs): :arg seq_dependencies: If *True*, dependencies that sequentially connect the given *instructions* will be added. Defaults to *False*. + :arg fixed_parameters: A dictionary of *name*/*value* pairs, where *name* + will be fixed to *value*. *name* may refer to :ref:`domain-parameters` + or :ref:`arguments`. See also :func:`loopy.fix_parameters`. + + .. versionchanged:: 2017.2 + + *parameters* added. .. versionchanged:: 2016.3 @@ -1876,6 +1883,7 @@ def make_kernel(domains, instructions, kernel_data=["..."], **kwargs): flags = kwargs.pop("flags", None) target = kwargs.pop("target", None) seq_dependencies = kwargs.pop("seq_dependencies", False) + fixed_parameters = kwargs.pop("fixed_parameters", {}) if defines: from warnings import warn @@ -1996,11 +2004,14 @@ def make_kernel(domains, instructions, kernel_data=["..."], **kwargs): # ------------------------------------------------------------------------- # Must create temporaries before inferring inames (because those temporaries # mediate dependencies that are then used for iname propagation.) + # Must create temporaries before fixing parameters. # ------------------------------------------------------------------------- knl = add_used_inames(knl) # NOTE: add_inferred_inames will be phased out and throws warnings if it # does something. knl = add_inferred_inames(knl) + from loopy.transform.parameter import fix_parameters + knl = fix_parameters(knl, **fixed_parameters) # ------------------------------------------------------------------------- # Ordering dependency: # ------------------------------------------------------------------------- diff --git a/loopy/version.py b/loopy/version.py index 2e86b974b..99e1b38ca 100644 --- a/loopy/version.py +++ b/loopy/version.py @@ -21,7 +21,7 @@ THE SOFTWARE. """ -VERSION = (2017, 1) +VERSION = (2017, 2) VERSION_STATUS = "" VERSION_TEXT = ".".join(str(x) for x in VERSION) + VERSION_STATUS diff --git a/test/test_loopy.py b/test/test_loopy.py index 3593019ad..563964cf0 100644 --- a/test/test_loopy.py +++ b/test/test_loopy.py @@ -2416,6 +2416,21 @@ def test_kernel_var_name_generator(): assert vng("b") != "b" +def test_fixed_parameters(ctx_factory): + ctx = ctx_factory() + queue = cl.CommandQueue(ctx) + + knl = lp.make_kernel( + "[n] -> {[i]: 0 <= i < n}", + """ + <>tmp[i] = i + tmp[0] = 0 + """, + fixed_parameters=dict(n=1)) + + knl(queue) + + def test_execution_backend_can_cache_dtypes(ctx_factory): # When the kernel is invoked, the execution backend uses it as a cache key # for the type inference and scheduling cache. This tests to make sure that -- GitLab From 5e7ce4994fb7426a8bc27f17b226f73d6909fa47 Mon Sep 17 00:00:00 2001 From: Matt Wala Date: Fri, 1 Sep 2017 17:11:15 -0500 Subject: [PATCH 2/2] Fix doc typo. --- loopy/kernel/creation.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/loopy/kernel/creation.py b/loopy/kernel/creation.py index a66ef99a9..aacd76c09 100644 --- a/loopy/kernel/creation.py +++ b/loopy/kernel/creation.py @@ -1865,7 +1865,7 @@ def make_kernel(domains, instructions, kernel_data=["..."], **kwargs): .. versionchanged:: 2017.2 - *parameters* added. + *fixed_parameters* added. .. versionchanged:: 2016.3 -- GitLab