[arrayfire] 20/284: Fixed asynchronous indexing & assignment in cpu backend

Ghislain Vaillant ghisvail-guest at moszumanska.debian.org
Sun Feb 7 18:59:15 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 2796770f1689358892fde35c7303fa406f1ceb78
Author: pradeep <pradeep at arrayfire.com>
Date:   Thu Nov 19 15:38:27 2015 -0500

    Fixed asynchronous indexing & assignment in cpu backend
---
 src/backend/cpu/assign.cpp | 100 ++++++++++++++++++++++-----------------------
 src/backend/cpu/index.cpp  |  18 ++++----
 2 files changed, 57 insertions(+), 61 deletions(-)

diff --git a/src/backend/cpu/assign.cpp b/src/backend/cpu/assign.cpp
index b75b6d5..b1578d4 100644
--- a/src/backend/cpu/assign.cpp
+++ b/src/backend/cpu/assign.cpp
@@ -16,12 +16,11 @@
 #include <err_cpu.hpp>
 #include <platform.hpp>
 #include <async_queue.hpp>
-#include <array>
 
 using af::dim4;
 using std::ref;
 using std::copy;
-using std::array;
+using std::vector;
 
 namespace cpu
 {
@@ -40,12 +39,11 @@ dim_t trimIndex(int idx, const dim_t &len)
 }
 
 template<typename T>
-void assign_(Array<T> out, const array<af_index_t, 4> idxrs, const Array<T> rhs)
+void assign(Array<T>& out, const af_index_t idxrs[], const Array<T>& rhs)
 {
-    bool isSeq[4];
-    std::vector<af_seq> seqs(4, af_span);
-    // create seq vector to retrieve output
-    // dimensions, offsets & offsets
+    vector<bool> isSeq(4);
+    vector<af_seq> seqs(4, af_span);
+    // create seq vector to retrieve output dimensions, offsets & offsets
     for (dim_t x=0; x<4; ++x) {
         if (idxrs[x].isSeq) {
             seqs[x] = idxrs[x].idx.seq;
@@ -53,17 +51,7 @@ void assign_(Array<T> out, const array<af_index_t, 4> idxrs, const Array<T> rhs)
         isSeq[x] = idxrs[x].isSeq;
     }
 
-    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();
-
-    std::vector< Array<uint> > idxArrs(4, createEmptyArray<uint>(dim4()));
+    vector< Array<uint> > idxArrs(4, createEmptyArray<uint>(dim4()));
     // look through indexs to read af_array indexs
     for (dim_t x=0; x<4; ++x) {
         if (!isSeq[x]) {
@@ -71,58 +59,66 @@ void assign_(Array<T> out, const array<af_index_t, 4> idxrs, const Array<T> rhs)
         }
     }
 
-    // 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();
+    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();
+        const T * src= rhs.get();
+        T * dst      = out.get();
 
-    for(dim_t l=0; l<src_dims[3]; ++l) {
+        for(dim_t l=0; l<src_dims[3]; ++l) {
 
-        dim_t src_loff = l*src_strides[3];
+            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];
+            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) {
+            for(dim_t k=0; k<src_dims[2]; ++k) {
 
-            dim_t src_koff = k*src_strides[2];
+                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];
+                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) {
+                for(dim_t j=0; j<src_dims[1]; ++j) {
 
-                dim_t src_joff = j*src_strides[1];
+                    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];
+                    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) {
+                    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 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;
+                        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];
+                        dst[dst_idx] = src[src_idx];
+                    }
                 }
             }
         }
-    }
-}
+    };
 
-template<typename T>
-void assign(Array<T>& out, const af_index_t idxrs[], const Array<T>& rhs)
-{
-    array<af_index_t, 4> idx;
-    copy(idxrs, idxrs+4, begin(idx));
-    getQueue().enqueue(assign_<T>, out, move(idx), rhs);
+    getQueue().enqueue(func, out, rhs, std::move(isSeq), std::move(seqs), std::move(idxArrs));
 }
 
 #define INSTANTIATE(T) \
diff --git a/src/backend/cpu/index.cpp b/src/backend/cpu/index.cpp
index 39502e9..c1beeea 100644
--- a/src/backend/cpu/index.cpp
+++ b/src/backend/cpu/index.cpp
@@ -19,6 +19,7 @@
 #include <async_queue.hpp>
 #include <utility>
 
+using std::vector;
 using af::dim4;
 
 namespace cpu
@@ -40,11 +41,11 @@ dim_t trimIndex(dim_t idx, const dim_t &len)
 template<typename T>
 Array<T> index(const Array<T>& in, const af_index_t idxrs[])
 {
-    bool isSeq[4];
-    std::vector<af_seq> seqs(4, af_span);
+    vector<bool> isSeq(4);
+    vector<af_seq> seqs(4, af_span);
     // create seq vector to retrieve output
     // dimensions, offsets & offsets
-    for (dim_t x=0; x<4; ++x) {
+    for (dim_t x=0; x<isSeq.size(); ++x) {
         if (idxrs[x].isSeq) {
             seqs[x] = idxrs[x].idx.seq;
         }
@@ -54,9 +55,9 @@ Array<T> index(const Array<T>& in, const af_index_t idxrs[])
     // retrieve
     dim4 oDims = toDims(seqs, in.dims());
 
-    std::vector< Array<uint> > idxArrs(4, createEmptyArray<uint>(dim4()));
+    vector< Array<uint> > idxArrs(4, createEmptyArray<uint>(dim4()));
     // look through indexs to read af_array indexs
-    for (dim_t x=0; x<4; ++x) {
+    for (dim_t x=0; x<isSeq.size(); ++x) {
         if (!isSeq[x]) {
             idxArrs[x] = castArray<uint>(idxrs[x].idx.arr);
             // set output array ith dimension value
@@ -66,11 +67,10 @@ Array<T> index(const Array<T>& in, const af_index_t idxrs[])
 
     Array<T> out = createEmptyArray<T>(oDims);
 
-
     auto func = [=] (Array<T> out, const Array<T> in,
-                     const bool isSeq[],
-                     const std::vector<af_seq> seqs,
-                     const std::vector< Array<uint> > idxArrs) {
+                     const vector<bool> isSeq,
+                     const vector<af_seq> seqs,
+                     const vector< Array<uint> > idxArrs) {
 
         const dim4 iDims    = in.dims();
         const dim4 dDims    = in.getDataDims();

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