File tree Expand file tree Collapse file tree 1 file changed +48
-0
lines changed Expand file tree Collapse file tree 1 file changed +48
-0
lines changed Original file line number Diff line number Diff line change @@ -282,4 +282,52 @@ def unlock_array(a):
282
282
"""
283
283
safe_call (backend .get ().af_unlock_array (a .arr ))
284
284
285
+ def alloc_device (num_bytes ):
286
+ """
287
+ Allocate a buffer on the device with specified number of bytes.
288
+ """
289
+ ptr = ct .c_void_p (0 )
290
+ c_num_bytes = ct .c_longlong (num_bytes )
291
+ safe_call (backend .get ().af_alloc_device (ct .pointer (ptr ), c_num_bytes ))
292
+ return ptr .value
293
+
294
+ def alloc_host (num_bytes ):
295
+ """
296
+ Allocate a buffer on the host with specified number of bytes.
297
+ """
298
+ ptr = ct .c_void_p (0 )
299
+ c_num_bytes = ct .c_longlong (num_bytes )
300
+ safe_call (backend .get ().af_alloc_host (ct .pointer (ptr ), c_num_bytes ))
301
+ return ptr .value
302
+
303
+ def alloc_pinned (num_bytes ):
304
+ """
305
+ Allocate a buffer on the host using pinned memory with specified number of bytes.
306
+ """
307
+ ptr = ct .c_void_p (0 )
308
+ c_num_bytes = ct .c_longlong (num_bytes )
309
+ safe_call (backend .get ().af_alloc_pinned (ct .pointer (ptr ), c_num_bytes ))
310
+ return ptr .value
311
+
312
+ def free_device (ptr ):
313
+ """
314
+ Free the device memory allocated by alloc_device
315
+ """
316
+ cptr = ct .c_void_p (ptr )
317
+ safe_call (backend .get ().af_free_device (cptr ))
318
+
319
+ def free_host (ptr ):
320
+ """
321
+ Free the host memory allocated by alloc_host
322
+ """
323
+ cptr = ct .c_void_p (ptr )
324
+ safe_call (backend .get ().af_free_host (cptr ))
325
+
326
+ def free_pinned (ptr ):
327
+ """
328
+ Free the pinned memory allocated by alloc_pinned
329
+ """
330
+ cptr = ct .c_void_p (ptr )
331
+ safe_call (backend .get ().af_free_pinned (cptr ))
332
+
285
333
from .array import Array
You can’t perform that action at this time.
0 commit comments