c-将字符映射从主机内存复制到CUDA中的设备



不知道如何将其从主机内存复制到设备内存,已经为此工作了一段时间,但没有取得任何进展,任何大大小小的帮助都将不胜感激。

 unsigned char map[256] = {
   8,0,2,0,0,0,0,0,0,0,2,0,2,0,0,0,
   0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,
   0,0,0,0,0,0,0,0,0,0,0,0,0,7,0,0,
   0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,
   0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,
   0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,
   0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
   0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
   0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
   0,2,0,0,0,1,0,0,0,0,0,0,0,1,0,0,
   0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
   0,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,
   0,1,1,1,0,0,0,0,0,0,0,0,3,0,0,0,
   0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
   0,0,0,1,0,0,0,5,0,0,0,3,0,0,0,0,
   0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
 };

它会和这个类似吗?

cudaMalloc(&d_n, sizeof(int));
  cudaMemcpy(d_n, &h_n, sizeof(int), cudaMemcpyHostToDevice);
  kernel <<<16,16>>>(d_n);
  cudaThreadSynchronize();
  cudaMemcpy(&h_n, d_n, sizeof(int), cudaMemcpyDeviceToHost);  
  cudaFree(d_n);

如果您的代码中存在segfault,这可能是由于以下错误造成的:

  1. 您正在使用sizeof(int)来复制一个无符号字符数组。

  2. h_n是您的名为"map"的数组吗?unsigned char[]是一个指针,您可以直接在cudaMemcpy方法中使用它。

    cudaMemcpy(d_n, map, 256 * sizeof(unsigned char), cudaMemcpyHostToDevice);

应该起作用。

相关内容

  • 没有找到相关文章

最新更新