[arrayfire] 11/34: Reduction fixes for smaller arrays (<4096 elements)

Ghislain Vaillant ghisvail-guest at moszumanska.debian.org
Sun Sep 27 14:46:02 UTC 2015


This is an automated email from the git hooks/post-receive script.

ghisvail-guest pushed a commit to branch dfsg-clean
in repository arrayfire.

commit b0c7c7bc6ed65a2f7abfa7cee0922fbd4a66cc72
Author: Pavan Yalamanchili <pavan at arrayfire.com>
Date:   Mon Sep 21 16:18:25 2015 -0400

    Reduction fixes for smaller arrays (<4096 elements)
---
 src/backend/cuda/kernel/reduce.hpp   | 11 +++++------
 src/backend/opencl/kernel/reduce.hpp | 12 ++++++------
 test/reduce.cpp                      |  8 ++++++++
 3 files changed, 19 insertions(+), 12 deletions(-)

diff --git a/src/backend/cuda/kernel/reduce.hpp b/src/backend/cuda/kernel/reduce.hpp
index 8cc720f..89b604e 100644
--- a/src/backend/cuda/kernel/reduce.hpp
+++ b/src/backend/cuda/kernel/reduce.hpp
@@ -372,14 +372,13 @@ namespace kernel
     To reduce_all(CParam<Ti> in, bool change_nan, double nanval)
     {
         int in_elements = in.dims[0] * in.dims[1] * in.dims[2] * in.dims[3];
+        bool is_linear = (in.strides[0] == 1);
+        for (int k = 1; k < 4; k++) {
+            is_linear &= (in.strides[k] == (in.strides[k - 1] * in.dims[k - 1]));
+        }
 
         // FIXME: Use better heuristics to get to the optimum number
-        if (in_elements > 4096) {
-
-            bool is_linear = (in.strides[0] == 1);
-            for (int k = 1; k < 4; k++) {
-                is_linear &= (in.strides[k] == (in.strides[k - 1] * in.dims[k - 1]));
-            }
+        if (in_elements > 4096 || !is_linear) {
 
             if (is_linear) {
                 in.dims[0] = in_elements;
diff --git a/src/backend/opencl/kernel/reduce.hpp b/src/backend/opencl/kernel/reduce.hpp
index e46d5e4..a35f5ea 100644
--- a/src/backend/opencl/kernel/reduce.hpp
+++ b/src/backend/opencl/kernel/reduce.hpp
@@ -289,13 +289,13 @@ namespace kernel
         try {
             int in_elements = in.info.dims[0] * in.info.dims[1] * in.info.dims[2] * in.info.dims[3];
 
-            // FIXME: Use better heuristics to get to the optimum number
-            if (in_elements > 4096) {
+            bool is_linear = (in.info.strides[0] == 1);
+            for (int k = 1; k < 4; k++) {
+                is_linear &= (in.info.strides[k] == (in.info.strides[k - 1] * in.info.dims[k - 1]));
+            }
 
-                bool is_linear = (in.info.strides[0] == 1);
-                for (int k = 1; k < 4; k++) {
-                    is_linear &= (in.info.strides[k] == (in.info.strides[k - 1] * in.info.dims[k - 1]));
-                }
+            // FIXME: Use better heuristics to get to the optimum number
+            if (in_elements > 4096 || !is_linear) {
 
                 if (is_linear) {
                     in.info.dims[0] = in_elements;
diff --git a/test/reduce.cpp b/test/reduce.cpp
index b37be15..45c0977 100644
--- a/test/reduce.cpp
+++ b/test/reduce.cpp
@@ -576,3 +576,11 @@ TEST(Reduce, KernelName)
                   af::min<float>(tmp));
     }
 }
+
+TEST(Reduce, AllSmallIndexed)
+{
+    int LEN = 1000;
+    array a = af::range(af::dim4(LEN, 2));
+    array b = a(af::seq(LEN/2), af::span);
+    ASSERT_EQ(af::max<float>(b), LEN/2-1);
+}

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/arrayfire.git



More information about the debian-science-commits mailing list