使用指针从 GPU 中使用 pyCuda 复制数组

Copying arrays with pyCuda from the GPU using pointers

我正在通过 pycuda 复制 GPU 上的一些数组,然后存储指向这些数组的指针。如何恢复数据?

dist = np.zeros(numPoints).astype(np.float32) distAddress = [gpuarray.to_gpu(dist).ptr for i in range(100)]

如果我调用 memcpy_dtoh 函数:

buf = np.zeros(400).astype(np.float32) cuda.memcpy_dtoh(buf,distAddress[0]),(其中 type(distAddress[0])long)我收到以下错误:

cuda.memcpy_dtoh(buf, distAddress[0]) LogicError: cuMemcpyDtoH failed: invalid argument

我做错了什么?

谢谢!

我认为如果您使用 GPUArrays 从设备复制到主机的方法是使用 .get() 方法。例如

dist = np.zeros(num_points).astype(np.float32)
dist_list = [gpuarray.to_gpu(dist) for i in range(100)]

buf = dist_list[0].get()