我可以使用thrust::host_vector还是我必须使用cudahostalloc进行带有Thrust的零拷贝?

StackOverflow https://stackoverflow.com//questions/11692326

  •  12-12-2019
  •  | 
  •  

我想通过以下方式在映射内存上使用零拷贝 cudaHostGetDevicePointer.我可以使用吗 thrust::host_vector 或者我必须使用 cudaHostAlloc(...,cudaHostAllocMapped)? 还是用推力更容易?

有帮助吗?

解决方案

我很确定仍然无法使用thrust::host_vector作为映射的主机分配。有一个固定的内存分配器,但我不相信映射内存可用。你需要做的是这样的事情:

  1. 分配映射的、固定的主机内存 cudaHostAlloc
  2. 获取零副本内存的设备指针使用 cudaHostGetDevicePointer
  3. 创建一个 thrust::device_ptr 使用 thrust::device_pointer_cast 在该设备指针(请参阅 这里 有关更多资料)

你可以做一个 thrust::device_vector 使用 thrust::device_ptr 或绕过 thrust::device_ptr 到任何接受迭代器的算法。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top