From 607f74af71e4f4c7d3eb75c01a60d3f05fe00ab4 Mon Sep 17 00:00:00 2001 From: Matt Wala Date: Wed, 6 Dec 2017 15:25:12 -0600 Subject: [PATCH 1/2] Dep resolution: Speed up resolution in the common case where the dependency is not a wildcard. Related: #110 Also fixes treatment for self-dependencies in wildcards (closes #111). --- loopy/kernel/creation.py | 15 +++++++++++++-- test/test_loopy.py | 21 +++++++++++++++++++++ 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/loopy/kernel/creation.py b/loopy/kernel/creation.py index fb935476d..c1236ba90 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 d6f2d6df6..7b875ef08 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 -- GitLab From 4fac320bd1a8bf97a6ea3b38d79723e5a7a778f0 Mon Sep 17 00:00:00 2001 From: Matt Wala Date: Wed, 6 Dec 2017 16:38:32 -0500 Subject: [PATCH 2/2] Flake8 fix --- test/test_loopy.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_loopy.py b/test/test_loopy.py index 7b875ef08..79d849727 100644 --- a/test/test_loopy.py +++ b/test/test_loopy.py @@ -2580,7 +2580,7 @@ def test_wildcard_dep_matching(): """, "...") - all_insns = set("insn%d" % i for i in range(1,6)) + 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"]) -- GitLab