GPU Programming, CUDA or OpenCL?

Arkapravo picture Arkapravo · Aug 2, 2013 · Viewed 51.9k times · Source

I am a newbie to GPU programming. I have a laptop with NVIDIA GeForce GT 640 card. I am faced with 2 dilemmas, suggestions are most welcome.

  1. If I go for CUDA -- Ubuntu or Windows Clearly CUDA is more suitable to windows while it can be a severe issue to install on Ubuntu. I have seen some blogposts which claim to have installed CUDA 5 on Ubuntu 11.10 and Ubuntu 12.04. However, I have not been able to get them to work. Also, standard CUDA textbooks prefer to work in the windows domain and are more or less silent in concern with Unix/Ubuntu installation and working.

  2. CUDA or OpenCL -- Now this is probably more trickier than my first question ! I have mostly come across GPGPU projects using CUDA/Nvidia but OpenCL is probably is the next best option in open source and installing in Ubuntu probably will not be an issue, though some suggestions here will be most useful. Am I sacrificing any functionality if I go for OpenCL and NOT CUDA ?

Any help or suggestions ?

Answer

Evren Yurtesen picture Evren Yurtesen · Oct 11, 2013
  1. If you use OpenCL, you can easily use it both on Windows and Linux because having display drivers is enough to run OpenCL programs and for programming you would simply need to install the SDK. CUDA has more requirements on specific GCC versions etc. But it is not much more difficult to install on Linux also.

  2. In Linux CUDA has strange requirements such as using GCC 4.6 or 4.7. If you use a different version of GCC, you won't be able to compile your program anymore. If you use OpenCL, you can use any compiler because you would just need to link with the common OpenCL library. So OpenCL is easier to setup, use and compile for. Once you compile an OpenCL program it can be run on any hardware (as long as it is coded to do so) even if it was compiled using another brand's OpenCL SDK.

You can write OpenCL programs which will function on Nvidia, AMD, and Intel hardware, on GPUs, CPUs, and Accelerators. Even more, Altera is working on supporting OpenCL on FPGAs! If you use CUDA, you will have to use Nvidia GPUs only and re-write your code again in OpenCL or other language for other platforms. A serious limitation of using CUDA and cause of serious waste of time in the long run.

I see that somebody posted some old references between CUDA and OpenCL, but they are old! When those documents were out, only AMD properly supported OpenCL. Since 2013, OpenCL is supported by ARM, Altera, Intel etc. and became an industry standard.

The only downside is that since OpenCL is so flexible, you are faced with more options and ways to code memory allocations, transfers etc. in your program. Therefore it may feel more complicated perhaps.