My apologies if that was asked before, I could not find the answer.
I wonder if I am correct in my understanding that if-else causes thread divergence in a kernel code even if all threads in a warp execute the same branch. I.e., for the code below:
if(cond) A; else B;
the compiler creates the following set of instructions for a warp:
mask1 = if cond == true
mask2 = not mask1
exec A for threads in mask1
exec B for threads in mask2
What if for all threads in a warp the condition is true? Then mask2 is empty - will the last instruction be executed even if there are no threads in mask2?
The essence of my question: is there ALWAYS thread divergence when there is if-else clause in the kernel?