Skip to content

Commit cbd909c

Browse files
committed
Retain event before setting deleter callback in Fill()
1 parent 975bd63 commit cbd909c

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
@@ -320,6 +320,13 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueUSMFill(
320320
numEventsInWaitList, cl_adapter::cast<const cl_event *>(phEventWaitList),
321321
&CopyEvent));
322322

323+
if (phEvent) {
324+
// Since we're releasing this in the callback above we need to retain it
325+
// here to keep the user copy alive.
326+
CL_RETURN_ON_FAILURE(clRetainEvent(CopyEvent));
327+
*phEvent = cl_adapter::cast<ur_event_handle_t>(CopyEvent);
328+
}
329+
323330
// This self destructs taking the event and allocation with it.
324331
auto Info = new AllocDeleterCallbackInfo(USMFree, CLContext, HostBuffer);
325332

@@ -334,12 +341,6 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueUSMFill(
334341
clReleaseEvent(CopyEvent);
335342
CL_RETURN_ON_FAILURE(ClErr);
336343
}
337-
if (phEvent) {
338-
// Since we're releasing this in the callback above we need to retain it
339-
// here to keep the user copy alive.
340-
CL_RETURN_ON_FAILURE(clRetainEvent(CopyEvent));
341-
*phEvent = cl_adapter::cast<ur_event_handle_t>(CopyEvent);
342-
}
343344

344345
return UR_RESULT_SUCCESS;
345346
}

0 commit comments

Comments
 (0)