@@ -419,10 +419,10 @@ inline static void piQueueRetainNoLock(pi_queue Queue) { Queue->RefCount++; }
419
419
// \param Event a pointer to hold the newly created pi_event
420
420
// \param CommandType various command type determined by the caller
421
421
// \param ZeCommandList the handle to associate with the newly created event
422
- // \param ZeEvent the ZeEvent handle to be associated with the event
423
- inline static pi_result createEventAndAssociateQueue (
424
- pi_queue Queue, pi_event *Event, pi_command_type CommandType,
425
- ze_command_list_handle_t ZeCommandList, ze_event_handle_t *ZeEvent ) {
422
+ inline static pi_result
423
+ createEventAndAssociateQueue (pi_queue Queue, pi_event *Event,
424
+ pi_command_type CommandType,
425
+ ze_command_list_handle_t ZeCommandList ) {
426
426
pi_result Res = piEventCreate (Queue->Context , Event);
427
427
if (Res != PI_SUCCESS)
428
428
return Res;
@@ -431,7 +431,6 @@ inline static pi_result createEventAndAssociateQueue(
431
431
(*Event)->CommandType = CommandType;
432
432
(*Event)->ZeCommandList = ZeCommandList;
433
433
434
- *ZeEvent = (*Event)->ZeEvent ;
435
434
// We need to increment the reference counter here to avoid pi_queue
436
435
// being released before the associated pi_event is released because
437
436
// piEventRelease requires access to the associated pi_queue.
@@ -2038,28 +2037,29 @@ pi_result piQueueRelease(pi_queue Queue) {
2038
2037
Queue->RefCount --;
2039
2038
if (Queue->RefCount == 0 )
2040
2039
RefCountZero = true ;
2041
- }
2042
2040
2043
- if (RefCountZero) {
2044
- // It is possible to get to here and still have an open command list
2045
- // if no wait or finish ever occurred for this queue. But still need
2046
- // to make sure commands get executed.
2047
- if (auto Res = Queue->executeOpenCommandList ())
2048
- return Res;
2041
+ if (RefCountZero) {
2042
+ // It is possible to get to here and still have an open command list
2043
+ // if no wait or finish ever occurred for this queue. But still need
2044
+ // // TODO: o make sure commands get executed.
2045
+ if (auto Res = Queue->executeOpenCommandList ())
2046
+ return Res;
2049
2047
2050
- // Destroy all the fences created associated with this queue.
2051
- for (const auto &MapEntry : Queue->ZeCommandListFenceMap ) {
2052
- ZE_CALL (zeFenceDestroy (MapEntry.second ));
2048
+ // Destroy all the fences created associated with this queue.
2049
+ for (const auto &MapEntry : Queue->ZeCommandListFenceMap ) {
2050
+ ZE_CALL (zeFenceDestroy (MapEntry.second ));
2051
+ }
2052
+ Queue->ZeCommandListFenceMap .clear ();
2053
+ ZE_CALL (zeCommandQueueDestroy (Queue->ZeCommandQueue ));
2054
+ Queue->ZeCommandQueue = nullptr ;
2055
+
2056
+ zePrint (" piQueueRelease NumTimesClosedFull %d, NumTimesClosedEarly %d\n " ,
2057
+ Queue->NumTimesClosedFull , Queue->NumTimesClosedEarly );
2053
2058
}
2054
- Queue->ZeCommandListFenceMap .clear ();
2055
- ZE_CALL (zeCommandQueueDestroy (Queue->ZeCommandQueue ));
2056
- Queue->ZeCommandQueue = nullptr ;
2059
+ }
2057
2060
2058
- zePrint (" piQueueRelease NumTimesClosedFull %d, NumTimesClosedEarly %d\n " ,
2059
- Queue->NumTimesClosedFull , Queue->NumTimesClosedEarly );
2060
- Queue->PiQueueMutex .unlock ();
2061
+ if (RefCountZero)
2061
2062
delete Queue;
2062
- }
2063
2063
return PI_SUCCESS;
2064
2064
}
2065
2065
@@ -3442,9 +3442,10 @@ piEnqueueKernelLaunch(pi_queue Queue, pi_kernel Kernel, pi_uint32 WorkDim,
3442
3442
3443
3443
ze_event_handle_t ZeEvent = nullptr ;
3444
3444
pi_result Res = createEventAndAssociateQueue (
3445
- Queue, Event, PI_COMMAND_TYPE_NDRANGE_KERNEL, ZeCommandList, &ZeEvent );
3445
+ Queue, Event, PI_COMMAND_TYPE_NDRANGE_KERNEL, ZeCommandList);
3446
3446
if (Res != PI_SUCCESS)
3447
3447
return Res;
3448
+ ZeEvent = (*Event)->ZeEvent ;
3448
3449
3449
3450
// Save the kernel in the event, so that when the event is signalled
3450
3451
// the code can do a piKernelRelease on this kernel.
@@ -3916,9 +3917,10 @@ pi_result piEnqueueEventsWaitWithBarrier(pi_queue Queue,
3916
3917
ze_event_handle_t ZeEvent = nullptr ;
3917
3918
if (Event) {
3918
3919
auto Res = createEventAndAssociateQueue (Queue, Event, PI_COMMAND_TYPE_USER,
3919
- ZeCommandList, &ZeEvent );
3920
+ ZeCommandList);
3920
3921
if (Res != PI_SUCCESS)
3921
3922
return Res;
3923
+ ZeEvent = (*Event)->ZeEvent ;
3922
3924
}
3923
3925
3924
3926
// TODO: use unique_ptr with custom deleter in the whole Level Zero plugin for
@@ -3994,10 +3996,11 @@ enqueueMemCopyHelper(pi_command_type CommandType, pi_queue Queue, void *Dst,
3994
3996
3995
3997
ze_event_handle_t ZeEvent = nullptr ;
3996
3998
if (Event) {
3997
- auto Res = createEventAndAssociateQueue (Queue, Event, CommandType,
3998
- ZeCommandList, &ZeEvent );
3999
+ auto Res =
4000
+ createEventAndAssociateQueue (Queue, Event, CommandType, ZeCommandList );
3999
4001
if (Res != PI_SUCCESS)
4000
4002
return Res;
4003
+ ZeEvent = (*Event)->ZeEvent ;
4001
4004
}
4002
4005
4003
4006
ze_event_handle_t *ZeEventWaitList =
@@ -4050,10 +4053,11 @@ static pi_result enqueueMemCopyRectHelper(
4050
4053
4051
4054
ze_event_handle_t ZeEvent = nullptr ;
4052
4055
if (Event) {
4053
- auto Res = createEventAndAssociateQueue (Queue, Event, CommandType,
4054
- ZeCommandList, &ZeEvent );
4056
+ auto Res =
4057
+ createEventAndAssociateQueue (Queue, Event, CommandType, ZeCommandList );
4055
4058
if (Res != PI_SUCCESS)
4056
4059
return Res;
4060
+ ZeEvent = (*Event)->ZeEvent ;
4057
4061
}
4058
4062
4059
4063
ze_event_handle_t *ZeEventWaitList =
@@ -4227,10 +4231,11 @@ enqueueMemFillHelper(pi_command_type CommandType, pi_queue Queue, void *Ptr,
4227
4231
4228
4232
ze_event_handle_t ZeEvent = nullptr ;
4229
4233
if (Event) {
4230
- auto Res = createEventAndAssociateQueue (Queue, Event, CommandType,
4231
- ZeCommandList, &ZeEvent );
4234
+ auto Res =
4235
+ createEventAndAssociateQueue (Queue, Event, CommandType, ZeCommandList );
4232
4236
if (Res != PI_SUCCESS)
4233
4237
return Res;
4238
+ ZeEvent = (*Event)->ZeEvent ;
4234
4239
}
4235
4240
4236
4241
ze_event_handle_t *ZeEventWaitList =
@@ -4311,9 +4316,10 @@ pi_result piEnqueueMemBufferMap(pi_queue Queue, pi_mem Buffer,
4311
4316
4312
4317
if (Event) {
4313
4318
auto Res = createEventAndAssociateQueue (
4314
- Queue, Event, PI_COMMAND_TYPE_MEM_BUFFER_MAP, ZeCommandList, &ZeEvent );
4319
+ Queue, Event, PI_COMMAND_TYPE_MEM_BUFFER_MAP, ZeCommandList);
4315
4320
if (Res != PI_SUCCESS)
4316
4321
return Res;
4322
+ ZeEvent = (*Event)->ZeEvent ;
4317
4323
}
4318
4324
4319
4325
// TODO: Level Zero is missing the memory "mapping" capabilities, so we are
@@ -4404,11 +4410,11 @@ pi_result piEnqueueMemUnmap(pi_queue Queue, pi_mem MemObj, void *MappedPtr,
4404
4410
std::lock_guard<std::mutex> lock (Queue->PiQueueMutex );
4405
4411
4406
4412
if (Event) {
4407
- auto Res = createEventAndAssociateQueue (Queue, Event,
4408
- PI_COMMAND_TYPE_MEM_BUFFER_UNMAP,
4409
- ZeCommandList, &ZeEvent);
4413
+ auto Res = createEventAndAssociateQueue (
4414
+ Queue, Event, PI_COMMAND_TYPE_MEM_BUFFER_UNMAP, ZeCommandList);
4410
4415
if (Res != PI_SUCCESS)
4411
4416
return Res;
4417
+ ZeEvent = (*Event)->ZeEvent ;
4412
4418
}
4413
4419
4414
4420
_pi_mem::Mapping MapInfo = {};
@@ -4547,10 +4553,11 @@ enqueueMemImageCommandHelper(pi_command_type CommandType, pi_queue Queue,
4547
4553
4548
4554
ze_event_handle_t ZeEvent = nullptr ;
4549
4555
if (Event) {
4550
- auto Res = createEventAndAssociateQueue (Queue, Event, CommandType,
4551
- ZeCommandList, &ZeEvent );
4556
+ auto Res =
4557
+ createEventAndAssociateQueue (Queue, Event, CommandType, ZeCommandList );
4552
4558
if (Res != PI_SUCCESS)
4553
4559
return Res;
4560
+ ZeEvent = (*Event)->ZeEvent ;
4554
4561
}
4555
4562
4556
4563
ze_event_handle_t *ZeEventWaitList =
@@ -5150,9 +5157,10 @@ pi_result piextUSMEnqueuePrefetch(pi_queue Queue, const void *Ptr, size_t Size,
5150
5157
ze_event_handle_t ZeEvent = nullptr ;
5151
5158
if (Event) {
5152
5159
auto Res = createEventAndAssociateQueue (Queue, Event, PI_COMMAND_TYPE_USER,
5153
- ZeCommandList, &ZeEvent );
5160
+ ZeCommandList);
5154
5161
if (Res != PI_SUCCESS)
5155
5162
return Res;
5163
+ ZeEvent = (*Event)->ZeEvent ;
5156
5164
}
5157
5165
5158
5166
ze_event_handle_t *ZeEventWaitList =
@@ -5205,9 +5213,10 @@ pi_result piextUSMEnqueueMemAdvise(pi_queue Queue, const void *Ptr,
5205
5213
ze_event_handle_t ZeEvent = nullptr ;
5206
5214
if (Event) {
5207
5215
auto Res = createEventAndAssociateQueue (Queue, Event, PI_COMMAND_TYPE_USER,
5208
- ZeCommandList, &ZeEvent );
5216
+ ZeCommandList);
5209
5217
if (Res != PI_SUCCESS)
5210
5218
return Res;
5219
+ ZeEvent = (*Event)->ZeEvent ;
5211
5220
}
5212
5221
5213
5222
ZE_CALL (zeCommandListAppendMemAdvise (ZeCommandList, Queue->Device ->ZeDevice ,
0 commit comments