[python-arrayfire] 225/250: FEAT: Functions to allocate and free memory on host, device

Ghislain Vaillant ghisvail-guest at moszumanska.debian.org
Mon Mar 28 22:59:51 UTC 2016


This is an automated email from the git hooks/post-receive script.

ghisvail-guest pushed a commit to branch debian/master
in repository python-arrayfire.

commit 842e42713602e097ef422b13b5ffda210f32b2e4
Author: Pavan Yalamanchili <pavan at arrayfire.com>
Date:   Wed Mar 2 15:22:22 2016 -0500

    FEAT: Functions to allocate and free memory on host, device
---
 arrayfire/device.py | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 48 insertions(+)

diff --git a/arrayfire/device.py b/arrayfire/device.py
index cfdbb76..a33ba51 100644
--- a/arrayfire/device.py
+++ b/arrayfire/device.py
@@ -282,4 +282,52 @@ def unlock_array(a):
     """
     safe_call(backend.get().af_unlock_array(a.arr))
 
+def alloc_device(num_bytes):
+    """
+    Allocate a buffer on the device with specified number of bytes.
+    """
+    ptr = ct.c_void_p(0)
+    c_num_bytes = ct.c_longlong(num_bytes)
+    safe_call(backend.get().af_alloc_device(ct.pointer(ptr), c_num_bytes))
+    return ptr.value
+
+def alloc_host(num_bytes):
+    """
+    Allocate a buffer on the host with specified number of bytes.
+    """
+    ptr = ct.c_void_p(0)
+    c_num_bytes = ct.c_longlong(num_bytes)
+    safe_call(backend.get().af_alloc_host(ct.pointer(ptr), c_num_bytes))
+    return ptr.value
+
+def alloc_pinned(num_bytes):
+    """
+    Allocate a buffer on the host using pinned memory with specified number of bytes.
+    """
+    ptr = ct.c_void_p(0)
+    c_num_bytes = ct.c_longlong(num_bytes)
+    safe_call(backend.get().af_alloc_pinned(ct.pointer(ptr), c_num_bytes))
+    return ptr.value
+
+def free_device(ptr):
+    """
+    Free the device memory allocated by alloc_device
+    """
+    cptr = ct.c_void_p(ptr)
+    safe_call(backend.get().af_free_device(cptr))
+
+def free_host(ptr):
+    """
+    Free the host memory allocated by alloc_host
+    """
+    cptr = ct.c_void_p(ptr)
+    safe_call(backend.get().af_free_host(cptr))
+
+def free_pinned(ptr):
+    """
+    Free the pinned memory allocated by alloc_pinned
+    """
+    cptr = ct.c_void_p(ptr)
+    safe_call(backend.get().af_free_pinned(cptr))
+
 from .array import Array

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/python-arrayfire.git



More information about the debian-science-commits mailing list