gpt4 book ai didi

cuda段错误

转载 作者:太空宇宙 更新时间:2023-11-04 06:41:30 25 4
gpt4 key购买 nike

我正在使用 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。 (以字节为单位)
  • Image_input 是 H*W。 (以字节为单位)

您正在处理超出其大小的 image_input。

关于cuda段错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7581791/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com