quick help with cudaMemcpy2D

I am new to cuda

I have read the definition of cudaMemcpy2D, but I do not quite get the following

If I want to tranfer an

int temp[max = 30][max = 50],

what should be my dpitch, spitch, width,and height,??

And also,

how do u call cudaMalloc in case of 2d arrays…

thanks, examples are more than welcome!!

You use the pitch that you get from the alloc function, and height / width depending on your data. I think there’s example code in the examples, search for cudaMemcpy2D in the sample projects.

can anyone write a small program showing how to right pitch function and how to access the values in the kernel function.

thanx in advance.

If you’re calculating the pitch manually, so you know the image is not padded, it is usually:

channels * width * sizeof ( pixel )

where pixel is the type you’re using to represent a pixel, uchar or float normally.

char* gpuBuf;

int temp [width][height];

cudaMalloc ( gpuBuf, width * height * sizeof(int) );

cudaMemcpy2D ( gpuBuf, width * sizeof(int), temp, width * sizeof(int), width, height, cudaMemcpyHostToDevice );

Should do it…