diff --git a/loopy/kernel/__init__.py b/loopy/kernel/__init__.py index 5b192934c8f56ccf364d1b9ba58d81fa8c28ff63..8806cf19b63a71512b8c5e052f96f3f53fbfc023 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 024d97c3fed14e9917f9c21be0f17f555947f600..712d036a1fc7f5c1d6d390170b27ee59159d719a 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 + # }}}