CUDA Samples#

Sample CUDA code is now available at the following GitHub repository:

However, the repository’s current instructions for Building for Automotive Linux Platforms are not valid for the Docker container environment described in this guide.

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

Important

See Prerequisites for Sample Applications before beginning.

Downloading and Building CUDA Samples#

  1. Inside the DriveOS Docker container, download the repository of CUDA samples by using the following command:

    # git clone https://github.com/NVIDIA/cuda-samples.git
    
  2. Because the CUDA samples are built using CMake, ensure that CMake version 3.20 or later is installed by using your package manager, for example:

    # sudo apt install cmake
    
  3. Navigate to the root of the cloned repository and create a build/ directory:

    # mkdir build && cd build
    
  4. You must 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.

    Note

    You must execute the bind step from Binding and Flashing the Target (for NVIDIA ONLINE users) or Binding and Flashing the Target (for NVIDIA Developer users) for the RFS image to be available to mount.

    Mount the target filesystem by running the following commands inside the container:

    1. Create a temporary directory by running the following command:

      # mkdir /drive/<temp>
      

      Where <temp> is any temporary directory of your choosing. This example uses /drive/temp for the remaining steps.

    2. 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
      
  5. Configure the project by running the following cmake command:

    # 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-12.8/thor/lib64/ \
      -DCMAKE_INCLUDE_PATH=/drive/temp/usr/local/cuda-12.8/thor/include/
    

    Note

    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.

  6. Build the samples by running the following command:

    # make -j$(nproc) --ignore-errors
    

Running a CUDA Sample Application#

  1. After building the CUDA samples, copy the files for the CUDA sample application of your choice from the host to the target, for example deviceQuery:

    # scp Samples/1_Utilities/deviceQuery/deviceQuery \
      <username>@<target>:/home/<username>
    
  2. From the target, run the sample application (in this example, deviceQuery) by running the following commands:

    $ cd ~/
    
    $ ./deviceQuery