From e9eaac9b72632af8f5d067990c90f54723b7d05a Mon Sep 17 00:00:00 2001 From: "Kenneth Benzie (Benie)" Date: Tue, 25 Apr 2023 15:12:56 +0100 Subject: [PATCH] [ur] Make native memory object creation extensible This patch replaces the `urMemCreateWithNativeHandle` entry point with two new entry points to handle buffers and images separately; `urMemBufferCreateWithNativeHandle` and `urMemImageCreateWithNativeHandle` (fixes #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 #392. --- include/ur.py | 35 +- include/ur_api.h | 305 +++++++++++------- include/ur_ddi.h | 18 +- scripts/core/common.yml | 2 + scripts/core/memory.yml | 64 +++- scripts/core/registry.yml | 9 +- source/common/ur_params.hpp | 101 +++++- source/drivers/null/ur_nullddi.cpp | 56 +++- source/loader/layers/tracing/ur_trcddi.cpp | 82 +++-- source/loader/layers/validation/ur_valddi.cpp | 85 ++++- source/loader/ur_ldrddi.cpp | 75 ++++- source/loader/ur_libapi.cpp | 64 +++- source/ur_api.cpp | 49 ++- test/conformance/memory/CMakeLists.txt | 3 +- .../urMemBufferCreateWithNativeHandle.cpp | 14 + .../memory/urMemCreateWithNativeHandle.cpp | 13 - .../memory/urMemGetNativeHandle.cpp | 8 +- .../urMemImageCreateWithNativeHandle.cpp | 32 ++ 18 files changed, 778 insertions(+), 237 deletions(-) create mode 100644 test/conformance/memory/urMemBufferCreateWithNativeHandle.cpp delete mode 100644 test/conformance/memory/urMemCreateWithNativeHandle.cpp create mode 100644 test/conformance/memory/urMemImageCreateWithNativeHandle.cpp diff --git a/include/ur.py b/include/ur.py index b8e1155409..7c7f4845d7 100644 --- a/include/ur.py +++ b/include/ur.py @@ -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): @@ -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): @@ -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 @@ -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): @@ -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 @@ -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 ] @@ -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) diff --git a/include/ur_api.h b/include/ur_api.h index f5f15da398..947deede39 100644 --- a/include/ur_api.h +++ b/include/ur_api.h @@ -242,6 +242,7 @@ typedef enum ur_structure_type_t { UR_STRUCTURE_TYPE_CONTEXT_NATIVE_PROPERTIES = 16, ///< ::ur_context_native_properties_t UR_STRUCTURE_TYPE_KERNEL_NATIVE_PROPERTIES = 17, ///< ::ur_kernel_native_properties_t UR_STRUCTURE_TYPE_QUEUE_NATIVE_PROPERTIES = 18, ///< ::ur_queue_native_properties_t + UR_STRUCTURE_TYPE_MEM_NATIVE_PROPERTIES = 19, ///< ::ur_mem_native_properties_t /// @cond UR_STRUCTURE_TYPE_FORCE_UINT32 = 0x7fffffff /// @endcond @@ -1961,10 +1962,21 @@ urMemGetNativeHandle( ); /////////////////////////////////////////////////////////////////////////////// -/// @brief Create runtime mem object from native mem handle. +/// @brief Native memory object creation properties +typedef struct ur_mem_native_properties_t { + ur_structure_type_t stype; ///< [in] type of this structure, must be + ///< ::UR_STRUCTURE_TYPE_MEM_NATIVE_PROPERTIES + void *pNext; ///< [in,out][optional] pointer to extension-specific structure + bool isNativeHandleOwned; ///< [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. + +} ur_mem_native_properties_t; + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Create runtime buffer memory object from native memory handle. /// /// @details -/// - Creates runtime mem handle from native driver mem handle. /// - The application may call this function from simultaneous threads for /// the same context. /// - The implementation of this function should be thread-safe. @@ -1979,10 +1991,42 @@ urMemGetNativeHandle( /// - ::UR_RESULT_ERROR_INVALID_NULL_POINTER /// + `NULL == phMem` UR_APIEXPORT ur_result_t UR_APICALL -urMemCreateWithNativeHandle( - ur_native_handle_t hNativeMem, ///< [in] the native handle of the mem. - ur_context_handle_t hContext, ///< [in] handle of the context object - ur_mem_handle_t *phMem ///< [out] pointer to the handle of the mem object created. +urMemBufferCreateWithNativeHandle( + ur_native_handle_t hNativeMem, ///< [in] the native handle to the memory. + ur_context_handle_t hContext, ///< [in] handle of the context object. + const ur_mem_native_properties_t *pProperties, ///< [in][optional] pointer to native memory creation properties. + ur_mem_handle_t *phMem ///< [out] pointer to handle of buffer memory object created. +); + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Create runtime image memory object from native memory handle. +/// +/// @details +/// - The application may call this function from simultaneous threads for +/// the same context. +/// - The implementation of this function should be thread-safe. +/// +/// @returns +/// - ::UR_RESULT_SUCCESS +/// - ::UR_RESULT_ERROR_UNINITIALIZED +/// - ::UR_RESULT_ERROR_DEVICE_LOST +/// - ::UR_RESULT_ERROR_INVALID_NULL_HANDLE +/// + `NULL == hNativeMem` +/// + `NULL == hContext` +/// - ::UR_RESULT_ERROR_INVALID_NULL_POINTER +/// + `NULL == pImageFormat` +/// + `NULL == pImageDesc` +/// + `NULL == phMem` +/// - ::UR_RESULT_ERROR_INVALID_ENUMERATION +/// + `::UR_MEM_TYPE_IMAGE1D_BUFFER < pImageDesc->type` +UR_APIEXPORT ur_result_t UR_APICALL +urMemImageCreateWithNativeHandle( + ur_native_handle_t hNativeMem, ///< [in] the native handle to the memory. + ur_context_handle_t hContext, ///< [in] handle of the context object. + const ur_image_format_t *pImageFormat, ///< [in] pointer to image format specification. + const ur_image_desc_t *pImageDesc, ///< [in] pointer to image description. + const ur_mem_native_properties_t *pProperties, ///< [in][optional] pointer to native memory creation properties. + ur_mem_handle_t *phMem ///< [out] pointer to handle of image memory object created. ); /////////////////////////////////////////////////////////////////////////////// @@ -4328,120 +4372,121 @@ urEventSetCallback( /////////////////////////////////////////////////////////////////////////////// /// @brief Defines unique stable identifiers for all functions typedef enum ur_function_t { - UR_FUNCTION_CONTEXT_CREATE = 1, ///< Enumerator for ::urContextCreate - UR_FUNCTION_CONTEXT_RETAIN = 2, ///< Enumerator for ::urContextRetain - UR_FUNCTION_CONTEXT_RELEASE = 3, ///< Enumerator for ::urContextRelease - UR_FUNCTION_CONTEXT_GET_INFO = 4, ///< Enumerator for ::urContextGetInfo - UR_FUNCTION_CONTEXT_GET_NATIVE_HANDLE = 5, ///< Enumerator for ::urContextGetNativeHandle - UR_FUNCTION_CONTEXT_CREATE_WITH_NATIVE_HANDLE = 6, ///< Enumerator for ::urContextCreateWithNativeHandle - UR_FUNCTION_CONTEXT_SET_EXTENDED_DELETER = 7, ///< Enumerator for ::urContextSetExtendedDeleter - UR_FUNCTION_DEVICE_GET = 8, ///< Enumerator for ::urDeviceGet - UR_FUNCTION_DEVICE_GET_INFO = 9, ///< Enumerator for ::urDeviceGetInfo - UR_FUNCTION_DEVICE_RETAIN = 10, ///< Enumerator for ::urDeviceRetain - UR_FUNCTION_DEVICE_RELEASE = 11, ///< Enumerator for ::urDeviceRelease - UR_FUNCTION_DEVICE_PARTITION = 12, ///< Enumerator for ::urDevicePartition - UR_FUNCTION_DEVICE_SELECT_BINARY = 13, ///< Enumerator for ::urDeviceSelectBinary - UR_FUNCTION_DEVICE_GET_NATIVE_HANDLE = 14, ///< Enumerator for ::urDeviceGetNativeHandle - UR_FUNCTION_DEVICE_CREATE_WITH_NATIVE_HANDLE = 15, ///< Enumerator for ::urDeviceCreateWithNativeHandle - UR_FUNCTION_DEVICE_GET_GLOBAL_TIMESTAMPS = 16, ///< Enumerator for ::urDeviceGetGlobalTimestamps - UR_FUNCTION_ENQUEUE_KERNEL_LAUNCH = 17, ///< Enumerator for ::urEnqueueKernelLaunch - UR_FUNCTION_ENQUEUE_EVENTS_WAIT = 18, ///< Enumerator for ::urEnqueueEventsWait - UR_FUNCTION_ENQUEUE_EVENTS_WAIT_WITH_BARRIER = 19, ///< Enumerator for ::urEnqueueEventsWaitWithBarrier - UR_FUNCTION_ENQUEUE_MEM_BUFFER_READ = 20, ///< Enumerator for ::urEnqueueMemBufferRead - UR_FUNCTION_ENQUEUE_MEM_BUFFER_WRITE = 21, ///< Enumerator for ::urEnqueueMemBufferWrite - UR_FUNCTION_ENQUEUE_MEM_BUFFER_READ_RECT = 22, ///< Enumerator for ::urEnqueueMemBufferReadRect - UR_FUNCTION_ENQUEUE_MEM_BUFFER_WRITE_RECT = 23, ///< Enumerator for ::urEnqueueMemBufferWriteRect - UR_FUNCTION_ENQUEUE_MEM_BUFFER_COPY = 24, ///< Enumerator for ::urEnqueueMemBufferCopy - UR_FUNCTION_ENQUEUE_MEM_BUFFER_COPY_RECT = 25, ///< Enumerator for ::urEnqueueMemBufferCopyRect - UR_FUNCTION_ENQUEUE_MEM_BUFFER_FILL = 26, ///< Enumerator for ::urEnqueueMemBufferFill - UR_FUNCTION_ENQUEUE_MEM_IMAGE_READ = 27, ///< Enumerator for ::urEnqueueMemImageRead - UR_FUNCTION_ENQUEUE_MEM_IMAGE_WRITE = 28, ///< Enumerator for ::urEnqueueMemImageWrite - UR_FUNCTION_ENQUEUE_MEM_IMAGE_COPY = 29, ///< Enumerator for ::urEnqueueMemImageCopy - UR_FUNCTION_ENQUEUE_MEM_BUFFER_MAP = 30, ///< Enumerator for ::urEnqueueMemBufferMap - UR_FUNCTION_ENQUEUE_MEM_UNMAP = 31, ///< Enumerator for ::urEnqueueMemUnmap - UR_FUNCTION_ENQUEUE_USM_FILL = 32, ///< Enumerator for ::urEnqueueUSMFill - UR_FUNCTION_ENQUEUE_USM_MEMCPY = 33, ///< Enumerator for ::urEnqueueUSMMemcpy - UR_FUNCTION_ENQUEUE_USM_PREFETCH = 34, ///< Enumerator for ::urEnqueueUSMPrefetch - UR_FUNCTION_ENQUEUE_USM_ADVISE = 35, ///< Enumerator for ::urEnqueueUSMAdvise - UR_FUNCTION_ENQUEUE_USM_FILL2_D = 36, ///< Enumerator for ::urEnqueueUSMFill2D - UR_FUNCTION_ENQUEUE_USM_MEMCPY2_D = 37, ///< Enumerator for ::urEnqueueUSMMemcpy2D - UR_FUNCTION_ENQUEUE_DEVICE_GLOBAL_VARIABLE_WRITE = 38, ///< Enumerator for ::urEnqueueDeviceGlobalVariableWrite - UR_FUNCTION_ENQUEUE_DEVICE_GLOBAL_VARIABLE_READ = 39, ///< Enumerator for ::urEnqueueDeviceGlobalVariableRead - UR_FUNCTION_EVENT_GET_INFO = 40, ///< Enumerator for ::urEventGetInfo - UR_FUNCTION_EVENT_GET_PROFILING_INFO = 41, ///< Enumerator for ::urEventGetProfilingInfo - UR_FUNCTION_EVENT_WAIT = 42, ///< Enumerator for ::urEventWait - UR_FUNCTION_EVENT_RETAIN = 43, ///< Enumerator for ::urEventRetain - UR_FUNCTION_EVENT_RELEASE = 44, ///< Enumerator for ::urEventRelease - UR_FUNCTION_EVENT_GET_NATIVE_HANDLE = 45, ///< Enumerator for ::urEventGetNativeHandle - UR_FUNCTION_EVENT_CREATE_WITH_NATIVE_HANDLE = 46, ///< Enumerator for ::urEventCreateWithNativeHandle - UR_FUNCTION_EVENT_SET_CALLBACK = 47, ///< Enumerator for ::urEventSetCallback - UR_FUNCTION_KERNEL_CREATE = 48, ///< Enumerator for ::urKernelCreate - UR_FUNCTION_KERNEL_SET_ARG_VALUE = 49, ///< Enumerator for ::urKernelSetArgValue - UR_FUNCTION_KERNEL_SET_ARG_LOCAL = 50, ///< Enumerator for ::urKernelSetArgLocal - UR_FUNCTION_KERNEL_GET_INFO = 51, ///< Enumerator for ::urKernelGetInfo - UR_FUNCTION_KERNEL_GET_GROUP_INFO = 52, ///< Enumerator for ::urKernelGetGroupInfo - UR_FUNCTION_KERNEL_GET_SUB_GROUP_INFO = 53, ///< Enumerator for ::urKernelGetSubGroupInfo - UR_FUNCTION_KERNEL_RETAIN = 54, ///< Enumerator for ::urKernelRetain - UR_FUNCTION_KERNEL_RELEASE = 55, ///< Enumerator for ::urKernelRelease - UR_FUNCTION_KERNEL_SET_ARG_POINTER = 56, ///< Enumerator for ::urKernelSetArgPointer - UR_FUNCTION_KERNEL_SET_EXEC_INFO = 57, ///< Enumerator for ::urKernelSetExecInfo - UR_FUNCTION_KERNEL_SET_ARG_SAMPLER = 58, ///< Enumerator for ::urKernelSetArgSampler - UR_FUNCTION_KERNEL_SET_ARG_MEM_OBJ = 59, ///< Enumerator for ::urKernelSetArgMemObj - UR_FUNCTION_KERNEL_SET_SPECIALIZATION_CONSTANTS = 60, ///< Enumerator for ::urKernelSetSpecializationConstants - UR_FUNCTION_KERNEL_GET_NATIVE_HANDLE = 61, ///< Enumerator for ::urKernelGetNativeHandle - UR_FUNCTION_KERNEL_CREATE_WITH_NATIVE_HANDLE = 62, ///< Enumerator for ::urKernelCreateWithNativeHandle - UR_FUNCTION_MEM_IMAGE_CREATE = 63, ///< Enumerator for ::urMemImageCreate - UR_FUNCTION_MEM_BUFFER_CREATE = 64, ///< Enumerator for ::urMemBufferCreate - UR_FUNCTION_MEM_RETAIN = 65, ///< Enumerator for ::urMemRetain - UR_FUNCTION_MEM_RELEASE = 66, ///< Enumerator for ::urMemRelease - UR_FUNCTION_MEM_BUFFER_PARTITION = 67, ///< Enumerator for ::urMemBufferPartition - UR_FUNCTION_MEM_GET_NATIVE_HANDLE = 68, ///< Enumerator for ::urMemGetNativeHandle - UR_FUNCTION_MEM_CREATE_WITH_NATIVE_HANDLE = 69, ///< Enumerator for ::urMemCreateWithNativeHandle - UR_FUNCTION_MEM_GET_INFO = 70, ///< Enumerator for ::urMemGetInfo - UR_FUNCTION_MEM_IMAGE_GET_INFO = 71, ///< Enumerator for ::urMemImageGetInfo - UR_FUNCTION_PLATFORM_GET = 72, ///< Enumerator for ::urPlatformGet - UR_FUNCTION_PLATFORM_GET_INFO = 73, ///< Enumerator for ::urPlatformGetInfo - UR_FUNCTION_PLATFORM_GET_API_VERSION = 74, ///< Enumerator for ::urPlatformGetApiVersion - UR_FUNCTION_PLATFORM_GET_NATIVE_HANDLE = 75, ///< Enumerator for ::urPlatformGetNativeHandle - UR_FUNCTION_PLATFORM_CREATE_WITH_NATIVE_HANDLE = 76, ///< Enumerator for ::urPlatformCreateWithNativeHandle - UR_FUNCTION_GET_LAST_RESULT = 77, ///< Enumerator for ::urGetLastResult - UR_FUNCTION_PROGRAM_CREATE_WITH_IL = 78, ///< Enumerator for ::urProgramCreateWithIL - UR_FUNCTION_PROGRAM_CREATE_WITH_BINARY = 79, ///< Enumerator for ::urProgramCreateWithBinary - UR_FUNCTION_PROGRAM_BUILD = 80, ///< Enumerator for ::urProgramBuild - UR_FUNCTION_PROGRAM_COMPILE = 81, ///< Enumerator for ::urProgramCompile - UR_FUNCTION_PROGRAM_LINK = 82, ///< Enumerator for ::urProgramLink - UR_FUNCTION_PROGRAM_RETAIN = 83, ///< Enumerator for ::urProgramRetain - UR_FUNCTION_PROGRAM_RELEASE = 84, ///< Enumerator for ::urProgramRelease - UR_FUNCTION_PROGRAM_GET_FUNCTION_POINTER = 85, ///< Enumerator for ::urProgramGetFunctionPointer - UR_FUNCTION_PROGRAM_GET_INFO = 86, ///< Enumerator for ::urProgramGetInfo - UR_FUNCTION_PROGRAM_GET_BUILD_INFO = 87, ///< Enumerator for ::urProgramGetBuildInfo - UR_FUNCTION_PROGRAM_SET_SPECIALIZATION_CONSTANTS = 88, ///< Enumerator for ::urProgramSetSpecializationConstants - UR_FUNCTION_PROGRAM_GET_NATIVE_HANDLE = 89, ///< Enumerator for ::urProgramGetNativeHandle - UR_FUNCTION_PROGRAM_CREATE_WITH_NATIVE_HANDLE = 90, ///< Enumerator for ::urProgramCreateWithNativeHandle - UR_FUNCTION_QUEUE_GET_INFO = 91, ///< Enumerator for ::urQueueGetInfo - UR_FUNCTION_QUEUE_CREATE = 92, ///< Enumerator for ::urQueueCreate - UR_FUNCTION_QUEUE_RETAIN = 93, ///< Enumerator for ::urQueueRetain - UR_FUNCTION_QUEUE_RELEASE = 94, ///< Enumerator for ::urQueueRelease - UR_FUNCTION_QUEUE_GET_NATIVE_HANDLE = 95, ///< Enumerator for ::urQueueGetNativeHandle - UR_FUNCTION_QUEUE_CREATE_WITH_NATIVE_HANDLE = 96, ///< Enumerator for ::urQueueCreateWithNativeHandle - UR_FUNCTION_QUEUE_FINISH = 97, ///< Enumerator for ::urQueueFinish - UR_FUNCTION_QUEUE_FLUSH = 98, ///< Enumerator for ::urQueueFlush - UR_FUNCTION_INIT = 99, ///< Enumerator for ::urInit - UR_FUNCTION_TEAR_DOWN = 100, ///< Enumerator for ::urTearDown - UR_FUNCTION_SAMPLER_CREATE = 101, ///< Enumerator for ::urSamplerCreate - UR_FUNCTION_SAMPLER_RETAIN = 102, ///< Enumerator for ::urSamplerRetain - UR_FUNCTION_SAMPLER_RELEASE = 103, ///< Enumerator for ::urSamplerRelease - UR_FUNCTION_SAMPLER_GET_INFO = 104, ///< Enumerator for ::urSamplerGetInfo - UR_FUNCTION_SAMPLER_GET_NATIVE_HANDLE = 105, ///< Enumerator for ::urSamplerGetNativeHandle - UR_FUNCTION_SAMPLER_CREATE_WITH_NATIVE_HANDLE = 106, ///< Enumerator for ::urSamplerCreateWithNativeHandle - UR_FUNCTION_USM_HOST_ALLOC = 107, ///< Enumerator for ::urUSMHostAlloc - UR_FUNCTION_USM_DEVICE_ALLOC = 108, ///< Enumerator for ::urUSMDeviceAlloc - UR_FUNCTION_USM_SHARED_ALLOC = 109, ///< Enumerator for ::urUSMSharedAlloc - UR_FUNCTION_USM_FREE = 110, ///< Enumerator for ::urUSMFree - UR_FUNCTION_USM_GET_MEM_ALLOC_INFO = 111, ///< Enumerator for ::urUSMGetMemAllocInfo - UR_FUNCTION_USM_POOL_CREATE = 112, ///< Enumerator for ::urUSMPoolCreate - UR_FUNCTION_USM_POOL_DESTROY = 113, ///< Enumerator for ::urUSMPoolDestroy - UR_FUNCTION_PLATFORM_GET_BACKEND_OPTION = 114, ///< Enumerator for ::urPlatformGetBackendOption + UR_FUNCTION_CONTEXT_CREATE = 1, ///< Enumerator for ::urContextCreate + UR_FUNCTION_CONTEXT_RETAIN = 2, ///< Enumerator for ::urContextRetain + UR_FUNCTION_CONTEXT_RELEASE = 3, ///< Enumerator for ::urContextRelease + UR_FUNCTION_CONTEXT_GET_INFO = 4, ///< Enumerator for ::urContextGetInfo + UR_FUNCTION_CONTEXT_GET_NATIVE_HANDLE = 5, ///< Enumerator for ::urContextGetNativeHandle + UR_FUNCTION_CONTEXT_CREATE_WITH_NATIVE_HANDLE = 6, ///< Enumerator for ::urContextCreateWithNativeHandle + UR_FUNCTION_CONTEXT_SET_EXTENDED_DELETER = 7, ///< Enumerator for ::urContextSetExtendedDeleter + UR_FUNCTION_DEVICE_GET = 8, ///< Enumerator for ::urDeviceGet + UR_FUNCTION_DEVICE_GET_INFO = 9, ///< Enumerator for ::urDeviceGetInfo + UR_FUNCTION_DEVICE_RETAIN = 10, ///< Enumerator for ::urDeviceRetain + UR_FUNCTION_DEVICE_RELEASE = 11, ///< Enumerator for ::urDeviceRelease + UR_FUNCTION_DEVICE_PARTITION = 12, ///< Enumerator for ::urDevicePartition + UR_FUNCTION_DEVICE_SELECT_BINARY = 13, ///< Enumerator for ::urDeviceSelectBinary + UR_FUNCTION_DEVICE_GET_NATIVE_HANDLE = 14, ///< Enumerator for ::urDeviceGetNativeHandle + UR_FUNCTION_DEVICE_CREATE_WITH_NATIVE_HANDLE = 15, ///< Enumerator for ::urDeviceCreateWithNativeHandle + UR_FUNCTION_DEVICE_GET_GLOBAL_TIMESTAMPS = 16, ///< Enumerator for ::urDeviceGetGlobalTimestamps + UR_FUNCTION_ENQUEUE_KERNEL_LAUNCH = 17, ///< Enumerator for ::urEnqueueKernelLaunch + UR_FUNCTION_ENQUEUE_EVENTS_WAIT = 18, ///< Enumerator for ::urEnqueueEventsWait + UR_FUNCTION_ENQUEUE_EVENTS_WAIT_WITH_BARRIER = 19, ///< Enumerator for ::urEnqueueEventsWaitWithBarrier + UR_FUNCTION_ENQUEUE_MEM_BUFFER_READ = 20, ///< Enumerator for ::urEnqueueMemBufferRead + UR_FUNCTION_ENQUEUE_MEM_BUFFER_WRITE = 21, ///< Enumerator for ::urEnqueueMemBufferWrite + UR_FUNCTION_ENQUEUE_MEM_BUFFER_READ_RECT = 22, ///< Enumerator for ::urEnqueueMemBufferReadRect + UR_FUNCTION_ENQUEUE_MEM_BUFFER_WRITE_RECT = 23, ///< Enumerator for ::urEnqueueMemBufferWriteRect + UR_FUNCTION_ENQUEUE_MEM_BUFFER_COPY = 24, ///< Enumerator for ::urEnqueueMemBufferCopy + UR_FUNCTION_ENQUEUE_MEM_BUFFER_COPY_RECT = 25, ///< Enumerator for ::urEnqueueMemBufferCopyRect + UR_FUNCTION_ENQUEUE_MEM_BUFFER_FILL = 26, ///< Enumerator for ::urEnqueueMemBufferFill + UR_FUNCTION_ENQUEUE_MEM_IMAGE_READ = 27, ///< Enumerator for ::urEnqueueMemImageRead + UR_FUNCTION_ENQUEUE_MEM_IMAGE_WRITE = 28, ///< Enumerator for ::urEnqueueMemImageWrite + UR_FUNCTION_ENQUEUE_MEM_IMAGE_COPY = 29, ///< Enumerator for ::urEnqueueMemImageCopy + UR_FUNCTION_ENQUEUE_MEM_BUFFER_MAP = 30, ///< Enumerator for ::urEnqueueMemBufferMap + UR_FUNCTION_ENQUEUE_MEM_UNMAP = 31, ///< Enumerator for ::urEnqueueMemUnmap + UR_FUNCTION_ENQUEUE_USM_FILL = 32, ///< Enumerator for ::urEnqueueUSMFill + UR_FUNCTION_ENQUEUE_USM_MEMCPY = 33, ///< Enumerator for ::urEnqueueUSMMemcpy + UR_FUNCTION_ENQUEUE_USM_PREFETCH = 34, ///< Enumerator for ::urEnqueueUSMPrefetch + UR_FUNCTION_ENQUEUE_USM_ADVISE = 35, ///< Enumerator for ::urEnqueueUSMAdvise + UR_FUNCTION_ENQUEUE_USM_FILL2_D = 36, ///< Enumerator for ::urEnqueueUSMFill2D + UR_FUNCTION_ENQUEUE_USM_MEMCPY2_D = 37, ///< Enumerator for ::urEnqueueUSMMemcpy2D + UR_FUNCTION_ENQUEUE_DEVICE_GLOBAL_VARIABLE_WRITE = 38, ///< Enumerator for ::urEnqueueDeviceGlobalVariableWrite + UR_FUNCTION_ENQUEUE_DEVICE_GLOBAL_VARIABLE_READ = 39, ///< Enumerator for ::urEnqueueDeviceGlobalVariableRead + UR_FUNCTION_EVENT_GET_INFO = 40, ///< Enumerator for ::urEventGetInfo + UR_FUNCTION_EVENT_GET_PROFILING_INFO = 41, ///< Enumerator for ::urEventGetProfilingInfo + UR_FUNCTION_EVENT_WAIT = 42, ///< Enumerator for ::urEventWait + UR_FUNCTION_EVENT_RETAIN = 43, ///< Enumerator for ::urEventRetain + UR_FUNCTION_EVENT_RELEASE = 44, ///< Enumerator for ::urEventRelease + UR_FUNCTION_EVENT_GET_NATIVE_HANDLE = 45, ///< Enumerator for ::urEventGetNativeHandle + UR_FUNCTION_EVENT_CREATE_WITH_NATIVE_HANDLE = 46, ///< Enumerator for ::urEventCreateWithNativeHandle + UR_FUNCTION_EVENT_SET_CALLBACK = 47, ///< Enumerator for ::urEventSetCallback + UR_FUNCTION_KERNEL_CREATE = 48, ///< Enumerator for ::urKernelCreate + UR_FUNCTION_KERNEL_SET_ARG_VALUE = 49, ///< Enumerator for ::urKernelSetArgValue + UR_FUNCTION_KERNEL_SET_ARG_LOCAL = 50, ///< Enumerator for ::urKernelSetArgLocal + UR_FUNCTION_KERNEL_GET_INFO = 51, ///< Enumerator for ::urKernelGetInfo + UR_FUNCTION_KERNEL_GET_GROUP_INFO = 52, ///< Enumerator for ::urKernelGetGroupInfo + UR_FUNCTION_KERNEL_GET_SUB_GROUP_INFO = 53, ///< Enumerator for ::urKernelGetSubGroupInfo + UR_FUNCTION_KERNEL_RETAIN = 54, ///< Enumerator for ::urKernelRetain + UR_FUNCTION_KERNEL_RELEASE = 55, ///< Enumerator for ::urKernelRelease + UR_FUNCTION_KERNEL_SET_ARG_POINTER = 56, ///< Enumerator for ::urKernelSetArgPointer + UR_FUNCTION_KERNEL_SET_EXEC_INFO = 57, ///< Enumerator for ::urKernelSetExecInfo + UR_FUNCTION_KERNEL_SET_ARG_SAMPLER = 58, ///< Enumerator for ::urKernelSetArgSampler + UR_FUNCTION_KERNEL_SET_ARG_MEM_OBJ = 59, ///< Enumerator for ::urKernelSetArgMemObj + UR_FUNCTION_KERNEL_SET_SPECIALIZATION_CONSTANTS = 60, ///< Enumerator for ::urKernelSetSpecializationConstants + UR_FUNCTION_KERNEL_GET_NATIVE_HANDLE = 61, ///< Enumerator for ::urKernelGetNativeHandle + UR_FUNCTION_KERNEL_CREATE_WITH_NATIVE_HANDLE = 62, ///< Enumerator for ::urKernelCreateWithNativeHandle + UR_FUNCTION_MEM_IMAGE_CREATE = 63, ///< Enumerator for ::urMemImageCreate + UR_FUNCTION_MEM_BUFFER_CREATE = 64, ///< Enumerator for ::urMemBufferCreate + UR_FUNCTION_MEM_RETAIN = 65, ///< Enumerator for ::urMemRetain + UR_FUNCTION_MEM_RELEASE = 66, ///< Enumerator for ::urMemRelease + UR_FUNCTION_MEM_BUFFER_PARTITION = 67, ///< Enumerator for ::urMemBufferPartition + UR_FUNCTION_MEM_GET_NATIVE_HANDLE = 68, ///< Enumerator for ::urMemGetNativeHandle + UR_FUNCTION_MEM_GET_INFO = 70, ///< Enumerator for ::urMemGetInfo + UR_FUNCTION_MEM_IMAGE_GET_INFO = 71, ///< Enumerator for ::urMemImageGetInfo + UR_FUNCTION_PLATFORM_GET = 72, ///< Enumerator for ::urPlatformGet + UR_FUNCTION_PLATFORM_GET_INFO = 73, ///< Enumerator for ::urPlatformGetInfo + UR_FUNCTION_PLATFORM_GET_API_VERSION = 74, ///< Enumerator for ::urPlatformGetApiVersion + UR_FUNCTION_PLATFORM_GET_NATIVE_HANDLE = 75, ///< Enumerator for ::urPlatformGetNativeHandle + UR_FUNCTION_PLATFORM_CREATE_WITH_NATIVE_HANDLE = 76, ///< Enumerator for ::urPlatformCreateWithNativeHandle + UR_FUNCTION_GET_LAST_RESULT = 77, ///< Enumerator for ::urGetLastResult + UR_FUNCTION_PROGRAM_CREATE_WITH_IL = 78, ///< Enumerator for ::urProgramCreateWithIL + UR_FUNCTION_PROGRAM_CREATE_WITH_BINARY = 79, ///< Enumerator for ::urProgramCreateWithBinary + UR_FUNCTION_PROGRAM_BUILD = 80, ///< Enumerator for ::urProgramBuild + UR_FUNCTION_PROGRAM_COMPILE = 81, ///< Enumerator for ::urProgramCompile + UR_FUNCTION_PROGRAM_LINK = 82, ///< Enumerator for ::urProgramLink + UR_FUNCTION_PROGRAM_RETAIN = 83, ///< Enumerator for ::urProgramRetain + UR_FUNCTION_PROGRAM_RELEASE = 84, ///< Enumerator for ::urProgramRelease + UR_FUNCTION_PROGRAM_GET_FUNCTION_POINTER = 85, ///< Enumerator for ::urProgramGetFunctionPointer + UR_FUNCTION_PROGRAM_GET_INFO = 86, ///< Enumerator for ::urProgramGetInfo + UR_FUNCTION_PROGRAM_GET_BUILD_INFO = 87, ///< Enumerator for ::urProgramGetBuildInfo + UR_FUNCTION_PROGRAM_SET_SPECIALIZATION_CONSTANTS = 88, ///< Enumerator for ::urProgramSetSpecializationConstants + UR_FUNCTION_PROGRAM_GET_NATIVE_HANDLE = 89, ///< Enumerator for ::urProgramGetNativeHandle + UR_FUNCTION_PROGRAM_CREATE_WITH_NATIVE_HANDLE = 90, ///< Enumerator for ::urProgramCreateWithNativeHandle + UR_FUNCTION_QUEUE_GET_INFO = 91, ///< Enumerator for ::urQueueGetInfo + UR_FUNCTION_QUEUE_CREATE = 92, ///< Enumerator for ::urQueueCreate + UR_FUNCTION_QUEUE_RETAIN = 93, ///< Enumerator for ::urQueueRetain + UR_FUNCTION_QUEUE_RELEASE = 94, ///< Enumerator for ::urQueueRelease + UR_FUNCTION_QUEUE_GET_NATIVE_HANDLE = 95, ///< Enumerator for ::urQueueGetNativeHandle + UR_FUNCTION_QUEUE_CREATE_WITH_NATIVE_HANDLE = 96, ///< Enumerator for ::urQueueCreateWithNativeHandle + UR_FUNCTION_QUEUE_FINISH = 97, ///< Enumerator for ::urQueueFinish + UR_FUNCTION_QUEUE_FLUSH = 98, ///< Enumerator for ::urQueueFlush + UR_FUNCTION_INIT = 99, ///< Enumerator for ::urInit + UR_FUNCTION_TEAR_DOWN = 100, ///< Enumerator for ::urTearDown + UR_FUNCTION_SAMPLER_CREATE = 101, ///< Enumerator for ::urSamplerCreate + UR_FUNCTION_SAMPLER_RETAIN = 102, ///< Enumerator for ::urSamplerRetain + UR_FUNCTION_SAMPLER_RELEASE = 103, ///< Enumerator for ::urSamplerRelease + UR_FUNCTION_SAMPLER_GET_INFO = 104, ///< Enumerator for ::urSamplerGetInfo + UR_FUNCTION_SAMPLER_GET_NATIVE_HANDLE = 105, ///< Enumerator for ::urSamplerGetNativeHandle + UR_FUNCTION_SAMPLER_CREATE_WITH_NATIVE_HANDLE = 106, ///< Enumerator for ::urSamplerCreateWithNativeHandle + UR_FUNCTION_USM_HOST_ALLOC = 107, ///< Enumerator for ::urUSMHostAlloc + UR_FUNCTION_USM_DEVICE_ALLOC = 108, ///< Enumerator for ::urUSMDeviceAlloc + UR_FUNCTION_USM_SHARED_ALLOC = 109, ///< Enumerator for ::urUSMSharedAlloc + UR_FUNCTION_USM_FREE = 110, ///< Enumerator for ::urUSMFree + UR_FUNCTION_USM_GET_MEM_ALLOC_INFO = 111, ///< Enumerator for ::urUSMGetMemAllocInfo + UR_FUNCTION_USM_POOL_CREATE = 112, ///< Enumerator for ::urUSMPoolCreate + UR_FUNCTION_USM_POOL_DESTROY = 113, ///< Enumerator for ::urUSMPoolDestroy + UR_FUNCTION_PLATFORM_GET_BACKEND_OPTION = 114, ///< Enumerator for ::urPlatformGetBackendOption + UR_FUNCTION_MEM_BUFFER_CREATE_WITH_NATIVE_HANDLE = 115, ///< Enumerator for ::urMemBufferCreateWithNativeHandle + UR_FUNCTION_MEM_IMAGE_CREATE_WITH_NATIVE_HANDLE = 116, ///< Enumerator for ::urMemImageCreateWithNativeHandle /// @cond UR_FUNCTION_FORCE_UINT32 = 0x7fffffff /// @endcond @@ -6187,14 +6232,28 @@ typedef struct ur_mem_get_native_handle_params_t { } ur_mem_get_native_handle_params_t; /////////////////////////////////////////////////////////////////////////////// -/// @brief Function parameters for urMemCreateWithNativeHandle +/// @brief Function parameters for urMemBufferCreateWithNativeHandle /// @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_mem_create_with_native_handle_params_t { +typedef struct ur_mem_buffer_create_with_native_handle_params_t { ur_native_handle_t *phNativeMem; ur_context_handle_t *phContext; + const ur_mem_native_properties_t **ppProperties; + ur_mem_handle_t **pphMem; +} ur_mem_buffer_create_with_native_handle_params_t; + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Function parameters for urMemImageCreateWithNativeHandle +/// @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_mem_image_create_with_native_handle_params_t { + ur_native_handle_t *phNativeMem; + ur_context_handle_t *phContext; + const ur_image_format_t **ppImageFormat; + const ur_image_desc_t **ppImageDesc; + const ur_mem_native_properties_t **ppProperties; ur_mem_handle_t **pphMem; -} ur_mem_create_with_native_handle_params_t; +} ur_mem_image_create_with_native_handle_params_t; /////////////////////////////////////////////////////////////////////////////// /// @brief Function parameters for urMemGetInfo diff --git a/include/ur_ddi.h b/include/ur_ddi.h index 72814666b0..b98ecf7c7e 100644 --- a/include/ur_ddi.h +++ b/include/ur_ddi.h @@ -670,10 +670,21 @@ typedef ur_result_t(UR_APICALL *ur_pfnMemGetNativeHandle_t)( ur_native_handle_t *); /////////////////////////////////////////////////////////////////////////////// -/// @brief Function-pointer for urMemCreateWithNativeHandle -typedef ur_result_t(UR_APICALL *ur_pfnMemCreateWithNativeHandle_t)( +/// @brief Function-pointer for urMemBufferCreateWithNativeHandle +typedef ur_result_t(UR_APICALL *ur_pfnMemBufferCreateWithNativeHandle_t)( ur_native_handle_t, ur_context_handle_t, + const ur_mem_native_properties_t *, + ur_mem_handle_t *); + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Function-pointer for urMemImageCreateWithNativeHandle +typedef ur_result_t(UR_APICALL *ur_pfnMemImageCreateWithNativeHandle_t)( + ur_native_handle_t, + ur_context_handle_t, + const ur_image_format_t *, + const ur_image_desc_t *, + const ur_mem_native_properties_t *, ur_mem_handle_t *); /////////////////////////////////////////////////////////////////////////////// @@ -703,7 +714,8 @@ typedef struct ur_mem_dditable_t { ur_pfnMemRelease_t pfnRelease; ur_pfnMemBufferPartition_t pfnBufferPartition; ur_pfnMemGetNativeHandle_t pfnGetNativeHandle; - ur_pfnMemCreateWithNativeHandle_t pfnCreateWithNativeHandle; + ur_pfnMemBufferCreateWithNativeHandle_t pfnBufferCreateWithNativeHandle; + ur_pfnMemImageCreateWithNativeHandle_t pfnImageCreateWithNativeHandle; ur_pfnMemGetInfo_t pfnGetInfo; ur_pfnMemImageGetInfo_t pfnImageGetInfo; } ur_mem_dditable_t; diff --git a/scripts/core/common.yml b/scripts/core/common.yml index 93f8592375..99b11d65f7 100644 --- a/scripts/core/common.yml +++ b/scripts/core/common.yml @@ -300,6 +300,8 @@ etors: desc: $x_kernel_native_properties_t - name: QUEUE_NATIVE_PROPERTIES desc: $x_queue_native_properties_t + - name: MEM_NATIVE_PROPERTIES + desc: $x_mem_native_properties_t --- #-------------------------------------------------------------------------- type: struct desc: "Base for all properties types" diff --git a/scripts/core/memory.yml b/scripts/core/memory.yml index 547f65ddf8..01fac98135 100644 --- a/scripts/core/memory.yml +++ b/scripts/core/memory.yml @@ -434,28 +434,72 @@ params: desc: | [out] a pointer to the native handle of the mem. --- #-------------------------------------------------------------------------- +type: struct +desc: "Native memory object creation properties" +class: $xMem +name: $x_mem_native_properties_t +base: $x_base_properties_t +members: + - type: bool + name: isNativeHandleOwned + desc: > + [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. +--- #-------------------------------------------------------------------------- type: function -desc: "Create runtime mem object from native mem handle." +desc: "Create runtime buffer memory object from native memory handle." class: $xMem -name: CreateWithNativeHandle +name: BufferCreateWithNativeHandle decl: static ordinal: "0" details: - - "Creates runtime mem handle from native driver mem handle." - - "The application may call this function from simultaneous threads for the same context." - - "The implementation of this function should be thread-safe." + - The application may call this function from simultaneous threads for the + same context. + - The implementation of this function should be thread-safe. params: - type: $x_native_handle_t name: hNativeMem - desc: | - [in] the native handle of the mem. + desc: "[in] the native handle to the memory." - type: $x_context_handle_t name: hContext - desc: "[in] handle of the context object" + desc: "[in] handle of the context object." + - type: const $x_mem_native_properties_t* + name: pProperties + desc: "[in][optional] pointer to native memory creation properties." - type: $x_mem_handle_t* name: phMem - desc: | - [out] pointer to the handle of the mem object created. + desc: "[out] pointer to handle of buffer memory object created." +--- #-------------------------------------------------------------------------- +type: function +desc: "Create runtime image memory object from native memory handle." +class: $xMem +name: ImageCreateWithNativeHandle +decl: static +ordinal: "0" +details: + - The application may call this function from simultaneous threads for the + same context. + - The implementation of this function should be thread-safe. +params: + - type: $x_native_handle_t + name: hNativeMem + desc: "[in] the native handle to the memory." + - type: $x_context_handle_t + name: hContext + desc: "[in] handle of the context object." + - type: "const $x_image_format_t*" + name: pImageFormat + desc: "[in] pointer to image format specification." + - type: "const $x_image_desc_t*" + name: pImageDesc + desc: "[in] pointer to image description." + - type: const $x_mem_native_properties_t* + name: pProperties + desc: "[in][optional] pointer to native memory creation properties." + - type: $x_mem_handle_t* + name: phMem + desc: "[out] pointer to handle of image memory object created." --- #-------------------------------------------------------------------------- type: function desc: "Retrieve information about a memory object." diff --git a/scripts/core/registry.yml b/scripts/core/registry.yml index 7daa012bf0..a065808868 100644 --- a/scripts/core/registry.yml +++ b/scripts/core/registry.yml @@ -211,9 +211,6 @@ etors: - name: MEM_GET_NATIVE_HANDLE desc: Enumerator for $xMemGetNativeHandle value: '68' -- name: MEM_CREATE_WITH_NATIVE_HANDLE - desc: Enumerator for $xMemCreateWithNativeHandle - value: '69' - name: MEM_GET_INFO desc: Enumerator for $xMemGetInfo value: '70' @@ -349,3 +346,9 @@ etors: - name: PLATFORM_GET_BACKEND_OPTION desc: Enumerator for $xPlatformGetBackendOption value: '114' +- name: MEM_BUFFER_CREATE_WITH_NATIVE_HANDLE + desc: Enumerator for $xMemBufferCreateWithNativeHandle + value: '115' +- name: MEM_IMAGE_CREATE_WITH_NATIVE_HANDLE + desc: Enumerator for $xMemImageCreateWithNativeHandle + value: '116' diff --git a/source/common/ur_params.hpp b/source/common/ur_params.hpp index 575778af0f..0690225cc3 100644 --- a/source/common/ur_params.hpp +++ b/source/common/ur_params.hpp @@ -187,6 +187,8 @@ inline std::ostream &operator<<(std::ostream &os, const struct ur_buffer_region_t params); inline std::ostream &operator<<(std::ostream &os, enum ur_buffer_create_type_t value); +inline std::ostream &operator<<(std::ostream &os, + const struct ur_mem_native_properties_t params); inline std::ostream &operator<<(std::ostream &os, enum ur_sampler_filter_mode_t value); inline std::ostream &operator<<(std::ostream &os, @@ -628,6 +630,10 @@ inline std::ostream &operator<<(std::ostream &os, case UR_STRUCTURE_TYPE_QUEUE_NATIVE_PROPERTIES: os << "UR_STRUCTURE_TYPE_QUEUE_NATIVE_PROPERTIES"; break; + + case UR_STRUCTURE_TYPE_MEM_NATIVE_PROPERTIES: + os << "UR_STRUCTURE_TYPE_MEM_NATIVE_PROPERTIES"; + break; default: os << "unknown enumerator"; break; @@ -749,6 +755,12 @@ inline void serializeStruct(std::ostream &os, const void *ptr) { (const ur_queue_native_properties_t *)ptr; ur_params::serializePtr(os, pstruct); } break; + + case UR_STRUCTURE_TYPE_MEM_NATIVE_PROPERTIES: { + const ur_mem_native_properties_t *pstruct = + (const ur_mem_native_properties_t *)ptr; + ur_params::serializePtr(os, pstruct); + } break; default: os << "unknown enumerator"; break; @@ -4712,6 +4724,27 @@ inline std::ostream &operator<<(std::ostream &os, } return os; } +inline std::ostream & +operator<<(std::ostream &os, const struct ur_mem_native_properties_t params) { + os << "(struct ur_mem_native_properties_t){"; + + os << ".stype = "; + + os << (params.stype); + + os << ", "; + os << ".pNext = "; + + ur_params::serializeStruct(os, (params.pNext)); + + os << ", "; + os << ".isNativeHandleOwned = "; + + os << (params.isNativeHandleOwned); + + os << "}"; + return os; +} inline std::ostream &operator<<(std::ostream &os, enum ur_sampler_filter_mode_t value) { switch (value) { @@ -7509,10 +7542,6 @@ inline std::ostream &operator<<(std::ostream &os, enum ur_function_t value) { os << "UR_FUNCTION_MEM_GET_NATIVE_HANDLE"; break; - case UR_FUNCTION_MEM_CREATE_WITH_NATIVE_HANDLE: - os << "UR_FUNCTION_MEM_CREATE_WITH_NATIVE_HANDLE"; - break; - case UR_FUNCTION_MEM_GET_INFO: os << "UR_FUNCTION_MEM_GET_INFO"; break; @@ -7692,6 +7721,14 @@ inline std::ostream &operator<<(std::ostream &os, enum ur_function_t value) { case UR_FUNCTION_PLATFORM_GET_BACKEND_OPTION: os << "UR_FUNCTION_PLATFORM_GET_BACKEND_OPTION"; break; + + case UR_FUNCTION_MEM_BUFFER_CREATE_WITH_NATIVE_HANDLE: + os << "UR_FUNCTION_MEM_BUFFER_CREATE_WITH_NATIVE_HANDLE"; + break; + + case UR_FUNCTION_MEM_IMAGE_CREATE_WITH_NATIVE_HANDLE: + os << "UR_FUNCTION_MEM_IMAGE_CREATE_WITH_NATIVE_HANDLE"; + break; default: os << "unknown enumerator"; break; @@ -9996,9 +10033,35 @@ operator<<(std::ostream &os, return os; } -inline std::ostream & -operator<<(std::ostream &os, - const struct ur_mem_create_with_native_handle_params_t *params) { +inline std::ostream &operator<<( + std::ostream &os, + const struct ur_mem_buffer_create_with_native_handle_params_t *params) { + + os << ".hNativeMem = "; + + ur_params::serializePtr(os, *(params->phNativeMem)); + + os << ", "; + os << ".hContext = "; + + ur_params::serializePtr(os, *(params->phContext)); + + os << ", "; + os << ".pProperties = "; + + ur_params::serializePtr(os, *(params->ppProperties)); + + os << ", "; + os << ".phMem = "; + + ur_params::serializePtr(os, *(params->pphMem)); + + return os; +} + +inline std::ostream &operator<<( + std::ostream &os, + const struct ur_mem_image_create_with_native_handle_params_t *params) { os << ".hNativeMem = "; @@ -10009,6 +10072,21 @@ operator<<(std::ostream &os, ur_params::serializePtr(os, *(params->phContext)); + os << ", "; + os << ".pImageFormat = "; + + ur_params::serializePtr(os, *(params->ppImageFormat)); + + os << ", "; + os << ".pImageDesc = "; + + ur_params::serializePtr(os, *(params->ppImageDesc)); + + os << ", "; + os << ".pProperties = "; + + ur_params::serializePtr(os, *(params->ppProperties)); + os << ", "; os << ".phMem = "; @@ -11397,8 +11475,13 @@ inline int serializeFunctionParams(std::ostream &os, uint32_t function, case UR_FUNCTION_MEM_GET_NATIVE_HANDLE: { os << (const struct ur_mem_get_native_handle_params_t *)params; } break; - case UR_FUNCTION_MEM_CREATE_WITH_NATIVE_HANDLE: { - os << (const struct ur_mem_create_with_native_handle_params_t *)params; + case UR_FUNCTION_MEM_BUFFER_CREATE_WITH_NATIVE_HANDLE: { + os << (const struct ur_mem_buffer_create_with_native_handle_params_t *) + params; + } break; + case UR_FUNCTION_MEM_IMAGE_CREATE_WITH_NATIVE_HANDLE: { + os << (const struct ur_mem_image_create_with_native_handle_params_t *) + params; } break; case UR_FUNCTION_MEM_GET_INFO: { os << (const struct ur_mem_get_info_params_t *)params; diff --git a/source/drivers/null/ur_nullddi.cpp b/source/drivers/null/ur_nullddi.cpp index 246442b246..4f403190f3 100644 --- a/source/drivers/null/ur_nullddi.cpp +++ b/source/drivers/null/ur_nullddi.cpp @@ -754,20 +754,52 @@ __urdlllocal ur_result_t UR_APICALL urMemGetNativeHandle( } /////////////////////////////////////////////////////////////////////////////// -/// @brief Intercept function for urMemCreateWithNativeHandle -__urdlllocal ur_result_t UR_APICALL urMemCreateWithNativeHandle( - ur_native_handle_t hNativeMem, ///< [in] the native handle of the mem. - ur_context_handle_t hContext, ///< [in] handle of the context object +/// @brief Intercept function for urMemBufferCreateWithNativeHandle +__urdlllocal ur_result_t UR_APICALL urMemBufferCreateWithNativeHandle( + ur_native_handle_t hNativeMem, ///< [in] the native handle to the memory. + ur_context_handle_t hContext, ///< [in] handle of the context object. + const ur_mem_native_properties_t * + pProperties, ///< [in][optional] pointer to native memory creation properties. ur_mem_handle_t - *phMem ///< [out] pointer to the handle of the mem object created. + *phMem ///< [out] pointer to handle of buffer memory object created. ) { ur_result_t result = UR_RESULT_SUCCESS; // if the driver has created a custom function, then call it instead of using the generic path - auto pfnCreateWithNativeHandle = - d_context.urDdiTable.Mem.pfnCreateWithNativeHandle; - if (nullptr != pfnCreateWithNativeHandle) { - result = pfnCreateWithNativeHandle(hNativeMem, hContext, phMem); + auto pfnBufferCreateWithNativeHandle = + d_context.urDdiTable.Mem.pfnBufferCreateWithNativeHandle; + if (nullptr != pfnBufferCreateWithNativeHandle) { + result = pfnBufferCreateWithNativeHandle(hNativeMem, hContext, + pProperties, phMem); + } else { + // generic implementation + *phMem = reinterpret_cast(d_context.get()); + } + + return result; +} + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Intercept function for urMemImageCreateWithNativeHandle +__urdlllocal ur_result_t UR_APICALL urMemImageCreateWithNativeHandle( + ur_native_handle_t hNativeMem, ///< [in] the native handle to the memory. + ur_context_handle_t hContext, ///< [in] handle of the context object. + const ur_image_format_t + *pImageFormat, ///< [in] pointer to image format specification. + const ur_image_desc_t *pImageDesc, ///< [in] pointer to image description. + const ur_mem_native_properties_t * + pProperties, ///< [in][optional] pointer to native memory creation properties. + ur_mem_handle_t + *phMem ///< [out] pointer to handle of image memory object created. +) { + ur_result_t result = UR_RESULT_SUCCESS; + + // if the driver has created a custom function, then call it instead of using the generic path + auto pfnImageCreateWithNativeHandle = + d_context.urDdiTable.Mem.pfnImageCreateWithNativeHandle; + if (nullptr != pfnImageCreateWithNativeHandle) { + result = pfnImageCreateWithNativeHandle( + hNativeMem, hContext, pImageFormat, pImageDesc, pProperties, phMem); } else { // generic implementation *phMem = reinterpret_cast(d_context.get()); @@ -3359,7 +3391,11 @@ UR_DLLEXPORT ur_result_t UR_APICALL urGetMemProcAddrTable( pDdiTable->pfnGetNativeHandle = driver::urMemGetNativeHandle; - pDdiTable->pfnCreateWithNativeHandle = driver::urMemCreateWithNativeHandle; + pDdiTable->pfnBufferCreateWithNativeHandle = + driver::urMemBufferCreateWithNativeHandle; + + pDdiTable->pfnImageCreateWithNativeHandle = + driver::urMemImageCreateWithNativeHandle; pDdiTable->pfnGetInfo = driver::urMemGetInfo; diff --git a/source/loader/layers/tracing/ur_trcddi.cpp b/source/loader/layers/tracing/ur_trcddi.cpp index edeb3fc02d..df21e757bd 100644 --- a/source/loader/layers/tracing/ur_trcddi.cpp +++ b/source/loader/layers/tracing/ur_trcddi.cpp @@ -923,30 +923,70 @@ __urdlllocal ur_result_t UR_APICALL urMemGetNativeHandle( } /////////////////////////////////////////////////////////////////////////////// -/// @brief Intercept function for urMemCreateWithNativeHandle -__urdlllocal ur_result_t UR_APICALL urMemCreateWithNativeHandle( - ur_native_handle_t hNativeMem, ///< [in] the native handle of the mem. - ur_context_handle_t hContext, ///< [in] handle of the context object +/// @brief Intercept function for urMemBufferCreateWithNativeHandle +__urdlllocal ur_result_t UR_APICALL urMemBufferCreateWithNativeHandle( + ur_native_handle_t hNativeMem, ///< [in] the native handle to the memory. + ur_context_handle_t hContext, ///< [in] handle of the context object. + const ur_mem_native_properties_t * + pProperties, ///< [in][optional] pointer to native memory creation properties. ur_mem_handle_t - *phMem ///< [out] pointer to the handle of the mem object created. + *phMem ///< [out] pointer to handle of buffer memory object created. ) { - auto pfnCreateWithNativeHandle = - context.urDdiTable.Mem.pfnCreateWithNativeHandle; + auto pfnBufferCreateWithNativeHandle = + context.urDdiTable.Mem.pfnBufferCreateWithNativeHandle; - if (nullptr == pfnCreateWithNativeHandle) { + if (nullptr == pfnBufferCreateWithNativeHandle) { return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; } - ur_mem_create_with_native_handle_params_t params = {&hNativeMem, &hContext, - &phMem}; + ur_mem_buffer_create_with_native_handle_params_t params = { + &hNativeMem, &hContext, &pProperties, &phMem}; uint64_t instance = - context.notify_begin(UR_FUNCTION_MEM_CREATE_WITH_NATIVE_HANDLE, - "urMemCreateWithNativeHandle", ¶ms); + context.notify_begin(UR_FUNCTION_MEM_BUFFER_CREATE_WITH_NATIVE_HANDLE, + "urMemBufferCreateWithNativeHandle", ¶ms); - ur_result_t result = pfnCreateWithNativeHandle(hNativeMem, hContext, phMem); + ur_result_t result = pfnBufferCreateWithNativeHandle(hNativeMem, hContext, + pProperties, phMem); - context.notify_end(UR_FUNCTION_MEM_CREATE_WITH_NATIVE_HANDLE, - "urMemCreateWithNativeHandle", ¶ms, &result, + context.notify_end(UR_FUNCTION_MEM_BUFFER_CREATE_WITH_NATIVE_HANDLE, + "urMemBufferCreateWithNativeHandle", ¶ms, &result, + instance); + + return result; +} + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Intercept function for urMemImageCreateWithNativeHandle +__urdlllocal ur_result_t UR_APICALL urMemImageCreateWithNativeHandle( + ur_native_handle_t hNativeMem, ///< [in] the native handle to the memory. + ur_context_handle_t hContext, ///< [in] handle of the context object. + const ur_image_format_t + *pImageFormat, ///< [in] pointer to image format specification. + const ur_image_desc_t *pImageDesc, ///< [in] pointer to image description. + const ur_mem_native_properties_t * + pProperties, ///< [in][optional] pointer to native memory creation properties. + ur_mem_handle_t + *phMem ///< [out] pointer to handle of image memory object created. +) { + auto pfnImageCreateWithNativeHandle = + context.urDdiTable.Mem.pfnImageCreateWithNativeHandle; + + if (nullptr == pfnImageCreateWithNativeHandle) { + return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; + } + + ur_mem_image_create_with_native_handle_params_t params = { + &hNativeMem, &hContext, &pImageFormat, + &pImageDesc, &pProperties, &phMem}; + uint64_t instance = + context.notify_begin(UR_FUNCTION_MEM_IMAGE_CREATE_WITH_NATIVE_HANDLE, + "urMemImageCreateWithNativeHandle", ¶ms); + + ur_result_t result = pfnImageCreateWithNativeHandle( + hNativeMem, hContext, pImageFormat, pImageDesc, pProperties, phMem); + + context.notify_end(UR_FUNCTION_MEM_IMAGE_CREATE_WITH_NATIVE_HANDLE, + "urMemImageCreateWithNativeHandle", ¶ms, &result, instance); return result; @@ -4120,9 +4160,15 @@ __urdlllocal ur_result_t UR_APICALL urGetMemProcAddrTable( dditable.pfnGetNativeHandle = pDdiTable->pfnGetNativeHandle; pDdiTable->pfnGetNativeHandle = ur_tracing_layer::urMemGetNativeHandle; - dditable.pfnCreateWithNativeHandle = pDdiTable->pfnCreateWithNativeHandle; - pDdiTable->pfnCreateWithNativeHandle = - ur_tracing_layer::urMemCreateWithNativeHandle; + dditable.pfnBufferCreateWithNativeHandle = + pDdiTable->pfnBufferCreateWithNativeHandle; + pDdiTable->pfnBufferCreateWithNativeHandle = + ur_tracing_layer::urMemBufferCreateWithNativeHandle; + + dditable.pfnImageCreateWithNativeHandle = + pDdiTable->pfnImageCreateWithNativeHandle; + pDdiTable->pfnImageCreateWithNativeHandle = + ur_tracing_layer::urMemImageCreateWithNativeHandle; dditable.pfnGetInfo = pDdiTable->pfnGetInfo; pDdiTable->pfnGetInfo = ur_tracing_layer::urMemGetInfo; diff --git a/source/loader/layers/validation/ur_valddi.cpp b/source/loader/layers/validation/ur_valddi.cpp index 3f95fef6dd..b8684c9ea5 100644 --- a/source/loader/layers/validation/ur_valddi.cpp +++ b/source/loader/layers/validation/ur_valddi.cpp @@ -1061,17 +1061,19 @@ __urdlllocal ur_result_t UR_APICALL urMemGetNativeHandle( } /////////////////////////////////////////////////////////////////////////////// -/// @brief Intercept function for urMemCreateWithNativeHandle -__urdlllocal ur_result_t UR_APICALL urMemCreateWithNativeHandle( - ur_native_handle_t hNativeMem, ///< [in] the native handle of the mem. - ur_context_handle_t hContext, ///< [in] handle of the context object +/// @brief Intercept function for urMemBufferCreateWithNativeHandle +__urdlllocal ur_result_t UR_APICALL urMemBufferCreateWithNativeHandle( + ur_native_handle_t hNativeMem, ///< [in] the native handle to the memory. + ur_context_handle_t hContext, ///< [in] handle of the context object. + const ur_mem_native_properties_t * + pProperties, ///< [in][optional] pointer to native memory creation properties. ur_mem_handle_t - *phMem ///< [out] pointer to the handle of the mem object created. + *phMem ///< [out] pointer to handle of buffer memory object created. ) { - auto pfnCreateWithNativeHandle = - context.urDdiTable.Mem.pfnCreateWithNativeHandle; + auto pfnBufferCreateWithNativeHandle = + context.urDdiTable.Mem.pfnBufferCreateWithNativeHandle; - if (nullptr == pfnCreateWithNativeHandle) { + if (nullptr == pfnBufferCreateWithNativeHandle) { return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; } @@ -1089,12 +1091,61 @@ __urdlllocal ur_result_t UR_APICALL urMemCreateWithNativeHandle( } } - ur_result_t result = pfnCreateWithNativeHandle(hNativeMem, hContext, phMem); + ur_result_t result = pfnBufferCreateWithNativeHandle(hNativeMem, hContext, + pProperties, phMem); - if (context.enableLeakChecking && result == UR_RESULT_SUCCESS) { - refCountContext.createRefCount(*phMem); + return result; +} + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Intercept function for urMemImageCreateWithNativeHandle +__urdlllocal ur_result_t UR_APICALL urMemImageCreateWithNativeHandle( + ur_native_handle_t hNativeMem, ///< [in] the native handle to the memory. + ur_context_handle_t hContext, ///< [in] handle of the context object. + const ur_image_format_t + *pImageFormat, ///< [in] pointer to image format specification. + const ur_image_desc_t *pImageDesc, ///< [in] pointer to image description. + const ur_mem_native_properties_t * + pProperties, ///< [in][optional] pointer to native memory creation properties. + ur_mem_handle_t + *phMem ///< [out] pointer to handle of image memory object created. +) { + auto pfnImageCreateWithNativeHandle = + context.urDdiTable.Mem.pfnImageCreateWithNativeHandle; + + if (nullptr == pfnImageCreateWithNativeHandle) { + return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; + } + + if (context.enableParameterValidation) { + if (NULL == hNativeMem) { + return UR_RESULT_ERROR_INVALID_NULL_HANDLE; + } + + if (NULL == hContext) { + return UR_RESULT_ERROR_INVALID_NULL_HANDLE; + } + + if (NULL == pImageFormat) { + return UR_RESULT_ERROR_INVALID_NULL_POINTER; + } + + if (NULL == pImageDesc) { + return UR_RESULT_ERROR_INVALID_NULL_POINTER; + } + + if (NULL == phMem) { + return UR_RESULT_ERROR_INVALID_NULL_POINTER; + } + + if (UR_MEM_TYPE_IMAGE1D_BUFFER < pImageDesc->type) { + return UR_RESULT_ERROR_INVALID_ENUMERATION; + } } + ur_result_t result = pfnImageCreateWithNativeHandle( + hNativeMem, hContext, pImageFormat, pImageDesc, pProperties, phMem); + return result; } @@ -5007,9 +5058,15 @@ UR_DLLEXPORT ur_result_t UR_APICALL urGetMemProcAddrTable( dditable.pfnGetNativeHandle = pDdiTable->pfnGetNativeHandle; pDdiTable->pfnGetNativeHandle = ur_validation_layer::urMemGetNativeHandle; - dditable.pfnCreateWithNativeHandle = pDdiTable->pfnCreateWithNativeHandle; - pDdiTable->pfnCreateWithNativeHandle = - ur_validation_layer::urMemCreateWithNativeHandle; + dditable.pfnBufferCreateWithNativeHandle = + pDdiTable->pfnBufferCreateWithNativeHandle; + pDdiTable->pfnBufferCreateWithNativeHandle = + ur_validation_layer::urMemBufferCreateWithNativeHandle; + + dditable.pfnImageCreateWithNativeHandle = + pDdiTable->pfnImageCreateWithNativeHandle; + pDdiTable->pfnImageCreateWithNativeHandle = + ur_validation_layer::urMemImageCreateWithNativeHandle; dditable.pfnGetInfo = pDdiTable->pfnGetInfo; pDdiTable->pfnGetInfo = ur_validation_layer::urMemGetInfo; diff --git a/source/loader/ur_ldrddi.cpp b/source/loader/ur_ldrddi.cpp index 2f4da65b55..5c47c7a815 100644 --- a/source/loader/ur_ldrddi.cpp +++ b/source/loader/ur_ldrddi.cpp @@ -1109,20 +1109,23 @@ __urdlllocal ur_result_t UR_APICALL urMemGetNativeHandle( } /////////////////////////////////////////////////////////////////////////////// -/// @brief Intercept function for urMemCreateWithNativeHandle -__urdlllocal ur_result_t UR_APICALL urMemCreateWithNativeHandle( - ur_native_handle_t hNativeMem, ///< [in] the native handle of the mem. - ur_context_handle_t hContext, ///< [in] handle of the context object +/// @brief Intercept function for urMemBufferCreateWithNativeHandle +__urdlllocal ur_result_t UR_APICALL urMemBufferCreateWithNativeHandle( + ur_native_handle_t hNativeMem, ///< [in] the native handle to the memory. + ur_context_handle_t hContext, ///< [in] handle of the context object. + const ur_mem_native_properties_t * + pProperties, ///< [in][optional] pointer to native memory creation properties. ur_mem_handle_t - *phMem ///< [out] pointer to the handle of the mem object created. + *phMem ///< [out] pointer to handle of buffer memory object created. ) { ur_result_t result = UR_RESULT_SUCCESS; // extract platform's function pointer table auto dditable = reinterpret_cast(hNativeMem)->dditable; - auto pfnCreateWithNativeHandle = dditable->ur.Mem.pfnCreateWithNativeHandle; - if (nullptr == pfnCreateWithNativeHandle) { + auto pfnBufferCreateWithNativeHandle = + dditable->ur.Mem.pfnBufferCreateWithNativeHandle; + if (nullptr == pfnBufferCreateWithNativeHandle) { return UR_RESULT_ERROR_UNINITIALIZED; } @@ -1133,7 +1136,57 @@ __urdlllocal ur_result_t UR_APICALL urMemCreateWithNativeHandle( hContext = reinterpret_cast(hContext)->handle; // forward to device-platform - result = pfnCreateWithNativeHandle(hNativeMem, hContext, phMem); + result = pfnBufferCreateWithNativeHandle(hNativeMem, hContext, pProperties, + phMem); + + if (UR_RESULT_SUCCESS != result) { + return result; + } + + try { + // convert platform handle to loader handle + *phMem = reinterpret_cast( + ur_mem_factory.getInstance(*phMem, dditable)); + } catch (std::bad_alloc &) { + result = UR_RESULT_ERROR_OUT_OF_HOST_MEMORY; + } + + return result; +} + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Intercept function for urMemImageCreateWithNativeHandle +__urdlllocal ur_result_t UR_APICALL urMemImageCreateWithNativeHandle( + ur_native_handle_t hNativeMem, ///< [in] the native handle to the memory. + ur_context_handle_t hContext, ///< [in] handle of the context object. + const ur_image_format_t + *pImageFormat, ///< [in] pointer to image format specification. + const ur_image_desc_t *pImageDesc, ///< [in] pointer to image description. + const ur_mem_native_properties_t * + pProperties, ///< [in][optional] pointer to native memory creation properties. + ur_mem_handle_t + *phMem ///< [out] pointer to handle of image memory object created. +) { + ur_result_t result = UR_RESULT_SUCCESS; + + // extract platform's function pointer table + auto dditable = + reinterpret_cast(hNativeMem)->dditable; + auto pfnImageCreateWithNativeHandle = + dditable->ur.Mem.pfnImageCreateWithNativeHandle; + if (nullptr == pfnImageCreateWithNativeHandle) { + return UR_RESULT_ERROR_UNINITIALIZED; + } + + // convert loader handle to platform handle + hNativeMem = reinterpret_cast(hNativeMem)->handle; + + // convert loader handle to platform handle + hContext = reinterpret_cast(hContext)->handle; + + // forward to device-platform + result = pfnImageCreateWithNativeHandle(hNativeMem, hContext, pImageFormat, + pImageDesc, pProperties, phMem); if (UR_RESULT_SUCCESS != result) { return result; @@ -5105,8 +5158,10 @@ UR_DLLEXPORT ur_result_t UR_APICALL urGetMemProcAddrTable( pDdiTable->pfnRelease = ur_loader::urMemRelease; pDdiTable->pfnBufferPartition = ur_loader::urMemBufferPartition; pDdiTable->pfnGetNativeHandle = ur_loader::urMemGetNativeHandle; - pDdiTable->pfnCreateWithNativeHandle = - ur_loader::urMemCreateWithNativeHandle; + pDdiTable->pfnBufferCreateWithNativeHandle = + ur_loader::urMemBufferCreateWithNativeHandle; + pDdiTable->pfnImageCreateWithNativeHandle = + ur_loader::urMemImageCreateWithNativeHandle; pDdiTable->pfnGetInfo = ur_loader::urMemGetInfo; pDdiTable->pfnImageGetInfo = ur_loader::urMemImageGetInfo; } else { diff --git a/source/loader/ur_libapi.cpp b/source/loader/ur_libapi.cpp index 1204fae39b..ef1f4cfcda 100644 --- a/source/loader/ur_libapi.cpp +++ b/source/loader/ur_libapi.cpp @@ -1175,10 +1175,9 @@ ur_result_t UR_APICALL urMemGetNativeHandle( } /////////////////////////////////////////////////////////////////////////////// -/// @brief Create runtime mem object from native mem handle. +/// @brief Create runtime buffer memory object from native memory handle. /// /// @details -/// - Creates runtime mem handle from native driver mem handle. /// - The application may call this function from simultaneous threads for /// the same context. /// - The implementation of this function should be thread-safe. @@ -1192,19 +1191,64 @@ ur_result_t UR_APICALL urMemGetNativeHandle( /// + `NULL == hContext` /// - ::UR_RESULT_ERROR_INVALID_NULL_POINTER /// + `NULL == phMem` -ur_result_t UR_APICALL urMemCreateWithNativeHandle( - ur_native_handle_t hNativeMem, ///< [in] the native handle of the mem. - ur_context_handle_t hContext, ///< [in] handle of the context object +ur_result_t UR_APICALL urMemBufferCreateWithNativeHandle( + ur_native_handle_t hNativeMem, ///< [in] the native handle to the memory. + ur_context_handle_t hContext, ///< [in] handle of the context object. + const ur_mem_native_properties_t * + pProperties, ///< [in][optional] pointer to native memory creation properties. ur_mem_handle_t - *phMem ///< [out] pointer to the handle of the mem object created. + *phMem ///< [out] pointer to handle of buffer memory object created. ) { - auto pfnCreateWithNativeHandle = - ur_lib::context->urDdiTable.Mem.pfnCreateWithNativeHandle; - if (nullptr == pfnCreateWithNativeHandle) { + auto pfnBufferCreateWithNativeHandle = + ur_lib::context->urDdiTable.Mem.pfnBufferCreateWithNativeHandle; + if (nullptr == pfnBufferCreateWithNativeHandle) { + return UR_RESULT_ERROR_UNINITIALIZED; + } + + return pfnBufferCreateWithNativeHandle(hNativeMem, hContext, pProperties, + phMem); +} + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Create runtime image memory object from native memory handle. +/// +/// @details +/// - The application may call this function from simultaneous threads for +/// the same context. +/// - The implementation of this function should be thread-safe. +/// +/// @returns +/// - ::UR_RESULT_SUCCESS +/// - ::UR_RESULT_ERROR_UNINITIALIZED +/// - ::UR_RESULT_ERROR_DEVICE_LOST +/// - ::UR_RESULT_ERROR_INVALID_NULL_HANDLE +/// + `NULL == hNativeMem` +/// + `NULL == hContext` +/// - ::UR_RESULT_ERROR_INVALID_NULL_POINTER +/// + `NULL == pImageFormat` +/// + `NULL == pImageDesc` +/// + `NULL == phMem` +/// - ::UR_RESULT_ERROR_INVALID_ENUMERATION +/// + `::UR_MEM_TYPE_IMAGE1D_BUFFER < pImageDesc->type` +ur_result_t UR_APICALL urMemImageCreateWithNativeHandle( + ur_native_handle_t hNativeMem, ///< [in] the native handle to the memory. + ur_context_handle_t hContext, ///< [in] handle of the context object. + const ur_image_format_t + *pImageFormat, ///< [in] pointer to image format specification. + const ur_image_desc_t *pImageDesc, ///< [in] pointer to image description. + const ur_mem_native_properties_t * + pProperties, ///< [in][optional] pointer to native memory creation properties. + ur_mem_handle_t + *phMem ///< [out] pointer to handle of image memory object created. +) { + auto pfnImageCreateWithNativeHandle = + ur_lib::context->urDdiTable.Mem.pfnImageCreateWithNativeHandle; + if (nullptr == pfnImageCreateWithNativeHandle) { return UR_RESULT_ERROR_UNINITIALIZED; } - return pfnCreateWithNativeHandle(hNativeMem, hContext, phMem); + return pfnImageCreateWithNativeHandle(hNativeMem, hContext, pImageFormat, + pImageDesc, pProperties, phMem); } /////////////////////////////////////////////////////////////////////////////// diff --git a/source/ur_api.cpp b/source/ur_api.cpp index de80668f57..422dc95fd2 100644 --- a/source/ur_api.cpp +++ b/source/ur_api.cpp @@ -1024,10 +1024,9 @@ ur_result_t UR_APICALL urMemGetNativeHandle( } /////////////////////////////////////////////////////////////////////////////// -/// @brief Create runtime mem object from native mem handle. +/// @brief Create runtime buffer memory object from native memory handle. /// /// @details -/// - Creates runtime mem handle from native driver mem handle. /// - The application may call this function from simultaneous threads for /// the same context. /// - The implementation of this function should be thread-safe. @@ -1041,11 +1040,49 @@ ur_result_t UR_APICALL urMemGetNativeHandle( /// + `NULL == hContext` /// - ::UR_RESULT_ERROR_INVALID_NULL_POINTER /// + `NULL == phMem` -ur_result_t UR_APICALL urMemCreateWithNativeHandle( - ur_native_handle_t hNativeMem, ///< [in] the native handle of the mem. - ur_context_handle_t hContext, ///< [in] handle of the context object +ur_result_t UR_APICALL urMemBufferCreateWithNativeHandle( + ur_native_handle_t hNativeMem, ///< [in] the native handle to the memory. + ur_context_handle_t hContext, ///< [in] handle of the context object. + const ur_mem_native_properties_t * + pProperties, ///< [in][optional] pointer to native memory creation properties. ur_mem_handle_t - *phMem ///< [out] pointer to the handle of the mem object created. + *phMem ///< [out] pointer to handle of buffer memory object created. +) { + ur_result_t result = UR_RESULT_SUCCESS; + return result; +} + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Create runtime image memory object from native memory handle. +/// +/// @details +/// - The application may call this function from simultaneous threads for +/// the same context. +/// - The implementation of this function should be thread-safe. +/// +/// @returns +/// - ::UR_RESULT_SUCCESS +/// - ::UR_RESULT_ERROR_UNINITIALIZED +/// - ::UR_RESULT_ERROR_DEVICE_LOST +/// - ::UR_RESULT_ERROR_INVALID_NULL_HANDLE +/// + `NULL == hNativeMem` +/// + `NULL == hContext` +/// - ::UR_RESULT_ERROR_INVALID_NULL_POINTER +/// + `NULL == pImageFormat` +/// + `NULL == pImageDesc` +/// + `NULL == phMem` +/// - ::UR_RESULT_ERROR_INVALID_ENUMERATION +/// + `::UR_MEM_TYPE_IMAGE1D_BUFFER < pImageDesc->type` +ur_result_t UR_APICALL urMemImageCreateWithNativeHandle( + ur_native_handle_t hNativeMem, ///< [in] the native handle to the memory. + ur_context_handle_t hContext, ///< [in] handle of the context object. + const ur_image_format_t + *pImageFormat, ///< [in] pointer to image format specification. + const ur_image_desc_t *pImageDesc, ///< [in] pointer to image description. + const ur_mem_native_properties_t * + pProperties, ///< [in][optional] pointer to native memory creation properties. + ur_mem_handle_t + *phMem ///< [out] pointer to handle of image memory object created. ) { ur_result_t result = UR_RESULT_SUCCESS; return result; diff --git a/test/conformance/memory/CMakeLists.txt b/test/conformance/memory/CMakeLists.txt index d688340677..ac0632623f 100644 --- a/test/conformance/memory/CMakeLists.txt +++ b/test/conformance/memory/CMakeLists.txt @@ -3,11 +3,12 @@ add_conformance_test_with_devices_environment(memory urMemBufferCreate.cpp + urMemBufferCreateWithNativeHandle.cpp urMemBufferPartition.cpp - urMemCreateWithNativeHandle.cpp urMemGetInfo.cpp urMemGetNativeHandle.cpp urMemImageCreate.cpp + urMemImageCreateWithNativeHandle.cpp urMemImageGetInfo.cpp urMemRelease.cpp urMemRetain.cpp) diff --git a/test/conformance/memory/urMemBufferCreateWithNativeHandle.cpp b/test/conformance/memory/urMemBufferCreateWithNativeHandle.cpp new file mode 100644 index 0000000000..4986ef7062 --- /dev/null +++ b/test/conformance/memory/urMemBufferCreateWithNativeHandle.cpp @@ -0,0 +1,14 @@ +// Copyright (C) 2023 Intel Corporation +// SPDX-License-Identifier: MIT + +#include + +using urMemBufferCreateWithNativeHandleTest = uur::urMemBufferTest; +UUR_INSTANTIATE_DEVICE_TEST_SUITE_P(urMemBufferCreateWithNativeHandleTest); + +TEST_P(urMemBufferCreateWithNativeHandleTest, InvalidNullHandleNativeMem) { + ur_mem_handle_t mem = nullptr; + ASSERT_EQ_RESULT( + UR_RESULT_ERROR_INVALID_NULL_HANDLE, + urMemBufferCreateWithNativeHandle(nullptr, context, nullptr, &mem)); +} diff --git a/test/conformance/memory/urMemCreateWithNativeHandle.cpp b/test/conformance/memory/urMemCreateWithNativeHandle.cpp deleted file mode 100644 index f78468ecad..0000000000 --- a/test/conformance/memory/urMemCreateWithNativeHandle.cpp +++ /dev/null @@ -1,13 +0,0 @@ -// Copyright (C) 2023 Intel Corporation -// SPDX-License-Identifier: MIT - -#include - -using urMemCreateWithNativeHandleTest = uur::urMemBufferTest; -UUR_INSTANTIATE_DEVICE_TEST_SUITE_P(urMemCreateWithNativeHandleTest); - -TEST_P(urMemCreateWithNativeHandleTest, InvalidNullHandleNativeMem) { - ur_mem_handle_t mem = nullptr; - ASSERT_EQ_RESULT(UR_RESULT_ERROR_INVALID_NULL_HANDLE, - urMemCreateWithNativeHandle(nullptr, context, &mem)); -} diff --git a/test/conformance/memory/urMemGetNativeHandle.cpp b/test/conformance/memory/urMemGetNativeHandle.cpp index 8ffda8398e..23dce2baf1 100644 --- a/test/conformance/memory/urMemGetNativeHandle.cpp +++ b/test/conformance/memory/urMemGetNativeHandle.cpp @@ -14,7 +14,13 @@ TEST_P(urMemGetNativeHandleTest, Success) { // We can however convert the native_handle back into a unified-runtime handle // and perform some query on it to verify that it works. ur_mem_handle_t mem = nullptr; - ASSERT_SUCCESS(urMemCreateWithNativeHandle(hNativeMem, context, &mem)); + ur_mem_native_properties_t props = { + /*.stype =*/UR_STRUCTURE_TYPE_MEM_NATIVE_PROPERTIES, + /*.pNext =*/nullptr, + /*.isNativeHandleOwned =*/false, + }; + ASSERT_SUCCESS( + urMemBufferCreateWithNativeHandle(hNativeMem, context, &props, &mem)); ASSERT_NE(mem, nullptr); size_t alloc_size = 0; diff --git a/test/conformance/memory/urMemImageCreateWithNativeHandle.cpp b/test/conformance/memory/urMemImageCreateWithNativeHandle.cpp new file mode 100644 index 0000000000..8056c7e194 --- /dev/null +++ b/test/conformance/memory/urMemImageCreateWithNativeHandle.cpp @@ -0,0 +1,32 @@ +// Copyright (C) 2023 Intel Corporation +// SPDX-License-Identifier: MIT + +#include + +using urMemImageCreateWithNativeHandleTest = uur::urMemBufferTest; +UUR_INSTANTIATE_DEVICE_TEST_SUITE_P(urMemImageCreateWithNativeHandleTest); + +TEST_P(urMemImageCreateWithNativeHandleTest, InvalidNullHandleNativeMem) { + ur_mem_handle_t mem = nullptr; + ur_image_format_t imageFormat = { + /*.channelOrder =*/UR_IMAGE_CHANNEL_ORDER_ARGB, + /*.channelType =*/UR_IMAGE_CHANNEL_TYPE_UNORM_INT8, + }; + ur_image_desc_t imageDesc = { + /*.stype =*/UR_STRUCTURE_TYPE_IMAGE_DESC, + /*.pNext =*/nullptr, + /*.type =*/UR_MEM_TYPE_IMAGE2D, + /*.width =*/16, + /*.height =*/16, + /*.depth =*/1, + /*.arraySize =*/1, + /*.rowPitch =*/16, + /*.slicePitch =*/16 * 16, + /*.numMipLevel =*/0, + /*.numSamples =*/0, + }; + ASSERT_EQ_RESULT(UR_RESULT_ERROR_INVALID_NULL_HANDLE, + urMemImageCreateWithNativeHandle(nullptr, context, + &imageFormat, &imageDesc, + nullptr, &mem)); +}