Skip to content

Commit e87d390

Browse files
authored
[Offload] Verify SyncCycle for events in AMDGPU (#149524)
This check ensures that events after a synchronise (and thus after the queue is reset) are always considered complete. A test has been added as well.
1 parent 8a307ae commit e87d390

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

offload/plugins-nextgen/amdgpu/src/rtl.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1665,6 +1665,11 @@ Error AMDGPUStreamTy::waitEvent(const AMDGPUEventTy &Event) {
16651665
Error AMDGPUStreamTy::synchronizeOn(AMDGPUEventTy &Event) {
16661666
std::lock_guard<std::mutex> Lock(Mutex);
16671667

1668+
// If this event was for an older sync cycle, it has already been finalized
1669+
if (Event.RecordedSyncCycle < SyncCycle)
1670+
return Plugin::success();
1671+
assert(Event.RecordedSyncCycle == SyncCycle && "event is from the future?");
1672+
16681673
// Wait until the requested slot has completed
16691674
if (auto Err = Slots[Event.RecordedSlot].Signal->wait(
16701675
StreamBusyWaitMicroseconds, &Device))

offload/unittests/OffloadAPI/event/olWaitEvent.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,20 @@ TEST_P(olWaitEventTest, Success) {
3030
TEST_P(olWaitEventTest, InvalidNullEvent) {
3131
ASSERT_ERROR(OL_ERRC_INVALID_NULL_HANDLE, olWaitEvent(nullptr));
3232
}
33+
34+
TEST_P(olWaitEventTest, SuccessMultipleWait) {
35+
uint32_t Src = 42;
36+
void *DstPtr;
37+
38+
ol_event_handle_t Event = nullptr;
39+
ASSERT_SUCCESS(
40+
olMemAlloc(Device, OL_ALLOC_TYPE_DEVICE, sizeof(uint32_t), &DstPtr));
41+
ASSERT_SUCCESS(
42+
olMemcpy(Queue, DstPtr, Device, &Src, Host, sizeof(Src), &Event));
43+
ASSERT_NE(Event, nullptr);
44+
45+
for (size_t I = 0; I < 10; I++)
46+
ASSERT_SUCCESS(olWaitEvent(Event));
47+
48+
ASSERT_SUCCESS(olDestroyEvent(Event));
49+
}

0 commit comments

Comments
 (0)