[arrayfire] 23/408: Make Array<T> a standard layout type

Ghislain Vaillant ghisvail-guest at moszumanska.debian.org
Mon Sep 21 19:11:08 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 91f7431caabefe7f2c1c7aa9b8546437c09cce88
Author: Umar Arshad <umar at arrayfire.com>
Date:   Sat Jun 20 17:55:01 2015 -0400

    Make Array<T> a standard layout type
    
    Cannot make Array<T> a POD type because shared_ptr is not a
    POD type.
---
 src/backend/cpu/Array.cpp    | 15 +++++---------
 src/backend/cpu/Array.hpp    | 47 +++++++++++++++++++++++++++++++++++++++++---
 src/backend/cuda/Array.cpp   | 10 +++++-----
 src/backend/cuda/Array.hpp   | 42 ++++++++++++++++++++++++++++++++++++++-
 src/backend/opencl/Array.cpp | 18 ++++++++---------
 src/backend/opencl/Array.hpp | 41 +++++++++++++++++++++++++++++++++++++-
 6 files changed, 144 insertions(+), 29 deletions(-)

diff --git a/src/backend/cpu/Array.cpp b/src/backend/cpu/Array.cpp
index 68859e1..6a4394e 100644
--- a/src/backend/cpu/Array.cpp
+++ b/src/backend/cpu/Array.cpp
@@ -27,14 +27,14 @@ namespace cpu
 
     template<typename T>
     Array<T>::Array(dim4 dims):
-        ArrayInfo(getActiveDeviceId(), dims, dim4(0,0,0,0), calcStrides(dims), (af_dtype)dtype_traits<T>::af_type),
+        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),
         node(), ready(true), offset(0), owner(true)
     { }
 
     template<typename T>
     Array<T>::Array(dim4 dims, const T * const in_data):
-        ArrayInfo(getActiveDeviceId(), dims, dim4(0,0,0,0), calcStrides(dims), (af_dtype)dtype_traits<T>::af_type),
+        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),
         node(), ready(true), offset(0), owner(true)
     {
@@ -44,7 +44,7 @@ namespace cpu
 
     template<typename T>
     Array<T>::Array(af::dim4 dims, TNJ::Node_ptr n) :
-        ArrayInfo(-1, dims, af::dim4(0,0,0,0), calcStrides(dims), (af_dtype)dtype_traits<T>::af_type),
+        info(-1, dims, af::dim4(0,0,0,0), calcStrides(dims), (af_dtype)dtype_traits<T>::af_type),
         data(), data_dims(dims),
         node(n), ready(false), offset(0), owner(true)
     {
@@ -52,7 +52,7 @@ namespace cpu
 
     template<typename T>
     Array<T>::Array(const Array<T>& parent, const dim4 &dims, const dim4 &offsets, const dim4 &strides) :
-        ArrayInfo(parent.getDevId(), dims, offsets, strides, (af_dtype)dtype_traits<T>::af_type),
+        info(parent.getDevId(), dims, offsets, strides, (af_dtype)dtype_traits<T>::af_type),
         data(parent.getData()), data_dims(parent.getDataDims()),
         node(), ready(true),
         offset(parent.getOffset() + calcOffset(parent.strides(), offsets)),
@@ -106,10 +106,6 @@ namespace cpu
     }
 
     template<typename T>
-    Array<T>::~Array()
-    { }
-
-    template<typename T>
     Node_ptr Array<T>::getNode() const
     {
         if (!node) {
@@ -159,7 +155,7 @@ namespace cpu
     }
 
     template<typename T>
-    Array<T> *initArray() { return new Array<T>(dim4()); }
+    Array<T> *initArray() { return new Array<T>(dim4(0, 0, 0, 0)); }
 
 
     template<typename T>
@@ -259,7 +255,6 @@ namespace cpu
     template       void      destroyArray<T>          (Array<T> *A);    \
     template       void      evalArray<T>             (const Array<T> &A); \
     template       Array<T>  createNodeArray<T>       (const dim4 &size, TNJ::Node_ptr node); \
-    template       Array<T>::~Array        ();                          \
     template       void Array<T>::eval();                               \
     template       void Array<T>::eval() const;                         \
     template       TNJ::Node_ptr Array<T>::getNode() const;             \
diff --git a/src/backend/cpu/Array.hpp b/src/backend/cpu/Array.hpp
index 4372655..47e5d0e 100644
--- a/src/backend/cpu/Array.hpp
+++ b/src/backend/cpu/Array.hpp
@@ -79,8 +79,9 @@ namespace cpu
 
     // Array Array Implementation
     template<typename T>
-    class Array : public ArrayInfo
+    class Array
     {
+         ArrayInfo info;
         //TODO: Generator based array
 
         //data if parent. empty if child
@@ -92,6 +93,7 @@ namespace cpu
         dim_t offset;
         bool owner;
 
+        Array() = default;
         Array(dim4 dims);
         explicit Array(dim4 dims, const T * const in_data);
         Array(const Array<T>& parnt, const dim4 &dims, const dim4 &offset, const dim4 &stride);
@@ -99,7 +101,46 @@ namespace cpu
 
     public:
 
-        ~Array();
+        void resetInfo(const af::dim4& dims)        { info.resetInfo(dims);         }
+        void resetDims(const af::dim4& dims)        { info.resetDims(dims);         }
+        void modDims(const af::dim4 &newDims)       { info.modDims(newDims);        }
+        void modStrides(const af::dim4 &newStrides) { info.modStrides(newStrides);  }
+        void setId(int id)                          { info.setId(id);               }
+
+#define INFO_FUNC(RET_TYPE, NAME)   \
+    RET_TYPE NAME() const { return info.NAME(); }
+
+        INFO_FUNC(const af_dtype& ,getType)
+        INFO_FUNC(const af::dim4& ,offsets)
+        INFO_FUNC(const af::dim4& ,strides)
+        INFO_FUNC(size_t          ,elements)
+        INFO_FUNC(size_t          ,ndims)
+        INFO_FUNC(const af::dim4& ,dims )
+        INFO_FUNC(int             ,getDevId)
+
+#undef INFO_FUNC
+
+#define INFO_IS_FUNC(NAME)\
+    bool NAME () const { return info.NAME(); }
+
+        INFO_IS_FUNC(isEmpty);
+        INFO_IS_FUNC(isScalar);
+        INFO_IS_FUNC(isRow);
+        INFO_IS_FUNC(isColumn);
+        INFO_IS_FUNC(isVector);
+        INFO_IS_FUNC(isComplex);
+        INFO_IS_FUNC(isReal);
+        INFO_IS_FUNC(isDouble);
+        INFO_IS_FUNC(isSingle);
+        INFO_IS_FUNC(isRealFloating);
+        INFO_IS_FUNC(isFloating);
+        INFO_IS_FUNC(isInteger);
+        INFO_IS_FUNC(isBool);
+        INFO_IS_FUNC(isLinear);
+
+#undef INFO_IS_FUNC
+
+        ~Array() = default;
 
         bool isReady() const { return ready; }
 
@@ -115,7 +156,7 @@ namespace cpu
         {
             // This is for moddims
             // dims and data_dims are different when moddims is used
-            return isOwner() ? dims() : data_dims;
+            return isOwner() ? info.dims() : data_dims;
         }
 
         T* get(bool withOffset = true)
diff --git a/src/backend/cuda/Array.cpp b/src/backend/cuda/Array.cpp
index 2d63985..97d67c3 100644
--- a/src/backend/cuda/Array.cpp
+++ b/src/backend/cuda/Array.cpp
@@ -28,14 +28,14 @@ namespace cuda
 
     template<typename T>
     Array<T>::Array(af::dim4 dims) :
-        ArrayInfo(getActiveDeviceId(), dims, af::dim4(0,0,0,0), calcStrides(dims), (af_dtype)dtype_traits<T>::af_type),
+        info(getActiveDeviceId(), dims, af::dim4(0,0,0,0), calcStrides(dims), (af_dtype)dtype_traits<T>::af_type),
         data(memAlloc<T>(dims.elements()), memFree<T>), data_dims(dims),
         node(), ready(true), offset(0), owner(true)
     {}
 
     template<typename T>
     Array<T>::Array(af::dim4 dims, const T * const in_data, bool is_device) :
-        ArrayInfo(getActiveDeviceId(), dims, af::dim4(0,0,0,0), calcStrides(dims), (af_dtype)dtype_traits<T>::af_type),
+        info(getActiveDeviceId(), dims, af::dim4(0,0,0,0), calcStrides(dims), (af_dtype)dtype_traits<T>::af_type),
         data((is_device ? (T *)in_data : memAlloc<T>(dims.elements())), memFree<T>),
         data_dims(dims),
         node(), ready(true), offset(0), owner(true)
@@ -47,7 +47,7 @@ namespace cuda
 
     template<typename T>
     Array<T>::Array(const Array<T>& parent, const dim4 &dims, const dim4 &offsets, const dim4 &strides) :
-        ArrayInfo(parent.getDevId(), dims, offsets, strides, (af_dtype)dtype_traits<T>::af_type),
+        info(parent.getDevId(), dims, offsets, strides, (af_dtype)dtype_traits<T>::af_type),
         data(parent.getData()), data_dims(parent.getDataDims()),
         node(), ready(true),
         offset(parent.getOffset() + calcOffset(parent.strides(), offsets)),
@@ -56,7 +56,7 @@ namespace cuda
 
     template<typename T>
     Array<T>::Array(Param<T> &tmp) :
-        ArrayInfo(getActiveDeviceId(), af::dim4(tmp.dims[0], tmp.dims[1], tmp.dims[2], tmp.dims[3]),
+        info(getActiveDeviceId(), af::dim4(tmp.dims[0], tmp.dims[1], tmp.dims[2], tmp.dims[3]),
                   af::dim4(0, 0, 0, 0),
                   af::dim4(tmp.strides[0], tmp.strides[1], tmp.strides[2], tmp.strides[3]),
                   (af_dtype)dtype_traits<T>::af_type),
@@ -68,7 +68,7 @@ namespace cuda
 
     template<typename T>
     Array<T>::Array(af::dim4 dims, JIT::Node_ptr n) :
-        ArrayInfo(-1, dims, af::dim4(0,0,0,0), calcStrides(dims), (af_dtype)dtype_traits<T>::af_type),
+        info(-1, dims, af::dim4(0,0,0,0), calcStrides(dims), (af_dtype)dtype_traits<T>::af_type),
         data(), data_dims(dims),
         node(n), ready(false), offset(0), owner(true)
     {
diff --git a/src/backend/cuda/Array.hpp b/src/backend/cuda/Array.hpp
index 55be634..8ce2a38 100644
--- a/src/backend/cuda/Array.hpp
+++ b/src/backend/cuda/Array.hpp
@@ -93,8 +93,9 @@ namespace cuda
     }
 
     template<typename T>
-    class Array : public ArrayInfo
+    class Array
     {
+        ArrayInfo       info;
         shared_ptr<T> data;
         af::dim4 data_dims;
 
@@ -110,6 +111,45 @@ namespace cuda
         Array(af::dim4 dims, JIT::Node_ptr n);
     public:
 
+        void resetInfo(const af::dim4& dims)        { info.resetInfo(dims);         }
+        void resetDims(const af::dim4& dims)        { info.resetDims(dims);         }
+        void modDims(const af::dim4 &newDims)       { info.modDims(newDims);        }
+        void modStrides(const af::dim4 &newStrides) { info.modStrides(newStrides);  }
+        void setId(int id)                          { info.setId(id);               }
+
+#define INFO_FUNC(RET_TYPE, NAME)   \
+    RET_TYPE NAME() const { return info.NAME(); }
+
+        INFO_FUNC(const af_dtype& ,getType)
+        INFO_FUNC(const af::dim4& ,offsets)
+        INFO_FUNC(const af::dim4& ,strides)
+        INFO_FUNC(size_t          ,elements)
+        INFO_FUNC(size_t          ,ndims)
+        INFO_FUNC(const af::dim4& ,dims )
+        INFO_FUNC(int             ,getDevId)
+
+#undef INFO_FUNC
+
+#define INFO_IS_FUNC(NAME)\
+    bool NAME () const { return info.NAME(); }
+
+        INFO_IS_FUNC(isEmpty);
+        INFO_IS_FUNC(isScalar);
+        INFO_IS_FUNC(isRow);
+        INFO_IS_FUNC(isColumn);
+        INFO_IS_FUNC(isVector);
+        INFO_IS_FUNC(isComplex);
+        INFO_IS_FUNC(isReal);
+        INFO_IS_FUNC(isDouble);
+        INFO_IS_FUNC(isSingle);
+        INFO_IS_FUNC(isRealFloating);
+        INFO_IS_FUNC(isFloating);
+        INFO_IS_FUNC(isInteger);
+        INFO_IS_FUNC(isBool);
+        INFO_IS_FUNC(isLinear);
+
+#undef INFO_IS_FUNC
+
         ~Array();
 
         bool isReady() const { return ready; }
diff --git a/src/backend/opencl/Array.cpp b/src/backend/opencl/Array.cpp
index fcaec5c..c1a0e0a 100644
--- a/src/backend/opencl/Array.cpp
+++ b/src/backend/opencl/Array.cpp
@@ -28,8 +28,8 @@ namespace opencl
 
     template<typename T>
     Array<T>::Array(af::dim4 dims) :
-        ArrayInfo(getActiveDeviceId(), dims, af::dim4(0,0,0,0), calcStrides(dims), (af_dtype)dtype_traits<T>::af_type),
-        data(bufferAlloc(ArrayInfo::elements() * sizeof(T)), bufferFree),
+        info(getActiveDeviceId(), dims, af::dim4(0,0,0,0), calcStrides(dims), (af_dtype)dtype_traits<T>::af_type),
+        data(bufferAlloc(info.elements() * sizeof(T)), bufferFree),
         data_dims(dims),
         node(), ready(true), offset(0), owner(true)
     {
@@ -37,7 +37,7 @@ namespace opencl
 
     template<typename T>
     Array<T>::Array(af::dim4 dims, JIT::Node_ptr n) :
-        ArrayInfo(-1, dims, af::dim4(0,0,0,0), calcStrides(dims), (af_dtype)dtype_traits<T>::af_type),
+        info(-1, dims, af::dim4(0,0,0,0), calcStrides(dims), (af_dtype)dtype_traits<T>::af_type),
         data(),
         data_dims(dims),
         node(n), ready(false), offset(0), owner(true)
@@ -46,17 +46,17 @@ namespace opencl
 
     template<typename T>
     Array<T>::Array(af::dim4 dims, const T * const in_data) :
-        ArrayInfo(getActiveDeviceId(), dims, af::dim4(0,0,0,0), calcStrides(dims), (af_dtype)dtype_traits<T>::af_type),
-        data(bufferAlloc(ArrayInfo::elements()*sizeof(T)), bufferFree),
+        info(getActiveDeviceId(), dims, af::dim4(0,0,0,0), calcStrides(dims), (af_dtype)dtype_traits<T>::af_type),
+        data(bufferAlloc(info.elements()*sizeof(T)), bufferFree),
         data_dims(dims),
         node(), ready(true), offset(0), owner(true)
     {
-        getQueue().enqueueWriteBuffer(*data.get(), CL_TRUE, 0, sizeof(T)*ArrayInfo::elements(), in_data);
+        getQueue().enqueueWriteBuffer(*data.get(), CL_TRUE, 0, sizeof(T)*info.elements(), in_data);
     }
 
     template<typename T>
     Array<T>::Array(af::dim4 dims, cl_mem mem) :
-        ArrayInfo(getActiveDeviceId(), dims, af::dim4(0,0,0,0), calcStrides(dims), (af_dtype)dtype_traits<T>::af_type),
+        info(getActiveDeviceId(), dims, af::dim4(0,0,0,0), calcStrides(dims), (af_dtype)dtype_traits<T>::af_type),
         data(new cl::Buffer(mem), bufferFree),
         data_dims(dims),
         node(), ready(true), offset(0), owner(true)
@@ -65,7 +65,7 @@ namespace opencl
 
     template<typename T>
     Array<T>::Array(const Array<T>& parent, const dim4 &dims, const dim4 &offsets, const dim4 &stride) :
-        ArrayInfo(parent.getDevId(), dims, offsets, stride, (af_dtype)dtype_traits<T>::af_type),
+        info(parent.getDevId(), dims, offsets, stride, (af_dtype)dtype_traits<T>::af_type),
         data(parent.getData()),
         data_dims(parent.getDataDims()),
         node(),
@@ -77,7 +77,7 @@ namespace opencl
 
     template<typename T>
     Array<T>::Array(Param &tmp) :
-        ArrayInfo(getActiveDeviceId(), af::dim4(tmp.info.dims[0], tmp.info.dims[1], tmp.info.dims[2], tmp.info.dims[3]),
+        info(getActiveDeviceId(), af::dim4(tmp.info.dims[0], tmp.info.dims[1], tmp.info.dims[2], tmp.info.dims[3]),
                   af::dim4(0, 0, 0, 0),
                   af::dim4(tmp.info.strides[0], tmp.info.strides[1],
                            tmp.info.strides[2], tmp.info.strides[3]),
diff --git a/src/backend/opencl/Array.hpp b/src/backend/opencl/Array.hpp
index 6372a6e..7169f09 100644
--- a/src/backend/opencl/Array.hpp
+++ b/src/backend/opencl/Array.hpp
@@ -83,8 +83,9 @@ namespace opencl
     }
 
     template<typename T>
-    class Array : public ArrayInfo
+    class Array
     {
+        ArrayInfo info;
         Buffer_ptr  data;
         af::dim4 data_dims;
 
@@ -102,6 +103,44 @@ namespace opencl
 
     public:
 
+        void resetInfo(const af::dim4& dims)        { info.resetInfo(dims);         }
+        void resetDims(const af::dim4& dims)        { info.resetDims(dims);         }
+        void modDims(const af::dim4 &newDims)       { info.modDims(newDims);        }
+        void modStrides(const af::dim4 &newStrides) { info.modStrides(newStrides);  }
+        void setId(int id)                          { info.setId(id);               }
+
+#define INFO_FUNC(RET_TYPE, NAME)   \
+    RET_TYPE NAME() const { return info.NAME(); }
+
+        INFO_FUNC(const af_dtype& ,getType)
+        INFO_FUNC(const af::dim4& ,offsets)
+        INFO_FUNC(const af::dim4& ,strides)
+        INFO_FUNC(size_t          ,elements)
+        INFO_FUNC(size_t          ,ndims)
+        INFO_FUNC(const af::dim4& ,dims )
+        INFO_FUNC(int             ,getDevId)
+
+#undef INFO_FUNC
+
+#define INFO_IS_FUNC(NAME)\
+    bool NAME () const { return info.NAME(); }
+
+        INFO_IS_FUNC(isEmpty);
+        INFO_IS_FUNC(isScalar);
+        INFO_IS_FUNC(isRow);
+        INFO_IS_FUNC(isColumn);
+        INFO_IS_FUNC(isVector);
+        INFO_IS_FUNC(isComplex);
+        INFO_IS_FUNC(isReal);
+        INFO_IS_FUNC(isDouble);
+        INFO_IS_FUNC(isSingle);
+        INFO_IS_FUNC(isRealFloating);
+        INFO_IS_FUNC(isFloating);
+        INFO_IS_FUNC(isInteger);
+        INFO_IS_FUNC(isBool);
+        INFO_IS_FUNC(isLinear);
+
+#undef INFO_IS_FUNC
         ~Array();
 
         bool isReady() const { return ready; }

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