cudaMemcpy syntax

So I have not been able to get my 2d array to copy into GPU space. I have tried with mallocpitch and memcpy2Dtoarray, with no success. I have simplified to malloc and memcpy to try and get results. The memory management functions execute and return cudaSuccess, but the array on the GPU is all 0’s. I assume i have a syntax issue somewhere. Relevant code:

double u[L+3][steps+1];
double *u_dev;

 cudaMalloc((void**)&u_dev, (L+3)*(steps+1)*sizeof(double));

 cudaMemcpy(u_dev, u, (L+3)*(steps+1)*sizeof(double), cudaMemcpyHostToDevice);

I cut out the initialization of u, but it is just a triangular wave. I expect to see a linear array with the values from u placed in u_dev after the memcpy. Instead I get from cuda-gdb:

(cuda-gdb) p u_dev
$5 = (double *) 0x200100000

Ideas? Thanks.

How about looking at [font=“Courier New”]*u_dev[/font]? I don’t print out my device pointers very often, but I can’t immediately see why [font=“Courier New”]0x200100000[/font] could not be a valid one.

Here’s what *u_dev prints as:

(cuda-gdb) p *u_dev
$4 = 0

Am I wrong to expect a linear array?

And when I initialize u_dev as:

double *u_dev[L+3][steps+1];

I just get a 2d array of zeros. 2D is fine but i need it to be filled with the values in u.


You need to look at the memory from inside a kernel. As long as you are in host code, you see the contents of host memory at that address, which are unrelated.

Thank you. I’ll do that when I get the chance. Hardware issue at the moment.