cudaMemcpy2D出错

时间:2011-01-27 18:10:56

标签: cuda


我试图复制从主机到设备的图像的RGB数据(假设每个都是int)。这是我的代码的一部分

 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*sizeof(int),img_height,cudaMemcpyHostToDevice);
     //I even tried with just img_redh above 
     //Similarly for green and blue

cudaMallocpitch工作正常但它在cudamemcpy2d行崩溃并打开host_runtime.h并指向

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

我觉得内存分配背后的逻辑很好。任何评论可能导致崩溃的原因是什么?

1 个答案:

答案 0 :(得分:1)

听起来你正在为img_redh的多维数组使用Iliffe向量。尝试使用常规多维数组(int* img_redh = (int*)malloc(img_width*img_height*sizeof(int)

相关问题