Samples for CUDA Developers which demonstrates features in CUDA Toolkit
Samples for CUDA Developers which demonstrates features in CUDA Toolkit
Samples for CUDA Developers which demonstrates features in CUDA Toolkit. This version supports CUDA Toolkit 13.4.
This section describes the release notes for the CUDA Samples on GitHub only.
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.
Using git clone the repository of CUDA Samples using the command below.
git clone https://github.com/NVIDIA/cuda-samples.gitWithout 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.
The CUDA Samples are built using CMake. Follow the instructions below for building on Linux, Windows, and for cross-compilation to Tegra devices.
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 buildConfigure 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.
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> ..
makeReplace <arch> with your GPU's SM version (e.g. 90 for sm_90).
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 buildConfigure the project with CMake - for example:
cmake .. -G "Visual Studio 16 2019" -A x64Open 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.
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 ...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 samplesTo build these samples, set the variables either on the command line or through your CMake GUI. For example:
cmake -DBUILD_TEGRA=True ..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 buildConfigure 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/systemBuild the samples:
make -j$(nproc)Transfer the built binaries to the Tegra device and execute them there.
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/tempConfigure 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:
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)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/targetBuild 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.
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:$PATHBuild 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.
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/ ..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>.pyUse each sample’s README.md for prerequisites, CLI options, and expected output.
run_tests.py fails on windows, but running tests individually works
Potential bug in simpleVulkan example
Improve matrixMul Tiling to support non-multiple BLOCK_SIZE dimensions in matrixMul.cu .
Missing check for CUDA failure in example
Request for Official CUDA support for Ubuntu 26.04 LTS (release timeline for native installer/apt repo)
Sample proposal: persistent kernel for tiny-model autoregressive inference (microGPT, ~4k MACs/token)
CUDA 13.2.1 libcudart causes SIGSEGV in cuInit on WSL2 (Driver 596.49, Blackwell)
helloTile: per-sample build fails on Ubuntu/Debian/Fedora — _FORTIFY_SOURCE rewrites printf to a non-tile-callable __printf_chk (v13.3)
4_CUDA_Libraries: cmake -S cpp fails — CUDA language not enabled for the subtree, so cuda_std_17 is unresolvable for 24 leaves (v13.3)
CUDA Tile 1.3: store_masked crashes on element-wise-computed tiles