Skip to content

Commit 75afcc8

Browse files
committed
Retain event before setting deleter callback in Fill()
1 parent b9ebd7b commit 75afcc8

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

source/adapters/opencl/usm.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,13 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueUSMFill(
313313
numEventsInWaitList, cl_adapter::cast<const cl_event *>(phEventWaitList),
314314
&CopyEvent));
315315

316+
if (phEvent) {
317+
// Since we're releasing this in the callback above we need to retain it
318+
// here to keep the user copy alive.
319+
CL_RETURN_ON_FAILURE(clRetainEvent(CopyEvent));
320+
*phEvent = cl_adapter::cast<ur_event_handle_t>(CopyEvent);
321+
}
322+
316323
// This self destructs taking the event and allocation with it.
317324
auto Info = new AllocDeleterCallbackInfo(USMFree, CLContext, HostBuffer);
318325

@@ -327,12 +334,6 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueUSMFill(
327334
clReleaseEvent(CopyEvent);
328335
CL_RETURN_ON_FAILURE(ClErr);
329336
}
330-
if (phEvent) {
331-
// Since we're releasing this in the callback above we need to retain it
332-
// here to keep the user copy alive.
333-
CL_RETURN_ON_FAILURE(clRetainEvent(CopyEvent));
334-
*phEvent = cl_adapter::cast<ur_event_handle_t>(CopyEvent);
335-
}
336337

337338
return UR_RESULT_SUCCESS;
338339
}

0 commit comments

Comments
 (0)