CUDA with C++

Hey all

I’m pretty sure I read somewhere that I can use CUDA with C++, but all the examples are in C, so could someone explain to me how I would take the example code and change it into a C++ program? Thanks :)

C++ can be used in host code. Kernel must be in C.

A few C++ features can be used in kernel code, but it must be predominantly C “style”. For example, you can’t use new or delete, or virtual functions, because memory allocation and function pointers are not available. But some kinds of templates are possible.

According to the documentation:

If you would prefer to program in C++, you could try checking out some wrappers such as Thrust (formerly Komrade)

Not sure if it has all of the capabilities you need, but it may be worth checking out if you really want to avoid C.

I just need to use C++ for my front-end program. I can write the kernel in C, that’s fine. It’s just because I need to use another tool in conjunction with CUDA that requires C++. So I just call the kernel header written in C into my C++ program?

Yeah, you just need to mark your C functions extern “C”. Check out the cppIntegration SDK example.