|
1 | 1 | use super::defines::AfError;
|
2 | 2 | use super::error::HANDLE_ERROR;
|
3 |
| -use super::util::free_host; |
| 3 | +use super::util::{dim_t, free_host, void_ptr}; |
4 | 4 |
|
5 | 5 | use libc::{c_char, c_int, size_t};
|
6 | 6 | use std::borrow::Cow;
|
@@ -33,6 +33,9 @@ extern "C" {
|
33 | 33 | fn af_get_mem_step_size(step_bytes: *mut size_t) -> c_int;
|
34 | 34 | fn af_device_gc() -> c_int;
|
35 | 35 | fn af_sync(device: c_int) -> c_int;
|
| 36 | + |
| 37 | + fn af_alloc_pinned(non_pagable_ptr: *mut void_ptr, bytes: dim_t) -> c_int; |
| 38 | + fn af_free_pinned(non_pagable_ptr: void_ptr) -> c_int; |
36 | 39 | }
|
37 | 40 |
|
38 | 41 | /// Get ArrayFire Version Number
|
@@ -314,3 +317,17 @@ pub fn sync(device: i32) {
|
314 | 317 | HANDLE_ERROR(AfError::from(err_val));
|
315 | 318 | }
|
316 | 319 | }
|
| 320 | + |
| 321 | +/// Allocate non-pageable memory on HOST memory |
| 322 | +pub unsafe fn alloc_pinned(bytes: usize) -> void_ptr { |
| 323 | + let mut out: void_ptr = std::ptr::null_mut(); |
| 324 | + let err_val = af_alloc_pinned(&mut out as *mut void_ptr, bytes as dim_t); |
| 325 | + HANDLE_ERROR(AfError::from(err_val)); |
| 326 | + out |
| 327 | +} |
| 328 | + |
| 329 | +/// Free the pointer returned by [alloc_pinned](./fn.alloc_pinned.html) |
| 330 | +pub unsafe fn free_pinned(ptr: void_ptr) { |
| 331 | + let err_val = af_free_pinned(ptr); |
| 332 | + HANDLE_ERROR(AfError::from(err_val)); |
| 333 | +} |
0 commit comments