Programming Cuda Cee

CUDA C is a language provided by NvidiaCorporation for programming their GPGPU devices.

The present version 4.1, March 2012, is an implementation of CeeLanguage with most of CeePlusPlus as well. It can compile code which will run on the host computer. It also has extensions which permit the writing of code sections which will be run on the GPGPU and return results to the host program. There are a lot of manuals and examples which help with this and in particular CudaApplicationDesignAndDevelopment (book).

The LLVM Blog ( says that CUDA 4.1 is based on the LLVM Compiler. (See LowLevelVirtualMachine)
The particular focus of this page is to discuss some problems encountered with CUDA C and ways to work around them.

CUDA C will compile different sorts of source code files. Files with an extension .cpp are processed by a C++ compiler and cannot contain GPGPU code. Files with extension .cu are compiled with NVIDIA's own compiler and result in code both for the host processor and the GPGPU. This compiler has restrictions on its C++ language which mean that some valid C++ will not compile. If the valid C++ is needed only on the host computer, the solution is to put this in a .cpp file. The compiler will compile and link a mixture of .cu and .cpp files into one binary program.

There is a problem when the proposed program uses a class with C++ details which the NVIDIA compiler will not compile. One solution to this is to use the PimplIdiom and provide in the .cu file only a header which will compile with the NVIDIA compiler, putting the details into a .cpp file which can be compiled and linked to the .cu file.

The case I am working on arose when I wanted to compile FC++ (see FunctoidsInCpp) to work with CUDA C and some of it would not compile, specifically the indirect functoids (Fun0, Fun1, etc). I have resolved this problem by using a new level of PimplIdiom on top of the Fun0, Fun1 and Fun2 objects. This has enabled me to make a new implementation of the ObserverPatternInCeePlusPlus example which will be usable with CUDA C.

Clang (see CeeLanguageFamilyFrontEnd) is my preferred compiler for sorting out problems while doing the development.

-- JohnFletcher
See also ComputeUnifiedDeviceArchitecture, GeneralPurposeGraphicsProcessUnits
CategoryCee CategoryCpp CategoryGpgpu CeePlusPlusRoadMap

View edit of March 16, 2012 or FindPage with title or text search