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

finish hw08 #1

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

finish hw08 #1

wants to merge 2 commits into from

Conversation

bolin12
Copy link

@bolin12 bolin12 commented Jan 30, 2022

1.这是基于“边角料法”的,请把他改成基于“网格跨步循环”的:
应用于线程和板块一起上的情况,可以匹配任意板块和线程数量。
2.这里有什么问题?请改正:
+=操作会导致线程冲突,因此改用原子加。
3.改成“网格跨步循环”以后,这里三重尖括号里的参数如何调整?:
将板块数改为1,每个线程处理n/1024个元素。
4.这里的“边角料法”对于不是 1024 整数倍的 n 会出错,为什么?:
除法向下取整,因此最后不满blockdim的数据无法被处理。板块数量改为(n+ blockdim -1)/ blockdim即可
5.这里 CPU 访问数据前漏了一步什么操作?:
当前时刻线程未全部执行完成,因此需要做一次同步。

Copy link
Contributor

@archibate archibate left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

基本没问题!

@@ -31,13 +30,13 @@ int main() {
std::vector<int, CudaAllocator<int>> counter(1);

// fill_sin 改成“网格跨步循环”以后,这里三重尖括号里的参数如何调整?10 分
fill_sin<<<n / 1024, 1024>>>(arr.data(), n);
fill_sin<<<1, 1024>>>(arr.data(), n);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gridDim是不是太小了,可以改成 n / 8192之类的。

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

Successfully merging this pull request may close these issues.

2 participants