Skip to content

Commit 26bd47a

Browse files
committed
Retain event before setting deleter callback in Fill()
1 parent 26b847f commit 26bd47a

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
@@ -298,6 +298,13 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueUSMFill(
298298
numEventsInWaitList, cl_adapter::cast<const cl_event *>(phEventWaitList),
299299
&CopyEvent));
300300

301+
if (phEvent) {
302+
// Since we're releasing this in the callback above we need to retain it
303+
// here to keep the user copy alive.
304+
CL_RETURN_ON_FAILURE(clRetainEvent(CopyEvent));
305+
*phEvent = cl_adapter::cast<ur_event_handle_t>(CopyEvent);
306+
}
307+
301308
// This self destructs taking the event and allocation with it.
302309
auto Info = new AllocDeleterCallbackInfo(USMFree, CLContext, HostBuffer);
303310

@@ -312,12 +319,6 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueUSMFill(
312319
clReleaseEvent(CopyEvent);
313320
CL_RETURN_ON_FAILURE(ClErr);
314321
}
315-
if (phEvent) {
316-
// Since we're releasing this in the callback above we need to retain it
317-
// here to keep the user copy alive.
318-
CL_RETURN_ON_FAILURE(clRetainEvent(CopyEvent));
319-
*phEvent = cl_adapter::cast<ur_event_handle_t>(CopyEvent);
320-
}
321322

322323
return UR_RESULT_SUCCESS;
323324
}

0 commit comments

Comments
 (0)