Skip to content

Commit c56a270

Browse files
[SYCL][PI][L0] Force reset of memcpy command-list. (#4001)
This change set forces a host synchronization on a memcpy's command list fence, and the reset of that commandlist. Resetting the command list has the effect of causing Level Zero to free any resources the command list may be using, and by doing this as early as possible helps remove any bookkeeping that level zero may be doing on memory regions.
1 parent fb97d21 commit c56a270

File tree

1 file changed

+20
-7
lines changed

1 file changed

+20
-7
lines changed

sycl/plugins/level_zero/pi_level_zero.cpp

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -185,10 +185,9 @@ template <> ze_result_t zeHostSynchronize(ze_event_handle_t Handle) {
185185
template <> ze_result_t zeHostSynchronize(ze_command_queue_handle_t Handle) {
186186
return zeHostSynchronizeImpl(zeCommandQueueSynchronize, Handle);
187187
}
188-
// template <>
189-
// ze_result_t zeHostSynchronize(ze_fence_handle_t Handle) {
190-
// return zeHostSynchronizeImpl(zeFenceHostSynchronize, Handle);
191-
// }
188+
template <> ze_result_t zeHostSynchronize(ze_fence_handle_t Handle) {
189+
return zeHostSynchronizeImpl(zeFenceHostSynchronize, Handle);
190+
}
192191

193192
template <typename T, typename Assign>
194193
pi_result getInfoImpl(size_t param_value_size, void *param_value,
@@ -4231,11 +4230,25 @@ static pi_result cleanupAfterEvent(pi_event Event) {
42314230
}
42324231

42334232
// It is possible that the fence was already noted as signalled and
4234-
// reset. In that case the InUse flag will be false, and there is
4235-
// no need to query the fence's status or try to reset it.
4233+
// reset. In that case the InUse flag will be false, and
4234+
// we shouldn't query it, synchronize on it, or try to reset it.
42364235
if (it->second.InUse) {
4236+
// Workaround for VM_BIND mode.
4237+
// Make sure that the command-list doing memcpy is reset before
4238+
// non-USM host memory potentially involved in the memcpy is freed.
4239+
//
4240+
// NOTE: it is valid to wait for the fence here as long as we aren't
4241+
// doing batching on the involved command-list. Today memcpy goes by
4242+
// itself in a command list.
4243+
//
4244+
// TODO: this will unnecessarily(?) wait for non-USM memory buffers
4245+
// too, so we might need to add a new command type to differentiate.
4246+
//
42374247
ze_result_t ZeResult =
4238-
ZE_CALL_NOCHECK(zeFenceQueryStatus, (it->second.ZeFence));
4248+
(Event->CommandType == PI_COMMAND_TYPE_MEM_BUFFER_COPY)
4249+
? ZE_CALL_NOCHECK(zeHostSynchronize, (it->second.ZeFence))
4250+
: ZE_CALL_NOCHECK(zeFenceQueryStatus, (it->second.ZeFence));
4251+
42394252
if (ZeResult == ZE_RESULT_SUCCESS) {
42404253
Queue->resetCommandListFenceEntry(*it, true);
42414254
Event->ZeCommandList = nullptr;

0 commit comments

Comments
 (0)