简体   繁体   English

如何cudaMemcpy由指向设备数组的指针数组指向的主机值Cuda

[英]How to cudaMemcpy host values pointed by an array of pointers to a device array Cuda

I am trying to find a way, if it is possible, to copy the values that are pointed by a host array of pointers pts that points to some elements of another host array s ( float2 type). 我试图找到一种方法,如果可能的话,复制指向另一个主机数组sfloat2类型)的某些指针的指针pts主机数组所指向的值。 The values that need to be dereferenced from pts with the -> operator are in random positions in the s array. 需要使用->运算符从pts解引用的值位于s数组中的随机位置。

Is there a way to copy these values pointed by pts without having to use an intermediate host buffer to write the values in it before using cudaMemcpy ? 有没有一种方法可以复制pts指向的这些值,而不必在使用cudaMemcpy之前使用中间主机缓冲区在其中写入值? I only came up with a for loop copying one element at a time but isnt this redundant? 我只想出了一次for循环,一次复制一个元素,但这不是多余的吗? I use cuda 5.5 Thanks. 我用cuda 5.5谢谢。

If the values you want to copy are in random locations, and you want to copy only those values to the device, you will need to write a separate loop in host code that aggregates those values first into a single contiguous buffer. 如果要复制的值位于随机位置,并且仅要将这些值复制到设备,则需要在主机代码中编写一个单独的循环,该循环首先将这些值聚合到单个连续的缓冲区中。

You can then copy that buffer using an ordinary approach like cudaMemcpy . 然后,您可以使用cudaMemcpy类的普通方法复制该缓冲区。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM