Can I use thrust::host_vector or I must use cudaHostAlloc for zero-copy with Thrust?
Question
I want to use zero-copy on mapped memory by cudaHostGetDevicePointer
. Can I use thrust::host_vector
or I must use cudaHostAlloc(...,cudaHostAllocMapped)?
Or is it somehow easier to do with Thrust?
Solution
I am pretty sure it still isn't possible to use a thrust::host_vector as a mapped host allocation. There is a pinned memory allocator, but I don't believe mapped memory is available. What you need to do is something like this:
- Allocated mapped, pinned host memory with
cudaHostAlloc
- Get the device pointer for the zero copy memory using
cudaHostGetDevicePointer
- Create a
thrust::device_ptr
usingthrust::device_pointer_cast
on that device pointer (see here for more information)
You can the either make a thrust::device_vector
using the thrust::device_ptr
or dirctly pass the thrust::device_ptr
to any algorithms which accept an iterator.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow