Skip to content

Thrust (CUDA) by example: transform/zip, scan, reduce, sort—minimal C++/CMake samples that run on WSL2/RTX.

Notifications You must be signed in to change notification settings

FlosMume/cpp-cuda-thust-intro

Repository files navigation

🧩 C++ CUDA Thrust (Windows + WSL2)

A minimal, production-ready CUDA C++ starter project for learning and testing GPU kernels in Windows + WSL2 environments.
Designed for reproducible builds, clean debugging, and automated testing.


🚀 Key Features

  • CUDA C++ example: src/thrust_intro.cu
  • Cross-platform build via CMake
  • GPU architecture targeting (Compute Capability 8.9, RTX 4070 SUPER)
  • .vscode/launch.json for GDB debugging
  • CTest integration for regression testing
  • check_cuda_starter_status.sh for device info + benchmark

🧱 Project Structure

cuda-starter-windows-wsl/
├── src/
│   └── thrust_intro.cu
├── build/                # Auto-generated by CMake
├── .vscode/              # VS Code launch configuration
├── .gitignore
├── CMakeLists.txt
├── check_cuda_starter_status.sh
└── README.md

⚙️ Build & Run

From project root:

cmake -S . -B build -DCMAKE_BUILD_TYPE=Release
cmake --build build -j
./build/thrust_intro

You should see output similar to:

Success! All 1,048,576 elements added correctly.

🧪 Testing with CTest

Run the integrated test target:

cd build
ctest

Expected:

Test project /path/to/build
    Start 1: thrust_intro_run
1/1 Test #1: thrust_intro_run ...   Passed
100% tests passed, 0 tests failed out of 1

⚡ Status Check Script

A helper script validates your CUDA environment and runs a quick benchmark.

./check_cuda_starter_status.sh

Typical output:

GPU: NVIDIA GeForce RTX 4070 SUPER (Compute Capability 8.9)
Driver Version: 560.xx, CUDA 12.8
Vector Add completed in 0.5 ms

🧠 Environment

Component Recommended Version
CUDA Toolkit 12.8+
CMake ≥ 3.24
Compiler g++ or nvcc
GPU RTX 4070 SUPER (SM 8.9)
OS Windows 11 + WSL2 (Ubuntu 22.04)

🛠 VS Code Integration

Launch configuration is in .vscode/launch.json:

{
  "name": "Run thrust_intro",
  "type": "cppdbg",
  "request": "launch",
  "program": "${workspaceFolder}/build/thrust_intro",
  "cwd": "${workspaceFolder}",
  "MIMode": "gdb"
}

Run or debug directly with F5 inside VS Code.


📚 References

  • CUDA by Example — Sanders & Kandrot
  • NVIDIA CUDA Toolkit Docs
  • CMake + CUDA Language Guide

© 2025 Samuel Huang — Toronto, ON
Clean CUDA template maintained for learning and professional use.

About

Thrust (CUDA) by example: transform/zip, scan, reduce, sort—minimal C++/CMake samples that run on WSL2/RTX.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published