3 ms·
I remember how shock I was when the first time I leanred branching (arguably the most basic building block of programming) can severely affect GPU's performance
by raincole 3y ago
I remember how shock I was when the first time I leanred branching (arguably the most basic building block of programming) can severely affect GPU's performance.
*techinically it's even true for CPU in some cases...
- c4mpute 3y ago> *techinically it's even true for CPU in some cases... Practically in all cases. It isn't as bad to branch as it is in a GPU. But branch prediction in CPUs is an important factor for performance critical code, and getting it right (e.g. by switching the 'branch/no branch' conditions in assembler or using branch hints such as likely/unlikely in the linux kernel) can make a very noticable difference. I've seen a factor of 2 in some tight loops, and 10% should often be achievable. And sometimes, by using bitmasks or multiplication by 1/0, one can design branchless code which can enable the use of e.g. more AVX instructions on CPUs, while also avoiding branch miss penalties.
- amagine 3y agoBranching isn't in and of itself too bad. It's divergent branching within a warp, especially if the blocks are large, that can kill perf.