ошибка сегментации CUDA - PullRequest
       5

ошибка сегментации CUDA

0 голосов
/ 28 сентября 2011

Я программирую с помощью cuda на C. Я получил ошибку сегментации со следующими строками кода:

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

Есть идеи?

Заранее спасибо.

1 Ответ

4 голосов
/ 28 сентября 2011
  • Размер - sizeof (int) * H * W.(в байтах)
  • Вход изображения: H * W.(в байтах)

Вы обращаетесь к image_input сверх его размера.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...