From 767de0cc9cf831eeb6896a49d8380fb7a00daa4b Mon Sep 17 00:00:00 2001 From: Dominic Kempf Date: Tue, 6 Dec 2016 13:51:19 +0100 Subject: [PATCH] Implement resolution of dependencies in LoopKernel.copy So far, objects of `loopy.match.MatchExpressionBase` can only be passed into `depends_on` or `no_sync_with` when using `loopy.make_kernel`. This commit also makes it possible use them when creating new kernels through copying. --- loopy/kernel/__init__.py | 17 +++++++++++++++++ loopy/kernel/creation.py | 12 ++++++++++++ 2 files changed, 29 insertions(+) diff --git a/loopy/kernel/__init__.py b/loopy/kernel/__init__.py index 5b192934c..8806cf19b 100644 --- a/loopy/kernel/__init__.py +++ b/loopy/kernel/__init__.py @@ -1436,6 +1436,23 @@ class LoopKernel(ImmutableRecordWithoutPickling): # }}} + # {{{ Copying loop kernels + + def copy(self, **kwargs): + from loopy.kernel.creation import (resolve_dependencies, + needs_dependency_resolution, + ) + ret = ImmutableRecordWithoutPickling.copy(self, **kwargs) + + # resolve_dependencies is also implemented through LoopKernel.copy, + # so we need to check for its necessity to avoid an infinite loop + if needs_dependency_resolution(ret): + return resolve_dependencies(ret) + else: + return ret + + # }}} + # }}} # vim: foldmethod=marker diff --git a/loopy/kernel/creation.py b/loopy/kernel/creation.py index 024d97c3f..712d036a1 100644 --- a/loopy/kernel/creation.py +++ b/loopy/kernel/creation.py @@ -1573,6 +1573,18 @@ def resolve_dependencies(knl): return knl.copy(instructions=new_insns) + +def needs_dependency_resolution(knl): + from loopy.match import MatchExpressionBase + for insn in knl.instructions: + for dep in insn.depends_on: + if isinstance(dep, MatchExpressionBase) or "*" in dep: + return True + for nosync, _ in insn.no_sync_with: + if isinstance(nosync, MatchExpressionBase) or "*" in nosync: + return True + return False + # }}} -- GitLab