Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I use thrust::host_vector or I must use cudaHostAlloc for zero-copy with Thrust?

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?

like image 473
Alex Avatar asked Jul 27 '12 16:07

Alex


1 Answers

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:

  1. Allocated mapped, pinned host memory with cudaHostAlloc
  2. Get the device pointer for the zero copy memory using cudaHostGetDevicePointer
  3. Create a thrust::device_ptr using thrust::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.

like image 73
talonmies Avatar answered Oct 28 '22 21:10

talonmies