[arrayfire] 69/284: FEAT added allocHost and freeHost functions
Ghislain Vaillant
ghisvail-guest at moszumanska.debian.org
Sun Feb 7 18:59:20 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 6b9c157bc3e8124b45146270789d48d13e0bba20
Author: Shehzan Mohammed <shehzan at arrayfire.com>
Date: Mon Dec 14 13:27:23 2015 -0500
FEAT added allocHost and freeHost functions
* Added corresponding C/unified API
* Documentation
---
docs/details/device.dox | 43 +++++++++++++++++++++++++++--
include/af/device.h | 68 ++++++++++++++++++++++++++++++++++++++--------
src/api/c/device.cpp | 18 ++++++++++++
src/api/cpp/device.cpp | 37 ++++++++++++++++++-------
src/api/unified/device.cpp | 10 +++++++
5 files changed, 152 insertions(+), 24 deletions(-)
diff --git a/docs/details/device.dox b/docs/details/device.dox
index 230199d..c89d2a1 100644
--- a/docs/details/device.dox
+++ b/docs/details/device.dox
@@ -62,6 +62,16 @@ allocation
===============================================================================
+\defgroup device_func_free free
+\ingroup device_mat
+
+\brief Free device memory allocated by ArrayFire's memory manager
+
+These calls free the device memory. These functions need to be called on
+pointers allocated using alloc function.
+
+===============================================================================
+
\defgroup device_func_pinned pinned
\ingroup device_mat
@@ -73,12 +83,39 @@ a limited resource.
===============================================================================
-\defgroup device_func_free free
+\defgroup device_func_free_pinned freePinned
\ingroup device_mat
-\brief Free device memory allocated by ArrayFire's memory manager
+\brief Free pinned memory allocated by ArrayFire's memory manager
+
+These calls free the pinned memory on host. These functions need to be called on
+pointers allocated using pinned function.
+
+===============================================================================
+
+\defgroup device_func_alloc_host allocHost
+\ingroup device_mat
+
+\brief Allocate memory on host
+
+This function is used for allocating regular memory on host. This is useful
+where the compiler version of ArrayFire library is different from the
+executable's compiler version.
+
+It does not use ArrayFire's memory manager.
+
+===============================================================================
+
+\defgroup device_func_free_host freeHost
+\ingroup device_mat
+
+\brief Free memory allocated on host internally by ArrayFire
+
+This function is used for freeing memory on host that was allocated within
+ArrayFire. This is useful where the compiler version of ArrayFire library is
+different from the executable's compiler version.
-These calls free the device or pinned memory. These functions need to be called
+It does not use ArrayFire's memory manager.
===============================================================================
diff --git a/include/af/device.h b/include/af/device.h
index 826863e..03800c3 100644
--- a/include/af/device.h
+++ b/include/af/device.h
@@ -101,6 +101,12 @@ namespace af
T* alloc(const size_t elements);
/// @}
+ /// \ingroup device_func_free
+ ///
+ /// \copydoc device_func_free
+ /// \param[in] ptr the memory to free
+ AFAPI void free(const void *ptr);
+
/// \ingroup device_func_pinned
/// @{
///
@@ -119,15 +125,45 @@ namespace af
T* pinned(const size_t elements);
/// @}
- /// \ingroup device_func_free
- /// @{
- /// \copydoc device_func_free
+ /// \ingroup device_func_free_pinned
+ ///
+ /// \copydoc device_func_free_pinned
/// \param[in] ptr the memory to free
- AFAPI void free(const void *ptr);
-
- /// \copydoc free()
AFAPI void freePinned(const void *ptr);
- ///@}
+
+ /// \brief Allocate memory on host
+ ///
+ /// \copydoc device_func_alloc_host
+ ///
+ /// \param[in] elements the number of elements to allocate
+ /// \param[in] type is the type of the elements to allocate
+ /// \returns the pointer to the memory
+ ///
+ /// \ingroup device_func_alloc_host
+ AFAPI void *allocHost(const size_t elements, const dtype type);
+
+ /// \brief Allocate memory on host
+ ///
+ /// \copydoc device_func_alloc_host
+ ///
+ /// \param[in] elements the number of elements to allocate
+ /// \returns the pointer to the memory
+ ///
+ /// \note the size of the memory allocated is the number of \p elements *
+ /// sizeof(type)
+ ///
+ /// \ingroup device_func_alloc_host
+ template<typename T>
+ AFAPI T* allocHost(const size_t elements);
+
+ /// \brief Free memory allocated internally by ArrayFire
+ //
+ /// \copydoc device_func_free_host
+ ///
+ /// \param[in] ptr the memory to free
+ ///
+ /// \ingroup device_func_free_host
+ AFAPI void freeHost(const void *ptr);
/// \ingroup device_func_mem
/// @{
@@ -207,14 +243,14 @@ extern "C" {
AFAPI af_err af_alloc_device(void **ptr, const dim_t bytes);
/**
- \ingroup device_func_pinned
+ \ingroup device_func_free
*/
- AFAPI af_err af_alloc_pinned(void **ptr, const dim_t bytes);
+ AFAPI af_err af_free_device(void *ptr);
/**
- \ingroup device_func_free
+ \ingroup device_func_pinned
*/
- AFAPI af_err af_free_device(void *ptr);
+ AFAPI af_err af_alloc_pinned(void **ptr, const dim_t bytes);
/**
\ingroup device_func_free_pinned
@@ -222,6 +258,16 @@ extern "C" {
AFAPI af_err af_free_pinned(void *ptr);
/**
+ \ingroup device_func_alloc_host
+ */
+ AFAPI af_err af_alloc_host(void **ptr, const dim_t bytes);
+
+ /**
+ \ingroup device_func_free_host
+ */
+ AFAPI af_err af_free_host(void *ptr);
+
+ /**
Create array from device memory
\ingroup construct_mat
*/
diff --git a/src/api/c/device.cpp b/src/api/c/device.cpp
index 28b4cc2..39ad217 100644
--- a/src/api/c/device.cpp
+++ b/src/api/c/device.cpp
@@ -297,6 +297,24 @@ af_err af_free_pinned(void *ptr)
return AF_SUCCESS;
}
+af_err af_alloc_host(void **ptr, const dim_t bytes)
+{
+ try {
+ AF_CHECK(af_init());
+ *ptr = malloc(bytes);
+ } CATCHALL;
+ return AF_SUCCESS;
+}
+
+af_err af_free_host(void *ptr)
+{
+ try {
+ AF_CHECK(af_init());
+ free(ptr);
+ } CATCHALL;
+ return AF_SUCCESS;
+}
+
af_err af_device_gc()
{
try {
diff --git a/src/api/cpp/device.cpp b/src/api/cpp/device.cpp
index bec0a60..622809e 100644
--- a/src/api/cpp/device.cpp
+++ b/src/api/cpp/device.cpp
@@ -140,6 +140,18 @@ namespace af
AF_THROW(af_free_pinned((void *)ptr));
}
+ void *allocHost(const size_t elements, const af::dtype type)
+ {
+ void *ptr;
+ AF_THROW(af_alloc_host(&ptr, elements * size_of(type)));
+ return ptr;
+ }
+
+ void freeHost(const void *ptr)
+ {
+ AF_THROW(af_free_host((void *)ptr));
+ }
+
void deviceGC()
{
AF_THROW(af_device_gc());
@@ -164,16 +176,21 @@ namespace af
return size_bytes;
}
-#define INSTANTIATE(T) \
- template<> AFAPI \
- T* alloc(const size_t elements) \
- { \
- return (T*)alloc(elements, (af::dtype)dtype_traits<T>::af_type); \
- } \
- template<> AFAPI \
- T* pinned(const size_t elements) \
- { \
- return (T*)pinned(elements, (af::dtype)dtype_traits<T>::af_type); \
+#define INSTANTIATE(T) \
+ template<> AFAPI \
+ T* alloc(const size_t elements) \
+ { \
+ return (T*)alloc(elements, (af::dtype)dtype_traits<T>::af_type); \
+ } \
+ template<> AFAPI \
+ T* pinned(const size_t elements) \
+ { \
+ return (T*)pinned(elements, (af::dtype)dtype_traits<T>::af_type); \
+ } \
+ template<> AFAPI \
+ T* allocHost(const size_t elements) \
+ { \
+ return (T*)allocHost(elements, (af::dtype)dtype_traits<T>::af_type);\
}
INSTANTIATE(float)
diff --git a/src/api/unified/device.cpp b/src/api/unified/device.cpp
index 43559a0..4f07788 100644
--- a/src/api/unified/device.cpp
+++ b/src/api/unified/device.cpp
@@ -95,6 +95,16 @@ af_err af_free_pinned(void *ptr)
return CALL(ptr);
}
+af_err af_alloc_host(void **ptr, const dim_t bytes)
+{
+ return CALL(ptr, bytes);
+}
+
+af_err af_free_host(void *ptr)
+{
+ return CALL(ptr);
+}
+
af_err af_device_array(af_array *arr, const void *data, const unsigned ndims, const dim_t * const dims, const af_dtype type)
{
return CALL(arr, data, ndims, dims, type);
--
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