Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Same codebase for CPU and GPU

Tags:

c

gpgpu

Does anybody have any experience in maintaining single codebase for both CPU and GPU? I want to create an application which when possible would use GPU for some long lasting calculations, but if a compatible GPU is not present on a target machine it would just use regular CPU version. It would be really helpfull if I could just write a portion of code using conditional compilation directives which would compile both to a CPU version and GPU version. Of course there will be some parts which are different for CPU and GPU, but I would like to keep the essense of the algorithm in one place. Is it at all possible?

like image 603
Max Avatar asked Nov 14 '22 09:11

Max


1 Answers

OpenCL is a C-based language. OpenCL platforms exist that run on GPUs (from NVidia and AMD) and CPUs (from Intel and AMD).

While it is possible to execute the same OpenCL code on both GPUs and CPUs, it really needs to be optimized for the target device. Different code would need to be written for different GPUs and CPUs to gain the best performance. However, a CPU OpenCL platform can function as a low-performance fallback for even GPU optimized code.

If you are happy writing conditional directives that execute depending on the target device (CPU or GPU) then that can help performance of OpenCL code on multiple devices.

like image 65
prunge Avatar answered Dec 20 '22 00:12

prunge