相关疑难解决方法(0)

删除线程后可以使用__syncthreads()吗?

__syncthreads()在我有意使用线程丢弃的块中使用是否安全return

文档说明__syncthreads() 必须由块中的每个线程调用,否则它将导致死锁,但实际上我从未经历过这样的行为.

示例代码:

__global__ void kernel(float* data, size_t size) {
    // Drop excess threads if user put too many in kernel call.
    // After the return, there are `size` active threads.
    if (threadIdx.x >= size) {
        return;
    }

    // ... do some work ...

    __syncthreads(); // Is this safe?

    // For the rest of the kernel, we need to drop one excess thread
    // After the return, there are `size - 1` active threads …
Run Code Online (Sandbox Code Playgroud)

synchronization cuda

35
推荐指数
2
解决办法
5974
查看次数

标签 统计

cuda ×1

synchronization ×1