c++ - block 的某些线程到达 __syncthreads() 而其中一些不到达是否重要?

标签 c++ cuda synchronization

<分区>

问题很简单, block 中的某些线程到达 __syncthreads() 而其中一些不到达是否重要?采取以下代码。

for (unsigned int s=blockDim.x/2; s>0; s>>=1) {
    if (tid < s) {
        sdata[tid] += sdata[tid + s];
    } else {
       break;
    }
    __syncthreads();
}

它会造成一些僵局或其他问题吗?我应该在 for 之后加上 __syncthreads() 还是这样好?

最佳答案

这是未定义的行为:

__syncthreads() is allowed in conditional code but only if the conditional evaluates identically across the entire thread block, otherwise the code execution is likely to hang or produce unintended side effects.

阅读更多信息:http://docs.nvidia.com/cuda/cuda-c-programming-guide/index.html

关于c++ - block 的某些线程到达 __syncthreads() 而其中一些不到达是否重要?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26205750/

相关文章:

c++ - 从文件 C++ 中读取一个单词的类

c# - 将状态更新从 C++ 中的函数发送到 C#

cuda - GPU 2D共享内存动态分配

CUDA 启动时请求的资源太多

java - 要同步哪些对象?为什么局部变量不好?

c++ - omp 单模拟通过 c++11

c++ - 如何在Qt中实现倒计时锁存器?

c++ - cilk reduce 是如何完成的(thread vs smid)

c++ - 在 Bullet Physics 中替代刚体模拟?

cuda - CUDA 流问题