[arrayfire] 86/284: moved assign cpu async fn to kernel space

Ghislain Vaillant ghisvail-guest at moszumanska.debian.org
Sun Feb 7 18:59:21 UTC 2016


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

ghisvail-guest pushed a commit to branch debian/experimental
in repository arrayfire.

commit 3cddae24f55870d565361de75c1fee55ae2ce19a
Author: pradeep <pradeep at arrayfire.com>
Date:   Fri Dec 18 15:45:36 2015 -0500

    moved assign cpu async fn to kernel space
---
 src/backend/cpu/assign.cpp        | 83 +++--------------------------------
 src/backend/cpu/kernel/Array.hpp  |  2 +-
 src/backend/cpu/kernel/assign.hpp | 91 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 97 insertions(+), 79 deletions(-)

diff --git a/src/backend/cpu/assign.cpp b/src/backend/cpu/assign.cpp
index c5d733b..95bb7e5 100644
--- a/src/backend/cpu/assign.cpp
+++ b/src/backend/cpu/assign.cpp
@@ -12,31 +12,16 @@
 #include <ArrayInfo.hpp>
 #include <Array.hpp>
 #include <handle.hpp>
+#include <kernel/assign.hpp>
 #include <assign.hpp>
-#include <err_cpu.hpp>
 #include <platform.hpp>
 #include <async_queue.hpp>
 
-using af::dim4;
-using std::ref;
-using std::copy;
-using std::vector;
-
 namespace cpu
 {
 
-static inline
-dim_t trimIndex(int idx, const dim_t &len)
-{
-    int ret_val = idx;
-    int offset  = abs(ret_val)%len;
-    if (ret_val<0) {
-        ret_val = offset-1;
-    } else if (ret_val>=(int)len) {
-        ret_val = len-offset-1;
-    }
-    return ret_val;
-}
+using af::dim4;
+using std::vector;
 
 template<typename T>
 void assign(Array<T>& out, const af_index_t idxrs[], const Array<T>& rhs)
@@ -63,66 +48,8 @@ void assign(Array<T>& out, const af_index_t idxrs[], const Array<T>& rhs)
         }
     }
 
-    auto func = [=] (Array<T> out, const Array<T> rhs,
-                     const vector<bool> isSeq,
-                     const vector<af_seq> seqs,
-                     const vector< Array<uint> > idxArrs) {
-
-        dim4 dDims = out.getDataDims();
-        dim4 pDims = out.dims();
-        // retrieve dimensions & strides for array to which rhs is being copied to
-        dim4 dst_offsets = toOffset(seqs, dDims);
-        dim4 dst_strides = toStride(seqs, dDims);
-        // retrieve rhs array dimenesions & strides
-        dim4 src_dims    = rhs.dims();
-        dim4 src_strides = rhs.strides();
-        // declare pointers to af_array index data
-        const uint* ptr0 = idxArrs[0].get();
-        const uint* ptr1 = idxArrs[1].get();
-        const uint* ptr2 = idxArrs[2].get();
-        const uint* ptr3 = idxArrs[3].get();
-
-        const T * src= rhs.get();
-        T * dst      = out.get();
-
-        for(dim_t l=0; l<src_dims[3]; ++l) {
-
-            dim_t src_loff = l*src_strides[3];
-
-            dim_t dst_lIdx = trimIndex(isSeq[3] ? l+dst_offsets[3] : ptr3[l], pDims[3]);
-            dim_t dst_loff = dst_lIdx * dst_strides[3];
-
-            for(dim_t k=0; k<src_dims[2]; ++k) {
-
-                dim_t src_koff = k*src_strides[2];
-
-                dim_t dst_kIdx = trimIndex(isSeq[2] ? k+dst_offsets[2] : ptr2[k], pDims[2]);
-                dim_t dst_koff = dst_kIdx * dst_strides[2];
-
-                for(dim_t j=0; j<src_dims[1]; ++j) {
-
-                    dim_t src_joff = j*src_strides[1];
-
-                    dim_t dst_jIdx = trimIndex(isSeq[1] ? j+dst_offsets[1] : ptr1[j], pDims[1]);
-                    dim_t dst_joff = dst_jIdx * dst_strides[1];
-
-                    for(dim_t i=0; i<src_dims[0]; ++i) {
-
-                        dim_t src_ioff = i*src_strides[0];
-                        dim_t src_idx  = src_ioff + src_joff + src_koff + src_loff;
-
-                        dim_t dst_iIdx = trimIndex(isSeq[0] ? i+dst_offsets[0] : ptr0[i], pDims[0]);
-                        dim_t dst_ioff = dst_iIdx * dst_strides[0];
-                        dim_t dst_idx  = dst_ioff + dst_joff + dst_koff + dst_loff;
-
-                        dst[dst_idx] = src[src_idx];
-                    }
-                }
-            }
-        }
-    };
-
-    getQueue().enqueue(func, out, rhs, std::move(isSeq), std::move(seqs), std::move(idxArrs));
+    getQueue().enqueue(kernel::assign<T>, out, rhs, std::move(isSeq),
+            std::move(seqs), std::move(idxArrs));
 }
 
 #define INSTANTIATE(T) \
diff --git a/src/backend/cpu/kernel/Array.hpp b/src/backend/cpu/kernel/Array.hpp
index 0666d43..b3a0200 100644
--- a/src/backend/cpu/kernel/Array.hpp
+++ b/src/backend/cpu/kernel/Array.hpp
@@ -1,5 +1,5 @@
 /*******************************************************
- * Copyright (c) 2014, ArrayFire
+ * Copyright (c) 2015, ArrayFire
  * All rights reserved.
  *
  * This file is distributed under 3-clause BSD license.
diff --git a/src/backend/cpu/kernel/assign.hpp b/src/backend/cpu/kernel/assign.hpp
new file mode 100644
index 0000000..16a623f
--- /dev/null
+++ b/src/backend/cpu/kernel/assign.hpp
@@ -0,0 +1,91 @@
+/*******************************************************
+ * Copyright (c) 2015, ArrayFire
+ * All rights reserved.
+ *
+ * This file is distributed under 3-clause BSD license.
+ * The complete license agreement can be obtained at:
+ * http://arrayfire.com/licenses/BSD-3-Clause
+ ********************************************************/
+
+#include <Array.hpp>
+#include <vector>
+
+namespace kernel
+{
+
+using af::dim4;
+using cpu::Array;
+using std::vector;
+
+inline
+dim_t trimIndex(int idx, const dim_t &len)
+{
+    int ret_val = idx;
+    int offset  = abs(ret_val)%len;
+    if (ret_val<0) {
+        ret_val = offset-1;
+    } else if (ret_val>=(int)len) {
+        ret_val = len-offset-1;
+    }
+    return ret_val;
+}
+
+template<typename T>
+void assign(Array<T> out, const Array<T> rhs, const vector<bool> isSeq,
+            const vector<af_seq> seqs, const vector< Array<uint> > idxArrs)
+{
+    dim4 dDims = out.getDataDims();
+    dim4 pDims = out.dims();
+    // retrieve dimensions & strides for array to which rhs is being copied to
+    dim4 dst_offsets = toOffset(seqs, dDims);
+    dim4 dst_strides = toStride(seqs, dDims);
+    // retrieve rhs array dimenesions & strides
+    dim4 src_dims    = rhs.dims();
+    dim4 src_strides = rhs.strides();
+    // declare pointers to af_array index data
+    const uint* ptr0 = idxArrs[0].get();
+    const uint* ptr1 = idxArrs[1].get();
+    const uint* ptr2 = idxArrs[2].get();
+    const uint* ptr3 = idxArrs[3].get();
+
+    const T * src= rhs.get();
+    T * dst      = out.get();
+
+    for(dim_t l=0; l<src_dims[3]; ++l) {
+
+        dim_t src_loff = l*src_strides[3];
+
+        dim_t dst_lIdx = trimIndex(isSeq[3] ? l+dst_offsets[3] : ptr3[l], pDims[3]);
+        dim_t dst_loff = dst_lIdx * dst_strides[3];
+
+        for(dim_t k=0; k<src_dims[2]; ++k) {
+
+            dim_t src_koff = k*src_strides[2];
+
+            dim_t dst_kIdx = trimIndex(isSeq[2] ? k+dst_offsets[2] : ptr2[k], pDims[2]);
+            dim_t dst_koff = dst_kIdx * dst_strides[2];
+
+            for(dim_t j=0; j<src_dims[1]; ++j) {
+
+                dim_t src_joff = j*src_strides[1];
+
+                dim_t dst_jIdx = trimIndex(isSeq[1] ? j+dst_offsets[1] : ptr1[j], pDims[1]);
+                dim_t dst_joff = dst_jIdx * dst_strides[1];
+
+                for(dim_t i=0; i<src_dims[0]; ++i) {
+
+                    dim_t src_ioff = i*src_strides[0];
+                    dim_t src_idx  = src_ioff + src_joff + src_koff + src_loff;
+
+                    dim_t dst_iIdx = trimIndex(isSeq[0] ? i+dst_offsets[0] : ptr0[i], pDims[0]);
+                    dim_t dst_ioff = dst_iIdx * dst_strides[0];
+                    dim_t dst_idx  = dst_ioff + dst_joff + dst_koff + dst_loff;
+
+                    dst[dst_idx] = src[src_idx];
+                }
+            }
+        }
+    }
+}
+
+}

-- 
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