if and while loops better on gpu or cpu

what is the effect of if and while loop in a kernel will it better on gpu or cpu

regards
megharaj

I think it depends. If all workthreads’ control flows are the same, then running on gpu can be faster. For example, if the number of iteration of the loop is the same acroos all the workthread. If not, the workthreads that have less iteration will finish first, and those threads will wait until other threads are done without doing anything. However, it might still run faster on gpu in the latter scenario depending on how big the difference between numbers of iteration is.

In the case that the control flow of the code has so many branches, and it is possible to reach all those branches, this is very bad on gpu.

I’ve tried running loop (with the same number of iteration across workthreads) on gpu, and it’s a lot faster than running on cpu, but I haven’t tried complicated if statements code.