MCPcopy Create free account
hub / github.com/NVIDIA/cuda-samples

github.com/NVIDIA/cuda-samples

Chat with this repo
repository ↗ · DeepWiki ↗ · release v13.4 ↗ · + Follow · compare 2 versions
3,173 symbols 6,734 edges 490 files ⚖ BSD-2-Clause 597 documented · 19% updated 1d agov13.4 · 2026-09-09★ 9,61180 open issues

Browse by type

Functions 2,691 Types & classes 482
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

CUDA Samples

Samples for CUDA Developers which demonstrates features in CUDA Toolkit. This version supports CUDA Toolkit 13.4.

Release Notes

This section describes the release notes for the CUDA Samples on GitHub only.

Change Log

Revision History

Getting Started

Prerequisites

Download and install the CUDA Toolkit for your corresponding platform. For system requirements and installation instructions of cuda toolkit, please refer to the Linux Installation Guide, and the Windows Installation Guide.

Getting the CUDA Samples

Using git clone the repository of CUDA Samples using the command below.

git clone https://github.com/NVIDIA/cuda-samples.git

Without using git the easiest way to use these samples is to download the zip file containing the current version by clicking the "Download ZIP" button on the repo page. You can then unzip the entire archive and use the samples.

Building CUDA Samples

The CUDA Samples are built using CMake. Follow the instructions below for building on Linux, Windows, and for cross-compilation to Tegra devices.

Linux

Ensure that CMake (version 3.20 or later) is installed. Install it using your package manager if necessary:

e.g. sudo apt install cmake

Navigate to the root of the cloned repository and create a build directory:

mkdir build && cd build

Configure the project with CMake:

cmake ..

Build the samples:

make -j$(nproc)

By default, samples are compiled for all GPU architectures supported by this release. If you only need to target a specific GPU, you can override this to build for a single architecture and reduce build time considerably:

cmake -DCMAKE_CUDA_ARCHITECTURES=<arch> ..

Replace <arch> with your GPU's SM version (e.g. 90 for sm_90).

Run the samples from their respective directories in the build folder.

Building a Single Sample

To build just one sample, configure CMake from within the sample's directory. You must explicitly specify a GPU architecture — standalone builds have no top-level default:

cd cpp/<category>/<sampleName>
mkdir -p build && cd build
cmake -DCMAKE_CUDA_ARCHITECTURES=<arch> ..
make

Replace <arch> with your GPU's SM version (e.g. 90 for sm_90).

Windows

Language services for CMake are available in Visual Studio 2019 version 16.5 or later, and you can directly import the CUDA samples repository from either the root level or from any subdirectory or individual sample.

To build from the command line, open the x64 Native Tools Command Prompt for VS provided with your Visual Studio installation.

Navigate to the root of the cloned repository and create a build directory:

mkdir build && cd build

Configure the project with CMake - for example:

cmake .. -G "Visual Studio 16 2019" -A x64

Open the generated solution file CUDA_Samples.sln in Visual Studio. Build the samples by selecting the desired configuration (e.g., Debug or Release) and pressing F7 (Build Solution).

Run the samples from the output directories specified in Visual Studio.

Enabling On-GPU Debugging

NVIDIA GPUs support on-GPU debugging through cuda-gdb. Enabling this may significantly affect application performance as certain compiler optimizations are disabled in this configuration, hence it's not on by default. Enablement of on-device debugging is controlled via the -G switch to nvcc.

To enable cuda-gdb for samples builds, define the ENABLE_CUDA_DEBUG flag on the CMake command line. For example:

cmake -DENABLE_CUDA_DEBUG=True ...

Platform-Specific Samples

Some CUDA samples are specific to certain platforms, and require passing flags into CMake to enable. In particular, we define the following platform-specific flags:

  • BUILD_TEGRA - for Tegra-specific samples

To build these samples, set the variables either on the command line or through your CMake GUI. For example:

cmake -DBUILD_TEGRA=True ..

Cross-Compilation for Tegra Platforms

Install the NVIDIA toolchain and cross-compilation environment for Tegra devices as described in the Tegra Development Guide.

Ensure that CMake (version 3.20 or later) is installed.

Navigate to the root of the cloned repository and create a build directory:

mkdir build && cd build

Configure the project with CMake, specifying the Tegra toolchain file. And you can use -DTARGET_FS to point to the target file system root path for necessary include and library files:

cmake .. -DCMAKE_TOOLCHAIN_FILE=../cmake/toolchains/toolchain-aarch64-linux.cmake -DTARGET_FS=/path/to/target/system/file/system

Build the samples:

make -j$(nproc)

Transfer the built binaries to the Tegra device and execute them there.

Cross Building for Automotive Linux Platforms from the DriveOS Docker containers

To build CUDA samples to the target platform from the DriveOS Docker containers, use the following instructions.

Mount the target Root Filesystem (RFS) in the container so that the CUDA cmake process has the correct paths to CUDA and other system libraries required to build the samples.

Create a temporary directory, <temp> is any temporary directory of your choosing, for example, you can use /drive/temp:

$ mkdir /drive/<temp>

Mount the filesystem by running the following command:

$ mount /drive/drive-linux/filesystem/targetfs-images/dev_nsr_desktop_ubuntu-24.04_thor_rfs.img /drive/temp

Configure the project by running the following cmake command:

$ mkdir build && cd build
$ cmake .. -DBUILD_TEGRA=True \
  -DCMAKE_CUDA_COMPILER=/usr/local/cuda/bin/nvcc \
  -DCMAKE_TOOLCHAIN_FILE=../cmake/toolchains/toolchain-aarch64-linux.cmake \
  -DTARGET_FS=/drive/temp \
  -DCMAKE_LIBRARY_PATH=/drive/temp/usr/local/cuda-13.1/thor/lib64/ \
  -DCMAKE_INCLUDE_PATH=/drive/temp/usr/local/cuda-13.1/thor/include/

Please note that the following libraries are not pre-installed in the DriveOS dev-nsr target filesystem: * libdrm-dev * Vulkan

This causes the cmake command to throw errors related to the missing files, and as a result, the related samples will not build in later steps. This issue will be addressed in a future DriveOS release.

To build the samples with ignore the error mentioned above, you can use --ignore-errors/--keep-going or comment out the comment out the corresponding add_subdirectory command in the CMakeLists.txt in the parent folder for the samples requiring Vulkan and libdrm_dev:

$ make -j$(nproc) --ignore-errors # or --keep-going
# In cpp/5_Domain_Specific/CMakeList.txt
# add_subdirectory(simpleGL)
# add_subdirectory(simpleVulkan)
# add_subdirectory(simpleVulkanMMAP)

# In cpp/8_Platform_Specific/Tegra/CMakeList.txt
# add_subdirectory(simpleGLES_EGLOutput)

QNX

Cross-compilation for QNX with CMake is supported in the CUDA 13.0 samples release and newer.

Set up the QNX SDP paths:

export QNX_HOST=/path/to/qnx/host
export QNX_TARGET=/path/to/qnx/target

Build the samples for the Tegra Thor QNX platform:

mkdir -p build && cd build
cmake .. \
  -DBUILD_TEGRA=True \
  -DCMAKE_CUDA_COMPILER=/usr/local/cuda-13.3/bin/nvcc \
  -DCMAKE_TOOLCHAIN_FILE=../cmake/toolchains/toolchain-aarch64-qnx.cmake \
  -DTARGET_FS=/path/to/qnx/targetfs \
  -DCMAKE_LIBRARY_PATH=/usr/local/cuda-13.3/thor/targets/aarch64-qnx/lib/stubs/ \
  -DCMAKE_INCLUDE_PATH=/usr/local/cuda-13.3/thor/targets/aarch64-qnx/include/
cmake --build .

TARGET_FS is the QNX target filesystem of your board. The cudaNvSci sample needs it, because the NvSci headers and libraries ship with the target filesystem and not with the CUDA toolkit. Without TARGET_FS the build reports NvSCI not found and skips the sample.

The target filesystem is part of the NVIDIA DRIVE OS QNX SDK, which registered users download from NVONLINE. After the SDK is installed, the filesystem is in the DRIVE OS workspace: <NV_WORKSPACE>/drive-qnx for the standard SDK and <NV_WORKSPACE>/drive-qnx-safety for the safety SDK. See the DRIVE OS documentation for the installation guides.

For both QNX toolchains the build looks for nvscibuf.h in <TARGET_FS>/include, <TARGET_FS>/../include and <TARGET_FS>/usr/include, and for libnvscibuf.so in <TARGET_FS>/lib-target, <TARGET_FS>/usr/libnvidia and <TARGET_FS>/usr/lib. If your filesystem uses a different layout, set NVSCIBUF_INCLUDE_DIR, NVSCISYNC_INCLUDE_DIR, NVSCIBUF_LIBRARY and NVSCISYNC_LIBRARY on the cmake command line instead.

QNX Safety (CUDA Safe toolkit)

Cross-compilation for QNX Safety uses the CUDA Safe toolkit (for example /usr/local/cuda-13.3-safe).

Set up the QNX SDP and Safe toolkit paths:

export QNX_HOST=/path/to/qnx/host
export QNX_TARGET=/path/to/qnx/target
export CUDA_PATH=/usr/local/cuda-13.3-safe
export PATH=$CUDA_PATH/nvvm/bin:$PATH

Build a single sample (standalone configure from the sample directory).

mkdir -p build && cd build
cmake .. \
  -DCMAKE_TOOLCHAIN_FILE=../../../cmake/toolchains/toolchain-aarch64-qnx-safe.cmake \
  -DCMAKE_CUDA_COMPILER=$CUDA_PATH/bin/nvcc \
  -DCMAKE_CUDA_ARCHITECTURES=110 \
  -DTARGET_FS=/path/to/qnx/safety/targetfs
cmake --build .

The safe toolchain sets -safety-compat, links shared libcudart and libcuda, and uses QNX q++ as the CUDA host compiler (CMAKE_CUDA_HOST_COMPILER). Set CMAKE_CUDA_ARCHITECTURES to match your GPU (87 for Orin, 110 for Thor).

Supported QNX Safety samples: matrixMul, cudaNvSci.

TARGET_FS is only needed for cudaNvSci, which links the NvSci libraries from the safety target filesystem (<NV_WORKSPACE>/drive-qnx-safety, part of the DRIVE OS QNX Safety SDK). matrixMul builds without it. The NvSci search paths are the same as for the standard QNX build above.

Forward Compatibility

To build samples with new CUDA Toolkit(CUDA 13.0 or later) and UMD(Version 580 or later) and old KMD(Version 550 or earlier),you need to set the CMAKE_PREFIX_PATH for using new driver library, the command might like this:

cmake -DCMAKE_PREFIX_PATH=/usr/local/cuda/lib64/stubs/ ..

CUDA Python samples

The repository includes Python examples under the python/ directory. These samples are cuda.core–focused: they use CUDA Python, with cuda.core for devices, programs, launches, and memory, alongside NumPy, CuPy, or framework interop where each sample notes.

Layout (same themes as the C++ samples):

Directory Contents
python/1_GettingStarted/ Introductory scripts (e.g. vectorAdd, deviceQuery, systemInfo, image blur with unified memory, NumPy vs CuPy).
python/2_CoreConcepts/ Algorithms and techniques (e.g. reductions, histograms, FFT, stream overlap, memoryResources, cudaGraphs, jitLtoLinking, tmaTensorMap).
python/3_FrameworkInterop/ Integration with PyTorch and TensorFlow.
python/4_DistributedComputing/ Multi-GPU, peer-to-peer, and IPC patterns (ipcMemoryPool).
python/Utilities/ Shared helpers imported by some samples.

How to run: The top-level CMake build does not compile these samples. For each sample, use a Python 3.10+ environment with a matching CUDA Toolkit (the samples target CUDA 13.x and document exact package pins in requirements.txt):

cd python/<category>/<sampleName>
pip install -r requirements.txt
python <sampleScript>.py

Use each sample’s README.md for prerequisites, CLI options, and expected output.

Install Samples

Installation Path Structure

The installation system automatically organizes samples into a structured directory layout based on: - Target Architecture: ${CMAKE_SYSTEM_PROCESSOR}, e.g. x64, aarch64, amd64, etc. - Target OS: linux, windows, darwin, qnx - Build Type: release, debug, etc.

The default installation path is: build/bin/${TARGET_ARCH}/${TARGET_OS}/${BUILD_TYPE}

Examples: - Linux x86_64 Release: build/bin/x64/linux/release - Linux aarch64 Release: build/bin/aarch64/linux/release - Windows amd64 Release: build/bin/amd64/windows/release

Customizing Installation Paths

You can customize the installation location using CMake variables during the configuration step:

  • CMAKE_INSTALL_PREFIX: Changes the root installation directory (default: build/bin) cmake -DCMAKE_INSTALL_PREFIX=/custom/path .. This will install to: /custom/path/${TARGET_ARCH}/${TARGET_OS}/${BUILD_TYPE}

  • CUDA_SAMPLES_INSTALL_DIR: Specifies the exact final installation directory (overrides the structured path) cmake -DCUDA_SAMPLES_INSTALL_DIR=/exact/install/path ..

Install Samples on Linux

Prerequisites: You must first configure the project with CMake as described in the Building CUDA Samples - Linux or [Building]section.

After configuring and building, install the samples:

cd build/
make install

Install Samples on Windows

Prerequisites: You must first configure the project with CMake as described in the Building CUDA Samples - Windows section.

Using Command Line

After configuring with CMake, build and install from the x64 Native Tools Command Prompt for VS:

cd build
cmake --build . --config Release
cmake --install . --config Release

Note: Replace Release with Debug if you want to install debug builds. For multi-configuration generators (like Visual Studio), the --config flag determines which build type to install.

Us

Core symbols most depended-on inside this repo

browse all functions →

Shape

Function 1,559
Method 1,132
Class 426
Enum 56

Languages

C++93%
Python6%
C1%

Modules by API surface

cpp/5_Domain_Specific/simpleD3D12/d3dx12.h103 symbols
cpp/5_Domain_Specific/simpleVulkanMMAP/VulkanBaseApp.cpp66 symbols
cpp/5_Domain_Specific/simpleVulkan/VulkanBaseApp.cpp65 symbols
Common/rendercheck_gles.h53 symbols
Common/rendercheck_gl.h53 symbols
cpp/5_Domain_Specific/vulkanImageCUDA/linmath.h51 symbols
cpp/5_Domain_Specific/simpleVulkan/linmath.h51 symbols
cpp/2_Concepts_and_Techniques/interval/boost/numeric/interval/rounded_arith.hpp51 symbols
cpp/0_Introduction/matrixMulDynlinkJIT/cuda_drvapi_dynlink_cuda.h45 symbols
cpp/5_Domain_Specific/nbody/nbody.cpp42 symbols
cpp/2_Concepts_and_Techniques/interval/cuda_interval_rounded_arith.h39 symbols
Common/param.h39 symbols

Dependencies from manifests, versioned

cuda-cccl1.0.0 · 1×
cuda-core1.0.0 · 1×
cuda-python13.0.0 · 1×
cudf-cu1326.0.0 · 1×
cugraph-cu1326.0.0 · 1×
cupy-cuda13x14.0.0 · 1×
dask-cuda26.4.0 · 1×
mpi4py3.1.4 · 1×
numba-cuda0.29.0 · 1×
numpy2.3.2 · 1×
nvidia-nvjitlink13.2.0 · 1×
nvidia-nvvm13.2.0 · 1×

For agents

$ claude mcp add cuda-samples \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page