2014-10-05 1 views
0

에 방어 적이기 장치, 여기에 내 코드내가 cudaMemcpy를 사용하여 장치 메모리에 데이터를 복사 할 장치 오류

unsigned char* red_src ; 
unsigned char* blue_src ; 
unsigned char* green_src; 

checkCudaErrors(cudaMalloc(&red_src, sizeof(unsigned char) * numRowsSource * numColsSource)); 
checkCudaErrors(cudaMalloc(&blue_src, sizeof(unsigned char) * numRowsSource * numColsSource)); 
checkCudaErrors(cudaMalloc(&green_src, sizeof(unsigned char) * numRowsSource * numColsSource)); 

//bla bla .......... 

//initialization 
compute_g<<<grid, block>>>(red_src, strictInteriorPixels,g_red, numRowsSource, numColsSource); 
compute_g<<<grid, block>>>(blue_src, strictInteriorPixels,g_blue, numRowsSource, numColsSource); 
compute_g<<<grid, block>>>(green_src, strictInteriorPixels,g_green, numRowsSource, numColsSource); 

float *blendedValsRed_1 ; 
float *blendedValsRed_2 ; 

//set memory 
checkCudaErrors(cudaMalloc(&blendedValsRed_1, sizeof(float) * numRowsSource * numColsSource)); 
checkCudaErrors(cudaMalloc(&blendedValsRed_2, sizeof(float) * numRowsSource * numColsSource)); 

checkCudaErrors(cudaMemcpy(blendedValsRed_1, red_src, sizeof(float) * numRowsSource * numColsSource,cudaMemcpyDeviceToDevice)); 
checkCudaErrors(cudaMemcpy(blendedValsRed_2, red_src, sizeof(float) * numRowsSource * numColsSource,cudaMemcpyDeviceToDevice)); 

는 컴파일,하지만 난 그것을 실행하려고 할 때 cudaMemcpy에 오류가있어 CUDA, 그 말 :

tintin ~/programming/cs344/Problem Sets/Problem Set 6 $ optirun ./HW6 source.png  destination.png 
CUDA error at: student_func.cu:365 
invalid argument cudaMemcpy(blendedValsRed_1, red_src, sizeof(float) * numRowsSource * numColsSource,cudaMemcpyDeviceToDevice) 

누구나 도움, 고마워!

답변

4

I 해요이이 오류의 정확한 이유이지만, 여기 당신이 잘못하고있는 한 가지 경우 매우 확실하지 : 당신은 sizeof(unsigned char) * SOMETHING의 크기 red_src에 대한 메모리를 할당하고

:

checkCudaErrors(cudaMemcpy(blendedValsRed_1, red_src, sizeof(float) * numRowsSource * numColsSource,cudaMemcpyDeviceToDevice)); 
:
checkCudaErrors(cudaMalloc(&red_src, sizeof(unsigned char) * numRowsSource * numColsSource)); 

sizeof(float) * SOMETHING의 크기에 액세스하는 동안