PeerToPeer Device Memory Access

PeerToPeer Device Memory Access#

HIP Runtime API Reference: PeerToPeer Device Memory Access
PeerToPeer Device Memory Access
Collaboration diagram for PeerToPeer Device Memory Access:

Functions

hipError_t hipDeviceCanAccessPeer (int *canAccessPeer, int deviceId, int peerDeviceId)
 Determines if a device can access a peer device's memory.
 
hipError_t hipDeviceEnablePeerAccess (int peerDeviceId, unsigned int flags)
 Enables direct access to memory allocations on a peer device.
 
hipError_t hipDeviceDisablePeerAccess (int peerDeviceId)
 Disables direct access to memory allocations on a peer device.
 
hipError_t hipMemcpyPeer (void *dst, int dstDeviceId, const void *src, int srcDeviceId, size_t sizeBytes)
 Copies memory between two peer accessible devices.
 
hipError_t hipMemcpyPeerAsync (void *dst, int dstDeviceId, const void *src, int srcDevice, size_t sizeBytes, hipStream_t stream)
 Copies memory between two peer accessible devices asynchronously.
 

Detailed Description



This section describes the PeerToPeer device memory access functions of HIP runtime API.

Function Documentation

◆ hipDeviceCanAccessPeer()

hipError_t hipDeviceCanAccessPeer ( int *  canAccessPeer,
int  deviceId,
int  peerDeviceId 
)

Determines if a device can access a peer device's memory.

Parameters
[out]canAccessPeer- Returns the peer access capability (0 or 1)
[in]deviceId- The device accessing the peer device memory.
[in]peerDeviceId- Peer device where memory is physically located

The value of canAccessPeer,

Returns "1" if the specified deviceId is capable of directly accessing memory physically located on peerDeviceId,

Returns "0" if the specified deviceId is not capable of directly accessing memory physically located on peerDeviceId.

Returns "0" if deviceId == peerDeviceId, both are valid devices, however, a device is not a peer of itself.

Returns hipErrorInvalidDevice if deviceId or peerDeviceId are not valid devices

Returns
hipSuccess, hipErrorInvalidDevice

◆ hipDeviceDisablePeerAccess()

hipError_t hipDeviceDisablePeerAccess ( int  peerDeviceId)

Disables direct access to memory allocations on a peer device.

If direct access to memory allocations on peer device has not been enabled yet from the current device, it returns hipErrorPeerAccessNotEnabled.

Parameters
[in]peerDeviceIdPeer device to disable direct access to
Returns
hipSuccess, hipErrorPeerAccessNotEnabled

◆ hipDeviceEnablePeerAccess()

hipError_t hipDeviceEnablePeerAccess ( int  peerDeviceId,
unsigned int  flags 
)

Enables direct access to memory allocations on a peer device.

When this API is successful, all memory allocations on peer device will be mapped into the address space of the current device. In addition, any future memory allocation on the peer device will remain accessible from the current device, until the access is disabled using hipDeviceDisablePeerAccess or device is reset using hipDeviceReset.

Parameters
[in]peerDeviceId- Peer device to enable direct access to from the current device
[in]flags- Reserved for future use, must be zero
Returns
hipSuccess, hipErrorInvalidDevice, hipErrorInvalidValue,
hipErrorPeerAccessAlreadyEnabled if peer access is already enabled for this device.

◆ hipMemcpyPeer()

hipError_t hipMemcpyPeer ( void *  dst,
int  dstDeviceId,
const void *  src,
int  srcDeviceId,
size_t  sizeBytes 
)

Copies memory between two peer accessible devices.

Parameters
[out]dst- Destination device pointer
[in]dstDeviceId- Destination device
[in]src- Source device pointer
[in]srcDeviceId- Source device
[in]sizeBytes- Size of memory copy in bytes
Returns
hipSuccess, hipErrorInvalidValue, hipErrorInvalidDevice

◆ hipMemcpyPeerAsync()

hipError_t hipMemcpyPeerAsync ( void *  dst,
int  dstDeviceId,
const void *  src,
int  srcDevice,
size_t  sizeBytes,
hipStream_t  stream 
)

Copies memory between two peer accessible devices asynchronously.

Parameters
[out]dst- Destination device pointer
[in]dstDeviceId- Destination device
[in]src- Source device pointer
[in]srcDevice- Source device
[in]sizeBytes- Size of memory copy in bytes
[in]stream- Stream identifier
Returns
hipSuccess, hipErrorInvalidValue, hipErrorInvalidDevice