What Is CUDA Peer-to-Peer Access? Check GPU Support and Exchange Data Safely
CUDA peer-to-peer (P2P) access lets one GPU directly access memory allocated on another GPU when that device pair and direction are supported. A GPU-to-GPU copy is also called a P2P transfer, but a kernel dereferencing a peer pointer and copying data into a second GPU allocation are different operations. Both depend on the GPU pair, access direction, driver, and PCIe/NVLink topology. The name P2P alone does not guarantee a host-free route or better performance.
What Is CUDA Peer-to-Peer Access? Check GPU Support and Exchange Data Safely
CUDA peer-to-peer (P2P) access lets one GPU directly access memory allocated on another GPU when that device pair and direction are supported. A GPU-to-GPU copy is also called a P2P transfer, but a kernel dereferencing a peer pointer and copying data into a second GPU allocation are different operations. Both depend on the GPU pair, access direction, driver, and PCIe/NVLink topology. The name P2P alone does not guarantee a host-free route or better performance.
For the relationship between NVLink as a physical connection and P2P, see the NVLink and NVSwitch overview. For how Unified Virtual Addressing identifies pointers across devices, see CUDA UVA. This article focuses on checking CUDA peer capability, enabling the right direction, and choosing between remote access and an explicit copy.
What is the difference between direct access and a GPU-to-GPU copy?
Suppose GPU 0 owns a buffer that GPU 1 needs to consume. With direct peer access, a kernel running on GPU 1 reads GPU 0’s pointer. With a peer copy, CUDA copies the contents into a separate allocation on GPU 1, and a later GPU 1 kernel reads its local buffer. When peer memory access is enabled between supported devices, CUDA can perform peer copies without staging the transfer through host memory, but a copy call and a kernel’s remote pointer dereference are not the same operation. CUDA documents use of copy engines and NVLink when available; the actual route and performance must still be checked on the target system. CUDA Programming Guide — Peer-to-Peer Transfers and Memory Access
GPU 0 allocation: x0
│
├─ Direct access: a GPU 1 kernel reads x0
│ (GPU 1 → GPU 0 access permission required)
│
└─ Peer copy: cudaMemcpyPeerAsync(x1, GPU 1, x0, GPU 0)
→ a later kernel reads x1 in GPU 1 memory
Both paths must order data production before consumptionThe arrows show which direction the API check must describe. For GPU 1 to read GPU 0 memory directly, check whether “GPU 1 can access GPU 0,” then enable access from GPU 1 to GPU 0. If GPU 0 must also read GPU 1 memory, check and enable the reverse direction separately. Enabling access does not make access bidirectional or synchronize the GPUs. CUDA Runtime API 13.5 — Peer Device Memory Access
| Operation | What GPU 1 does | May fit when | Main cost or condition |
|---|---|---|---|
| Direct peer access | A GPU 1 kernel dereferences an allocation on GPU 0 | It needs only some peer data, or avoiding a copy simplifies a pipeline | Remote access latency or bandwidth may affect the kernel; directional permission and correct synchronization are required |
| Peer copy, then local use | Copy a range into a separate GPU 1 allocation | GPU 1 reuses the same data across several kernels or local access matters | Copy time and extra memory; do not consume the destination before the copy completes |
| Host-staged copy | Move GPU 0 → host buffer → GPU 1 | The pair does not support peer access or another route needs comparison | Host memory and extra copies; synchronization and buffer management can be more involved |
Unified Virtual Addressing (UVA) gives CUDA a common virtual address space for CPU and GPU allocations. The CUDA guide explains that supported peer devices use this address space, so the same pointer value can identify peer memory. But UVA is not access permission. Do not assume a peer kernel can use an allocation merely because the pointer is recognizable or has the same value; the device pair must support the requested access and the permission must be enabled. CUDA Programming Guide — Unified Virtual Address Space and Peer Access
How do you check peer capability and the path between GPUs?
First identify the accessing GPU and the GPU that owns the allocation. The CUDA Runtime API call cudaDeviceCanAccessPeer(&canAccess, consumerDevice, ownerDevice) asks whether the first device can directly access memory on the second. A result of 1 says that access is possible; it does not mean permission has already been enabled. If supported, select the accessing device as current and call cudaDeviceEnablePeerAccess(ownerDevice, 0). This grants access in one direction only. Handle the already-enabled result separately. The Runtime API also notes that these functions may report errors from earlier asynchronous work. CUDA Runtime API 13.5 — Peer Device Memory Access
These three APIs answer different questions: whether a direction is supported, whether permission is enabled from the current device, and what attributes the device pair exposes.
| API | What it checks or changes | How to interpret it |
|---|---|---|
cudaDeviceCanAccessPeer | Whether the proposed consumer can access the owner’s memory | canAccess == 1 reports capability; it does not enable permission |
cudaDeviceEnablePeerAccess | Enables access from the current device to the specified peer | The setting is directional; check and enable the reverse direction separately |
cudaDeviceGetP2PAttribute | Queries pair attributes such as rank, read, write, or atomic support | Capability and relative rank are not an application benchmark |
Inspect the system path with nvidia-smi topo -m. In the matrix, NV# denotes a bonded group of NVLinks; PIX a single PCIe switch; PXB multiple PCIe switches; PHB a PCIe host bridge; and NODE or SYS broader host/NUMA paths. This output reports topology, not CUDA permission or application throughput. Commands such as nvidia-smi topo -p2p r, -p2p w, and -p2p a can report P2P read, write, and atomic capabilities; -p2p p and -p2p n query PCIe and NVLink P2P capability. Check the installed driver’s nvidia-smi topo -h for supported options. NVIDIA System Management Interface — Topology Commands
nvidia-smi topo -m
nvidia-smi topo -p2p r
nvidia-smi topo -p2p wCUDA Runtime API’s cudaDeviceGetP2PAttribute can query link attributes by direction. For example, cudaDevP2PAttrPerformanceRank is a relative rank: a lower value indicates a higher documented rank, with 0 used for the most performant link. It is not an application benchmark, so measure your real data size and kernel access pattern. Check atomic or CUDA array support separately if your workload needs those operations. CUDA Runtime API 13.5 — Device Management
Even a promising hardware path can be limited by the execution environment. NVIDIA’s CUDA guide states that PCIe P2P transfer with IOMMU enabled is unsupported on Linux bare-metal systems, while virtual-machine PCIe passthrough has separate requirements. Do not change IOMMU or firmware settings on a shared host without consulting its administrator and the applicable CUDA/driver documentation. GPUDirect RDMA refers to transfers between a GPU and a third-party PCIe device such as a NIC, so it is distinct from CUDA P2P between GPUs. CUDA Programming Guide — Multi-GPU System Limitations NVIDIA GPUDirect RDMA — Supported Systems and IOMMU
How do you enable P2P and order data correctly?
The example below assumes GPU 0 produces data and GPU 1 consumes it. Pass the GPU that owns the allocation as ownerDevice and the GPU that will read the pointer as consumerDevice. The function queries capability first and enables GPU 1’s access to GPU 0 only when supported. In an application, check and handle every CUDA API and kernel error.
#include <cuda_runtime.h>
cudaError_t enablePeerRead(int consumerDevice, int ownerDevice, bool* enabled) {
if (enabled == nullptr || consumerDevice == ownerDevice) {
return cudaErrorInvalidValue;
}
*enabled = false;
int canAccess = 0;
cudaError_t err = cudaDeviceCanAccessPeer(
&canAccess, consumerDevice, ownerDevice);
if (err != cudaSuccess) return err;
if (canAccess == 0) return cudaSuccess;
err = cudaSetDevice(consumerDevice);
if (err != cudaSuccess) return err;
err = cudaDeviceEnablePeerAccess(ownerDevice, 0);
if (err == cudaErrorPeerAccessAlreadyEnabled) {
*enabled = true;
return cudaSuccess;
}
if (err != cudaSuccess) return err;
*enabled = true;
return cudaSuccess;
}
// A successful return may still mean the pair is unsupported.
// Keep the copy path unless enabled becomes true.
bool usePeerRead = false;
cudaError_t peerStatus = enablePeerRead(1, 0, &usePeerRead);
if (peerStatus != cudaSuccess) {
// Handle the CUDA error; do not silently assume peer access works.
}
// After GPU 0 has produced peerData on producerStream:
cudaSetDevice(0);
cudaEventRecord(dataReady, producerStream);
// Order GPU 1's consumer work after GPU 0's producer event.
cudaSetDevice(1);
cudaStreamWaitEvent(consumerStream, dataReady, 0);
// Choose direct access or peer copy only when peer access is enabled.
if (usePeerRead && preferDirectRead) {
consumePeerData<<<grid, block, 0, consumerStream>>>(peerData);
} else if (usePeerRead) {
cudaMemcpyPeerAsync(localData, 1, peerData, 0, bytes, consumerStream);
consumeLocalData<<<grid, block, 0, consumerStream>>>(localData);
} else {
// Use an application-defined supported fallback, such as host staging.
stageThroughHostAndConsume(peerData, localData, bytes);
}This fragment demonstrates API order; it is not a complete program. preferDirectRead represents the path selected by the application, and stageThroughHostAndConsume is a placeholder for an application-defined helper that must correctly perform and order the fallback copies. The application creates producerStream, consumerStream, dataReady, buffers, and kernels and must check all API and launch errors. Record the event after GPU 0’s producing work, then wait for it in GPU 1’s stream before consuming. CUDA documents cudaStreamWaitEvent for ordering streams and events across devices. If kernels write peer memory concurrently or use atomics, review system-scope synchronization and the link’s atomic capabilities; pointer permission alone does not make concurrent writes safe. CUDA Programming Guide — Multi-Device Stream and Peer Memory Consistency
cudaMemcpyPeerAsync(dst, dstDevice, src, srcDevice, count, stream) asynchronously copies a range between devices. It is asynchronous with respect to the host and work on other devices, so wait for the copy in its stream or establish an event dependency before reading the destination. The synchronous cudaMemcpyPeer can serialize with asynchronous work on the current, source, and destination devices, which can cause a broader wait than intended. CUDA documents that copies between devices with peer access enabled need not be staged through host memory. This does not guarantee a transfer route for every GPU pair; if the route is unsupported, choose host staging or a supported communication library explicitly and measure the actual performance. CUDA Runtime API 13.5 — Peer-to-Peer Memory Transfers
cudaDeviceEnablePeerAccess makes all existing and future allocations from the peer device accessible to the current device. This global scope can add memory-allocation overhead, especially when many peers are enabled. NVIDIA describes CUDA Virtual Memory Management as a more scoped alternative when only selected memory ranges should be peer-accessible. Systems also have peer-connection limits; avoid enabling every possible pair without considering the communication graph and allocation strategy. CUDA Programming Guide — Peer Access Scope and Virtual Memory Management
When should you read peer memory directly or copy it locally?
The choice does not end at “P2P is available.” If GPU 1 reads only a small part of GPU 0’s data once, direct access may avoid a copy stage. If GPU 1 reuses the same range across many kernels, one copy into GPU 1’s local memory may pay off through reuse. Neither path is universally faster across topologies and data patterns, so compare end-to-end time for the actual workload.
| Observed use pattern | First path to compare | What to check |
|---|---|---|
| Read a small amount of peer data once | Direct peer reads versus copy-then-local reads | Whether remote latency overlaps with computation and how much data is actually consumed |
| Reuse a large range across several GPU stages | One cudaMemcpyPeerAsync followed by local reuse | Whether repeated reuse offsets the initial copy and whether the extra allocation fits |
| Consumer GPU must keep modifying the source data | Assign a clear owner or add an explicit exchange phase | Concurrent read/write conflicts and system-scope synchronization requirements |
| Peer access is unavailable for the pair | Compare host staging, a different GPU placement, or a supported communication library | Copy count, pinned-buffer lifetime, and whether the host round trip is a measured bottleneck |
Use this diagnostic order:
**Record device direction.** Write down which GPU owns the source allocation and which GPU will read or copy it, including ordinals or PCI bus IDs.
**Check capability and topology.** Compare `cudaDeviceCanAccessPeer`, any relevant `cudaDeviceGetP2PAttribute` values, and `nvidia-smi topo -m`/ `-p2p` output.
**Choose one simple path.** Implement direct access or a peer copy. If unsupported, select an explicit fallback rather than assuming the path will work.
**Order producer and consumer work.** Use event/stream ordering so reads start after writes complete; confirm earlier consumers have finished before a reused buffer is overwritten.
**Compare under real load.** Hold data, kernels, and concurrent GPU work constant; measure the full path from preparation to final result and check correctness, transfer volume, and synchronization. A copy-bandwidth result from one device alone is not a substitute for application performance.
GPU P2P is a CUDA capability for one GPU to access or copy another GPU’s memory. NVLink is one physical interconnect that may carry the traffic; UVA is an address-identification system; GPUDirect RDMA is a data path between a GPU and an external device such as a network adapter. Check the supported direction, synchronization, and actual throughput separately on the system you deploy.
References
[NVIDIA CUDA Programming Guide — Multi-GPU Systems](https://docs.nvidia.com/cuda/cuda-programming-guide/03-advanced/multi-gpu-systems.html)
[NVIDIA CUDA Runtime API 13.5 — Peer Device Memory Access](https://docs.nvidia.com/cuda/cuda-runtime-api/cuda_runtime_api/group__CUDART__PEER.html)
[NVIDIA CUDA Runtime API 13.5 — Device Management and P2P Attributes](https://docs.nvidia.com/cuda/cuda-runtime-api/cuda_runtime_api/group__CUDART__DEVICE.html)
[NVIDIA System Management Interface — GPU Topology](https://docs.nvidia.com/deploy/nvidia-smi/index.html)
[NVIDIA GPUDirect RDMA — Supported Systems](https://docs.nvidia.com/cuda/gpudirect-rdma/)
References
- NVIDIA CUDA Programming Guide — Multi-GPU Systems
- NVIDIA CUDA Runtime API 13.5 — Peer Device Memory Access
- NVIDIA CUDA Runtime API 13.5 — Memory Management
- NVIDIA CUDA Runtime API 13.5 — Device Management and P2P Attributes
- NVIDIA System Management Interface — GPU Topology
- NVIDIA GPUDirect RDMA — Supported Systems