Skip to content

Commit 599dd57

Browse files
committed
[L0 v2] implement USM import/release support
1 parent 87b2722 commit 599dd57

File tree

2 files changed

+35
-11
lines changed

2 files changed

+35
-11
lines changed

source/adapters/level_zero/v2/api.cpp

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -474,15 +474,4 @@ ur_result_t urCommandBufferCommandGetInfoExp(
474474
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
475475
}
476476

477-
ur_result_t urUSMImportExp(ur_context_handle_t hContext, void *pMem,
478-
size_t size) {
479-
logger::error("{} function not implemented!", __FUNCTION__);
480-
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
481-
}
482-
483-
ur_result_t urUSMReleaseExp(ur_context_handle_t hContext, void *pMem) {
484-
logger::error("{} function not implemented!", __FUNCTION__);
485-
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
486-
}
487-
488477
} // namespace ur::level_zero

source/adapters/level_zero/v2/usm.cpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)