Skip to content

Commit b61c5f2

Browse files
[SYCL][PI][L0][NFC] Refactor setting of LastCommandEvent (intel#3528)
This change moves the setting of LastCommandEvent into executeCommandList. This cleans up the code a bit. It also makes it possible for future changes to executeCommandList to use the state or information about Queue's current LastCommandList and the future/next LastCommandList to guide batch submission decisions.
1 parent 5860468 commit b61c5f2

File tree

2 files changed

+26
-39
lines changed

2 files changed

+26
-39
lines changed

sycl/plugins/level_zero/pi_level_zero.cpp

Lines changed: 23 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -841,8 +841,10 @@ void _pi_queue::adjustBatchSizeForPartialBatch(pi_uint32 PartialBatchSize) {
841841

842842
pi_result _pi_queue::executeCommandList(ze_command_list_handle_t ZeCommandList,
843843
ze_fence_handle_t ZeFence,
844-
bool IsBlocking,
844+
pi_event Event, bool IsBlocking,
845845
bool OKToBatchCommand) {
846+
this->LastCommandEvent = Event;
847+
846848
if (OKToBatchCommand && this->isBatchingAllowed()) {
847849
if (this->ZeOpenCommandList != nullptr &&
848850
this->ZeOpenCommandList != ZeCommandList)
@@ -906,7 +908,7 @@ pi_result _pi_queue::executeOpenCommandList() {
906908
this->ZeOpenCommandListFence = nullptr;
907909
this->ZeOpenCommandListSize = 0;
908910

909-
return executeCommandList(OpenList, OpenListFence);
911+
return executeCommandList(OpenList, OpenListFence, this->LastCommandEvent);
910912
}
911913

912914
return PI_SUCCESS;
@@ -969,9 +971,9 @@ pi_result _pi_ze_event_list_t::createAndRetainPiZeEventList(
969971
}
970972
}
971973

972-
// For in-order queues, every command should be executed once after the
974+
// For in-order queues, every command should be executed only after the
973975
// previous command has finished. The event associated with the last
974-
// enqued command is added into the waitlist to ensure in-order semantics.
976+
// enqueued command is added into the waitlist to ensure in-order semantics.
975977
if (CurQueue->isInOrderQueue() && CurQueue->LastCommandEvent != nullptr) {
976978
this->ZeEventList[TmpListLength] = CurQueue->LastCommandEvent->ZeEvent;
977979
this->PiEventList[TmpListLength] = CurQueue->LastCommandEvent;
@@ -3841,11 +3843,10 @@ piEnqueueKernelLaunch(pi_queue Queue, pi_kernel Kernel, pi_uint32 WorkDim,
38413843
pi_cast<std::uintptr_t>(ZeEvent));
38423844
printZeEventList((*Event)->WaitList);
38433845

3844-
Queue->LastCommandEvent = *Event;
3845-
38463846
// Execute command list asynchronously, as the event will be used
38473847
// to track down its completion.
3848-
if (auto Res = Queue->executeCommandList(ZeCommandList, ZeFence, false, true))
3848+
if (auto Res = Queue->executeCommandList(ZeCommandList, ZeFence, *Event,
3849+
false, true))
38493850
return Res;
38503851

38513852
return PI_SUCCESS;
@@ -4364,11 +4365,9 @@ pi_result piEnqueueEventsWait(pi_queue Queue, pi_uint32 NumEventsInWaitList,
43644365

43654366
ZE_CALL(zeCommandListAppendSignalEvent, (ZeCommandList, ZeEvent));
43664367

4367-
Queue->LastCommandEvent = *Event;
4368-
43694368
// Execute command list asynchronously as the event will be used
43704369
// to track down its completion.
4371-
return Queue->executeCommandList(ZeCommandList, ZeFence);
4370+
return Queue->executeCommandList(ZeCommandList, ZeFence, *Event);
43724371
}
43734372

43744373
// If wait-list is empty, then this particular command should wait until
@@ -4428,11 +4427,9 @@ pi_result piEnqueueEventsWaitWithBarrier(pi_queue Queue,
44284427
(ZeCommandList, ZeEvent, (*Event)->WaitList.Length,
44294428
(*Event)->WaitList.ZeEventList));
44304429

4431-
Queue->LastCommandEvent = *Event;
4432-
44334430
// Execute command list asynchronously as the event will be used
44344431
// to track down its completion.
4435-
return Queue->executeCommandList(ZeCommandList, ZeFence);
4432+
return Queue->executeCommandList(ZeCommandList, ZeFence, *Event);
44364433
}
44374434

44384435
pi_result piEnqueueMemBufferRead(pi_queue Queue, pi_mem Src,
@@ -4520,10 +4517,8 @@ static pi_result enqueueMemCopyHelper(pi_command_type CommandType,
45204517
pi_cast<std::uintptr_t>(ZeEvent));
45214518
printZeEventList(WaitList);
45224519

4523-
Queue->LastCommandEvent = *Event;
4524-
4525-
if (auto Res =
4526-
Queue->executeCommandList(ZeCommandList, ZeFence, BlockingWrite))
4520+
if (auto Res = Queue->executeCommandList(ZeCommandList, ZeFence, *Event,
4521+
BlockingWrite))
45274522
return Res;
45284523

45294524
return PI_SUCCESS;
@@ -4619,9 +4614,8 @@ static pi_result enqueueMemCopyRectHelper(
46194614
zePrint("calling zeCommandListAppendBarrier() with Event %#lx\n",
46204615
pi_cast<std::uintptr_t>(ZeEvent));
46214616

4622-
Queue->LastCommandEvent = *Event;
4623-
4624-
if (auto Res = Queue->executeCommandList(ZeCommandList, ZeFence, Blocking))
4617+
if (auto Res =
4618+
Queue->executeCommandList(ZeCommandList, ZeFence, *Event, Blocking))
46254619
return Res;
46264620

46274621
return PI_SUCCESS;
@@ -4761,11 +4755,9 @@ enqueueMemFillHelper(pi_command_type CommandType, pi_queue Queue, void *Ptr,
47614755
pi_cast<pi_uint64>(ZeEvent));
47624756
printZeEventList(WaitList);
47634757

4764-
Queue->LastCommandEvent = *Event;
4765-
47664758
// Execute command list asynchronously, as the event will be used
47674759
// to track down its completion.
4768-
if (auto Res = Queue->executeCommandList(ZeCommandList, ZeFence))
4760+
if (auto Res = Queue->executeCommandList(ZeCommandList, ZeFence, *Event))
47694761
return Res;
47704762

47714763
return PI_SUCCESS;
@@ -4905,9 +4897,8 @@ pi_result piEnqueueMemBufferMap(pi_queue Queue, pi_mem Buffer,
49054897
pi_cast<char *>(Buffer->getZeHandle()) + Offset, Size, ZeEvent, 0,
49064898
nullptr));
49074899

4908-
Queue->LastCommandEvent = *Event;
4909-
4910-
if (auto Res = Queue->executeCommandList(ZeCommandList, ZeFence, BlockingMap))
4900+
if (auto Res = Queue->executeCommandList(ZeCommandList, ZeFence, *Event,
4901+
BlockingMap))
49114902
return Res;
49124903

49134904
return Buffer->addMapping(*RetMap, Offset, Size);
@@ -5017,11 +5008,9 @@ pi_result piEnqueueMemUnmap(pi_queue Queue, pi_mem MemObj, void *MappedPtr,
50175008
pi_cast<char *>(MemObj->getZeHandle()) + MapInfo.Offset, MappedPtr,
50185009
MapInfo.Size, ZeEvent, 0, nullptr));
50195010

5020-
Queue->LastCommandEvent = *Event;
5021-
50225011
// Execute command list asynchronously, as the event will be used
50235012
// to track down its completion.
5024-
if (auto Res = Queue->executeCommandList(ZeCommandList, ZeFence))
5013+
if (auto Res = Queue->executeCommandList(ZeCommandList, ZeFence, *Event))
50255014
return Res;
50265015

50275016
return PI_SUCCESS;
@@ -5215,9 +5204,8 @@ static pi_result enqueueMemImageCommandHelper(
52155204
return PI_INVALID_OPERATION;
52165205
}
52175206

5218-
Queue->LastCommandEvent = *Event;
5219-
5220-
if (auto Res = Queue->executeCommandList(ZeCommandList, ZeFence, IsBlocking))
5207+
if (auto Res =
5208+
Queue->executeCommandList(ZeCommandList, ZeFence, *Event, IsBlocking))
52215209
return Res;
52225210

52235211
return PI_SUCCESS;
@@ -5756,9 +5744,8 @@ pi_result piextUSMEnqueuePrefetch(pi_queue Queue, const void *Ptr, size_t Size,
57565744
// so manually add command to signal our event.
57575745
ZE_CALL(zeCommandListAppendSignalEvent, (ZeCommandList, ZeEvent));
57585746

5759-
Queue->LastCommandEvent = *Event;
5760-
5761-
if (auto Res = Queue->executeCommandList(ZeCommandList, ZeFence, false))
5747+
if (auto Res =
5748+
Queue->executeCommandList(ZeCommandList, ZeFence, *Event, false))
57625749
return Res;
57635750

57645751
return PI_SUCCESS;
@@ -5815,13 +5802,11 @@ pi_result piextUSMEnqueueMemAdvise(pi_queue Queue, const void *Ptr,
58155802
ZE_CALL(zeCommandListAppendMemAdvise,
58165803
(ZeCommandList, Queue->Device->ZeDevice, Ptr, Length, ZeAdvice));
58175804

5818-
Queue->LastCommandEvent = *Event;
5819-
58205805
// TODO: Level Zero does not have a completion "event" with the advise API,
58215806
// so manually add command to signal our event.
58225807
ZE_CALL(zeCommandListAppendSignalEvent, (ZeCommandList, ZeEvent));
58235808

5824-
Queue->executeCommandList(ZeCommandList, ZeFence, false);
5809+
Queue->executeCommandList(ZeCommandList, ZeFence, *Event, false);
58255810
return PI_SUCCESS;
58265811
}
58275812

sycl/plugins/level_zero/pi_level_zero.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,13 +416,15 @@ struct _pi_queue : _pi_object {
416416
// The "IsBlocking" tells if the wait for completion is required.
417417
// The "ZeFence" passed is used to track when the command list passed
418418
// has completed execution on the device and can be reused.
419+
// The Event parameter is the pi_event that the last command in the command
420+
// list will signal upon its completion.
419421
// If OKToBatchCommand is true, then this command list may be executed
420422
// immediately, or it may be left open for other future command to be
421423
// batched into.
422424
// If IsBlocking is true, then batching will not be allowed regardless
423425
// of the value of OKToBatchCommand
424426
pi_result executeCommandList(ze_command_list_handle_t ZeCommandList,
425-
ze_fence_handle_t ZeFence,
427+
ze_fence_handle_t ZeFence, pi_event Event,
426428
bool IsBlocking = false,
427429
bool OKToBatchCommand = false);
428430

0 commit comments

Comments
 (0)