我正用C语言编写cuda。我的代码行出现了分段错误:
int width = 0;
int height = 0;
// load input image
unsigned char * image_input = loadFile(&width, &height, "test.bmp");
// allocate memory for output
unsigned char * image_output = (unsigned char *) malloc(width*height*sizeof(unsigned char));
// set the size of the input and out array 2D
int size = width*height*sizeof(int);
// Allocate space on the GPU for input and output
char* GPU_input = 0;
char* GPU_output = 0;
cudaMalloc(&GPU_input, size);
cudaMalloc(&GPU_output, size);
// Copy the input data to the GPU (host to device)
cudaMemcpy(GPU_input, image_input, size, cudaMemcpyHostToDevice); //segmentation fault here
有什么想法吗?
提前致谢。
答案 0 :(得分:4)
您正在处理超出其大小的image_input。