-
Notifications
You must be signed in to change notification settings - Fork 14.5k
[Offload] Verify SyncCycle for events in AMDGPU #149524
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
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.
@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));
+}
|
@@ -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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, this is if the user consumes an event twice?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
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.