r/gpgpu • u/SPYFF0 • Mar 08 '16
Programming GPU with modern C++
There is lots of libraries for high level C++11/14 GPU coding, but its a bit confusing for me as a completely beginner. I'm familiar with modern C++ but not familiar with the state of the art GPU programming libraries. I found some:
CUDA with C++11 wrappers
Thrust (looks like its included with the latest CUDA)
boost::compute
HCC
Which one offers the most convenient environment (and some good paralell algorithms)?
3
u/lets_trade_pikmin Mar 09 '16
I haven't tried any of the others, but native CUDA is identical to C++ with additional features for GPGPU. (At least it's identical as far as I've seen, I usually stick to old school C++ though.)
2
u/squidgyhead Mar 09 '16
There's OpenCL C++, which adds some features of C++14 to the OpenCL language. OpenCL is a C-based language that can run on GPUs, CPUs, and co-processor boards like the Xeon Phi. I've been using OpenCL, and I really like it, but driver support is sometimes an issue.
https://www.khronos.org/registry/cl/specs/opencl-2.1-openclc++.pdf
3
Mar 09 '16 edited Mar 09 '16
I liked the fact that OpenCL had simple C syntax and am unsure about the move. Reading the 2.1 spec, however, it seems to just be adding template syntax for type conversion and namespaces. Nothing else really screams "C++" to me. Not sure how I'd use classes in particular on statically allocated structures in restricted local memory environments. Maybe I've just never written OpenCL kernels large enough to need that kind of encapsulation.
1
Mar 09 '16
If you are targeting Nvidia cards I would not consider anything beyond CUDA. If you are targeting multiple platforms go for OpenCL.
1
3
u/Plazmatic Mar 09 '16
CUDA is natively c++. Additionally CUDA isn't a library, its a GPU binding.
Thrust is a library for CUDA.
Boost compute is a wrapper for OpenCL, which is like CUDA in that it is a binding except it works on most modern hardware regardless of vendor, so that includes you CPU, as well as any other GPUs connected or most peripheral compute devices (like GPUs) however Nvidia has bad support for it. Boost predates Bolt, the modern C++ implementation of OpenCL for AMD GPUs. Boost however works with most hardware that OpenCL supports.
What the hell is that?
Any way, if you want to develop for AMD only, use Bolt, if you want to use C++ and not just C for openCL (I actually find C easier to use with OpenCL some times) use Boost::compute. If you want to develop for Nvidia hardware only, use CUDA, thrust is like the std library of CUDA, it has some really efficient reduction and basic sorting for GPUs.
If you want to do high level GPU programming with C++ you are probably SOL. Maybe ArrayFire would be more your forte? But that is really just a bunch of utilities, you still will have to know how the hardware works.