From 771864612baa3be288840a2df33cb1c58fb89df3 Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Tue, 15 Nov 2016 18:40:36 -0600 Subject: [PATCH 1/2] Introduce a check for writes to predicate variables (and prevent those) (Fixes #57 on Github) --- loopy/preprocess.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/loopy/preprocess.py b/loopy/preprocess.py index 027e98ae5..1300a7d33 100644 --- a/loopy/preprocess.py +++ b/loopy/preprocess.py @@ -72,6 +72,21 @@ def prepare_for_caching(kernel): # }}} +# {{{ check for writes to predicates + +def check_for_writes_to_predicates(kernel): + from loopy.symbolic import get_dependencies + for insn in kernel.instructions: + written_pred_vars = frozenset(insn.assignee_var_names()) & frozenset.union( + *(get_dependencies(pred) for pred in insn.predicates)) + if written_pred_vars: + raise LoopyError("In instruction '%s': may not write to " + "variable(s) '%s' involved in the instruction's predicates" + % (insn.id, ", ".join(written_pred_vars))) + +# }}} + + # {{{ check reduction iname uniqueness def check_reduction_iname_uniqueness(kernel): @@ -876,6 +891,7 @@ def preprocess_kernel(kernel, device=None): kernel = infer_unknown_types(kernel, expect_completion=False) + check_for_writes_to_predicates(kernel) check_reduction_iname_uniqueness(kernel) from loopy.kernel.creation import apply_single_writer_depencency_heuristic -- GitLab From d67686aabca16da8e91866dbd70f77b7ff5059fa Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Wed, 16 Nov 2016 11:15:06 -0600 Subject: [PATCH 2/2] check_for_writes_to_predicates: Handle no-predicates-in-insn case (oops) --- loopy/preprocess.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/loopy/preprocess.py b/loopy/preprocess.py index 1300a7d33..f93ea891f 100644 --- a/loopy/preprocess.py +++ b/loopy/preprocess.py @@ -77,8 +77,11 @@ def prepare_for_caching(kernel): def check_for_writes_to_predicates(kernel): from loopy.symbolic import get_dependencies for insn in kernel.instructions: - written_pred_vars = frozenset(insn.assignee_var_names()) & frozenset.union( - *(get_dependencies(pred) for pred in insn.predicates)) + pred_vars = ( + frozenset.union( + *(get_dependencies(pred) for pred in insn.predicates)) + if insn.predicates else frozenset()) + written_pred_vars = frozenset(insn.assignee_var_names()) & pred_vars if written_pred_vars: raise LoopyError("In instruction '%s': may not write to " "variable(s) '%s' involved in the instruction's predicates" -- GitLab