sách gpt4 ai đã đi

cuda - CUDA 中的协作组

In lại 作者:行者123 更新时间:2023-12-05 05:18:51 37 4
mua khóa gpt4 Nike

自从 CUDA 9 发布以来,显然可以将不同的线程和 block 分组到同一组中,以便您可以一起管理它们。这对我来说非常有用,因为我需要启动一个包含多个 block 的内核并等待所有 block 都同步(cudaThreadSynchronize() 对我来说不值得,因为线程同步后我必须继续在我的内核中工作)。

我的想法是将这些线程 block 包含在同一个组中,并等待所有线程都同步,如 Nvdia 主页示例所示。

他们做这样的事情:

__device__ int reduce_sum(thread_group g, int *temp, int val)
{
int lane = g.thread_rank();

// Each iteration halves the number of active threads
// Each thread adds its partial sum[i] to sum[lane+i]
for (int i = g.size() / 2; i > 0; i /= 2)
{
temp[lane] = val;
g.sync(); // wait for all threads to store
if(lane
g.sync(); // wait for all threads to load
}

我的问题是如何将这些 block 分组到 g 组中。这就是我最初启动内核的方式:

asap << <5, 1000 >> > (cuda_E2, cuda_A2, cuda_temp, Nb, *binM, Nspb);

每当我尝试使用 thread_group 时,编译器都会说它是未定义的。我正在使用 cooperative_groups.h header 。

有人知道怎么处理吗?提前致谢。

1 Câu trả lời

引自tài liệu :

Cooperative Groups requires CUDA 9.0 or later. To use Cooperative Groups, include the header file:

#include 

and use the Cooperative Groups namespace:

using namespace cooperative_groups; 

Then code containing any intra-block Cooperative Groups functionality can be compiled in the normal way using nvcc.

命名空间是您所缺少的。

关于cuda - CUDA 中的协作组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47157759/

37 4 0
Bài viết được đề xuất: c# - Zedgraph FillType.GradientByY 固体
Bài viết được đề xuất: postman - Newman 不使用环境变量
Bài viết được đề xuất: laravel - 预加载三向数据透视表 Laravel
Bài viết được đề xuất: c# - 如何使用元数据创建 png 文件
行者123
Hồ sơ cá nhân

Tôi là một lập trình viên xuất sắc, rất giỏi!

Nhận phiếu giảm giá Didi Taxi miễn phí
Mã giảm giá Didi Taxi
Giấy chứng nhận ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com