开发者

Error with cudaMemcpy2D

I am trying to copy the RGB data(assuming each is an int) of an image from the host to the device.Here is portion of my code

 int *img_redd,*img_greend,*img_blued;//d denotes device
 int **img_redh,**img_greenh,**img_blueh;// h denotes host 


     //Initialize+ copy values into the arrays pointed by img_redh,img_greenh etc   
     // then Copy the values of RGB into host array <here>
     //Allocating memory on device below
     cudaMallocPitch((void**)&img_redd,&pitch1,img_width*sizeof(int),img_height);
     cudaMallocPitch((void**)&img_greend,&pitch2,img_width*sizeof(int),img_height);
     cudaMallocPitch((void**)&img_blued,&pitch3,img_width*sizeof(int),img_height);
     // copy it to CUDA device   
     cudaMemcpy2D(img_redd,pitch1,img_redh[0],img_width*sizeof(int),img_width*s开发者_运维百科izeof(int),img_height,cudaMemcpyHostToDevice);
     //I even tried with just img_redh above 
     //Similarly for green and blue

The cudaMallocpitch works fine but it crashes on the cudamemcpy2d line and opens up host_runtime.h and points to

static void __cudaUnregisterBinaryUtil(void)
{
  __cudaUnregisterFatBinary(__cudaFatCubinHandle);
}

I feel that the logic behind memory allocation is fine .Any comments what might be causing the crash?


It sounds like you're using a Iliffe vector for a multidimensional array for img_redh. Try using a regular multidimensional array (int* img_redh = (int*)malloc(img_width*img_height*sizeof(int))

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜