diff --git a/offload/plugins-nextgen/amdgpu/src/rtl.cpp b/offload/plugins-nextgen/amdgpu/src/rtl.cpp index d4400547f9568..f8db9bf0ae739 100644 --- a/offload/plugins-nextgen/amdgpu/src/rtl.cpp +++ b/offload/plugins-nextgen/amdgpu/src/rtl.cpp @@ -1665,6 +1665,11 @@ Error AMDGPUStreamTy::waitEvent(const AMDGPUEventTy &Event) { Error AMDGPUStreamTy::synchronizeOn(AMDGPUEventTy &Event) { std::lock_guard Lock(Mutex); + // If this event was for an older sync cycle, it has already been finalized + if (Event.RecordedSyncCycle < SyncCycle) + return Plugin::success(); + assert(Event.RecordedSyncCycle == SyncCycle && "event is from the future?"); + // Wait until the requested slot has completed if (auto Err = Slots[Event.RecordedSlot].Signal->wait( StreamBusyWaitMicroseconds, &Device)) diff --git a/offload/unittests/OffloadAPI/event/olWaitEvent.cpp b/offload/unittests/OffloadAPI/event/olWaitEvent.cpp index f80dabb4fc93f..1f2977eda64e2 100644 --- a/offload/unittests/OffloadAPI/event/olWaitEvent.cpp +++ b/offload/unittests/OffloadAPI/event/olWaitEvent.cpp @@ -30,3 +30,20 @@ TEST_P(olWaitEventTest, Success) { TEST_P(olWaitEventTest, InvalidNullEvent) { ASSERT_ERROR(OL_ERRC_INVALID_NULL_HANDLE, olWaitEvent(nullptr)); } + +TEST_P(olWaitEventTest, SuccessMultipleWait) { + uint32_t Src = 42; + void *DstPtr; + + ol_event_handle_t Event = nullptr; + ASSERT_SUCCESS( + olMemAlloc(Device, OL_ALLOC_TYPE_DEVICE, sizeof(uint32_t), &DstPtr)); + ASSERT_SUCCESS( + olMemcpy(Queue, DstPtr, Device, &Src, Host, sizeof(Src), &Event)); + ASSERT_NE(Event, nullptr); + + for (size_t I = 0; I < 10; I++) + ASSERT_SUCCESS(olWaitEvent(Event)); + + ASSERT_SUCCESS(olDestroyEvent(Event)); +}