cuda分段故障

cuda分段故障,c,cuda,C,Cuda,我正在用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(wi

我正在用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
有什么想法吗

提前感谢。

  • 大小为sizeof(int)*H*W(以字节为单位)
  • 图像输入为H*W(以字节为单位)
您正在寻址超出其大小的图像输入。

  • 大小为sizeof(int)*H*W(以字节为单位)
  • 图像输入为H*W(以字节为单位)

您正在处理超出其大小的图像输入。

您好,wildplasser,我应该更改什么?我不清楚。谢谢我不知道你打算做什么。有两种类型的数组:一种由字符组成,另一种由整数组成。我不知道你的CUDA想要什么。(但我怀疑ints)是的,这是一个错误。我把它改成(字符)大小。解决了这个问题。谢谢嗨,wildplasser,我该换什么?我不清楚。谢谢我不知道你打算做什么。有两种类型的数组:一种由字符组成,另一种由整数组成。我不知道你的CUDA想要什么。(但我怀疑ints)是的,这是一个错误。我把它改成(字符)大小。解决了这个问题。谢谢