Posso usar __syncthreads () depois de descartar tópico
É seguro usar__syncthreads()
em um bloco em que eliminei propositalmente threads usandoreturn
?
A documentação afirma que__syncthreads()
deve ser chamado por cada thread no bloco ou isso levará a um impasse, mas na prática nunca experimentei esse comportamento.
Código de amostra
__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
if (threadIdx.x + 1 == size) {
return;
}
// ... do more work ...
__syncthreads(); // Is this safe?
}