From 9ecdddcea1c366ee4c96c0600e47cee93e32538f Mon Sep 17 00:00:00 2001
From: Andreas Kloeckner <inform@tiker.net>
Date: Mon, 26 Mar 2012 10:48:19 -0400
Subject: [PATCH] Fix a variety of bugs in tagged subst rule use.

---
 MEMO                      |  2 ++
 loopy/cse.py              | 10 +++++-----
 loopy/symbolic.py         | 12 +++++++++---
 test/test_fem_assembly.py |  7 +++----
 test/test_linalg.py       |  2 +-
 5 files changed, 20 insertions(+), 13 deletions(-)

diff --git a/MEMO b/MEMO
index c5df0112c..ad071836c 100644
--- a/MEMO
+++ b/MEMO
@@ -57,6 +57,8 @@ To-do
 
 - Scalar insn priority
 
+- If finding a maximum proves troublesome, move parameters into the domain
+
 - : (as in, Matlab full-sclice) in prefetches
 
 Future ideas
diff --git a/loopy/cse.py b/loopy/cse.py
index d46c5f7fe..640a69bb4 100644
--- a/loopy/cse.py
+++ b/loopy/cse.py
@@ -396,12 +396,12 @@ def precompute(kernel, subst_use, dtype, sweep_inames=[],
         else:
             subst_name_as_expr = use
 
-        if isinstance(subst_name_as_expr, Variable):
-            new_subst_name = subst_name_as_expr.name
-            new_subst_tag = None
-        elif isinstance(subst_name_as_expr, TaggedVariable):
+        if isinstance(subst_name_as_expr, TaggedVariable):
             new_subst_name = subst_name_as_expr.name
             new_subst_tag = subst_name_as_expr.tag
+        elif isinstance(subst_name_as_expr, Variable):
+            new_subst_name = subst_name_as_expr.name
+            new_subst_tag = None
         else:
             raise ValueError("unexpected type of subst_name")
 
@@ -473,7 +473,7 @@ def precompute(kernel, subst_use, dtype, sweep_inames=[],
             else:
                 return None
 
-        if subst_tag != tag:
+        if subst_tag is None or subst_tag != tag:
             # use fall-back identity mapper
             return None
 
diff --git a/loopy/symbolic.py b/loopy/symbolic.py
index e20ddbec2..e089440b8 100644
--- a/loopy/symbolic.py
+++ b/loopy/symbolic.py
@@ -535,10 +535,10 @@ class SubstitutionCallbackMapper(IdentityMapper):
 
     def parse_name(self, expr):
         from pymbolic.primitives import Variable
-        if isinstance(expr, Variable):
-            e_name, e_tag = expr.name, None
-        elif isinstance(expr, TaggedVariable):
+        if isinstance(expr, TaggedVariable):
             e_name, e_tag = expr.name, expr.tag
+        elif isinstance(expr, Variable):
+            e_name, e_tag = expr.name, None
         else:
             return None
 
@@ -568,7 +568,13 @@ class SubstitutionCallbackMapper(IdentityMapper):
     map_tagged_variable = map_variable
 
     def map_call(self, expr):
+        from pymbolic.primitives import Lookup
+        if isinstance(expr.function, Lookup):
+            raise RuntimeError("dotted name '%s' not allowed as "
+                    "function identifier" % expr.function)
+
         parsed_name = self.parse_name(expr.function)
+
         if parsed_name is None:
             return IdentityMapper.map_call(self, expr)
 
diff --git a/test/test_fem_assembly.py b/test/test_fem_assembly.py
index 7a9ff15a4..d5e439514 100644
--- a/test/test_fem_assembly.py
+++ b/test/test_fem_assembly.py
@@ -32,7 +32,7 @@ def test_laplacian_stiffness(ctx_factory):
                 "dPsi(ij, dxi) := sum_float32(@ax_b,"
                     "  jacInv[ax_b,dxi,K,q] * DPsi[ax_b,ij,q])",
                 "A[K, i, j] = sum_float32(q, w[q] * jacDet[K,q] * ("
-                    "sum_float32(dx_axis, dPsi.one(i,dx_axis)*dPsi.two(j,dx_axis))))"
+                    "sum_float32(dx_axis, dPsi$one(i,dx_axis)*dPsi$two(j,dx_axis))))"
                 ],
             [
             lp.ArrayArg("jacInv", dtype, shape=(dim, dim, Nc_sym, Nq), order=order),
@@ -79,7 +79,7 @@ def test_laplacian_stiffness(ctx_factory):
         Ncloc = 16
         knl = lp.split_dimension(knl, "K", Ncloc,
                 outer_iname="Ko", inner_iname="Kloc")
-        knl = lp.precompute(knl, "dPsi.one", np.float32, ["dx_axis"], default_tag=None)
+        knl = lp.precompute(knl, "dPsi$one", np.float32, ["dx_axis"], default_tag=None)
         knl = lp.tag_dimensions(knl, {"j": "ilp.seq"})
 
         return knl, ["Ko", "Kloc"]
@@ -131,8 +131,7 @@ def test_laplacian_stiffness(ctx_factory):
 
         lp.auto_test_vs_ref(seq_knl, ctx, kernel_gen,
                 op_count=0, op_label="GFlops",
-                parameters={"Nc": Nc}, print_ref_code=True,
-                timing_rounds=30)
+                parameters={"Nc": Nc}, print_ref_code=True)
 
 
 
diff --git a/test/test_linalg.py b/test/test_linalg.py
index a833a83fc..ffd99a6c7 100644
--- a/test/test_linalg.py
+++ b/test/test_linalg.py
@@ -89,7 +89,7 @@ def get_suitable_size(ctx):
 
 def check_float4(result, ref_result):
     for comp in ["x", "y", "z", "w"]:
-        return np.allclose(ref_result[comp], result[comp], rtol=1e-3, atol=1e-3)
+        return np.allclose(ref_result[comp], result[comp], rtol=1e-3, atol=1e-3), None
 
 def test_axpy(ctx_factory):
     ctx = ctx_factory()
-- 
GitLab