4 ms·
On the other hand, high branch usage is the ideal scenario for using CPUs vs GPUs.
by 323 5y ago
On the other hand, high branch usage is the ideal scenario for using CPUs vs GPUs.
- dragontamer 5y agoNot necessarily. GPUs are outstandingly good at uniform branches. Only divergent branches are GPUs bad at.
- ashvardanian 5y agoI would further emphasize - locally uniform branches. Mostly the cores within the same warp should be well synchronized.
- dragontamer 5y agoIt also should be noted that CPUs are _ALSO_ bad at divergent branches. Its just that in the CPU-world, "divergent branches" is called "branch misprediction". In the GPU-world, we have a better idea of how the "branch predictor" (or the equivalent thing to the branch predictor) works. Its called SIMD-execution / branch divergence. ------- That being said: CPUs are way better than GPUs at divergent scenarios. Not only is the CPU branch predictor able to guess patterns, but its also able to execute in parallel to the rest of the CPU (out-of-order speculative execution and all). So in highly divergent branchy code, CPUs work but somewhat slowly (if the branch predictor can't predict, then its useless). But if there's a simple pattern, GPUs are great. If there's a pattern that can be detected at runtime, but is too difficult to program in to a GPU (ex: a binary search over a million elements will probably loop roughly 20 times), that's where CPUs win exceptionally over GPUs. The CPU-branch predictor will predict 20-loops in your binary search. It might be a little bit wrong (19-loops needed or 21-loops needed), but speeding up those 20-loops is a huge benefit.
- moonchild 5y agoWrt branches, GPUs want spatial locality, and CPUs want temporal locality :)