2011-01-27 71 views
0


我试图复制的RGB数据(假设每个是一个int)从主机到device.Here图像的是我的代码部分误差cudaMemcpy2D

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); 
} 

我觉得后面的内存分配的逻辑是罚款。任何评论什么可能导致崩溃?

+0

img_redh [0]是否包含指向包含“img_width * img_height * sizeof(int)`连续字节的内存块的指针? – tkerwin 2011-01-27 18:30:23

回答

1

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