Skip to content

Commit d8c8e08

Browse files
[SYCL][L0] Handle empty wait-list for zeCommandListAppendWaitOnEvents (#3075)
Signed-off-by: Sergey V Maslov <[email protected]>
1 parent 5e7cbef commit d8c8e08

File tree

1 file changed

+39
-31
lines changed

1 file changed

+39
-31
lines changed

sycl/plugins/level_zero/pi_level_zero.cpp

100644100755
Lines changed: 39 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -817,7 +817,7 @@ pi_result _pi_ze_event_list_t::createAndRetainPiZeEventList(
817817
return PI_SUCCESS;
818818
}
819819

820-
static void printZeEventList(_pi_ze_event_list_t &PiZeEventList) {
820+
static void printZeEventList(const _pi_ze_event_list_t &PiZeEventList) {
821821
zePrint(" NumEventsInWaitList %d:", PiZeEventList.Length);
822822

823823
for (pi_uint32 I = 0; I < PiZeEventList.Length; I++) {
@@ -4194,9 +4194,11 @@ enqueueMemCopyHelper(pi_command_type CommandType, pi_queue Queue, void *Dst,
41944194
ZeEvent = (*Event)->ZeEvent;
41954195
(*Event)->WaitList = TmpWaitList;
41964196

4197-
ZE_CALL(zeCommandListAppendWaitOnEvents(ZeCommandList,
4198-
(*Event)->WaitList.Length,
4199-
(*Event)->WaitList.ZeEventList));
4197+
const auto &WaitList = (*Event)->WaitList;
4198+
if (WaitList.Length) {
4199+
ZE_CALL(zeCommandListAppendWaitOnEvents(ZeCommandList, WaitList.Length,
4200+
WaitList.ZeEventList));
4201+
}
42004202

42014203
ZE_CALL(zeCommandListAppendMemoryCopy(ZeCommandList, Dst, Src, Size, ZeEvent,
42024204
0, nullptr));
@@ -4208,7 +4210,7 @@ enqueueMemCopyHelper(pi_command_type CommandType, pi_queue Queue, void *Dst,
42084210
zePrint("calling zeCommandListAppendMemoryCopy() with\n"
42094211
" ZeEvent %#lx\n",
42104212
pi_cast<std::uintptr_t>(ZeEvent));
4211-
printZeEventList((*Event)->WaitList);
4213+
printZeEventList(WaitList);
42124214

42134215
return PI_SUCCESS;
42144216
}
@@ -4249,14 +4251,15 @@ static pi_result enqueueMemCopyRectHelper(
42494251
ZeEvent = (*Event)->ZeEvent;
42504252
(*Event)->WaitList = TmpWaitList;
42514253

4252-
ZE_CALL(zeCommandListAppendWaitOnEvents(ZeCommandList,
4253-
(*Event)->WaitList.Length,
4254-
(*Event)->WaitList.ZeEventList));
4255-
4254+
const auto &WaitList = (*Event)->WaitList;
4255+
if (WaitList.Length) {
4256+
ZE_CALL(zeCommandListAppendWaitOnEvents(ZeCommandList, WaitList.Length,
4257+
WaitList.ZeEventList));
4258+
}
42564259
zePrint("calling zeCommandListAppendMemoryCopy() with\n"
42574260
" ZeEvent %#lx\n",
42584261
pi_cast<std::uintptr_t>(ZeEvent));
4259-
printZeEventList((*Event)->WaitList);
4262+
printZeEventList(WaitList);
42604263

42614264
uint32_t SrcOriginX = pi_cast<uint32_t>(SrcOrigin->x_bytes);
42624265
uint32_t SrcOriginY = pi_cast<uint32_t>(SrcOrigin->y_scalar);
@@ -4415,10 +4418,11 @@ enqueueMemFillHelper(pi_command_type CommandType, pi_queue Queue, void *Ptr,
44154418
ZeEvent = (*Event)->ZeEvent;
44164419
(*Event)->WaitList = TmpWaitList;
44174420

4418-
ZE_CALL(zeCommandListAppendWaitOnEvents(ZeCommandList,
4419-
(*Event)->WaitList.Length,
4420-
(*Event)->WaitList.ZeEventList));
4421-
4421+
const auto &WaitList = (*Event)->WaitList;
4422+
if (WaitList.Length) {
4423+
ZE_CALL(zeCommandListAppendWaitOnEvents(ZeCommandList, WaitList.Length,
4424+
WaitList.ZeEventList));
4425+
}
44224426
// Pattern size must be a power of two
44234427
PI_ASSERT((PatternSize > 0) && ((PatternSize & (PatternSize - 1)) == 0),
44244428
PI_INVALID_VALUE);
@@ -4429,7 +4433,7 @@ enqueueMemFillHelper(pi_command_type CommandType, pi_queue Queue, void *Ptr,
44294433
zePrint("calling zeCommandListAppendMemoryFill() with\n"
44304434
" ZeEvent %#lx\n",
44314435
pi_cast<pi_uint64>(ZeEvent));
4432-
printZeEventList((*Event)->WaitList);
4436+
printZeEventList(WaitList);
44334437

44344438
// Execute command list asynchronously, as the event will be used
44354439
// to track down its completion.
@@ -4547,10 +4551,11 @@ pi_result piEnqueueMemBufferMap(pi_queue Queue, pi_mem Buffer,
45474551
zeMemAllocHost(Queue->Context->ZeContext, &ZeDesc, Size, 1, RetMap));
45484552
}
45494553

4550-
ZE_CALL(zeCommandListAppendWaitOnEvents(ZeCommandList,
4551-
(*Event)->WaitList.Length,
4552-
(*Event)->WaitList.ZeEventList));
4553-
4554+
const auto &WaitList = (*Event)->WaitList;
4555+
if (WaitList.Length) {
4556+
ZE_CALL(zeCommandListAppendWaitOnEvents(ZeCommandList, WaitList.Length,
4557+
WaitList.ZeEventList));
4558+
}
45544559
ZE_CALL(zeCommandListAppendMemoryCopy(
45554560
ZeCommandList, *RetMap, pi_cast<char *>(Buffer->getZeHandle()) + Offset,
45564561
Size, ZeEvent, 0, nullptr));
@@ -4634,10 +4639,11 @@ pi_result piEnqueueMemUnmap(pi_queue Queue, pi_mem MemObj, void *MappedPtr,
46344639
// Set the commandlist in the event
46354640
(*Event)->ZeCommandList = ZeCommandList;
46364641

4637-
ZE_CALL(zeCommandListAppendWaitOnEvents(ZeCommandList,
4638-
(*Event)->WaitList.Length,
4639-
(*Event)->WaitList.ZeEventList));
4640-
4642+
if ((*Event)->WaitList.Length) {
4643+
ZE_CALL(zeCommandListAppendWaitOnEvents(ZeCommandList,
4644+
(*Event)->WaitList.Length,
4645+
(*Event)->WaitList.ZeEventList));
4646+
}
46414647
// TODO: Level Zero is missing the memory "mapping" capabilities, so we are
46424648
// left to doing copy (write back to the device).
46434649
//
@@ -4750,10 +4756,11 @@ enqueueMemImageCommandHelper(pi_command_type CommandType, pi_queue Queue,
47504756
ZeEvent = (*Event)->ZeEvent;
47514757
(*Event)->WaitList = TmpWaitList;
47524758

4753-
ZE_CALL(zeCommandListAppendWaitOnEvents(ZeCommandList,
4754-
(*Event)->WaitList.Length,
4755-
(*Event)->WaitList.ZeEventList));
4756-
4759+
const auto &WaitList = (*Event)->WaitList;
4760+
if (WaitList.Length) {
4761+
ZE_CALL(zeCommandListAppendWaitOnEvents(ZeCommandList, WaitList.Length,
4762+
WaitList.ZeEventList));
4763+
}
47574764
if (CommandType == PI_COMMAND_TYPE_IMAGE_READ) {
47584765
pi_mem SrcMem = pi_cast<pi_mem>(const_cast<void *>(Src));
47594766

@@ -5359,10 +5366,11 @@ pi_result piextUSMEnqueuePrefetch(pi_queue Queue, const void *Ptr, size_t Size,
53595366
NumEventsInWaitList, EventWaitList, Queue))
53605367
return Res;
53615368

5362-
ZE_CALL(zeCommandListAppendWaitOnEvents(ZeCommandList,
5363-
(*Event)->WaitList.Length,
5364-
(*Event)->WaitList.ZeEventList));
5365-
5369+
const auto &WaitList = (*Event)->WaitList;
5370+
if (WaitList.Length) {
5371+
ZE_CALL(zeCommandListAppendWaitOnEvents(ZeCommandList, WaitList.Length,
5372+
WaitList.ZeEventList));
5373+
}
53665374
// TODO: figure out how to translate "flags"
53675375
ZE_CALL(zeCommandListAppendMemoryPrefetch(ZeCommandList, Ptr, Size));
53685376

0 commit comments

Comments
 (0)