$ show NVIDIA/cuda-samples
NVIDIA's official CUDA Samples repository is a large catalog of self-contained, compilable example programs demonstrating the CUDA platform across C++ and Python. The C++ collection spans hundreds of samples organized into ten categories: fundamentals (vector add, matrix multiply), utilities (deviceQuery), concepts and techniques (reduction, scan, convolution, histograms), feature showcases (CUDA graphs, cooperative groups, Tensor Core GEMMs, dynamic parallelism, NVRTC JIT), CUDA libraries (cuFFT, cuRAND, cuBLAS, cuSOLVER, CUB), domain-specific applications (Black-Scholes, N-body, optical flow, fluid simulation, volume rendering, Monte Carlo), performance studies, libNVVM/PTX generation, platform-specific Tegra/embedded examples, and CUDA Tile C++ microbenchmarks. A parallel Python collection uses the modern cuda.core API with CuPy/NumPy interop and framework integrations (PyTorch, TensorFlow, RAPIDS). Each sample is typically a standalone CLI or interactive graphics program with its own main() entry point; most include a CPU 'gold' reference implementation and automated pass/fail verification, making the collection both educational and regression-tested.
The LLM identified 7 files worth highlighting for reuse:
The canonical NVIDIA CUDA helper header. Provides checkCudaErrors/getLastCudaError macros, device selection (findCudaDevice, getMaxGflopsDeviceId), CUDA error-string mapping, and SM-version-to-core-count conversion. Used pervasively by C++ samples; it is self-contained (only depends on helper_string.h) and can be dropped into any CUDA project unchanged.
Header-only image I/O and comparison library for PPM/PGM/BMP/binary formats, including golden-output verification via sdkComparePPM and compareBin2BinFloat with configurable L1/L2 error tolerances. Reusable in any CUDA image-processing or rendering project that needs file loading plus automated correctness checking.
Cross-platform IPC abstraction (Windows, Linux/POSIX, QNX) for shared memory, message passing, Unix sockets/mailslots, and process spawning, used by the multi-GPU samples. Demonstrates non-obvious platform-portability engineering and lifts cleanly into C++ applications needing small-footprint interprocess communication.
Wraps the NVRTC runtime-compilation flow: compile CUDA source to PTX, load the module through the driver API, and retrieve kernel metadata, with proper error handling. Self-contained and immediately useful in any project doing runtime JIT compilation of CUDA C++.
GPU interval-arithmetic template library implementing directed rounding with CUDA arithmetic intrinsics (__fadd_rd, __fmul_rd, __ddiv_rd), interval division case analysis, square/intersection/bisection operations, and a device-side stack. Demonstrates genuinely non-obvious numerical craftsmanship and is extractable for verified-computing GPU projects.
Shared Python utility module for the Python samples: CUDA runtime-version checks, GPU property printing, and verify_array_result() which compares GPU output against NumPy/CuPy references with configurable absolute/relative tolerances. A clean, parameterized validation pattern reusable across any CuPy or cuda.core project.
Multi-GPU allocation helper built on the CUDA Virtual Memory Management API (cuMemMap/cuMemCreate), encapsulating the low-level mechanics of reserving virtual address space and mapping physical memory per device. Extractable pattern for applications that need driver-level VMM control across multiple GPUs.