[Offload] Verify SyncCycle for events in AMDGPU#149524
Merged
RossBrunton merged 1 commit intollvm:mainfrom Jul 21, 2025
Merged
Conversation
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.
Member
|
@llvm/pr-subscribers-offload @llvm/pr-subscribers-backend-amdgpu Author: Ross Brunton (RossBrunton) ChangesThis check ensures that events after a synchronise (and thus after the Full diff: https://github.com/llvm/llvm-project/pull/149524.diff 2 Files Affected:
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));
+}
|
jhuber6
reviewed
Jul 18, 2025
| 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) |
Contributor
There was a problem hiding this comment.
So, this is if the user consumes an event twice?
Contributor
Author
There was a problem hiding this comment.
That, or if a later event gets consumed before an earlier one. If the latest event in the queue is synced on, the queue is reset and SyncCycle incremented.
jhuber6
approved these changes
Jul 18, 2025
This was referenced Jul 23, 2025
mahesh-attarde
pushed a commit
to mahesh-attarde/llvm-project
that referenced
this pull request
Jul 28, 2025
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.