Skip to content

Commit

Permalink
[ur] Make native memory object creation extensible
Browse files Browse the repository at this point in the history
This patch replaces the `urMemCreateWithNativeHandle` entry point with
two new entry points to handle buffers and images separately;
`urMemBufferCreateWithNativeHandle` and
`urMemImageCreateWithNativeHandle` (fixes oneapi-src#428). Both take a
`pProperites` argument to enable extensibility of native memory handle
creation via `pNext` chaining. The `ur_mem_native_properties_t`
structure includes `isNativeHandleOwned` in line with discussions in
issue oneapi-src#392.
  • Loading branch information
kbenzie committed May 1, 2023
1 parent 803871f commit e9eaac9
Show file tree
Hide file tree
Showing 18 changed files with 778 additions and 237 deletions.
35 changes: 29 additions & 6 deletions include/ur.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ class ur_structure_type_v(IntEnum):
CONTEXT_NATIVE_PROPERTIES = 16 ## ::ur_context_native_properties_t
KERNEL_NATIVE_PROPERTIES = 17 ## ::ur_kernel_native_properties_t
QUEUE_NATIVE_PROPERTIES = 18 ## ::ur_queue_native_properties_t
MEM_NATIVE_PROPERTIES = 19 ## ::ur_mem_native_properties_t

class ur_structure_type_t(c_int):
def __str__(self):
Expand Down Expand Up @@ -957,6 +958,18 @@ def __str__(self):
return str(ur_buffer_create_type_v(self.value))


###############################################################################
## @brief Native memory object creation properties
class ur_mem_native_properties_t(Structure):
_fields_ = [
("stype", ur_structure_type_t), ## [in] type of this structure, must be
## ::UR_STRUCTURE_TYPE_MEM_NATIVE_PROPERTIES
("pNext", c_void_p), ## [in,out][optional] pointer to extension-specific structure
("isNativeHandleOwned", c_bool) ## [in] Indicates UR owns the native handle or if it came from an
## interoperability operation in the application that asked to not
## transfer the ownership to the unified-runtime.
]

###############################################################################
## @brief Sampler Filter Mode
class ur_sampler_filter_mode_v(IntEnum):
Expand Down Expand Up @@ -1619,7 +1632,6 @@ class ur_function_v(IntEnum):
MEM_RELEASE = 66 ## Enumerator for ::urMemRelease
MEM_BUFFER_PARTITION = 67 ## Enumerator for ::urMemBufferPartition
MEM_GET_NATIVE_HANDLE = 68 ## Enumerator for ::urMemGetNativeHandle
MEM_CREATE_WITH_NATIVE_HANDLE = 69 ## Enumerator for ::urMemCreateWithNativeHandle
MEM_GET_INFO = 70 ## Enumerator for ::urMemGetInfo
MEM_IMAGE_GET_INFO = 71 ## Enumerator for ::urMemImageGetInfo
PLATFORM_GET = 72 ## Enumerator for ::urPlatformGet
Expand Down Expand Up @@ -1665,6 +1677,8 @@ class ur_function_v(IntEnum):
USM_POOL_CREATE = 112 ## Enumerator for ::urUSMPoolCreate
USM_POOL_DESTROY = 113 ## Enumerator for ::urUSMPoolDestroy
PLATFORM_GET_BACKEND_OPTION = 114 ## Enumerator for ::urPlatformGetBackendOption
MEM_BUFFER_CREATE_WITH_NATIVE_HANDLE = 115 ## Enumerator for ::urMemBufferCreateWithNativeHandle
MEM_IMAGE_CREATE_WITH_NATIVE_HANDLE = 116 ## Enumerator for ::urMemImageCreateWithNativeHandle

class ur_function_t(c_int):
def __str__(self):
Expand Down Expand Up @@ -2220,11 +2234,18 @@ class ur_sampler_dditable_t(Structure):
_urMemGetNativeHandle_t = CFUNCTYPE( ur_result_t, ur_mem_handle_t, POINTER(ur_native_handle_t) )

###############################################################################
## @brief Function-pointer for urMemCreateWithNativeHandle
## @brief Function-pointer for urMemBufferCreateWithNativeHandle
if __use_win_types:
_urMemBufferCreateWithNativeHandle_t = WINFUNCTYPE( ur_result_t, ur_native_handle_t, ur_context_handle_t, POINTER(ur_mem_native_properties_t), POINTER(ur_mem_handle_t) )
else:
_urMemBufferCreateWithNativeHandle_t = CFUNCTYPE( ur_result_t, ur_native_handle_t, ur_context_handle_t, POINTER(ur_mem_native_properties_t), POINTER(ur_mem_handle_t) )

###############################################################################
## @brief Function-pointer for urMemImageCreateWithNativeHandle
if __use_win_types:
_urMemCreateWithNativeHandle_t = WINFUNCTYPE( ur_result_t, ur_native_handle_t, ur_context_handle_t, POINTER(ur_mem_handle_t) )
_urMemImageCreateWithNativeHandle_t = WINFUNCTYPE( ur_result_t, ur_native_handle_t, ur_context_handle_t, POINTER(ur_image_format_t), POINTER(ur_image_desc_t), POINTER(ur_mem_native_properties_t), POINTER(ur_mem_handle_t) )
else:
_urMemCreateWithNativeHandle_t = CFUNCTYPE( ur_result_t, ur_native_handle_t, ur_context_handle_t, POINTER(ur_mem_handle_t) )
_urMemImageCreateWithNativeHandle_t = CFUNCTYPE( ur_result_t, ur_native_handle_t, ur_context_handle_t, POINTER(ur_image_format_t), POINTER(ur_image_desc_t), POINTER(ur_mem_native_properties_t), POINTER(ur_mem_handle_t) )

###############################################################################
## @brief Function-pointer for urMemGetInfo
Expand All @@ -2251,7 +2272,8 @@ class ur_mem_dditable_t(Structure):
("pfnRelease", c_void_p), ## _urMemRelease_t
("pfnBufferPartition", c_void_p), ## _urMemBufferPartition_t
("pfnGetNativeHandle", c_void_p), ## _urMemGetNativeHandle_t
("pfnCreateWithNativeHandle", c_void_p), ## _urMemCreateWithNativeHandle_t
("pfnBufferCreateWithNativeHandle", c_void_p), ## _urMemBufferCreateWithNativeHandle_t
("pfnImageCreateWithNativeHandle", c_void_p), ## _urMemImageCreateWithNativeHandle_t
("pfnGetInfo", c_void_p), ## _urMemGetInfo_t
("pfnImageGetInfo", c_void_p) ## _urMemImageGetInfo_t
]
Expand Down Expand Up @@ -2847,7 +2869,8 @@ def __init__(self, version : ur_api_version_t):
self.urMemRelease = _urMemRelease_t(self.__dditable.Mem.pfnRelease)
self.urMemBufferPartition = _urMemBufferPartition_t(self.__dditable.Mem.pfnBufferPartition)
self.urMemGetNativeHandle = _urMemGetNativeHandle_t(self.__dditable.Mem.pfnGetNativeHandle)
self.urMemCreateWithNativeHandle = _urMemCreateWithNativeHandle_t(self.__dditable.Mem.pfnCreateWithNativeHandle)
self.urMemBufferCreateWithNativeHandle = _urMemBufferCreateWithNativeHandle_t(self.__dditable.Mem.pfnBufferCreateWithNativeHandle)
self.urMemImageCreateWithNativeHandle = _urMemImageCreateWithNativeHandle_t(self.__dditable.Mem.pfnImageCreateWithNativeHandle)
self.urMemGetInfo = _urMemGetInfo_t(self.__dditable.Mem.pfnGetInfo)
self.urMemImageGetInfo = _urMemImageGetInfo_t(self.__dditable.Mem.pfnImageGetInfo)

Expand Down
Loading

0 comments on commit e9eaac9

Please sign in to comment.