我想使用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上得到了一个错误,它说:
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)任何人都可以帮忙,谢谢!
发布于 2014-10-05 12:41:47
我不太确定这是否是你犯错误的确切原因,但有一件事你做错了:
您正在为red_src分配大小为sizeof(unsigned char) * SOMETHING的内存
checkCudaErrors(cudaMalloc(&red_src, sizeof(unsigned char) * numRowsSource * numColsSource));当尝试使用sizeof(float) * SOMETHING大小访问它时
checkCudaErrors(cudaMemcpy(blendedValsRed_1, red_src, sizeof(float) * numRowsSource * numColsSource,cudaMemcpyDeviceToDevice));https://stackoverflow.com/questions/26202573
复制相似问题