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:
wget https://developer.download.nvidia.com/compute/cuda/12.8.0/local_installers/cuda_12.8.0_545.23.06_linux.run
sudo sh cuda_12.8.0_545.23.06_linux.run
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)
git clone https://github.com/NVIDIA/cuda-samples.git
cd cuda-samples
Option 2: Download ZIP
- Visit the NVIDIA CUDA Samples GitHub repository
- Click the "Code" button and select "Download ZIP"
- Extract the ZIP file to your preferred location
- Navigate to the extracted directory
3. Build CUDA Samples
The CUDA Samples use CMake as their build system.
For Linux:
- Install CMake if not already installed:
sudo apt install cmake # Ubuntu/Debian
sudo yum install cmake # CentOS/RHEL/Rocky - Create a build directory and navigate to it:
mkdir build && cd build
- Configure the project with CMake:
cmake ..
- Build the samples:
make -j$(nproc)
4. Verifying the Installation
Once built, you can test if the samples are working correctly:
- Navigate to a basic sample in the build directory:
bash
cd Samples/0_Introduction/vectorAdd/
- Run the sample:
bash
./vectorAdd # Linux
- 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:
- Introduction - Basic samples for beginners demonstrating key CUDA concepts
- Utilities - Tools for querying device capabilities and measuring GPU/CPU bandwidth
- Concepts and Techniques - Samples demonstrating common CUDA problem-solving techniques
- CUDA Features - Examples of advanced CUDA features like Cooperative Groups and CUDA Graphs
- CUDA Libraries - Samples using CUDA platform libraries like cuBLAS, cuFFT, and NPP
- Domain Specific - Applications in specific domains like graphics and image processing
- Performance - Samples demonstrating performance optimization techniques
- 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:
-
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
-
Runtime errors:
- Ensure your NVIDIA drivers are up-to-date
- Check system logs for GPU-related errors:
bash
dmesg | grep -i nvidia
-
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
Comments
0 comments
Please sign in to leave a comment.