diff --git a/loopy/kernel/creation.py b/loopy/kernel/creation.py index fb935476d54b3f9eb0a3bf858c883fe4c75eaa5a..c1236ba90c9209625dd357b71535ca00e75e8aca 100644 --- a/loopy/kernel/creation.py +++ b/loopy/kernel/creation.py @@ -1656,6 +1656,13 @@ def apply_default_order_to_args(kernel, default_order): # {{{ resolve instruction dependencies +WILDCARD_SYMBOLS = "*?[" + + +def _is_wildcard(s): + return any(c in s for c in WILDCARD_SYMBOLS) + + def _resolve_dependencies(knl, insn, deps): from loopy import find_instructions from loopy.match import MatchExpressionBase @@ -1670,12 +1677,16 @@ def _resolve_dependencies(knl, insn, deps): if new_dep.id != insn.id: new_deps.append(new_dep.id) found_any = True - else: + elif _is_wildcard(dep): from fnmatch import fnmatchcase for other_insn in knl.instructions: - if fnmatchcase(other_insn.id, dep): + if other_insn.id != insn.id and fnmatchcase(other_insn.id, dep): new_deps.append(other_insn.id) found_any = True + else: + if dep in knl.id_to_insn: + new_deps.append(dep) + found_any = True if not found_any and knl.options.check_dep_resolution: raise LoopyError("instruction '%s' declared a depency on '%s', " diff --git a/test/test_loopy.py b/test/test_loopy.py index d6f2d6df6d01f2f81df09e1b9af62fc15bb5081e..79d84972795df67d6c1b996c6e844e3d1f658836 100644 --- a/test/test_loopy.py +++ b/test/test_loopy.py @@ -2568,6 +2568,27 @@ def test_execution_backend_can_cache_dtypes(ctx_factory): knl(queue) +def test_wildcard_dep_matching(): + knl = lp.make_kernel( + "{[i]: 0 <= i < 10}", + """ + <>a = 0 {id=insn1} + <>b = 0 {id=insn2,dep=insn?} + <>c = 0 {id=insn3,dep=insn*} + <>d = 0 {id=insn4,dep=insn[12]} + <>e = 0 {id=insn5,dep=insn[!1]} + """, + "...") + + all_insns = set("insn%d" % i for i in range(1, 6)) + + assert knl.id_to_insn["insn1"].depends_on == set() + assert knl.id_to_insn["insn2"].depends_on == all_insns - set(["insn2"]) + assert knl.id_to_insn["insn3"].depends_on == all_insns - set(["insn3"]) + assert knl.id_to_insn["insn4"].depends_on == set(["insn1", "insn2"]) + assert knl.id_to_insn["insn5"].depends_on == all_insns - set(["insn1", "insn5"]) + + def test_preamble_with_separate_temporaries(ctx_factory): from loopy.kernel.data import temp_var_scope as scopes # create a function mangler