[arrayfire] 60/75: FEAT, TEST, DOC: Adding function to query which device an array was created.
Ghislain Vaillant
ghisvail-guest at moszumanska.debian.org
Mon Feb 29 08:01:18 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 9b793f00927d3253fbfe28840171e34b749ebdf7
Author: Pavan Yalamanchili <pavan at arrayfire.com>
Date: Tue Feb 23 18:20:35 2016 -0500
FEAT,TEST,DOC: Adding function to query which device an array was created.
- Adding relevant tests and docs
---
docs/details/backend.dox | 9 +++++++++
include/af/backend.h | 24 ++++++++++++++++++++++++
src/api/c/device.cpp | 12 +++++++++++-
src/api/cpp/device.cpp | 7 +++++++
src/api/unified/device.cpp | 6 ++++++
test/array.cpp | 31 +++++++++++++++++++++++++++++++
6 files changed, 88 insertions(+), 1 deletion(-)
diff --git a/docs/details/backend.dox b/docs/details/backend.dox
index 146cc14..893567b 100644
--- a/docs/details/backend.dox
+++ b/docs/details/backend.dox
@@ -80,5 +80,14 @@ The return value specifies which backend the array was created on.
=======================================================================
+\defgroup unified_func_getdeviceid getDeviceId
+
+\brief Get's the id of the device an array was created on.
+
+\ingroup unified_func
+\ingroup arrayfire_func
+
+=======================================================================
+
@}
*/
diff --git a/include/af/backend.h b/include/af/backend.h
index 0342ef0..0770feb 100644
--- a/include/af/backend.h
+++ b/include/af/backend.h
@@ -66,6 +66,18 @@ AFAPI af_err af_get_backend_id(af_backend *backend, const af_array in);
AFAPI af_err af_get_active_backend(af_backend *backend);
#endif
+#if AF_API_VERSION >= 33
+/**
+ \param[out] dev contains the device on which \p in was created.
+ \param[in] in is the array who's device is to be queried.
+ \returns \ref af_err error code
+
+ \ingroup unified_func_getdeviceid
+ */
+AFAPI af_err af_get_device_id(int *device, const af_array in);
+#endif
+
+
#ifdef __cplusplus
}
#endif
@@ -121,5 +133,17 @@ AFAPI af::Backend getBackendId(const array &in);
AFAPI af::Backend getActiveBackend();
#endif
+#if AF_API_VERSION >= 33
+/**
+ \param[in] in is the array who's device is to be queried.
+ \returns The id of the device on which this array was created.
+
+ \note Device ID can be the same for arrays belonging to different backends.
+
+ \ingroup unified_func_getdeviceid
+ */
+AFAPI int getDeviceId(const array &in);
+#endif
+
}
#endif
diff --git a/src/api/c/device.cpp b/src/api/c/device.cpp
index 6c089f5..abe0b01 100644
--- a/src/api/c/device.cpp
+++ b/src/api/c/device.cpp
@@ -48,12 +48,22 @@ af_err af_get_backend_id(af_backend *result, const af_array in)
{
try {
ARG_ASSERT(1, in != 0);
- ArrayInfo info = getInfo(in);
+ ArrayInfo info = getInfo(in, false);
*result = info.getBackendId();
} CATCHALL;
return AF_SUCCESS;
}
+af_err af_get_device_id(int *device, const af_array in)
+{
+ try {
+ ARG_ASSERT(1, in != 0);
+ ArrayInfo info = getInfo(in, false);
+ *device = info.getDevId();
+ } CATCHALL;
+ return AF_SUCCESS;
+}
+
af_err af_get_active_backend(af_backend *result)
{
*result = (af_backend)getBackend();
diff --git a/src/api/cpp/device.cpp b/src/api/cpp/device.cpp
index 5e4b0f7..faf0b0e 100644
--- a/src/api/cpp/device.cpp
+++ b/src/api/cpp/device.cpp
@@ -42,6 +42,13 @@ namespace af
return result;
}
+ int getDeviceId(const array &in)
+ {
+ int device = getDevice();;
+ AF_THROW(af_get_device_id(&device, in.get()));
+ return device;
+ }
+
af::Backend getActiveBackend()
{
af::Backend result = (af::Backend)0;
diff --git a/src/api/unified/device.cpp b/src/api/unified/device.cpp
index fbd8e32..ed8e6a3 100644
--- a/src/api/unified/device.cpp
+++ b/src/api/unified/device.cpp
@@ -35,6 +35,12 @@ af_err af_get_backend_id(af_backend *result, const af_array in)
return CALL(result, in);
}
+af_err af_get_device_id(int *device, const af_array in)
+{
+ CHECK_ARRAYS(in);
+ return CALL(device, in);
+}
+
af_err af_get_active_backend(af_backend *result)
{
*result = unified::AFSymbolManager::getInstance().getActiveBackend();
diff --git a/test/array.cpp b/test/array.cpp
index 6c1f511..293b888 100644
--- a/test/array.cpp
+++ b/test/array.cpp
@@ -454,3 +454,34 @@ TEST(Device, unequal)
ASSERT_EQ(ptr, b.device<float>());
}
}
+
+TEST(DeviceId, Same)
+{
+ array a = randu(5,5);
+ ASSERT_EQ(getDevice(), getDeviceId(a));
+}
+
+TEST(DeviceId, Different)
+{
+ int ndevices = getDeviceCount();
+ if (ndevices < 2) return;
+
+ int id0 = getDevice();
+ int id1 = (id0 + 1) % ndevices;
+
+ array a = randu(5,5);
+ ASSERT_EQ(getDeviceId(a), id0);
+ setDevice(id1);
+
+ array b = randu(5,5);
+
+ ASSERT_EQ(getDeviceId(a), id0);
+ ASSERT_EQ(getDeviceId(b), id1);
+ ASSERT_NE(getDevice(), getDeviceId(a));
+ ASSERT_EQ(getDevice(), getDeviceId(b));
+
+ af_array c;
+ af_err err = af_matmul(&c, a.get(), b.get(), AF_MAT_NONE, AF_MAT_NONE);
+ ASSERT_EQ(err, AF_ERR_DEVICE);
+ setDevice(id0);
+}
--
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