cuda segmentation fault
I am programming with cuda in C. I got a segmentation fault with the code l开发者_StackOverflow中文版ines following:
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
Any idea?
Thanks in advance.
- Size is sizeof(int) *H*W. (in bytes)
- Image_input is H*W. (in bytes)
You are addressing image_input beyond its size.
精彩评论