Skip to content

Commit 1a87eec

Browse files
authored
[SYCL][UR][L0] Fix urEnqueueEventsWait (#18343)
The path for non-immediate command lists was incorrect. queue->synchronize() was called without closing and executing command lists leading to deadlock. Fix this by replacing synchronize() call with executeCommandList()
1 parent 9b36c18 commit 1a87eec

File tree

2 files changed

+46
-21
lines changed

2 files changed

+46
-21
lines changed

unified-runtime/source/adapters/level_zero/event.cpp

+19-21
Original file line numberDiff line numberDiff line change
@@ -114,35 +114,33 @@ ur_result_t urEnqueueEventsWait(
114114
false /*OKToBatchCommand*/);
115115
}
116116

117-
{
118-
// If wait-list is empty, then this particular command should wait until
119-
// all previous enqueued commands to the command-queue have completed.
120-
//
121-
// TODO: find a way to do that without blocking the host.
117+
// If wait-list is empty, then this particular command should wait until
118+
// all previous enqueued commands to the command-queue have completed.
119+
//
120+
// TODO: find a way to do that without blocking the host.
122121

123-
// Lock automatically releases when this goes out of scope.
124-
std::scoped_lock<ur_shared_mutex> lock(Queue->Mutex);
122+
// Lock automatically releases when this goes out of scope.
123+
std::scoped_lock<ur_shared_mutex> lock(Queue->Mutex);
125124

126-
if (OutEvent) {
127-
UR_CALL(createEventAndAssociateQueue(Queue, OutEvent,
128-
UR_COMMAND_EVENTS_WAIT,
129-
Queue->CommandListMap.end(), false,
130-
/* IsInternal */ false));
131-
}
125+
if (OutEvent) {
126+
UR_CALL(createEventAndAssociateQueue(Queue, OutEvent,
127+
UR_COMMAND_EVENTS_WAIT,
128+
Queue->CommandListMap.end(), false,
129+
/* IsInternal */ false));
130+
}
132131

133-
UR_CALL(Queue->synchronize());
132+
UR_CALL(Queue->executeAllOpenCommandLists());
133+
UR_CALL(Queue->synchronize());
134134

135-
if (OutEvent) {
136-
Queue->LastCommandEvent = reinterpret_cast<ur_event_handle_t>(*OutEvent);
135+
if (OutEvent) {
136+
Queue->LastCommandEvent = reinterpret_cast<ur_event_handle_t>(*OutEvent);
137137

138-
if (!(*OutEvent)->CounterBasedEventsEnabled)
139-
ZE2UR_CALL(zeEventHostSignal, ((*OutEvent)->ZeEvent));
140-
(*OutEvent)->Completed = true;
141-
}
138+
if (!(*OutEvent)->CounterBasedEventsEnabled)
139+
ZE2UR_CALL(zeEventHostSignal, ((*OutEvent)->ZeEvent));
140+
(*OutEvent)->Completed = true;
142141
}
143142

144143
if (!Queue->UsingImmCmdLists) {
145-
std::unique_lock<ur_shared_mutex> Lock(Queue->Mutex);
146144
resetCommandLists(Queue);
147145
}
148146

unified-runtime/test/conformance/enqueue/urEnqueueEventsWait.cpp

+27
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,33 @@ struct urEnqueueEventsWaitTest : uur::urMultiQueueTest {
3838

3939
UUR_INSTANTIATE_DEVICE_TEST_SUITE(urEnqueueEventsWaitTest);
4040

41+
TEST_P(urEnqueueEventsWaitTest, SuccessWithEmptyWaitList) {
42+
void *ptr1, *ptr2;
43+
size_t size = 1024;
44+
size_t count = size / sizeof(int);
45+
46+
ASSERT_SUCCESS(
47+
urUSMDeviceAlloc(context, device, nullptr, nullptr, size, &ptr1));
48+
ASSERT_SUCCESS(
49+
urUSMDeviceAlloc(context, device, nullptr, nullptr, size, &ptr2));
50+
51+
std::vector<int> input(count, 99);
52+
std::vector<int> output(count, 0);
53+
54+
ASSERT_SUCCESS(urEnqueueUSMMemcpy(queue1, false, ptr1, input.data(), size, 0,
55+
nullptr, nullptr));
56+
ASSERT_SUCCESS(
57+
urEnqueueUSMMemcpy(queue1, false, ptr2, ptr1, size, 0, nullptr, nullptr));
58+
ASSERT_SUCCESS(urEnqueueUSMMemcpy(queue1, false, output.data(), ptr2, size, 0,
59+
nullptr, nullptr));
60+
61+
ur_event_handle_t event;
62+
ASSERT_SUCCESS(urEnqueueEventsWait(queue1, 0, nullptr, &event));
63+
ASSERT_SUCCESS(urEventWait(1, &event));
64+
65+
ASSERT_EQ(input, output);
66+
}
67+
4168
TEST_P(urEnqueueEventsWaitTest, Success) {
4269
UUR_KNOWN_FAILURE_ON(uur::LevelZero{}, uur::NativeCPU{});
4370

0 commit comments

Comments
 (0)