2011-01-27 32 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)