[arrayfire] 159/408: Made cpu::Array constructor consistent with CUDA & OpenCL

Ghislain Vaillant ghisvail-guest at moszumanska.debian.org
Mon Sep 21 19:11:45 UTC 2015


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

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

commit 4c34bf252d7cdabb40c0d4d5f3c8c9870e0f59fc
Author: pradeep <pradeep at arrayfire.com>
Date:   Tue Jul 21 15:08:48 2015 -0400

    Made cpu::Array constructor consistent with CUDA & OpenCL
    
    cpu::Array constructor that takes dim4 and a pointer was behaving
    inconsistently w.r.t CUDA & OpenCL. This commit fixes it.
    
    Harris cpu implementation had a bug due to this inconsistent
    behavior, which is fixed now.
---
 src/backend/cpu/Array.cpp  | 12 +++++++-----
 src/backend/cpu/Array.hpp  |  2 +-
 src/backend/cpu/harris.cpp | 22 ++++++++--------------
 3 files changed, 16 insertions(+), 20 deletions(-)

diff --git a/src/backend/cpu/Array.cpp b/src/backend/cpu/Array.cpp
index bed7597..15515fa 100644
--- a/src/backend/cpu/Array.cpp
+++ b/src/backend/cpu/Array.cpp
@@ -34,14 +34,16 @@ namespace cpu
     { }
 
     template<typename T>
-    Array<T>::Array(dim4 dims, const T * const in_data):
+    Array<T>::Array(dim4 dims, const T * const in_data, bool is_device):
         info(getActiveDeviceId(), dims, dim4(0,0,0,0), calcStrides(dims), (af_dtype)dtype_traits<T>::af_type),
-        data(memAlloc<T>(dims.elements()), memFree<T>), data_dims(dims),
+        data(is_device ? (T*)in_data : memAlloc<T>(dims.elements()), memFree<T>), data_dims(dims),
         node(), offset(0), ready(true), owner(true)
     {
         static_assert(std::is_standard_layout<Array<T>>::value, "Array<T> must be a standard layout type");
         static_assert(offsetof(Array<T>, info) == 0, "Array<T>::info must be the first member variable of Array<T>");
-        std::copy(in_data, in_data + dims.elements(), data.get());
+        if (!is_device) {
+            std::copy(in_data, in_data + dims.elements(), data.get());
+        }
     }
 
 
@@ -131,14 +133,14 @@ namespace cpu
     Array<T>
     createHostDataArray(const dim4 &size, const T * const data)
     {
-        return Array<T>(size, data);
+        return Array<T>(size, data, false);
     }
 
     template<typename T>
     Array<T>
     createDeviceDataArray(const dim4 &size, const void *data)
     {
-        return Array<T>(size, (const T * const) data);
+        return Array<T>(size, (const T * const) data, true);
     }
 
     template<typename T>
diff --git a/src/backend/cpu/Array.hpp b/src/backend/cpu/Array.hpp
index 3b0ff6d..7f23bc8 100644
--- a/src/backend/cpu/Array.hpp
+++ b/src/backend/cpu/Array.hpp
@@ -95,7 +95,7 @@ namespace cpu
 
         Array() = default;
         Array(dim4 dims);
-        explicit Array(dim4 dims, const T * const in_data);
+        explicit Array(dim4 dims, const T * const in_data, bool is_device);
         Array(const Array<T>& parnt, const dim4 &dims, const dim4 &offset, const dim4 &stride);
         explicit Array(af::dim4 dims, TNJ::Node_ptr n);
 
diff --git a/src/backend/cpu/harris.cpp b/src/backend/cpu/harris.cpp
index efbb2c9..d16c56a 100644
--- a/src/backend/cpu/harris.cpp
+++ b/src/backend/cpu/harris.cpp
@@ -131,15 +131,9 @@ void non_maximal(
     }
 }
 
-void keep_corners(
-    float* x_out,
-    float* y_out,
-    float* resp_out,
-    const float* x_in,
-    const float* y_in,
-    const float* resp_in,
-    const unsigned* resp_idx,
-    const unsigned n_corners)
+static void keep_corners(float* x_out, float* y_out, float* resp_out,
+                         const float* x_in, const float* y_in, const float* resp_in,
+                         const unsigned* resp_idx, const unsigned n_corners)
 {
     // Keep only the first n_feat features
     for (unsigned f = 0; f < n_corners; f++) {
@@ -166,7 +160,7 @@ unsigned harris(Array<float> &x_out, Array<float> &y_out, Array<float> &resp_out
     else {
         gaussian1D<convAccT>(h_filter, (int)filter_len, sigma);
     }
-    Array<convAccT> filter = createHostDataArray(filter_len, h_filter);
+    Array<convAccT> filter = createDeviceDataArray<convAccT>(dim4(filter_len), (const void*)h_filter);
 
     unsigned border_len = filter_len / 2 + 1;
 
@@ -219,7 +213,7 @@ unsigned harris(Array<float> &x_out, Array<float> &y_out, Array<float> &resp_out
         return 0;
 
     if (max_corners > 0 && corners_found > corners_out) {
-        Array<float> harris_responses = createHostDataArray<float>(dim4(corners_found), resp_corners);
+        Array<float> harris_responses = createDeviceDataArray<float>(dim4(corners_found), (void*)resp_corners);
         Array<float> harris_sorted = createEmptyArray<float>(dim4(corners_found));
         Array<unsigned> harris_idx = createEmptyArray<unsigned>(dim4(corners_found));
 
@@ -252,9 +246,9 @@ unsigned harris(Array<float> &x_out, Array<float> &y_out, Array<float> &resp_out
         memFree(resp_corners);
     }
     else {
-        x_out = createHostDataArray<float>(dim4(corners_out), x_corners);
-        y_out = createHostDataArray<float>(dim4(corners_out), y_corners);
-        resp_out = createHostDataArray<float>(dim4(corners_out), resp_corners);
+        x_out = createDeviceDataArray<float>(dim4(corners_out), (void*)x_corners);
+        y_out = createDeviceDataArray<float>(dim4(corners_out), (void*)y_corners);
+        resp_out = createDeviceDataArray<float>(dim4(corners_out), (void*)resp_corners);
     }
 
     return corners_out;

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