[arrayfire] 198/284: Adding lock to memory allocated using af_alloc_device / af::alloc
Ghislain Vaillant
ghisvail-guest at moszumanska.debian.org
Sun Feb 7 18:59:33 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 d75b899d2e4dc88607fe69bbcdfdebf20a764765
Author: Pavan Yalamanchili <pavan at arrayfire.com>
Date: Mon Jan 11 14:16:55 2016 -0500
Adding lock to memory allocated using af_alloc_device / af::alloc
---
include/af/array.h | 4 +++-
include/af/device.h | 10 ++++++++++
src/api/c/device.cpp | 1 +
3 files changed, 14 insertions(+), 1 deletion(-)
diff --git a/include/af/array.h b/include/af/array.h
index 03f3eeb..de746d9 100644
--- a/include/af/array.h
+++ b/include/af/array.h
@@ -672,6 +672,8 @@ namespace af
Get the device pointer from the array and lock the buffer in memory manager.
@{
+ The device memory returned by this function is not freed until unlock() is called.
+
\ingroup arrayfire_func
\ingroup device_mat
*/
@@ -961,7 +963,7 @@ namespace af
/// \brief Locks the device buffer in the memory manager.
///
/// This method can be called to take control of the device pointer from the memory manager.
- /// While a buffer is locked, the memory manager does not free the memory.
+ /// While a buffer is locked, the memory manager doesn't free the memory until unlock() is invoked.
void lock() const;
///
diff --git a/include/af/device.h b/include/af/device.h
index 4a3006f..2883067 100644
--- a/include/af/device.h
+++ b/include/af/device.h
@@ -108,6 +108,8 @@ namespace af
/// \param[in] type is the type of the elements to allocate
/// \returns the pointer to the memory
///
+ /// \note The device memory returned by this function is only freed if af::free() is called explicitly
+
AFAPI void *alloc(const size_t elements, const dtype type);
/// \brief Allocates memory using ArrayFire's memory manager
@@ -118,6 +120,8 @@ namespace af
///
/// \note the size of the memory allocated is the number of \p elements *
/// sizeof(type)
+ ///
+ /// \note The device memory returned by this function is only freed if af::free() is called explicitly
template<typename T>
T* alloc(const size_t elements);
/// @}
@@ -126,6 +130,8 @@ namespace af
///
/// \copydoc device_func_free
/// \param[in] ptr the memory to free
+ ///
+ /// This function will free a device pointer even if it has been previously locked.
AFAPI void free(const void *ptr);
/// \ingroup device_func_pinned
@@ -292,11 +298,15 @@ extern "C" {
/**
\ingroup device_func_alloc
+
+ This device memory returned by this function can only be freed using af_free_device
*/
AFAPI af_err af_alloc_device(void **ptr, const dim_t bytes);
/**
\ingroup device_func_free
+
+ This function will free a device pointer even if it has been previously locked.
*/
AFAPI af_err af_free_device(void *ptr);
diff --git a/src/api/c/device.cpp b/src/api/c/device.cpp
index c37e293..24a8ad5 100644
--- a/src/api/c/device.cpp
+++ b/src/api/c/device.cpp
@@ -298,6 +298,7 @@ af_err af_alloc_device(void **ptr, const dim_t bytes)
try {
AF_CHECK(af_init());
*ptr = (void *)memAlloc<char>(bytes);
+ memLock<char>((const char *)*ptr);
} CATCHALL;
return AF_SUCCESS;
}
--
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