How to Install CUDA Samples for Testing

Alexander Hill
Alexander Hill
  • Updated

Overview

NVIDIA CUDA Samples provide a comprehensive set of examples that demonstrate various CUDA features, programming techniques, and applications across different domains. These samples are valuable for testing GPU functionality, learning CUDA programming, and benchmarking performance. This guide outlines the process to install and build CUDA Samples for testing purposes.

Prerequisites

  • NVIDIA GPU with CUDA support
  • CUDA Toolkit (version 12.8 or compatible version) installed on your system
  • Basic knowledge of terminal/command-line operations
  • CMake (version 3.20 or later)
  • Git (optional, for cloning repository)
  • Appropriate build tools (GCC/G++ on Linux, Visual Studio on Windows)

Steps

1. Install CUDA Toolkit

Before installing CUDA Samples, ensure you have the CUDA Toolkit installed on your system.

For Linux:

For Windows: Download the installer from the NVIDIA CUDA Toolkit website and follow the installation wizard.

For detailed installation instructions, refer to:

2. Obtain CUDA Samples

You can get the CUDA Samples in two ways:

Option 1: Using Git (Recommended)

 

Option 2: Download ZIP

  1. Visit the NVIDIA CUDA Samples GitHub repository
  2. Click the "Code" button and select "Download ZIP"
  3. Extract the ZIP file to your preferred location
  4. Navigate to the extracted directory

3. Build CUDA Samples

The CUDA Samples use CMake as their build system.

For Linux:

  1. Install CMake if not already installed:
    sudo apt install cmake # Ubuntu/Debian 
    sudo yum install cmake # CentOS/RHEL/Rocky
  2. Create a build directory and navigate to it:
     
    mkdir build && cd build
  3. Configure the project with CMake:
     
    cmake ..
  4. Build the samples:
     
    make -j$(nproc)

4. Verifying the Installation

Once built, you can test if the samples are working correctly:

  1. Navigate to a basic sample in the build directory:
    bash
     
    cd Samples/0_Introduction/vectorAdd/
  2. Run the sample:
    bash
     
    ./vectorAdd # Linux
  3. You should see output similar to:
     
     
    [Vector addition of 50000 elements] 
    Copy input data from the host memory to the
    CUDA device CUDA kernel launch with 196 blocks of 256 threads
    Copy output data from the CUDA device to the host memory
    Test PASSED
    Done

5. Exploring Available Samples

CUDA Samples are organized into categories:

  1. Introduction - Basic samples for beginners demonstrating key CUDA concepts
  2. Utilities - Tools for querying device capabilities and measuring GPU/CPU bandwidth
  3. Concepts and Techniques - Samples demonstrating common CUDA problem-solving techniques
  4. CUDA Features - Examples of advanced CUDA features like Cooperative Groups and CUDA Graphs
  5. CUDA Libraries - Samples using CUDA platform libraries like cuBLAS, cuFFT, and NPP
  6. Domain Specific - Applications in specific domains like graphics and image processing
  7. Performance - Samples demonstrating performance optimization techniques
  8. libNVVM - Examples of using libNVVVM and NVVM IR

 

6. Running Specific Tests for GPU Validation

For testing GPU functionality, these samples are particularly useful:

  • deviceQuery - Provides detailed information about your GPU
     
    cd Samples/0_Introduction/deviceQuery/ 
    ./deviceQuery
  • bandwidthTest - Tests memory bandwidth between host and device
     
    cd Samples/0_Introduction/bandwidthTest/ 
    ./bandwidthTest
  • matrixMul - Tests matrix multiplication performance

    cd Samples/0_Introduction/matrixMul/ 
    ./matrixMul
  • nbody - N-body simulation for testing compute performance
     
    cd Samples/5_Domain_Specific/nbody/ 
    ./nbody

Troubleshooting

If you encounter issues:

  1. Compilation errors:
    • Ensure CUDA Toolkit is properly installed
    • Verify that your GPU is supported by the installed CUDA version
    • Check that you have the required development packages installed

  2. Runtime errors:
    • Ensure your NVIDIA drivers are up-to-date
    • Check system logs for GPU-related errors:
      bash
       
      dmesg | grep -i nvidia
  3. Sample doesn't run:
    • Verify GPU compatibility with the specific sample
    • Some samples require specific GPU architectures or CUDA capabilities

Additional Resources

For more detailed information about CUDA Samples, refer to:

Related to

Was this article helpful?

0 out of 0 found this helpful

Have more questions? Submit a request

Comments

0 comments

Please sign in to leave a comment.