-
Notifications
You must be signed in to change notification settings - Fork 769
[UR][L0 v2][draft] Port USM alloc to adapter v2 #18179
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: sycl
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -153,6 +153,10 @@ ur_result_t ur_queue_immediate_in_order_t::queueGetNativeHandle( | |
ur_result_t ur_queue_immediate_in_order_t::queueFinish() { | ||
TRACK_SCOPE_LATENCY("ur_queue_immediate_in_order_t::queueFinish"); | ||
|
||
// TODO: have ur_queue_handle_t here | ||
// hContext->getAsyncPool()->cleanupPoolsForQueue(this); | ||
hContext->getAsyncPool()->cleanupPools(); | ||
|
||
auto commandListLocked = commandListManager.lock(); | ||
// TODO: use zeEventHostSynchronize instead? | ||
TRACK_SCOPE_LATENCY( | ||
|
@@ -712,25 +716,106 @@ ur_result_t ur_queue_immediate_in_order_t::enqueueWriteHostPipe( | |
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; | ||
} | ||
|
||
ur_result_t ur_queue_immediate_in_order_t::enqueueUSMAllocHelper( | ||
ur_queue_handle_t hQueue, ur_usm_pool_handle_t pPool, const size_t size, | ||
const ur_exp_async_usm_alloc_properties_t *, uint32_t numEventsInWaitList, | ||
const ur_event_handle_t *phEventWaitList, void **ppMem, | ||
ur_event_handle_t *phEvent, ur_usm_type_t type) { | ||
auto commandListLocked = commandListManager.lock(); | ||
|
||
if (!pPool) { | ||
pPool = hContext->getAsyncPool(); | ||
} | ||
|
||
auto device = (type == UR_USM_TYPE_HOST) ? nullptr : hDevice; | ||
|
||
std::vector<ur_event_handle_t> extendedWaitList; | ||
ur_event_handle_t originAllocEvent = nullptr; | ||
auto asyncAlloc = | ||
pPool->allocateEnqueued(hContext, hQueue, device, nullptr, type, size); | ||
if (!asyncAlloc) { | ||
auto Ret = pPool->allocate(hContext, device, nullptr, type, size, ppMem); | ||
if (Ret) { | ||
return Ret; | ||
} | ||
} else { | ||
*ppMem = std::get<0>(*asyncAlloc); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: |
||
originAllocEvent = std::get<1>(*asyncAlloc); | ||
if (originAllocEvent) { | ||
for (size_t i = 0; i < numEventsInWaitList; i++) { | ||
extendedWaitList.push_back(phEventWaitList[i]); | ||
} | ||
extendedWaitList.push_back(originAllocEvent); | ||
} | ||
} | ||
|
||
if (!extendedWaitList.empty()) { | ||
numEventsInWaitList = static_cast<uint32_t>(extendedWaitList.size()); | ||
phEventWaitList = extendedWaitList.data(); | ||
} | ||
|
||
ur_command_t commandType = UR_COMMAND_FORCE_UINT32; | ||
switch (type) { | ||
case UR_USM_TYPE_HOST: | ||
commandType = UR_COMMAND_ENQUEUE_USM_HOST_ALLOC_EXP; | ||
break; | ||
case UR_USM_TYPE_DEVICE: | ||
commandType = UR_COMMAND_ENQUEUE_USM_DEVICE_ALLOC_EXP; | ||
break; | ||
case UR_USM_TYPE_SHARED: | ||
commandType = UR_COMMAND_ENQUEUE_USM_SHARED_ALLOC_EXP; | ||
break; | ||
default: | ||
logger::error("enqueueUSMAllocHelper: unsupported USM type"); | ||
throw UR_RESULT_ERROR_UNKNOWN; | ||
} | ||
|
||
auto zeSignalEvent = getSignalEvent(commandListLocked, phEvent, commandType); | ||
auto [pWaitEvents, numWaitEvents] = | ||
getWaitListView(commandListLocked, phEventWaitList, numEventsInWaitList); | ||
|
||
if (numWaitEvents > 0) { | ||
ZE2UR_CALL( | ||
zeCommandListAppendWaitOnEvents, | ||
(commandListLocked->getZeCommandList(), numWaitEvents, pWaitEvents)); | ||
} | ||
|
||
if (zeSignalEvent) { | ||
ZE2UR_CALL(zeCommandListAppendSignalEvent, | ||
(commandListLocked->getZeCommandList(), zeSignalEvent)); | ||
} | ||
|
||
return UR_RESULT_SUCCESS; | ||
} | ||
|
||
ur_result_t ur_queue_immediate_in_order_t::enqueueUSMDeviceAllocExp( | ||
ur_usm_pool_handle_t, const size_t, | ||
const ur_exp_async_usm_alloc_properties_t *, uint32_t, | ||
const ur_event_handle_t *, void **, ur_event_handle_t *) { | ||
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; | ||
ur_queue_handle_t hQueue, ur_usm_pool_handle_t pPool, const size_t size, | ||
const ur_exp_async_usm_alloc_properties_t *pProperties, | ||
uint32_t numEventsInWaitList, const ur_event_handle_t *phEventWaitList, | ||
void **ppMem, ur_event_handle_t *phEvent) { | ||
return enqueueUSMAllocHelper(hQueue, pPool, size, pProperties, | ||
numEventsInWaitList, phEventWaitList, ppMem, | ||
phEvent, UR_USM_TYPE_DEVICE); | ||
} | ||
|
||
ur_result_t ur_queue_immediate_in_order_t::enqueueUSMSharedAllocExp( | ||
ur_usm_pool_handle_t, const size_t, | ||
const ur_exp_async_usm_alloc_properties_t *, uint32_t, | ||
const ur_event_handle_t *, void **, ur_event_handle_t *) { | ||
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; | ||
ur_queue_handle_t hQueue, ur_usm_pool_handle_t pPool, const size_t size, | ||
const ur_exp_async_usm_alloc_properties_t *pProperties, | ||
uint32_t numEventsInWaitList, const ur_event_handle_t *phEventWaitList, | ||
void **ppMem, ur_event_handle_t *phEvent) { | ||
return enqueueUSMAllocHelper(hQueue, pPool, size, pProperties, | ||
numEventsInWaitList, phEventWaitList, ppMem, | ||
phEvent, UR_USM_TYPE_SHARED); | ||
} | ||
|
||
ur_result_t ur_queue_immediate_in_order_t::enqueueUSMHostAllocExp( | ||
ur_usm_pool_handle_t, const size_t, | ||
const ur_exp_async_usm_alloc_properties_t *, uint32_t, | ||
const ur_event_handle_t *, void **, ur_event_handle_t *) { | ||
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; | ||
ur_queue_handle_t hQueue, ur_usm_pool_handle_t pPool, const size_t size, | ||
const ur_exp_async_usm_alloc_properties_t *pProperties, | ||
uint32_t numEventsInWaitList, const ur_event_handle_t *phEventWaitList, | ||
void **ppMem, ur_event_handle_t *phEvent) { | ||
return enqueueUSMAllocHelper(hQueue, pPool, size, pProperties, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add |
||
numEventsInWaitList, phEventWaitList, ppMem, | ||
phEvent, UR_USM_TYPE_HOST); | ||
} | ||
|
||
ur_result_t ur_queue_immediate_in_order_t::enqueueUSMFreeExp( | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don;t need to create a temporary vector here. commandListManger has getWaitListView function that you should use here (it also accepts an optional extra wait event). You just call:
getWaitListView(commandListLocked, phEventWaitList, numEventsInWaitList, originAllocEvent);