¿Puedo usar __syncthreads () después de haber soltado hilos?
¿Es seguro usar__syncthreads()
en un bloque donde he dejado caer hilos a propósito usandoreturn
?
La documentación indica que__syncthreads()
debe ser llamado por cada hilo en el bloque o de lo contrario conducirá a un punto muerto, pero en la práctica nunca he experimentado tal comportamiento.
Código de muestra
__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?
}