CUDA-Programming
CUDA-Programming copied to clipboard
书与GitHub代码不一致(及再勘误)
针对最新的勘误表核对了下2022年10月第5次印刷的书籍。 大部分已经该改正。除了以下几处。
- 书中Listing 12.4代码与现GitHub项目中的oversubscription2.cu代码差别较大,与之前CUDA-Programming-v1.0的代码也有出入。至少“size 应改为 size / sizeof(uint64_t)”改的不成功,改成了“size) / sizeof(uint64_t)”。至少是笔误了。
| 我自己 | 不安全的代码 | 第 143 页 | 程序中第 23 行核函数的第二个参数 size 应改为 size / sizeof(uint64_t)。我已修改本仓库中 对应的程序。 |
|---|
-
2022年10月第5次印刷的书中代码:
-
最新oversubscription2.cu代码:
int main(void)
{
for (int n = 1; n <= N; ++n)
{
const size_t memory_size = size_t(n) * 1024 * 1024 * 1024;
const size_t data_size = memory_size / sizeof(uint64_t);
uint64_t *x;
CHECK(cudaMallocManaged(&x, memory_size));
gpu_touch<<<(data_size - 1) / 1024 + 1, 1024>>>(x, data_size);
CHECK(cudaGetLastError());
CHECK(cudaDeviceSynchronize());
CHECK(cudaFree(x));
printf("Allocated %d GB unified memory with GPU touch.\n", n);
}
return 0;
}
- 老版本oversubscription2.cu代码:
int main(void)
{
for (int n = 1; n <= N; ++n)
{
const size_t size = size_t(n) * 1024 * 1024 * 1024;
uint64_t *x;
CHECK(cudaMallocManaged(&x, size));
gpu_touch<<<size / sizeof(uint64_t) / 1024, 1024>>>(x, size);
CHECK(cudaGetLastError());
CHECK(cudaDeviceSynchronize());
CHECK(cudaFree(x));
printf("Allocated %d GB unified memory with GPU touch.\n", n);
}
return 0;
}
- 核函数的笔误还没改。(虽然没啥影响)
| EverNorif | 笔误 | 第 34 页 | “调用该核函时” 应改为 “调用该核函数时”。 |
|---|
- 这个认知错误,2022年10月书中好像没看到说明。(或者转述了没看出来?)
| 静听风吟 | 认知错误 | 第 12 章 | 本章中关于统一内存的使用,错误地认为在使用第二代统一内存(在 Linux 系统中使用帕斯卡及以上架构的 GPU)的情况下,在调用核函数之后不需要进行主机与设备的同步即可 1)从主机访问任何统一内存数据;2)并总是得到正确的结果。以上论断中,1)是正确的,而 2)不正确,因为无论是使用第一代统一内存,还是使用第二代统一内存,在从主机访问被核函数修改的统一内存数据之前,都需要某种(显式的或隐式的)同步操作,才能避免读写竞争,从而保证结果的正确性。 |
|---|
谢谢,您发给我的邮件已经收到,我会尽快处理。Thank you,the email you sent me has been received and I will handle it as soon as possible.王景博fever wong