CUDA C++
An extension of C++ that implements the CUDA programming model, adding syntax for defining and launching GPU kernels.
CUDA C++ implements the CUDA programming model as an extension of the C++ language. It adds a small set of keywords, syntax and built-ins for writing code that runs on the GPU and launching it from the CPU.
What it adds to C++#
- Kernel definition with
__global__. A kernel is a C++ function annotated with this keyword. It takes pointers as arguments and returnsvoid. - Kernel launches with
<<<>>>. The CPU host launches kernels with a triple angle bracket syntax that sets the dimensions of the thread block grid. - Shared memory allocation with the
__shared__keyword. - Barrier synchronization with the
__syncthreads()intrinsic function. - Thread block and thread indexing with the
blockDimandthreadIdxbuilt-in variables.
Compilation#
CUDA C++ programs are compiled by a host C/C++ compiler driver like gcc working together with the NVIDIA CUDA Compiler Driver, nvcc.
For running CUDA C++ on Modal, see this guide.
Related#
- nvcc — the compiler for CUDA C++
- Kernel — the unit of GPU code CUDA C++ defines
- CUDA Software Platform — the wider toolkit around the language