Problems with Memcpy

Hi,

I’m new to CUDA and to this board. I was able to memcpy a dozen times, but instantly memcpy does not work for this small code. Could anyone please help me to find out where an error is.

Thank you in advance.

Here’s the debugging code. I just want to copy an array to device and back. But somehow there is an error that in my second printout all of the F still remain 0;

mesh->numPoints = 15;

float *F = (float*)malloc(sizeof(float) * mesh->numPoints*3);

for(int i = 0;i<mesh->numPoints*3;i++){

	F[i]=1;

	printf("%.1f ",F[i]);

}

cudaMemcpy(mesh->F, F, sizeof(float) * mesh->numPoints*3, cudaMemcpyHostToDevice);

printf("\n\n F   ");

for(int i = 0;i<mesh->numPoints*3;i++){

	F[i]=0;

}

cudaMemcpy(F,mesh->F, mesh->numPoints * 3, cudaMemcpyDeviceToHost);

for(int i=0; i < mesh->numPoints*3; i++){

	printf(" %.1f",F[i]);

}

You need to check what poiters are host and what are device and do not mix them.

In the second memcpy you didn’t multiply by sizeof(float)