[llvm] [Offload] Verify SyncCycle for events in AMDGPU (PR #149524)
Ross Brunton via llvm-commits
llvm-commits at lists.llvm.org
Fri Jul 18 07:53:46 PDT 2025
https://github.com/RossBrunton created https://github.com/llvm/llvm-project/pull/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.
>From d6e15bca091a770d969e28045c4bde3fc922714c Mon Sep 17 00:00:00 2001
From: Ross Brunton <ross at codeplay.com>
Date: Fri, 18 Jul 2025 15:51:23 +0100
Subject: [PATCH] [Offload] Verify SyncCycle for events in AMDGPU
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.
---
offload/plugins-nextgen/amdgpu/src/rtl.cpp | 5 +++++
.../unittests/OffloadAPI/event/olWaitEvent.cpp | 17 +++++++++++++++++
2 files changed, 22 insertions(+)
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<std::mutex> 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));
+}
More information about the llvm-commits
mailing list