From 94190ef2b3d2b87b8a5fcde5da8283f88a792013 Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner <inform@tiker.net> Date: Sun, 28 Jul 2013 16:34:32 -0400 Subject: [PATCH] Allow wilcards in insn_deps --- doc/reference.rst | 3 +++ loopy/kernel/creation.py | 30 ++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/doc/reference.rst b/doc/reference.rst index fb579a2b5..bf11a96cc 100644 --- a/doc/reference.rst +++ b/doc/reference.rst @@ -183,6 +183,9 @@ These are usually key-value pairs. The following attributes are recognized: code generated for this instruction appears textually after both of these instructions' generated code. + Identifiers here are allowed to be wildcards as defined by + :mod:`fnmatchcase`. + .. note:: If this is not specified, :mod:`loopy` will automatically add diff --git a/loopy/kernel/creation.py b/loopy/kernel/creation.py index d51f788a5..fa0b91be8 100644 --- a/loopy/kernel/creation.py +++ b/loopy/kernel/creation.py @@ -849,6 +849,35 @@ def apply_default_order_to_args(kernel, default_order): # }}} +# {{{ resolve wildcard insn dependencies + +def resolve_wildcard_deps(knl): + new_insns = [] + + from fnmatch import fnmatchcase + for insn in knl.instructions: + if insn.insn_deps is not None: + new_deps = set() + for dep in insn.insn_deps: + match_count = 0 + for other_insn in knl.instructions: + if fnmatchcase(other_insn.id, dep): + new_deps.add(other_insn.id) + match_count += 1 + + if match_count == 0: + # Uh, best we can do + new_deps.append(dep) + + insn = insn.copy(insn_deps=frozenset(new_deps)) + + new_insns.append(insn) + + return knl.copy(instructions=new_insns) + +# }}} + + # {{{ kernel creation top-level def make_kernel(device, domains, instructions, kernel_data=["..."], **kwargs): @@ -1001,6 +1030,7 @@ def make_kernel(device, domains, instructions, kernel_data=["..."], **kwargs): knl = expand_defines_in_shapes(knl, defines) knl = guess_arg_shape_if_requested(knl, default_order) knl = apply_default_order_to_args(knl, default_order) + knl = resolve_wildcard_deps(knl) # ------------------------------------------------------------------------- # Ordering dependency: -- GitLab