Skip to content

Commit

Permalink
Merge pull request #631 from JackAKirk/exp-usm-p2p
Browse files Browse the repository at this point in the history
[Exp][usm-p2p] Initial usm-p2p UR extension.
  • Loading branch information
veselypeta authored Jun 21, 2023
2 parents cbea4aa + 2a1ac14 commit 65b8cb4
Show file tree
Hide file tree
Showing 14 changed files with 1,529 additions and 0 deletions.
60 changes: 60 additions & 0 deletions include/ur.py
Original file line number Diff line number Diff line change
Expand Up @@ -1978,6 +1978,9 @@ class ur_function_v(IntEnum):
PHYSICAL_MEM_RELEASE = 162 ## Enumerator for ::urPhysicalMemRelease
USM_IMPORT_EXP = 163 ## Enumerator for ::urUSMImportExp
USM_RELEASE_EXP = 164 ## Enumerator for ::urUSMReleaseExp
USM_P2P_ENABLE_PEER_ACCESS_EXP = 165 ## Enumerator for ::urUsmP2PEnablePeerAccessExp
USM_P2P_DISABLE_PEER_ACCESS_EXP = 166 ## Enumerator for ::urUsmP2PDisablePeerAccessExp
USM_P2P_PEER_ACCESS_GET_INFO_EXP = 167 ## Enumerator for ::urUsmP2PPeerAccessGetInfoExp

class ur_function_t(c_int):
def __str__(self):
Expand Down Expand Up @@ -2082,6 +2085,19 @@ class ur_exp_command_buffer_sync_point_t(c_ulong):
class ur_exp_command_buffer_handle_t(c_void_p):
pass

###############################################################################
## @brief Supported peer info
class ur_exp_peer_info_v(IntEnum):
UR_PEER_ACCESS_SUPPORTED = 0 ## [uint32_t] 1 if P2P access is supported otherwise P2P access is not
## supported.
UR_PEER_ATOMICS_SUPPORTED = 1 ## [uint32_t] 1 if atomic operations are supported over the P2P link,
## otherwise such operations are not supported.

class ur_exp_peer_info_t(c_int):
def __str__(self):
return str(ur_exp_peer_info_v(self.value))


###############################################################################
__use_win_types = "Windows" == platform.uname()[0]

Expand Down Expand Up @@ -3303,6 +3319,37 @@ class ur_command_buffer_exp_dditable_t(Structure):
("pfnEnqueueExp", c_void_p) ## _urCommandBufferEnqueueExp_t
]

###############################################################################
## @brief Function-pointer for urUsmP2PEnablePeerAccessExp
if __use_win_types:
_urUsmP2PEnablePeerAccessExp_t = WINFUNCTYPE( ur_result_t, ur_device_handle_t, ur_device_handle_t )
else:
_urUsmP2PEnablePeerAccessExp_t = CFUNCTYPE( ur_result_t, ur_device_handle_t, ur_device_handle_t )

###############################################################################
## @brief Function-pointer for urUsmP2PDisablePeerAccessExp
if __use_win_types:
_urUsmP2PDisablePeerAccessExp_t = WINFUNCTYPE( ur_result_t, ur_device_handle_t, ur_device_handle_t )
else:
_urUsmP2PDisablePeerAccessExp_t = CFUNCTYPE( ur_result_t, ur_device_handle_t, ur_device_handle_t )

###############################################################################
## @brief Function-pointer for urUsmP2PPeerAccessGetInfoExp
if __use_win_types:
_urUsmP2PPeerAccessGetInfoExp_t = WINFUNCTYPE( ur_result_t, ur_device_handle_t, ur_device_handle_t, ur_exp_peer_info_t, c_size_t, c_void_p, POINTER(c_size_t) )
else:
_urUsmP2PPeerAccessGetInfoExp_t = CFUNCTYPE( ur_result_t, ur_device_handle_t, ur_device_handle_t, ur_exp_peer_info_t, c_size_t, c_void_p, POINTER(c_size_t) )


###############################################################################
## @brief Table of UsmP2PExp functions pointers
class ur_usm_p2p_exp_dditable_t(Structure):
_fields_ = [
("pfnEnablePeerAccessExp", c_void_p), ## _urUsmP2PEnablePeerAccessExp_t
("pfnDisablePeerAccessExp", c_void_p), ## _urUsmP2PDisablePeerAccessExp_t
("pfnPeerAccessGetInfoExp", c_void_p) ## _urUsmP2PPeerAccessGetInfoExp_t
]

###############################################################################
## @brief Function-pointer for urInit
if __use_win_types:
Expand Down Expand Up @@ -3485,6 +3532,7 @@ class ur_dditable_t(Structure):
("USM", ur_usm_dditable_t),
("USMExp", ur_usm_exp_dditable_t),
("CommandBufferExp", ur_command_buffer_exp_dditable_t),
("UsmP2PExp", ur_usm_p2p_exp_dditable_t),
("Global", ur_global_dditable_t),
("VirtualMem", ur_virtual_mem_dditable_t),
("Device", ur_device_dditable_t)
Expand Down Expand Up @@ -3772,6 +3820,18 @@ def __init__(self, version : ur_api_version_t):
self.urCommandBufferAppendMembufferCopyRectExp = _urCommandBufferAppendMembufferCopyRectExp_t(self.__dditable.CommandBufferExp.pfnAppendMembufferCopyRectExp)
self.urCommandBufferEnqueueExp = _urCommandBufferEnqueueExp_t(self.__dditable.CommandBufferExp.pfnEnqueueExp)

# call driver to get function pointers
UsmP2PExp = ur_usm_p2p_exp_dditable_t()
r = ur_result_v(self.__dll.urGetUsmP2PExpProcAddrTable(version, byref(UsmP2PExp)))
if r != ur_result_v.SUCCESS:
raise Exception(r)
self.__dditable.UsmP2PExp = UsmP2PExp

# attach function interface to function address
self.urUsmP2PEnablePeerAccessExp = _urUsmP2PEnablePeerAccessExp_t(self.__dditable.UsmP2PExp.pfnEnablePeerAccessExp)
self.urUsmP2PDisablePeerAccessExp = _urUsmP2PDisablePeerAccessExp_t(self.__dditable.UsmP2PExp.pfnDisablePeerAccessExp)
self.urUsmP2PPeerAccessGetInfoExp = _urUsmP2PPeerAccessGetInfoExp_t(self.__dditable.UsmP2PExp.pfnPeerAccessGetInfoExp)

# call driver to get function pointers
Global = ur_global_dditable_t()
r = ur_result_v(self.__dll.urGetGlobalProcAddrTable(version, byref(Global)))
Expand Down
180 changes: 180 additions & 0 deletions include/ur_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -5274,6 +5274,9 @@ typedef enum ur_function_t {
UR_FUNCTION_PHYSICAL_MEM_RELEASE = 162, ///< Enumerator for ::urPhysicalMemRelease
UR_FUNCTION_USM_IMPORT_EXP = 163, ///< Enumerator for ::urUSMImportExp
UR_FUNCTION_USM_RELEASE_EXP = 164, ///< Enumerator for ::urUSMReleaseExp
UR_FUNCTION_USM_P2P_ENABLE_PEER_ACCESS_EXP = 165, ///< Enumerator for ::urUsmP2PEnablePeerAccessExp
UR_FUNCTION_USM_P2P_DISABLE_PEER_ACCESS_EXP = 166, ///< Enumerator for ::urUsmP2PDisablePeerAccessExp
UR_FUNCTION_USM_P2P_PEER_ACCESS_GET_INFO_EXP = 167, ///< Enumerator for ::urUsmP2PPeerAccessGetInfoExp
/// @cond
UR_FUNCTION_FORCE_UINT32 = 0x7fffffff
/// @endcond
Expand Down Expand Up @@ -7442,6 +7445,152 @@ urUSMReleaseExp(
void *pMem ///< [in] pointer to host memory object
);

#if !defined(__GNUC__)
#pragma endregion
#endif
// Intel 'oneAPI' Unified Runtime Experimental APIs for USM P2P
#if !defined(__GNUC__)
#pragma region usm p2p(experimental)
#endif
///////////////////////////////////////////////////////////////////////////////
/// @brief Supported peer info
typedef enum ur_exp_peer_info_t {
UR_EXP_PEER_INFO_UR_PEER_ACCESS_SUPPORTED = 0, ///< [uint32_t] 1 if P2P access is supported otherwise P2P access is not
///< supported.
UR_EXP_PEER_INFO_UR_PEER_ATOMICS_SUPPORTED = 1, ///< [uint32_t] 1 if atomic operations are supported over the P2P link,
///< otherwise such operations are not supported.
/// @cond
UR_EXP_PEER_INFO_FORCE_UINT32 = 0x7fffffff
/// @endcond

} ur_exp_peer_info_t;

///////////////////////////////////////////////////////////////////////////////
/// @brief Enable access to peer device memory
///
/// @details
/// - Enables the command device to access and write device memory
/// allocations located on the peer device, provided that a P2P link
/// between the two devices is available.
/// - When Peer Access is successfully enabled, P2P memory accesses are
/// guaranteed to be allowed on the peer device until
/// ::urUsmP2PDisablePeerAccessExp is called.
/// - Note that the function operands may, but aren't guaranteed to, commute
/// for a given adapter: the peer device is not guaranteed to have access
/// to device memory allocations located on the command device.
/// - It is not guaranteed that the commutation relations of the function
/// arguments are identical for peer access and peer copies: For example,
/// for a given adapter the peer device may be able to copy data from the
/// command device, but not access and write the same data on the command
/// device.
/// - Consult the appropriate adapter driver documentation for details of
/// adapter specific behavior and native error codes that may be returned.
///
/// @remarks
/// _Analogues_
/// - **cuCtxEnablePeerAccess**
///
/// @returns
/// - ::UR_RESULT_SUCCESS
/// - ::UR_RESULT_ERROR_UNINITIALIZED
/// - ::UR_RESULT_ERROR_DEVICE_LOST
/// - ::UR_RESULT_ERROR_INVALID_NULL_HANDLE
/// + `NULL == commandDevice`
/// + `NULL == peerDevice`
/// - ::UR_RESULT_SUCCESS
/// - ::UR_RESULT_ERROR_ADAPTER_SPECIFIC
UR_APIEXPORT ur_result_t UR_APICALL
urUsmP2PEnablePeerAccessExp(
ur_device_handle_t commandDevice, ///< [in] handle of the command device object
ur_device_handle_t peerDevice ///< [in] handle of the peer device object
);

///////////////////////////////////////////////////////////////////////////////
/// @brief Disable access to peer device memory
///
/// @details
/// - Disables the ability of the command device to access and write device
/// memory allocations located on the peer device, provided that a P2P
/// link between the two devices was enabled prior to the call.
/// - Note that the function operands may, but aren't guaranteed to, commute
/// for a given adapter. If, prior to the function call, the peer device
/// had access to device memory allocations on the command device, it is
/// not guaranteed to still have such access following the function
/// return.
/// - It is not guaranteed that the commutation relations of the function
/// arguments are identical for peer access and peer copies: For example
/// for a given adapter, if, prior to the call, the peer device had access
/// to device memory allocations on the command device, the peer device
/// may still, following the function call, be able to copy data from the
/// command device, but not access and write the same data on the command
/// device.
/// - Consult the appropriate adapter driver documentation for details of
/// adapter specific behavior and native error codes that may be returned.
///
/// @remarks
/// _Analogues_
/// - **cuCtxDisablePeerAccess**
///
/// @returns
/// - ::UR_RESULT_SUCCESS
/// - ::UR_RESULT_ERROR_UNINITIALIZED
/// - ::UR_RESULT_ERROR_DEVICE_LOST
/// - ::UR_RESULT_ERROR_INVALID_NULL_HANDLE
/// + `NULL == commandDevice`
/// + `NULL == peerDevice`
/// - ::UR_RESULT_SUCCESS
/// - ::UR_RESULT_ERROR_ADAPTER_SPECIFIC
UR_APIEXPORT ur_result_t UR_APICALL
urUsmP2PDisablePeerAccessExp(
ur_device_handle_t commandDevice, ///< [in] handle of the command device object
ur_device_handle_t peerDevice ///< [in] handle of the peer device object
);

///////////////////////////////////////////////////////////////////////////////
/// @brief Disable access to peer device memory
///
/// @details
/// - Queries the peer access capabilities from the command device to the
/// peer device according to the query `propName`.
///
/// @remarks
/// _Analogues_
/// - **cuDeviceGetP2PAttribute**
///
/// @returns
/// - ::UR_RESULT_SUCCESS
/// - ::UR_RESULT_ERROR_UNINITIALIZED
/// - ::UR_RESULT_ERROR_DEVICE_LOST
/// - ::UR_RESULT_ERROR_INVALID_NULL_HANDLE
/// + `NULL == commandDevice`
/// + `NULL == peerDevice`
/// - ::UR_RESULT_ERROR_INVALID_ENUMERATION
/// + `::UR_EXP_PEER_INFO_UR_PEER_ATOMICS_SUPPORTED < propName`
/// - ::UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION
/// + If `propName` is not supported by the adapter.
/// - ::UR_RESULT_ERROR_INVALID_SIZE
/// + `propSize == 0 && pPropValue != NULL`
/// + If `propSize` is less than the real number of bytes needed to return the info.
/// - ::UR_RESULT_ERROR_INVALID_NULL_POINTER
/// + `propSize != 0 && pPropValue == NULL`
/// + `pPropValue == NULL && pPropSizeRet == NULL`
/// - ::UR_RESULT_SUCCESS
/// - ::UR_RESULT_ERROR_ADAPTER_SPECIFIC
UR_APIEXPORT ur_result_t UR_APICALL
urUsmP2PPeerAccessGetInfoExp(
ur_device_handle_t commandDevice, ///< [in] handle of the command device object
ur_device_handle_t peerDevice, ///< [in] handle of the peer device object
ur_exp_peer_info_t propName, ///< [in] type of the info to retrieve
size_t propSize, ///< [in] the number of bytes pointed to by pPropValue.
void *pPropValue, ///< [out][optional][typename(propName, propSize)] array of bytes holding
///< the info.
///< If propSize is not equal to or greater than the real number of bytes
///< needed to return the info
///< then the ::UR_RESULT_ERROR_INVALID_SIZE error is returned and
///< pPropValue is not used.
size_t *pPropSizeRet ///< [out][optional] pointer to the actual size in bytes of the queried propName.
);

#if !defined(__GNUC__)
#pragma endregion
#endif
Expand Down Expand Up @@ -9075,6 +9224,37 @@ typedef struct ur_command_buffer_enqueue_exp_params_t {
ur_event_handle_t **pphEvent;
} ur_command_buffer_enqueue_exp_params_t;

///////////////////////////////////////////////////////////////////////////////
/// @brief Function parameters for urUsmP2PEnablePeerAccessExp
/// @details Each entry is a pointer to the parameter passed to the function;
/// allowing the callback the ability to modify the parameter's value
typedef struct ur_usm_p2p_enable_peer_access_exp_params_t {
ur_device_handle_t *pcommandDevice;
ur_device_handle_t *ppeerDevice;
} ur_usm_p2p_enable_peer_access_exp_params_t;

///////////////////////////////////////////////////////////////////////////////
/// @brief Function parameters for urUsmP2PDisablePeerAccessExp
/// @details Each entry is a pointer to the parameter passed to the function;
/// allowing the callback the ability to modify the parameter's value
typedef struct ur_usm_p2p_disable_peer_access_exp_params_t {
ur_device_handle_t *pcommandDevice;
ur_device_handle_t *ppeerDevice;
} ur_usm_p2p_disable_peer_access_exp_params_t;

///////////////////////////////////////////////////////////////////////////////
/// @brief Function parameters for urUsmP2PPeerAccessGetInfoExp
/// @details Each entry is a pointer to the parameter passed to the function;
/// allowing the callback the ability to modify the parameter's value
typedef struct ur_usm_p2p_peer_access_get_info_exp_params_t {
ur_device_handle_t *pcommandDevice;
ur_device_handle_t *ppeerDevice;
ur_exp_peer_info_t *ppropName;
size_t *ppropSize;
void **ppPropValue;
size_t **ppPropSizeRet;
} ur_usm_p2p_peer_access_get_info_exp_params_t;

///////////////////////////////////////////////////////////////////////////////
/// @brief Function parameters for urInit
/// @details Each entry is a pointer to the parameter passed to the function;
Expand Down
52 changes: 52 additions & 0 deletions include/ur_ddi.h
Original file line number Diff line number Diff line change
Expand Up @@ -1731,6 +1731,57 @@ typedef ur_result_t(UR_APICALL *ur_pfnGetCommandBufferExpProcAddrTable_t)(
ur_api_version_t,
ur_command_buffer_exp_dditable_t *);

///////////////////////////////////////////////////////////////////////////////
/// @brief Function-pointer for urUsmP2PEnablePeerAccessExp
typedef ur_result_t(UR_APICALL *ur_pfnUsmP2PEnablePeerAccessExp_t)(
ur_device_handle_t,
ur_device_handle_t);

///////////////////////////////////////////////////////////////////////////////
/// @brief Function-pointer for urUsmP2PDisablePeerAccessExp
typedef ur_result_t(UR_APICALL *ur_pfnUsmP2PDisablePeerAccessExp_t)(
ur_device_handle_t,
ur_device_handle_t);

///////////////////////////////////////////////////////////////////////////////
/// @brief Function-pointer for urUsmP2PPeerAccessGetInfoExp
typedef ur_result_t(UR_APICALL *ur_pfnUsmP2PPeerAccessGetInfoExp_t)(
ur_device_handle_t,
ur_device_handle_t,
ur_exp_peer_info_t,
size_t,
void *,
size_t *);

///////////////////////////////////////////////////////////////////////////////
/// @brief Table of UsmP2PExp functions pointers
typedef struct ur_usm_p2p_exp_dditable_t {
ur_pfnUsmP2PEnablePeerAccessExp_t pfnEnablePeerAccessExp;
ur_pfnUsmP2PDisablePeerAccessExp_t pfnDisablePeerAccessExp;
ur_pfnUsmP2PPeerAccessGetInfoExp_t pfnPeerAccessGetInfoExp;
} ur_usm_p2p_exp_dditable_t;

///////////////////////////////////////////////////////////////////////////////
/// @brief Exported function for filling application's UsmP2PExp table
/// with current process' addresses
///
/// @returns
/// - ::UR_RESULT_SUCCESS
/// - ::UR_RESULT_ERROR_UNINITIALIZED
/// - ::UR_RESULT_ERROR_INVALID_NULL_POINTER
/// - ::UR_RESULT_ERROR_UNSUPPORTED_VERSION
UR_DLLEXPORT ur_result_t UR_APICALL
urGetUsmP2PExpProcAddrTable(
ur_api_version_t version, ///< [in] API version requested
ur_usm_p2p_exp_dditable_t *pDdiTable ///< [in,out] pointer to table of DDI function pointers
);

///////////////////////////////////////////////////////////////////////////////
/// @brief Function-pointer for urGetUsmP2PExpProcAddrTable
typedef ur_result_t(UR_APICALL *ur_pfnGetUsmP2PExpProcAddrTable_t)(
ur_api_version_t,
ur_usm_p2p_exp_dditable_t *);

///////////////////////////////////////////////////////////////////////////////
/// @brief Function-pointer for urInit
typedef ur_result_t(UR_APICALL *ur_pfnInit_t)(
Expand Down Expand Up @@ -1981,6 +2032,7 @@ typedef struct ur_dditable_t {
ur_usm_dditable_t USM;
ur_usm_exp_dditable_t USMExp;
ur_command_buffer_exp_dditable_t CommandBufferExp;
ur_usm_p2p_exp_dditable_t UsmP2PExp;
ur_global_dditable_t Global;
ur_virtual_mem_dditable_t VirtualMem;
ur_device_dditable_t Device;
Expand Down
Loading

0 comments on commit 65b8cb4

Please sign in to comment.