Device Memory Access

hipDeviceCanAccessPeer

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

Determine if a device can access a peer’s memory.

Returns “1” in

canAccessPeer if the specified device is capable of directly accessing memory physically located on peerDevice , or “0” if not.
Parameters
  • [out] canAccessPeer: Returns the peer access capability (0 or 1)

  • [in] device: - device from where memory may be accessed.

  • [in] peerDevice: - device where memory is physically located

Returns “0” in canAccessPeer if deviceId == peerDeviceId, and both are valid devices : a device is not a peer of itself.

Return

#hipSuccess,

Return

#hipErrorInvalidDevice if deviceId or peerDeviceId are not valid devices

hipDeviceEnablePeerAccess

hipError_t hipDeviceEnablePeerAccess(int peerDeviceId, unsigned int flags)

Enable direct access from current device’s virtual address space to memory allocations physically located on a peer device.

Memory which already allocated on peer device will be mapped into the address space of the current device. In addition, all future memory allocations on peerDeviceId will be mapped into the address space of the current device when the memory is allocated. The peer memory remains accessible from the current device until a call to hipDeviceDisablePeerAccess or hipDeviceReset.

Return

#hipErrorPeerAccessAlreadyEnabled if peer access is already enabled for this device.

Parameters
  • [in] peerDeviceId:

  • [in] flags: Returns #hipSuccess, #hipErrorInvalidDevice, #hipErrorInvalidValue,

hipDeviceDisablePeerAccess

hipError_t hipDeviceDisablePeerAccess(int peerDeviceId)

Disable direct access from current device’s virtual address space to memory allocations physically located on a peer device.

Returns hipErrorPeerAccessNotEnabled if direct access to memory on peerDevice has not yet been enabled from the current device.

Return

#hipSuccess, #hipErrorPeerAccessNotEnabled

Parameters
  • [in] peerDeviceId:

hipMemGetAddressRange

hipError_t hipMemGetAddressRange(hipDeviceptr_t *pbase, size_t *psize, hipDeviceptr_t dptr)

Get information on memory allocations.

Return

#hipSuccess, #hipErrorInvalidDevicePointer

See

hipCtxCreate, hipCtxDestroy, hipCtxGetFlags, hipCtxPopCurrent, hipCtxGetCurrent, hipCtxSetCurrent, hipCtxPushCurrent, hipCtxSetCacheConfig, hipCtxSynchronize, hipCtxGetDevice

Parameters
  • [out] pbase: - BAse pointer address

  • [out] psize: - Size of allocation

  • [in] dptr-: Device Pointer

hipMemcpyPeer

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

Copies memory from one device to memory on another device.

Return

#hipSuccess, #hipErrorInvalidValue, #hipErrorInvalidDevice

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

hipMemcpyPeerAsync

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

Copies memory from one device to memory on another device.

Return

#hipSuccess, #hipErrorInvalidValue, #hipErrorInvalidDevice

Parameters
  • [out] dst: - Destination device pointer.

  • [in] dstDevice: - Destination device

  • [in] src: - Source device pointer

  • [in] srcDevice: - Source device

  • [in] sizeBytes: - Size of memory copy in bytes

  • [in] stream: - Stream identifier