Peer-memory access and locality
Establish peer permissions, ordering, and lifetime before comparing remote tensor reads with local replication.
On this page
The question for today
What you’ll understand
- Distinguish unified addressing, peer capability, and allocation access permission.
- Order producers and consumers across devices and preserve shared lifetimes.
- Compare remote access with copy-once reuse under declared bandwidth assumptions.
A tensor-parallel application can sometimes read a tensor residing on another GPU without staging it through host memory. That capability does not turn the other GPU’s memory into local DRAM, and it does not order the producer before the reader. This lesson follows CUDA 12.8.1 on two supported Ampere-class devices, with explicit capability checks and an actual PCIe or NVLink topology. Platform, allocation type, link path, and synchronization scope all matter.
Permissions depend on device and allocation
Query peer capability for the device pair and relevant direction instead of assuming any two visible GPUs can access each other’s memory. Enable the needed peer-access relationship for ordinary allocations where supported. Unified virtual addressing can make a pointer recognizable without granting access permission or establishing locality. A peer path can also have a different bandwidth and latency from a device’s own memory. Record the topology and access direction; symmetric application code does not prove symmetric capabilities or performance.
Stream-ordered memory-pool allocations require their documented pool-access configuration, including cudaMemPoolSetAccess for the intended devices. Merely calling cudaDeviceEnablePeerAccess is not the corresponding permission mechanism for those pool allocations. Device-native peer atomics and ordering guarantees also need explicit capability and memory-model checks. Do not turn the existence of a working peer read into a claim that every atomic type, scope, or multi-device synchronization pattern is supported. Allocation provenance is part of the access contract, not an incidental implementation detail.
Addressability is not a producer-consumer dependency
A producer kernel on GPU zero must finish the writes required by a consumer on GPU one before that consumer reads them. Establish the documented dependency, for example a suitable recorded event and supported cross-device stream wait, or an appropriate host synchronization before submission. A pointer arriving in the consumer’s launch arguments is not a completion signal. Separate access permissions from ordering and visibility so that a later performance change does not accidentally remove the dependency that made the original program correct.
The allocation must remain valid until every device that may access it has finished. Freeing on the owner device after its own last local use is insufficient if a peer still reads the tensor. Similarly, a remote write or atomic protocol needs the correct scope rather than an assumption that the interconnect provides application-level synchronization automatically. For an inference weight shard, immutable reads after one ordered publication are simpler than concurrent mutation, but even immutable data still require publication and lifetime ownership.
Choose placement for the reuse pattern
Remote access can avoid a copy when only a small portion of a tensor is consumed once. Copying a whole tensor locally can amortize its transfer when many full scans follow, but it uses additional capacity and introduces a copy-completion boundary. A real design may instead partition work, use a collective communication primitive, or cache selected blocks. Compare representative tensor sizes and reuse counts under concurrent load, because isolated link throughput does not capture contention with other collectives or transfers.
The Roofline lab illustrates only an assumed bandwidth change. Reset, set operational intensity to 2 and bandwidth to 80, predict the synthetic ceiling, then Step. Compare a fresh Reset with both intensity at 2 and bandwidth at 40 before Step. The ceilings are 160 and 80 GFLOP/s under a fixed synthetic compute limit of 1000. These values do not represent a particular peer link, GPU, copy operation, permissions check, or cross-device memory-order implementation.
Work it through
Amortize one declared replication cost
Assume a two-GB tensor in decimal units, five complete reads, peer-path bandwidth of 50 GB/s and local bandwidth of 500 GB/s. Ignore latency, caching, overlap, capacity pressure, and every other operation. Compare repeated remote reads with copying once and then reading locally.
Five remote scans move 10 GB across the peer path, taking 10/50 = 0.20 seconds in this model.
Copying once costs 2/50 = 0.04 seconds. Five local scans cost 10/500 = 0.02 seconds.
The copy-then-local total is 0.06 seconds, saving 0.14 seconds in the bandwidth-only comparison while requiring a local two-GB replica and correct copy completion.
Reuse can amortize replication under stated assumptions, but topology, capacity, and measured traffic determine the actual choice.
The living notebook
Explore the model
Interactive lab · roofline
Bandwidth sensitivity without a peer-fabric simulator
Reset, set I = 2 and B = 80, predict the ceiling, then Step: 160 GFLOP/s. Compare a fresh Reset with both I = 2 and B = 40 before Step: 80 GFLOP/s. The fixed compute ceiling is 1000 GFLOP/s; these hypothetical settings do not benchmark a peer link or implement ordering.
- Attainable ceiling
- 640 GFLOP/s
- Ridge intensity
- 12.5 FLOP/byte
- Ceiling regime
- Memory-bound ceiling
Synthetic roofline ceiling min(1000, B·I), in GFLOP/s, with B in decimal GB/s and I in FLOP/byte. Playback traces the roof without changing the selected kernel. This upper-bound model is not a measured throughput prediction, hardware comparison or price model. Parameter changes pause playback and recompute the model at the current elapsed time. Reset restores both parameters and returns time to zero. Playback starts paused. Adjust either parameter, then choose Play or Step.
Look forAn assumed bandwidth reduction changes a model ceiling, while peer permissions, topology, and synchronization need separate evidence.
Pause & reason
Check your understanding
Your turn
Try it yourself
Under the same simplified assumptions, compare three full reads of one decimal GB with a 25-GB/s peer path and 250-GB/s local memory. Include the initial copy in the replication option and state one reason to measure the real application.
Take a moment to make a prediction or work it out on paper. Open a hint when you need one.
Give me a hint
Remote cost uses three link transfers; replication uses one link transfer plus three local scans.
Compare with the solution
Remote time is 3/25 = 0.12 seconds. Replication costs 1/25 + 3/250 = 0.04 + 0.012 = 0.052 seconds. Caching, partial reads, link contention, overlap, and local-capacity pressure can change that comparison. Measurements also need correct producer completion and a lifetime long enough for all three reads; a faster but racy result is not a valid alternative.
Keep the idea
Take it with you
- Peer capability, allocation-specific permissions, and address recognition are distinct.
- Cross-device consumers require ordering and shared allocation lifetime.
- Remote reads versus replication depends on reuse, topology, and local capacity.
Read further
Original sources and deeper explanations to follow at your own pace.
Optional progress, saved in this browser when available. Revisit any lesson at any time.
Lesson not marked complete.