2 ms·
The other poster is right. The CPU and GPU are just two execution resources available to the programmer, no different than spinning up a new pthread_create (wel
by dragontamer 5y ago
The other poster is right. The CPU and GPU are just two execution resources available to the programmer, no different than spinning up a new pthread_create (well... a bit more complicated but you get the gist).
Even in video games, where GPUs do graphics and CPUs do physics, the lines have been blurred with TressFX (hair physics on GPU instead of CPU) or PhysX (collision physics done on GPU instead of CPU).
GPUs are general purpose computers now. You can program them to do whatever you want. So when the programmer is writing code, it pays to experiment a little: maybe run the code on the GPU... see if the GPU really is slower or faster. You might be surprised.
Ditto on the reverse: maybe some bit of GPU code would be better run on the CPU.
--------
This guess-and-check, program-and-profile methodology is the same as any other high-performance code people write. You throw away assumptions and just test the heck out of all your ideas, because you're surprised far more often than not in this field.
As such, having the ability to quickly move code from GPU-side to CPU-side (and vice versa) for these tests is extremely beneficial. You don't really know which device will run your code faster until you actually test it. (Though your instincts get better the more experience you gain)
- nl 5y agoTo expand on this: GPUs are (basically) hardware devices for doing vast numbers of matrix manipulations very very fast in parallel, with limitations on the size of the matrix. CPUs can do matrix manipulations, with less parallelism. Things like TressFX uses the tridiagonal matrix algorithm[1] to solve a linear system representing the hair constraints system. This could be implemented on a CPU as well, doing exactly the same thing with the same algorithm. It would run slower though! [1] https://en.wikipedia.org/wiki/Tridiagonal_matrix_algorithm https://en.wikipedia.org/wiki/Tridiagonal_matrix_algorithm [2] Slide 37, https://www.slideshare.net/DevCentralAMD/gs4147-billbilodeau https://www.slideshare.net/DevCentralAMD/gs4147-billbilodeau