Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Github提供的代码与书本所示代码(p129)不一致 #22

Open
liwd190019 opened this issue Feb 12, 2023 · 2 comments
Open

Github提供的代码与书本所示代码(p129)不一致 #22

liwd190019 opened this issue Feb 12, 2023 · 2 comments

Comments

@liwd190019
Copy link

liwd190019 commented Feb 12, 2023

在本书的第129页,Listing 11.2 中列举了本章程序 kernel-kernel.cu 的部分内容。
Feishu20230212-213028
另外,在书本的第130页,第二段的末尾,您也说明,“为了计时方便,核函数中故意做了10^6次加法运算。”
但是,在Github相应的代码库中(CUDA-Programming/src/11-stream/kernel-kernel.cu),我们可以发现,其中的add函数仅仅增加了10^5次,也就是说,您展示于库中的代码,与书本展示的代码并不匹配。

void __global__ add(const real *d_x, const real *d_y, real *d_z)
{
    const int n = blockDim.x * blockIdx.x + threadIdx.x;
    if (n < N1)
    {
        for (int i = 0; i < 100000; ++i)
        {
            d_z[n] = d_x[n] + d_y[n];
        }
    }
}
@fever-Wong
Copy link

fever-Wong commented Feb 12, 2023 via email

@brucefan1983
Copy link
Owner

在本书的第129页,Listing 11.2 中列举了本章程序 kernel-kernel.cu 的部分内容。 Feishu20230212-213028 另外,在书本的第130页,第二段的末尾,您也说明,“为了计时方便,核函数中故意做了10^6次加法运算。” 但是,在Github相应的代码库中(CUDA-Programming/src/11-stream/kernel-kernel.cu),我们可以发现,其中的add函数仅仅增加了10^5次,也就是说,您展示于库中的代码,与书本展示的代码并不匹配。

void __global__ add(const real *d_x, const real *d_y, real *d_z)
{
    const int n = blockDim.x * blockIdx.x + threadIdx.x;
    if (n < N1)
    {
        for (int i = 0; i < 100000; ++i)
        {
            d_z[n] = d_x[n] + d_y[n];
        }
    }
}

多谢指出。这里我也记不清当初是如何犯错的了。也许是写书的时候多写了一个0,也许是一开始想用1000000次加法展示,后来测试的时候为了节约时间换成了100000。这个数字只要不太小,对此处的讨论不是很重要。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants