Copying from array to array *on* the device

Hi all,

I have a pointer to an array that is a member of a struct on the device.

struct __align__(16) Example{

	float *something;

		size_t something_size;

}

I am passing in another global memory pointer in to a kernel, and wish to copy everything in the struct array to this incoming array. Right now I am using a for loop, but there must be a better way to do this. Can anyone help with ideas?

I can not use cudaMemcpyDeviceToDevice on the host, because somehow it doesn’t work when one array is a struct member.

Current Code:

__global__ void copy (Example *myexample, float *copytoThis){

if (some condition) {

	  for (int i=0; i< (myexample->something_size); i++)

		copytoThis[i] = myexample->something[i];

  }

}

Thanks in advance!

I have the exact same issue. Were you able to find a better way to do this than a loop? Thanks!

May I ask a question? Does compiler optimize your loop to get better performance? Does such loop lower the performance?

Thanks.