我可以使用thrust::host_vector还是我必须使用cudahostalloc进行带有Thrust的零拷贝?
题
我想通过以下方式在映射内存上使用零拷贝 cudaHostGetDevicePointer
.我可以使用吗 thrust::host_vector
或者我必须使用 cudaHostAlloc(...,cudaHostAllocMapped)?
还是用推力更容易?
解决方案
我很确定仍然无法使用thrust::host_vector作为映射的主机分配。有一个固定的内存分配器,但我不相信映射内存可用。你需要做的是这样的事情:
- 分配映射的、固定的主机内存
cudaHostAlloc
- 获取零副本内存的设备指针使用
cudaHostGetDevicePointer
- 创建一个
thrust::device_ptr
使用thrust::device_pointer_cast
在该设备指针(请参阅 这里 有关更多资料)
你可以做一个 thrust::device_vector
使用 thrust::device_ptr
或绕过 thrust::device_ptr
到任何接受迭代器的算法。
不隶属于 StackOverflow