GPU Glossary
Host Software·1 min read

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 returns void.
  • 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 blockDim and threadIdx built-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.