Memcpy2D error?

Hello,

I’ve got a problem with Memcpy2D.

devPtr = picture in global memory width=512 height=512 srcpitch=8192 (float4-data)

   int dstpitch = width*sizeof(float4);

    void* dst = malloc(dstpitch*height);

    cudaMemcpy2D ( dst,dstpitch,devPtr,srcpitch,width,height,cudaMemcpyDeviceToHost);

The problem is that only 32pixel of every line is copied.

If I use

cudaMemcpy(dst,devPtr,width*height*sizeof(float4),cudaMemcpyDeviceToHost)

instead it works. But Memcpy doesn’t care about pitch and I don’t want to use it.

Am I doing anything wrong here?

regards

Pototschnig

You still need to specify the width in bytes, ie. row_width = width*sizeof(float4), which happens to be the value of dstpitch as well in this case. The correct code would hence be:

   size_t dstpitch = width*sizeof(float4);

    size_t row_width = width*sizeof(float4);

    void* dst = malloc(dstpitch*height);

    cudaMemcpy2D(dst, dstpitch, devPtr, srcpitch, row_width, height, cudaMemcpyDeviceToHost);

HTH.

Uuups … your are right … how can cuda know that one pixel of my data are 16bytes …

regards

Pototschnig