Does __syncthreads() synchronize all threads in the grid?

前端 未结 5 1054
栀梦
栀梦 2021-02-02 05:43

...or just the threads in the current warp or block?

Also, when the threads in a particular block encounter (in the kernel) the following line

__shared__         


        
5条回答
  •  独厮守ぢ
    2021-02-02 06:27

    Existing answers have done a great job answering how __syncthreads() works (it allows intra-block synchronization), I just wanted to add an update that there are now newer methods for inter-block synchronization. Since CUDA 9.0, "Cooperative Groups" have been introduced, which allow synchronizing an entire grid of blocks (as explained in the Cuda Programming Guide). This achieves the same functionality as launching a new kernel (as mentioned above), but can usually do so with lower overhead and make your code more readable.

提交回复
热议问题