From 4b34ba94bd1d1fcab727e26773dba75def08d637 Mon Sep 17 00:00:00 2001
From: Andreas Kloeckner <inform@tiker.net>
Date: Mon, 16 Jan 2012 02:30:00 -0500
Subject: [PATCH] Parse vectorized reductions. Spelling: 'sum_vec_float4'

---
 loopy/kernel.py | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/loopy/kernel.py b/loopy/kernel.py
index ed83b30c3..cd590211a 100644
--- a/loopy/kernel.py
+++ b/loopy/kernel.py
@@ -387,12 +387,6 @@ class ProductReductionOperation(TypedReductionOperation):
     def __call__(self, operand1, operand2):
         return operand1 * operand2
 
-class FloatingPointMaxOperation(TypedReductionOperation):
-    neutral_element = -var("INFINITY")
-
-    def __call__(self, operand1, operand2):
-        return var("max")(operand1, operand2)
-
 class FloatingPointMaxOperation(TypedReductionOperation):
     # OpenCL 1.1, section 6.11.2
     neutral_element = -var("INFINITY")
@@ -433,15 +427,23 @@ def register_reduction_parser(parser):
 
 def parse_reduction_op(name):
     import re
-    red_op_match = re.match(r"^([a-z]+)_([a-z0-9]+)$", name)
+    red_op_match = re.match(r"^([a-z]+)_([a-z0-9_]+)$", name)
     if red_op_match:
         op_name = red_op_match.group(1)
         op_type = red_op_match.group(2)
+
         try:
             op_dtype = np.dtype(op_type)
         except TypeError:
             op_dtype = None
 
+        if op_dtype is None and op_type.startswith("vec_"):
+            import pyopencl.array as cl_array
+            try:
+                op_dtype = getattr(cl_array.vec, op_type[4:])
+            except AttributeError:
+                op_dtype = None
+
         if op_name in _REDUCTION_OPS and op_dtype is not None:
             return _REDUCTION_OPS[op_name](op_dtype)
 
-- 
GitLab