The same base for CPU and GPU

Does anyone have experience supporting a single code base for a processor and GPU? I want to create an application that, if possible, would use the GPU for some lengthy calculations, but if there is no compatible GPU on the target machine, it will simply use the regular version of the processor. It would be very useful if I could just write part of the code using conditional compilation directives that would compile both the CPU version and the GPU version. Of course, there will be some parts that differ for the CPU and GPU, but I would like to keep the essence of the algorithm in one place. Is it possible?

+4
source share
1 answer

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

Although you can run the same OpenCL code on both GPUs and processors, it really needs to be optimized for the target device. For maximum performance, you will need to write different code for different GPUs and processors. However, the OpenCL CPU platform can function as a low-performance reserve for even optimized graphics code.

If you are happy to write conditional directives that are executed depending on the target device (CPU or GPU), then this can help in the performance of OpenCL code on multiple devices.

+1
source

Source: https://habr.com/ru/post/1400545/


All Articles