Skip to content

Cpp Coding Guidelines

Bernhard Manfred Gruber edited this page Aug 18, 2025 · 17 revisions

General

  1. Always use entities from cuda::std:: over std::. They work in host and device code, work with NVRTC, and help testing our implementation.
  2. Use CCCL internal macros over compiler/vendor-specific keywords. E.g., use _CCCL_HOST_DEVICE instead of __host__ __device_, or _CCCL_FORCEINLINE over __forceinline. Examples and documentation must not use these macros and should support vendor attributes and keywords instead.
  3. Fully qualify any reference to a libcu++ entity in any C++ library header with ::cuda::std::. This avoids ambiguities when users define namespaces called cuda themselves. Use just cuda::std in examples, tests and documentation.
  4. Doxygen comments should start with //!
  5. Macros for function attributes, like _CCCL_HOST_DEVICE, should be ordered before declaration specifiers like constexpr or static
  6. Don't include libcu++ detail headers (starting with __) in downstream projects (like CUB, Thrust, etc.). Always prefer the public headers.

CUB

Implementation Code

TBD

Tests and Examples

  1. Namespace Qualification: Do not use the global namespace qualification (::cuda::xyz or ::cuda::std::xyz). Instead, use cuda::xyz and cuda::std::xyz.
  2. Internal Macros: Do not use internal macros like _CCCL_HOST_DEVICE.

Thrust

Implementation Code

TBD

Tests and Examples

  1. Namespace Qualification: Do not use the global namespace qualification (::cuda::xyz or ::cuda::std::xyz). Instead, use cuda::xyz and cuda::std::xyz.
  2. Internal Macros: Do not use internal macros like _CCCL_HOST_DEVICE, unless the internal macros are strictly required for the tests to work. For instance, _CCCL_HOST_DEVICE may be required for tests targeting non-CUDA backends.

libcu++

  1. Always fully qualify function calls, even to functions in the same namespace. This avoids ADL.
  2. Defaulted constructors should be marked with _CCCL_HIDE_FROM_ABI
  3. libcu++ headers like <cuda/foo> are strict supersets of <cuda/std/foo> and thus always include the corresponding <cuda/std/...> header.

Licensing

CCCL uses a mix of different licenses for historical reasons.

  1. Any net new file should be licsensed under Apache-2.0 WITH LLVM-exception.
  2. For files with license headers, strongly prefer a 2-line SPDX header like:
// SPDX-FileCopyrightText: Copyright (c) 2025, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
Clone this wiki locally