Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Explanation of CUDA C and C++

Tags:

c++

c

cuda

nvidia

Can anyone give me a good explanation as to the nature of CUDA C and C++? As I understand it, CUDA is supposed to be C with NVIDIA's GPU libraries. As of right now CUDA C supports some C++ features but not others.

What is NVIDIA's plan? Are they going to build upon C and add their own libraries (e.g. Thrust vs. STL) that parallel those of C++? Are they eventually going to support all of C++? Is it bad to use C++ headers in a .cu file?

like image 625
Tianxiang Xiong Avatar asked Mar 23 '12 21:03

Tianxiang Xiong


People also ask

Is CUDA written in C?

CUDA C is a programming language with C syntax.

Is CUDA based on C++?

WHAT IS CUDA? Based on industry-standard C++ Set of extensions to enable heterogeneous programming Straightforward APIs to manage devices, memory etc.

Does Nvidia use C?

NVIDIA was very secretive about its internal development until 2013 when they started supporting open-source software development. They have released several documents ever since and most of the documents mention C as the primary programming language used in the development of the core-level software.


1 Answers

CUDA is a platform (architecture, programming model, assembly virtual machine, compilation tools, etc.), not just a single programming language. CUDA C is just one of a number of language systems built on this platform (CUDA C, C++, CUDA Fortran, PyCUDA, are others.)

CUDA C++

Currently CUDA C++ supports the subset of C++ described in Appendix D ("C/C++ Language Support") of the CUDA C Programming Guide.

To name a few:

  • Classes
  • __device__ member functions (including constructors and destructors)
  • Inheritance / derived classes
  • virtual functions
  • class and function templates
  • operators and overloading
  • functor classes

Edit: As of CUDA 7.0, CUDA C++ includes support for most language features of the C++11 standard in __device__ code (code that runs on the GPU), including auto, lambda expressions, range-based for loops, initializer lists, static assert, and more.

Examples and specific limitations are also detailed in the same appendix linked above. As a very mature example of C++ usage with CUDA, I recommend checking out Thrust.

Future Plans

(Disclosure: I work for NVIDIA.)

I can't be explicit about future releases and timing, but I can illustrate the trend that almost every release of CUDA has added additional language features to get CUDA C++ support to its current (In my opinion very useful) state. We plan to continue this trend in improving support for C++, but naturally we prioritize features that are useful and performant on a massively parallel computational architecture (GPU).

like image 137
harrism Avatar answered Oct 12 '22 01:10

harrism