brucefan1983 / CUDA-Programming

Sample codes for my CUDA programming book
GNU General Public License v3.0
1.51k stars 316 forks source link

4.1.1节运行结果似乎有问题 #30

Open liu-chunzhang opened 3 months ago

liu-chunzhang commented 3 months ago

我将该仓库中的check1api.cu及error.cuh代码直接拷贝在ubuntu 22.04 LTS的VS code中并保存在同一文件夹下,后用命令nvcc check1api.cu,编译结果是no error。GPU是GeForce RTX 4090。不知道具体原因为何,希望查看解答一下。

fever-Wong commented 3 months ago

谢谢,您发给我的邮件已经收到,我会尽快处理。Thank you,the email you sent me has been received and I will handle it as soon as possible.王景博fever wong

brucefan1983 commented 3 months ago

你说的 “编译结果是no error” 指的是编译还是运行?能否截图说明具体情况?

liu-chunzhang commented 3 months ago

是编译运行后的结果。我用的操作系统为Ubuntu 22.04 LTS,显卡为GeForce RTX 4090(计算能力8.9),当前CUDA版本12.5。 之后我又做了些测试,结果可以简单概括为拷贝实际方向只和cudaMemcpy的前两个参数有关系,和第四个参数cudaMemcpyKind的具体取值无关。 现在我推测,应该是在Linux系统下,采用了CUDA 6.x及之后版本统一内存特性(windows OS下,即使计算能力达到了6.x及更高,也强制限制为6.x以下,只能使用基本的统一内存特性)后,设备不区分显存和内存(自然,CPU部内存和GPU部显存也没必要分清楚,那么H2D还是D2H都没啥区分意义),cudaMemcpy指定第四个参数就没用了(此时个人觉得一律默认default就好)。