Alex
Alex

Reputation: 13136

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?

Upvotes: 7

Views: 1627

Answers (1)

talonmies
talonmies

Reputation: 72353

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.

Upvotes: 5

Related Questions