gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 19:12:49 26 4
gpt4 key购买 nike

不确定如何将其从主机内存复制到设备内存,已经研究了一段时间但没有取得任何进展,任何大大小小的帮助将不胜感激。

 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);

最佳答案

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

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

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

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

应该可以。

关于将字符映射表从主机内存复制到 CUDA 中的设备,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36425733/

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