Divergence in CUDA - exit from a thread in the core

I am wondering how I can exit a thread whose thread index is large. I see two possibilities:

int i = threadIdx.x;
if(i >= count)
    return;
// do logic

or

int i = threadIdx.x;
if(i < count) {
    // do logic
}

I know that both are correct, but which one affects performance?

+5
source share
1 answer

Although both options are the same in terms of performance, you should consider that the former is not recommended.

Returning the thread inside the kernel may lead to unexpected behavior in the rest of your code.

, , . , if / else, , , , .

CUDA , 5, :

__syncthreads() . CUDA , __syncthreads(), __syncthreads()

, . / : __syncthreads() ?

, , , . ,

+3

All Articles