Compilation on the GPU? A Feasibility Study
dl.acm.org
dl.acm.org
In general you can't compile on GPU because program analysis is holistic at basically every level after lexing. Of course if you resign yourself to peephole optimization then sure maybe you can build a "compiler" that's parallelizable. But that's a crappy compiler that goes really fast and I have no idea what a compelling use case would be for such a thing.
Even if a GPU core is slower than a CPU core, you have vastly more of them. If you have a project with more TUs than you have CPU cores, I don't see how it couldn't be faster.
Hell, you can even trivially compile on different remote machines with distcc. If that's faster, how could a GPU be worse?
It's not any different because ordinary compilation isn't parallelizable either. Chopping up your program into TUs is a work around for the fact that it isn't, not proof that it is. Think about it: why does ODR exist? Why does LTO exist? Also think about it: is linking parallelizable?
GNU does have a separate project to parallelize gcc: https://gcc.gnu.org/wiki/ParallelGcc. The Wiki has limitations, challenges, and benchmarks. It can speed things up a tiny bit, but barely, and benefits seem to vanish after 4 threads.
Ultimately this, like many things, boils down to P=?NP (search/optimization is NP hard).
If/else in GPU land is implemented by having the GPU execute the if() side with (EXEC-mask), THEN the else() side with (not EXEC-mask).
Ie: the exec mask makes the appearance of skipping over the unnecessary code. But in practice, one of the 32 CUDA threads executes on one or the other branch. And this the system must physically execute both while throwing away the results.
---------
CPU parallelization in contrast is a true skip of the unnecessary if/else side. It takes a branch predictor to do it well though.
This also means that in a GPU, if one (of the 32 CUDA threads aka lanes) needs to loop 10,000 times, then ALL the CUDA lanes loop 10,000 times (with the other lanes possibly throwing away 9,999+ iterations of work as waste heat).
There is no inherent reason why we might not design programming language syntax to be much more parallelizable.