CUDA的合作小组

时间:2017-11-07 12:15:37

标签: cuda

因为CUDA 9版本显然可以将不同的线程和块组合到同一组中,因此您可以一起管理它们。这对我来说非常有用,因为我需要启动一个包含几个块的内核并等到所有这些块同步(cudaThreadSynchronize()对我来说不值得,因为在线程同步后我必须继续在我的内核中工作)。

我想到的是将这些线程块包含在同一个组中,并等待所有这些线程同步,如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<i) val += temp[lane + i];
    g.sync(); // wait for all threads to load
}

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

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

每当我尝试使用 thread_group 时,编译器都会说它没有被删除。我正在使用 cooperative_groups.h 标题。

有谁知道如何处理这个问题?提前谢谢。

1 个答案:

答案 0 :(得分:1)

来自documentation

的引用
  

合作组需要CUDA 9.0或更高版本。使用Cooperative   组,包括头文件:

#include <cooperative_groups.h>
     

并使用Cooperative Groups命名空间:

using namespace cooperative_groups; 
     

然后包含任何代码   块内协作组功能可以在中编译   正常使用nvcc。

命名空间是你缺少的。