@@ -461,4 +461,39 @@ ur_result_t urUSMGetMemAllocInfo(
461461} catch (...) {
462462 return exceptionToResult (std::current_exception ());
463463}
464+
465+ ur_result_t urUSMImportExp (ur_context_handle_t hContext, void *hostPtr,
466+ size_t size) {
467+ UR_ASSERT (hContext, UR_RESULT_ERROR_INVALID_CONTEXT);
468+
469+ // Promote the host ptr to USM host memory.
470+ if (ZeUSMImport.Supported && hostPtr != nullptr ) {
471+ // Query memory type of the host pointer
472+ ze_device_handle_t hDevice;
473+ ZeStruct<ze_memory_allocation_properties_t > zeMemoryAllocationProperties;
474+ ZE2UR_CALL (zeMemGetAllocProperties,
475+ (hContext->getZeHandle (), hostPtr, &zeMemoryAllocationProperties,
476+ &hDevice));
477+
478+ // If not shared of any type, we can import the ptr
479+ if (zeMemoryAllocationProperties.type == ZE_MEMORY_TYPE_UNKNOWN) {
480+ // Promote the host ptr to USM host memory
481+ ze_driver_handle_t driverHandle =
482+ hContext->getPlatform ()->ZeDriverHandleExpTranslated ;
483+ ZeUSMImport.doZeUSMImport (driverHandle, hostPtr, size);
484+ }
485+ }
486+ return UR_RESULT_SUCCESS;
487+ }
488+
489+ ur_result_t urUSMReleaseExp (ur_context_handle_t hContext, void *hostPtr) {
490+ UR_ASSERT (hContext, UR_RESULT_ERROR_INVALID_CONTEXT);
491+
492+ // Release the imported memory.
493+ if (ZeUSMImport.Supported && hostPtr != nullptr )
494+ ZeUSMImport.doZeUSMRelease (
495+ hContext->getPlatform ()->ZeDriverHandleExpTranslated , hostPtr);
496+ return UR_RESULT_SUCCESS;
497+ }
498+
464499} // namespace ur::level_zero
0 commit comments