Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 19 additions & 21 deletions unified-runtime/source/adapters/level_zero/event.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,35 +114,33 @@ ur_result_t urEnqueueEventsWait(
false /*OKToBatchCommand*/);
}

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

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

if (OutEvent) {
UR_CALL(createEventAndAssociateQueue(Queue, OutEvent,
UR_COMMAND_EVENTS_WAIT,
Queue->CommandListMap.end(), false,
/* IsInternal */ false));
}
if (OutEvent) {
UR_CALL(createEventAndAssociateQueue(Queue, OutEvent,
UR_COMMAND_EVENTS_WAIT,
Queue->CommandListMap.end(), false,
/* IsInternal */ false));
}

UR_CALL(Queue->synchronize());
UR_CALL(Queue->executeAllOpenCommandLists());
UR_CALL(Queue->synchronize());

if (OutEvent) {
Queue->LastCommandEvent = reinterpret_cast<ur_event_handle_t>(*OutEvent);
if (OutEvent) {
Queue->LastCommandEvent = reinterpret_cast<ur_event_handle_t>(*OutEvent);

if (!(*OutEvent)->CounterBasedEventsEnabled)
ZE2UR_CALL(zeEventHostSignal, ((*OutEvent)->ZeEvent));
(*OutEvent)->Completed = true;
}
if (!(*OutEvent)->CounterBasedEventsEnabled)
ZE2UR_CALL(zeEventHostSignal, ((*OutEvent)->ZeEvent));
(*OutEvent)->Completed = true;
}

if (!Queue->UsingImmCmdLists) {
std::unique_lock<ur_shared_mutex> Lock(Queue->Mutex);
resetCommandLists(Queue);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,33 @@ struct urEnqueueEventsWaitTest : uur::urMultiQueueTest {

UUR_INSTANTIATE_DEVICE_TEST_SUITE(urEnqueueEventsWaitTest);

TEST_P(urEnqueueEventsWaitTest, SuccessWithEmptyWaitList) {
void *ptr1, *ptr2;
size_t size = 1024;
size_t count = size / sizeof(int);

ASSERT_SUCCESS(
urUSMDeviceAlloc(context, device, nullptr, nullptr, size, &ptr1));
ASSERT_SUCCESS(
urUSMDeviceAlloc(context, device, nullptr, nullptr, size, &ptr2));

std::vector<int> input(count, 99);
std::vector<int> output(count, 0);

ASSERT_SUCCESS(urEnqueueUSMMemcpy(queue1, false, ptr1, input.data(), size, 0,
nullptr, nullptr));
ASSERT_SUCCESS(
urEnqueueUSMMemcpy(queue1, false, ptr2, ptr1, size, 0, nullptr, nullptr));
ASSERT_SUCCESS(urEnqueueUSMMemcpy(queue1, false, output.data(), ptr2, size, 0,
nullptr, nullptr));

ur_event_handle_t event;
ASSERT_SUCCESS(urEnqueueEventsWait(queue1, 0, nullptr, &event));
ASSERT_SUCCESS(urEventWait(1, &event));

ASSERT_EQ(input, output);
}

TEST_P(urEnqueueEventsWaitTest, Success) {
UUR_KNOWN_FAILURE_ON(uur::LevelZero{}, uur::NativeCPU{});

Expand Down
Loading