NVIDIA/multi-gpu-programming-models
Examples demonstrating available options to program multiple GPUs in a single node or a cluster
What is this project?
This repository contains a Jacobi solver — a classic numerical method for solving partial differential equations — implemented in many different ways to show how to program multiple GPUs. Each implementation uses a different technique for getting GPUs to talk to each other, so you can compare them and learn the trade-offs.
The project is meant as a teaching and reference tool. It was presented in NVIDIA GTC talks and is also used as the basis for an interactive tutorial.
What does it do?
The core computation is the same in every variant: it iteratively solves a 2D grid problem (like heat diffusion) using the Jacobi method. The differences are in how the GPUs exchange boundary data — the values at the edges of each GPU's portion of the grid. The README lists 14 variants, each with a different communication strategy:
- Single‑threaded copy – one CPU thread, uses
cudaMemcpyto move data between GPUs. - Multi‑threaded copy – multiple CPU threads (via OpenMP) with
cudaMemcpy. - Multi‑threaded copy with overlap – same, but overlaps communication with computation.
- Multi‑threaded P2P – uses GPUDirect Peer‑to‑Peer (P2P) mappings for direct GPU‑to‑GPU transfers.
- Multi‑threaded P2P optimized – adds a delayed norm calculation to improve performance.
- Multi‑threaded Unified Memory – relies on CUDA Unified Memory, letting the system handle transfers transparently.
- MPI – uses CUDA‑aware MPI (Message Passing Interface) for inter‑GPU communication.
- MPI with overlap – MPI with overlapping communication and computation.
- NCCL – uses NVIDIA’s NCCL library for high‑speed GPU communication.
- NCCL with overlap – NCCL with overlapping.
- NCCL with CUDA Graphs – combines NCCL with CUDA Graphs to reduce launch overhead.
- NVSHMEM – uses NVSHMEM, a partitioned global address space library.
- NCCL device API – uses the NCCL device API for device‑initiated communication; neighbors on the same NVLink domain use load/store, others use GIN (GPU‑Initiated Networking).
- Multi‑node P2P – a low‑level example using CUDA Virtual Memory Management and Multicast APIs. This is aimed at library developers (like NCCL or NVSHMEM) to show how those libraries work internally; application developers are advised to use the higher‑level interfaces instead.
Each variant is a standalone project with its own Makefile.
Requirements
- CUDA version 11.0 or later (9.2 if built with
DISABLE_CUB=1). - OpenMP – needed for the multi‑threaded variants (tested with GCC).
- MPI – required for MPI, NVSHMEM, NCCL, and multi‑node P2P variants. The MPI variants need a CUDA‑aware MPI; the others only need a basic MPI.
- NVSHMEM (≥ 0.4.1) for the NVSHMEM variant.
- NCCL (≥ 2.8) for the NCCL variants;
nccl_graphsneeds NCCL 2.15.1, CUDA 11.7, and driver 515.65.01+;nccl_deviceneeds NCCL 2.31+. - Multi‑node P2P additionally requires CUDA 12.4, driver 550.54.14+, and the NVIDIA IMEX daemon.
Building
Each variant is built by running make in its directory. For example:
cd multi_threaded_copy
make
This produces an executable named jacobi. You can limit the build to a specific GPU architecture (SM) by setting BUILD_SM_ARCH (supported values: 80, 90, 100).
Running
All variants accept the same command‑line options:
-niter– number of iterations (default 1000)-nccheck– how often to check convergence (default 1)-nx,-ny– grid size in x and y (default 16384×16384)-csv– print results in CSV format-use_hp_streams– (only inmpi_overlap) use high‑priority streams to hide kernel launch latency
Some variants have extra options:
nvshmem:-use_block_comm,-norm_overlap,-neighborhood_syncmulti_node_p2p:-use_mc_red(use Multicast objects for barrier/allreduce)ncclvariants:-user_buffer_reg(requires NCCL 2.19.1+)nccl_device:-force_gin(use GIN for all neighbors)
The script bench.sh contains example commands that reproduce the benchmarks from the GTC talks.
Developer notes
The code follows the style defined in .clang-format. Contributors should run clang-format (version 7 or later) on jacobi.cu before submitting changes.
All information above is taken directly from the project’s README.
Related
- Project
- Project
- Project
- Project