From 28e5c12511d56eafabef7b250690a2dfea89841b Mon Sep 17 00:00:00 2001
From: Andreas Kloeckner <inform@tiker.net>
Date: Mon, 31 Oct 2011 02:10:00 -0400
Subject: [PATCH] For forced workgroup sizes: check that at least one iname
 maps to them.

---
 MEMO           | 11 ++++-------
 loopy/check.py | 32 ++++++++++++++++++++++----------
 2 files changed, 26 insertions(+), 17 deletions(-)

diff --git a/MEMO b/MEMO
index 225dfffd9..4b22218b8 100644
--- a/MEMO
+++ b/MEMO
@@ -26,9 +26,6 @@ Things to consider
   other inames
   -> Is that reasonable?
 
-- Parallel dimension splitting/merging via tags
-  -> unnecessary?
-
 - Not using all hw loop dimensions causes an error, as
   is the case for variant 3 in the rank_one test.
 
@@ -36,7 +33,7 @@ Things to consider
 
 - Loopy as a data model for implementing custom rewritings
 
-- We won't generate WAWs barrier-needing dependencies
+- We won't generate WAW barrier-needing dependencies
   from one instruction to itself.
 
 To-do
@@ -44,9 +41,6 @@ To-do
 
 - Automatically generate testing code vs. sequential.
 
-- For forced workgroup sizes: check that at least one iname
-  maps to them.
-
 - If isl can prove that all operands are positive, may use '/' instead of
   'floor_div'.
 
@@ -92,6 +86,9 @@ Future ideas
 Dealt with
 ^^^^^^^^^^
 
+- For forced workgroup sizes: check that at least one iname
+  maps to them.
+
 - variable shuffle detection
   -> will need unification
 
diff --git a/loopy/check.py b/loopy/check.py
index cb20950bc..e9ff2425e 100644
--- a/loopy/check.py
+++ b/loopy/check.py
@@ -5,7 +5,7 @@ from __future__ import division
 
 # {{{ sanity checks run during scheduling
 
-def check_for_unused_hw_axes(kernel):
+def check_for_unused_hw_axes_in_insns(kernel):
     group_size, local_size = kernel.get_grid_sizes_as_exprs()
 
     group_axes = set(range(len(group_size)))
@@ -144,8 +144,29 @@ def check_for_write_races(kernel):
                     "is/are not referenced in the assignee index"
                     % (insn.id, ",".join(inames_without_write_dep)))
 
+def check_for_orphaned_user_hardware_axes(kernel):
+    from loopy.kernel import LocalIndexTag
+    for axis in kernel.local_sizes:
+        found = False
+        for tag in kernel.iname_to_tag.itervalues():
+            if isinstance(tag, LocalIndexTag) and tag.axis == axis:
+                found = True
+                break
+
+        if not found:
+            raise RuntimeError("user-requested local hardware axis %d "
+                    "has no iname mapped to it" % axis)
+
 # }}}
 
+def run_automatic_checks(kernel):
+    check_for_orphaned_user_hardware_axes(kernel)
+    check_for_double_use_of_hw_axes(kernel)
+    check_for_unused_hw_axes_in_insns(kernel)
+    check_for_inactive_iname_access(kernel)
+    check_for_write_races(kernel)
+
+
 # {{{ sanity-check for implemented domains of each instruction
 
 def check_implemented_domains(kernel, implemented_domains):
@@ -210,15 +231,6 @@ def check_implemented_domains(kernel, implemented_domains):
 
 # }}}
 
-def run_automatic_checks(kernel):
-    import loopy.check as chk
-
-    chk.check_for_double_use_of_hw_axes(kernel)
-    chk.check_for_unused_hw_axes(kernel)
-    chk.check_for_inactive_iname_access(kernel)
-    chk.check_for_write_races(kernel)
-
-
 # {{{ user-invoked checks
 
 def get_problems(kernel, parameters):
-- 
GitLab