Table of Contents

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

sourceDeviceId int

The source GPU device ID.

targetDeviceId int

The target GPU device ID.

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

sourcePtr nint
sourceDeviceId int
destinationPtr nint
destinationDeviceId int
sizeBytes long

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

sourcePtr nint

Source memory pointer (on source device).

sourceDeviceId int

Source device ID.

destinationPtr nint

Destination memory pointer (on target device).

destinationDeviceId int

Destination device ID.

sizeBytes long

Number of bytes to copy.

cancellationToken CancellationToken

Cancellation 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

sourceDeviceId int

The source GPU device ID.

targetDeviceId int

The target GPU device ID.

cancellationToken CancellationToken

Cancellation token.

Returns

Task

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

sourceDeviceId int

The source GPU device ID.

targetDeviceId int

The target GPU device ID.

cancellationToken CancellationToken

Cancellation token.

Returns

Task<bool>

True if P2P access was enabled successfully.

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

sourceDeviceId int

Source device ID.

targetDeviceId int

Target device ID.

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

localPtr nint

Local memory pointer.

localDeviceId int

Local device ID where memory is allocated.

remoteDeviceId int

Remote device ID that needs access.

sizeBytes long

Size of the memory region to map.

cancellationToken CancellationToken

Cancellation token.

Returns

Task<nint>

Pointer accessible from the remote device.

UnmapPeerMemoryAsync(nint, int, CancellationToken)

Unmaps previously mapped peer memory.

Task UnmapPeerMemoryAsync(nint mappedPtr, int remoteDeviceId, CancellationToken cancellationToken = default)

Parameters

mappedPtr nint

The mapped pointer returned by MapPeerMemoryAsync.

remoteDeviceId int

The remote device ID.

cancellationToken CancellationToken

Cancellation token.

Returns

Task