r/gpgpu • • 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)?

0 Upvotes

9 comments sorted by

3

u/Plazmatic Mar 09 '16

CUDA with C++11 wrappers

CUDA is natively c++. Additionally CUDA isn't a library, its a GPU binding.

Thrust (looks like its included with the latest CUDA)

Thrust is a library for CUDA.

boost::compute

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.

HCC

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.

1

u/SPYFF0 Mar 09 '16

Thanks for the detailed answer, very helpful! I know the very basics of the hardware (completed the HPP course on Coursera) and now I browsing example codes. Looks like the boost::compute will be the most suitable solution for me.

HCC

I never really heard about that one but Google is, so I mentioned: https://bitbucket.org/multicoreware/hcc/wiki/Home

2

u/Plazmatic Mar 09 '16

I'd recommend Udacity's Nvidia Parrallel programming course if you haven't looked into it, its free, actually made by nvidia, and has a tonne of stuff covered (I think way more than what is handled in coursera) You don't need an Nvidia GPU to complete it either since they run programs off of amazon servers on site.

1

u/James20k Mar 09 '16

Nvidia has bad support for it

As someone writing a cross platform opencl app, nvidia's support is now officially ok with their support for 1.2 (it used to be poor until very recently). You have to be a bit more correct with API usage on their platform (properly handing gl interop acquiring and release), but these days most of my problems come from old cards, not vendor specific problems

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

u/[deleted] 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

u/[deleted] 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

u/NervousBrowBoy Mar 09 '16

Hey, don't forget OpenACC !