pitch / spitch

Still trying to get the memory transfers down…

I have a 13x2 matrix of type double at the moment. cudaMallocPitch generates a linear array capable of holding this data, with padding. (pitch returns as 512). cudaMemcpy2DToArray should fill this array from what I understand.

double *u_dev;
double u[height][width];
size_t spitch, pitch;

cudaMallocPitch( (void**)&u_dev, &pitch, (width)*sizeof(double), height );
cudaMemcpy2DToArray( u_dev, 0, 0, u, spitch, (width)*sizeof(double), (height), cudaMemcpyHostToDevice);
kernel<<<>>>

Do i need to define spitch? or does the machine do that? I’m getting an invalidPitchValue error.

The pitch returned by cudaMallocPitch() is what you need to pass-on to cudaMemcpy2DToArray()…!!!

Thank you, and if youre still around…

Is it okay for me to define my device array ( double *u_dev ) as I have? I have seen it done as type double, type cudaArray, and type float. I now get an error because the arguement (*u_dev) is not of type cudaArray. Is it required that I define it as type cudaArray?

The array needs to be of type [font=“Courier New”]struct cudaArray[/font] as it is an opaque type that does not just consist of the element data.

Thanks for all the help.
Any idea why the cudaMemcpy2DToArray isnt working then? I have the code set to exit if i dont get returns of cudaSuccess. It exits at the cudaMemcpy2DToArray.

int main(void)
{

double u[height][width];
cudaArray *u_dev;
size_t pitch;

// Initialize u … not shown

 cudaMallocPitch( (void**)&u_dev, &pitch, (width)*sizeof(double), height);
 cudaMemcpy2DToArray( u_dev, 0, 0, u, pitch, (width)*sizeof(double), height, cudaMemcpyHostToDevice);

Sorry I didn’t look at your whole sample. cudaMallocPitch() returns a device pointer to a linear array, it does not allocate a cudaArray. And since it is on the device already, you can’t use cudaMemcpyHostToDevice in the cudaMemcpy2DToArray.

I think what you are looking for are cudaMallocArray() and cudaMemcpyToArray(…, cudaMemcpyHostToDevice). There is an example in the Programming GuideI believe, in the chapter about textures and surfaces.

I think that using cudaMemcpy2DToArray is okay here. I am filling the linear array created by mallocPitch with a my 2D array in u. Is that not correct?
It should copy my 2D array on the host side to a linear array on the device side. I’ve read that these functions provide the most efficient way to accomplish this memory transfer.

Thanks for the responses by the way I really appreciate it. The literature only gets me so far at the moment.

No. A cudaArray is not the same as a generic 2D array. I’m sure you don’t have a cudaArray on the host because its layout is opaque and not documented.