Interface IGpuPeerToPeerMemory
- Namespace
- Orleans.GpuBridge.Abstractions.K2K
- Assembly
- Orleans.GpuBridge.Abstractions.dll
Interface for GPU peer-to-peer (P2P) memory operations. Enables direct GPU-to-GPU memory access without CPU involvement.
public interface IGpuPeerToPeerMemory
Remarks
P2P memory access allows GPUs to directly read/write each other's memory, enabling sub-microsecond latency communication between GPU-resident actors.
**Performance Characteristics:**
- NVLink: 600+ GB/s bandwidth, 100-200ns latency
- PCIe P2P: 32-64 GB/s bandwidth, 500ns-1μs latency
- CPU-routed (fallback): 15-25 GB/s bandwidth, 2-10μs latency
**Implementation Notes:** - CUDA: Uses cuMemcpyPeer, cuCtxEnablePeerAccess - ROCm: Uses hipMemcpyPeer, hipDeviceEnablePeerAccess - DotCompute: Backend-specific implementation
Methods
CanAccessPeer(int, int)
Checks if peer-to-peer access is supported between two GPU devices.
bool CanAccessPeer(int sourceDeviceId, int targetDeviceId)
Parameters
Returns
- bool
True if P2P access is supported between the devices.
CopyPeerToPeer(nint, int, nint, int, long)
Copies memory directly between two GPU devices synchronously.
void CopyPeerToPeer(nint sourcePtr, int sourceDeviceId, nint destinationPtr, int destinationDeviceId, long sizeBytes)
Parameters
Remarks
Use this for small, latency-critical transfers where async overhead is undesirable.
CopyPeerToPeerAsync(nint, int, nint, int, long, CancellationToken)
Copies memory directly between two GPU devices using P2P transfer.
Task CopyPeerToPeerAsync(nint sourcePtr, int sourceDeviceId, nint destinationPtr, int destinationDeviceId, long sizeBytes, CancellationToken cancellationToken = default)
Parameters
sourcePtrnintSource memory pointer (on source device).
sourceDeviceIdintSource device ID.
destinationPtrnintDestination memory pointer (on target device).
destinationDeviceIdintDestination device ID.
sizeByteslongNumber of bytes to copy.
cancellationTokenCancellationTokenCancellation token.
Returns
- Task
Task that completes when the copy is done.
DisablePeerAccessAsync(int, int, CancellationToken)
Disables peer-to-peer access from source device to target device.
Task DisablePeerAccessAsync(int sourceDeviceId, int targetDeviceId, CancellationToken cancellationToken = default)
Parameters
sourceDeviceIdintThe source GPU device ID.
targetDeviceIdintThe target GPU device ID.
cancellationTokenCancellationTokenCancellation token.
Returns
EnablePeerAccessAsync(int, int, CancellationToken)
Enables peer-to-peer access from source device to target device.
Task<bool> EnablePeerAccessAsync(int sourceDeviceId, int targetDeviceId, CancellationToken cancellationToken = default)
Parameters
sourceDeviceIdintThe source GPU device ID.
targetDeviceIdintThe target GPU device ID.
cancellationTokenCancellationTokenCancellation token.
Returns
Exceptions
- InvalidOperationException
If P2P is not supported between devices.
GetP2PCapability(int, int)
Gets detailed P2P capability information between devices.
P2PCapabilityInfo? GetP2PCapability(int sourceDeviceId, int targetDeviceId)
Parameters
Returns
- P2PCapabilityInfo
P2P capability details, or null if not available.
MapPeerMemoryAsync(nint, int, int, long, CancellationToken)
Maps a device memory pointer to be accessible from another device.
Task<nint> MapPeerMemoryAsync(nint localPtr, int localDeviceId, int remoteDeviceId, long sizeBytes, CancellationToken cancellationToken = default)
Parameters
localPtrnintLocal memory pointer.
localDeviceIdintLocal device ID where memory is allocated.
remoteDeviceIdintRemote device ID that needs access.
sizeByteslongSize of the memory region to map.
cancellationTokenCancellationTokenCancellation token.
Returns
UnmapPeerMemoryAsync(nint, int, CancellationToken)
Unmaps previously mapped peer memory.
Task UnmapPeerMemoryAsync(nint mappedPtr, int remoteDeviceId, CancellationToken cancellationToken = default)
Parameters
mappedPtrnintThe mapped pointer returned by MapPeerMemoryAsync.
remoteDeviceIdintThe remote device ID.
cancellationTokenCancellationTokenCancellation token.