From a7be6a8c64088832b6fcc0667ef114332841dd71 Mon Sep 17 00:00:00 2001
From: Matt Wala <wala1@illinois.edu>
Date: Sun, 6 Aug 2017 14:42:18 -0500
Subject: [PATCH] check_insn_attributes(): Check no_sync_with.

Closes #55
---
 loopy/check.py | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/loopy/check.py b/loopy/check.py
index e72f9e3e6..6ac058b93 100644
--- a/loopy/check.py
+++ b/loopy/check.py
@@ -60,6 +60,12 @@ def check_identifiers_in_subst_rules(knl):
 
 # {{{ sanity checks run pre-scheduling
 
+
+# FIXME: Replace with an enum. See
+# https://gitlab.tiker.net/inducer/loopy/issues/85
+VALID_NOSYNC_SCOPES = frozenset(["local", "global", "any"])
+
+
 def check_insn_attributes(kernel):
     all_insn_ids = set(insn.id for insn in kernel.instructions)
 
@@ -76,6 +82,19 @@ def check_insn_attributes(kernel):
                     % (insn.id, ", ".join(
                         insn.depends_on - all_insn_ids)))
 
+        no_sync_with_insn_ids = set(id for id, scope in insn.no_sync_with)
+        if not no_sync_with_insn_ids <= all_insn_ids:
+            raise LoopyError("insn '%s' has nosync directive with unknown "
+                    "instruction ids: %s"
+                    % (insn.id,
+                       ", ".join(no_sync_with_insn_ids - all_insn_ids)))
+
+        no_sync_with_scopes = set(scope for id, scope in insn.no_sync_with)
+        if not no_sync_with_scopes <= VALID_NOSYNC_SCOPES:
+            raise LoopyError("insn '%s' has invalid nosync scopes: %s"
+                    % (insn.id,
+                       ", ".join(VALID_NOSYNC_SCOPES - no_sync_with_scopes)))
+
 
 def check_loop_priority_inames_known(kernel):
     for prio in kernel.loop_priority:
-- 
GitLab