Unfortunately we have not built in this capability into ArrayFire since we did a direct port of ArrayFire rather than take advantage of this feature.

The first step would be to allocate host data using array::pinned function (http://www.sandbox.arrayfire.com/docs/group__array__func__cpp__pinned.htm). This function calls cudaHostAlloc internally.

You can then fetch the device pointer using cudaHostGetDevicePointer as shown in the code. Then pass the device pointer to array a(size, dev_ptr, af::device);.



The problem here would be that there is no way to stop ArrayFire from deleting the device memory when the array goes out of scope, this may lead to errors since CUDA does not like the device pointer being freed using cudaFree.


To free the host memory, use the array::free function as shown in the documentation for array::pinned.


I haven't tested this out. But if you would like to, let me know how it goes.