[arrayfire] 56/75: Make getInfo check if af_array belongs to current device.

Ghislain Vaillant ghisvail-guest at moszumanska.debian.org
Mon Feb 29 08:01:17 UTC 2016


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 f0d11b30427e2199a4121a4de4819783ebde15ee
Author: Pavan Yalamanchili <pavan at arrayfire.com>
Date:   Tue Feb 23 17:09:54 2016 -0500

    Make getInfo check if af_array belongs to current device.
    
    - This behavior can be turned off optionally
---
 include/af/defines.h      |  7 ++++
 src/api/c/array.cpp       | 96 +++++++++++++++++++++++++++++++++++++++++++++++
 src/api/c/data.cpp        | 52 -------------------------
 src/api/c/handle.hpp      |  2 +
 src/api/c/imageio.cpp     |  1 +
 src/api/c/imageio2.cpp    |  1 +
 src/api/c/print.cpp       |  1 +
 src/backend/ArrayInfo.cpp | 20 ----------
 src/backend/ArrayInfo.hpp |  6 ---
 9 files changed, 108 insertions(+), 78 deletions(-)

diff --git a/include/af/defines.h b/include/af/defines.h
index 2b53baa..77508f2 100644
--- a/include/af/defines.h
+++ b/include/af/defines.h
@@ -120,6 +120,13 @@ typedef enum {
     AF_ERR_BATCH          = 207,
 
 
+#if AF_API_VERSION >= 33
+    ///
+    /// Input does not belong to the current device.
+    ///
+    AF_ERR_DEVICE         = 208,
+#endif
+
     // 300-399 Errors for missing software features
 
     ///
diff --git a/src/api/c/array.cpp b/src/api/c/array.cpp
new file mode 100644
index 0000000..cefdde1
--- /dev/null
+++ b/src/api/c/array.cpp
@@ -0,0 +1,96 @@
+/*******************************************************
+ * Copyright (c) 2016, 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 <handle.hpp>
+#include <ArrayInfo.hpp>
+#include <platform.hpp>
+
+const ArrayInfo&
+getInfo(const af_array arr, bool check)
+{
+    const ArrayInfo *info = static_cast<ArrayInfo*>(reinterpret_cast<void *>(arr));
+
+    if (check && info->getDevId() != detail::getActiveDeviceId()) {
+        AF_ERROR("Input Array not created on current device", AF_ERR_DEVICE);
+    }
+
+    return *info;
+}
+
+af_err af_get_elements(dim_t *elems, const af_array arr)
+{
+    try {
+        // Do not check for device mismatch
+        *elems =  getInfo(arr, false).elements();
+    } CATCHALL
+    return AF_SUCCESS;
+}
+
+af_err af_get_type(af_dtype *type, const af_array arr)
+{
+    try {
+        // Do not check for device mismatch
+        *type = getInfo(arr, false).getType();
+    } CATCHALL
+    return AF_SUCCESS;
+}
+
+af_err af_get_dims(dim_t *d0, dim_t *d1, dim_t *d2, dim_t *d3,
+                   const af_array in)
+{
+    try {
+        // Do not check for device mismatch
+        ArrayInfo info = getInfo(in, false);
+        *d0 = info.dims()[0];
+        *d1 = info.dims()[1];
+        *d2 = info.dims()[2];
+        *d3 = info.dims()[3];
+    }
+    CATCHALL
+    return AF_SUCCESS;
+}
+
+af_err af_get_numdims(unsigned *nd, const af_array in)
+{
+    try {
+        // Do not check for device mismatch
+        ArrayInfo info = getInfo(in, false);
+        *nd = info.ndims();
+    }
+    CATCHALL
+    return AF_SUCCESS;
+}
+
+
+#undef INSTANTIATE
+#define INSTANTIATE(fn1, fn2)                           \
+    af_err fn1(bool *result, const af_array in)         \
+    {                                                   \
+        try {                                           \
+            ArrayInfo info = getInfo(in, false);   \
+            *result = info.fn2();                       \
+        }                                               \
+        CATCHALL                                        \
+            return AF_SUCCESS;                          \
+    }
+
+INSTANTIATE(af_is_empty       , isEmpty       )
+INSTANTIATE(af_is_scalar      , isScalar      )
+INSTANTIATE(af_is_row         , isRow         )
+INSTANTIATE(af_is_column      , isColumn      )
+INSTANTIATE(af_is_vector      , isVector      )
+INSTANTIATE(af_is_complex     , isComplex     )
+INSTANTIATE(af_is_real        , isReal        )
+INSTANTIATE(af_is_double      , isDouble      )
+INSTANTIATE(af_is_single      , isSingle      )
+INSTANTIATE(af_is_realfloating, isRealFloating)
+INSTANTIATE(af_is_floating    , isFloating    )
+INSTANTIATE(af_is_integer     , isInteger     )
+INSTANTIATE(af_is_bool        , isBool        )
+
+#undef INSTANTIATE
diff --git a/src/api/c/data.cpp b/src/api/c/data.cpp
index 2de2f13..522eb7d 100644
--- a/src/api/c/data.cpp
+++ b/src/api/c/data.cpp
@@ -539,58 +539,6 @@ af_err af_iota(af_array *result, const unsigned ndims, const dim_t * const dims,
     return AF_SUCCESS;
 }
 
-#undef INSTANTIATE
-#define INSTANTIATE(fn1, fn2)                   \
-    af_err fn1(bool *result, const af_array in) \
-    {                                           \
-        try {                                   \
-            ArrayInfo info = getInfo(in);       \
-            *result = info.fn2();               \
-        }                                       \
-        CATCHALL                                \
-            return AF_SUCCESS;                  \
-    }
-
-INSTANTIATE(af_is_empty       , isEmpty       )
-INSTANTIATE(af_is_scalar      , isScalar      )
-INSTANTIATE(af_is_row         , isRow         )
-INSTANTIATE(af_is_column      , isColumn      )
-INSTANTIATE(af_is_vector      , isVector      )
-INSTANTIATE(af_is_complex     , isComplex     )
-INSTANTIATE(af_is_real        , isReal        )
-INSTANTIATE(af_is_double      , isDouble      )
-INSTANTIATE(af_is_single      , isSingle      )
-INSTANTIATE(af_is_realfloating, isRealFloating)
-INSTANTIATE(af_is_floating    , isFloating    )
-INSTANTIATE(af_is_integer     , isInteger     )
-INSTANTIATE(af_is_bool        , isBool        )
-
-#undef INSTANTIATE
-
-af_err af_get_dims(dim_t *d0, dim_t *d1, dim_t *d2, dim_t *d3,
-                   const af_array in)
-{
-    try {
-        ArrayInfo info = getInfo(in);
-        *d0 = info.dims()[0];
-        *d1 = info.dims()[1];
-        *d2 = info.dims()[2];
-        *d3 = info.dims()[3];
-    }
-    CATCHALL
-    return AF_SUCCESS;
-}
-
-af_err af_get_numdims(unsigned *nd, const af_array in)
-{
-    try {
-        ArrayInfo info = getInfo(in);
-        *nd = info.ndims();
-    }
-    CATCHALL
-    return AF_SUCCESS;
-}
-
 template<typename T>
 static inline void eval(af_array arr)
 {
diff --git a/src/api/c/handle.hpp b/src/api/c/handle.hpp
index 70f17eb..ac7b74a 100644
--- a/src/api/c/handle.hpp
+++ b/src/api/c/handle.hpp
@@ -16,6 +16,8 @@
 #include <copy.hpp>
 #include <cast.hpp>
 
+const ArrayInfo& getInfo(const af_array arr, bool check = true);
+
 template<typename T>
 static const detail::Array<T> &
 getArray(const af_array &arr)
diff --git a/src/api/c/imageio.cpp b/src/api/c/imageio.cpp
index 9f996eb..5e3f7a5 100644
--- a/src/api/c/imageio.cpp
+++ b/src/api/c/imageio.cpp
@@ -24,6 +24,7 @@
 #include <traits.hpp>
 #include <memory.hpp>
 #include <err_common.hpp>
+#include <handle.hpp>
 
 #include <string>
 #include <cstring>
diff --git a/src/api/c/imageio2.cpp b/src/api/c/imageio2.cpp
index cfad2fa..76c53f4 100644
--- a/src/api/c/imageio2.cpp
+++ b/src/api/c/imageio2.cpp
@@ -24,6 +24,7 @@
 #include <traits.hpp>
 #include <memory.hpp>
 #include <err_common.hpp>
+#include <handle.hpp>
 
 #include <string>
 #include <cstring>
diff --git a/src/api/c/print.cpp b/src/api/c/print.cpp
index b243491..6613350 100644
--- a/src/api/c/print.cpp
+++ b/src/api/c/print.cpp
@@ -21,6 +21,7 @@
 #include <err_common.hpp>
 #include <backend.hpp>
 #include <type_util.hpp>
+#include <handle.hpp>
 
 #include <af/index.h>
 
diff --git a/src/backend/ArrayInfo.cpp b/src/backend/ArrayInfo.cpp
index 43d2627..a835353 100644
--- a/src/backend/ArrayInfo.cpp
+++ b/src/backend/ArrayInfo.cpp
@@ -18,26 +18,6 @@
 
 using af::dim4;
 
-const ArrayInfo&
-getInfo(af_array arr)
-{
-    const ArrayInfo *info = static_cast<ArrayInfo*>(reinterpret_cast<void *>(arr));
-    return *info;
-}
-
-af_err
-af_get_elements(dim_t *elems, const af_array arr)
-{
-    *elems =  getInfo(arr).elements();
-    return AF_SUCCESS; //FIXME: Catch exceptions correctly
-}
-
-af_err af_get_type(af_dtype *type, const af_array arr)
-{
-    *type = getInfo(arr).getType();
-    return AF_SUCCESS; //FIXME: Catch exceptions correctly
-}
-
 dim4 calcStrides(const dim4 &parentDim)
 {
     dim4 out(1, 1, 1, 1);
diff --git a/src/backend/ArrayInfo.hpp b/src/backend/ArrayInfo.hpp
index 0983f06..88ba26b 100644
--- a/src/backend/ArrayInfo.hpp
+++ b/src/backend/ArrayInfo.hpp
@@ -140,12 +140,6 @@ public:
     static_assert(std::is_standard_layout<ArrayInfo>::value, "ArrayInfo must be a standard layout type");
 #endif
 
-// Returns size and time info for an array object.
-// Note this doesn't require template parameters.
-const  ArrayInfo&
-getInfo(const af_array arr);
-
-
 af::dim4 toDims(const std::vector<af_seq>& seqs, const af::dim4 &parentDims);
 
 af::dim4 toOffset(const std::vector<af_seq>& seqs, const af::dim4 &parentDims);

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