Hello. Is it safe to have threads that map outside some array return on a conditional, for example, is it safe to do
int tid = threadIdx.x + blockDim.x * blockIdx.x;
if (tid >= size) return;
// do some useful job
instead of
int tid = threadIdx.x + blockDim.x * blockIdx.x;
if (tid < size)
{
// do some useful job
}
How about __syncthreads()? It is unsafe to do a block synchronization point inside a conditional for which some threads of a same block will return false, what happens if we do a block sync after we have some threads of the block return, for example
int tid = threadIdx.x + blockDim.x * blockIdx.x;
if (tid >= size) return;
// do some useful job
__syncthreads();
// do some other useful job
Is this unsafe? What about multiple sync points after the return?
Thanks in advance.