From ee561bb8da29a5e97fbb724eb1327edc881a2dc4 Mon Sep 17 00:00:00 2001 From: Matt Wala Date: Sat, 15 Jul 2017 18:32:45 -0500 Subject: [PATCH] get_typed_and_scheduled_kernel(): Make sure the kernel's dtypes are cacheable before creating the cache key. --- loopy/execution.py | 7 ++++++- test/test_loopy.py | 15 +++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/loopy/execution.py b/loopy/execution.py index dac5b2ff8..07e28f06d 100644 --- a/loopy/execution.py +++ b/loopy/execution.py @@ -187,7 +187,12 @@ class KernelExecutorBase(object): def get_typed_and_scheduled_kernel(self, arg_to_dtype_set): from loopy import CACHING_ENABLED - cache_key = (type(self).__name__, self.kernel, arg_to_dtype_set) + from loopy.preprocess import prepare_for_caching + # prepare_for_caching() gets run by preprocess, but the kernel at this + # stage is not guaranteed to be preprocessed. + cacheable_kernel = prepare_for_caching(self.kernel) + cache_key = (type(self).__name__, cacheable_kernel, arg_to_dtype_set) + if CACHING_ENABLED: try: return typed_and_scheduled_cache[cache_key] diff --git a/test/test_loopy.py b/test/test_loopy.py index d8bf76f96..61f992c5d 100644 --- a/test/test_loopy.py +++ b/test/test_loopy.py @@ -2335,6 +2335,21 @@ def test_kernel_var_name_generator(): assert vng("b") != "b" +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 + # dtypes in the kernel can be cached, even though they may not have a + # target. + + ctx = ctx_factory() + queue = cl.CommandQueue(ctx) + + knl = lp.make_kernel("{[i]: 0 <= i < 10}", "<>tmp[i] = i") + knl = lp.add_dtypes(knl, dict(tmp=int)) + + knl(queue) + + if __name__ == "__main__": if len(sys.argv) > 1: exec(sys.argv[1]) -- GitLab