-
Notifications
You must be signed in to change notification settings - Fork 13.4k
[Offload] Adding missing Offload unit tests for event entry points #137315
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
Merged
Conversation
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
@llvm/pr-subscribers-offload Author: Callum Fare (callumfare) ChangesA couple of liboffload entry points were missed out from the tests, and unsurprisingly a crash in one of them made it in. Add the tests and fix the unchecked error in Full diff: https://github.com/llvm/llvm-project/pull/137315.diff 4 Files Affected:
diff --git a/offload/liboffload/src/OffloadImpl.cpp b/offload/liboffload/src/OffloadImpl.cpp
index d956d274b5eb1..fdd22c441aef6 100644
--- a/offload/liboffload/src/OffloadImpl.cpp
+++ b/offload/liboffload/src/OffloadImpl.cpp
@@ -69,7 +69,6 @@ struct ol_queue_impl_t {
struct ol_event_impl_t {
ol_event_impl_t(void *EventInfo, ol_queue_handle_t Queue)
: EventInfo(EventInfo), Queue(Queue) {}
- ~ol_event_impl_t() { (void)Queue->Device->Device->destroyEvent(EventInfo); }
void *EventInfo;
ol_queue_handle_t Queue;
};
@@ -378,6 +377,10 @@ ol_impl_result_t olWaitEvent_impl(ol_event_handle_t Event) {
}
ol_impl_result_t olDestroyEvent_impl(ol_event_handle_t Event) {
+ auto Res = Event->Queue->Device->Device->destroyEvent(Event->EventInfo);
+ if (Res)
+ return {OL_ERRC_INVALID_EVENT, "The event could not be destroyed"};
+
return olDestroy(Event);
}
diff --git a/offload/unittests/OffloadAPI/CMakeLists.txt b/offload/unittests/OffloadAPI/CMakeLists.txt
index c4d628a5a87f8..73202076ab114 100644
--- a/offload/unittests/OffloadAPI/CMakeLists.txt
+++ b/offload/unittests/OffloadAPI/CMakeLists.txt
@@ -21,6 +21,8 @@ add_libompt_unittest("offload.unittests"
${CMAKE_CURRENT_SOURCE_DIR}/program/olDestroyProgram.cpp
${CMAKE_CURRENT_SOURCE_DIR}/kernel/olGetKernel.cpp
${CMAKE_CURRENT_SOURCE_DIR}/kernel/olLaunchKernel.cpp
+ ${CMAKE_CURRENT_SOURCE_DIR}/event/olDestroyEvent.cpp
+ ${CMAKE_CURRENT_SOURCE_DIR}/event/olWaitEvent.cpp
)
add_dependencies("offload.unittests" ${PLUGINS_TEST_COMMON} LibomptUnitTestsDeviceBins)
target_compile_definitions("offload.unittests" PRIVATE DEVICE_CODE_PATH="${OFFLOAD_TEST_DEVICE_CODE_PATH}")
diff --git a/offload/unittests/OffloadAPI/event/olDestroyEvent.cpp b/offload/unittests/OffloadAPI/event/olDestroyEvent.cpp
new file mode 100644
index 0000000000000..1a6b7aebb0781
--- /dev/null
+++ b/offload/unittests/OffloadAPI/event/olDestroyEvent.cpp
@@ -0,0 +1,31 @@
+//===------- Offload API tests - olDestroyEvent ---------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "../common/Fixtures.hpp"
+#include <OffloadAPI.h>
+#include <gtest/gtest.h>
+
+using olDestroyEventTest = OffloadQueueTest;
+
+TEST_F(olDestroyEventTest, Success) {
+ 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);
+ ASSERT_SUCCESS(olWaitQueue(Queue));
+ ASSERT_SUCCESS(olDestroyEvent(Event));
+}
+
+TEST_F(olDestroyEventTest, InvalidNullEvent) {
+ ASSERT_ERROR(OL_ERRC_INVALID_NULL_HANDLE, olDestroyEvent(nullptr));
+}
diff --git a/offload/unittests/OffloadAPI/event/olWaitEvent.cpp b/offload/unittests/OffloadAPI/event/olWaitEvent.cpp
new file mode 100644
index 0000000000000..632d99288c71b
--- /dev/null
+++ b/offload/unittests/OffloadAPI/event/olWaitEvent.cpp
@@ -0,0 +1,31 @@
+//===------- Offload API tests - olWaitEvent -====-------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "../common/Fixtures.hpp"
+#include <OffloadAPI.h>
+#include <gtest/gtest.h>
+
+using olWaitEventTest = OffloadQueueTest;
+
+TEST_F(olWaitEventTest, Success) {
+ 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);
+ ASSERT_SUCCESS(olWaitEvent(Event));
+ ASSERT_SUCCESS(olDestroyEvent(Event));
+}
+
+TEST_F(olWaitEventTest, InvalidNullEvent) {
+ ASSERT_ERROR(OL_ERRC_INVALID_NULL_HANDLE, olWaitEvent(nullptr));
+}
|
7541da3
to
186cfbc
Compare
jhuber6
approved these changes
Apr 30, 2025
IanWood1
pushed a commit
to IanWood1/llvm-project
that referenced
this pull request
May 6, 2025
…lvm#137315) A couple of liboffload entry points were missed out from the tests, and unsurprisingly a crash in one of them made it in. Add the tests and fix the unchecked error in `olDestroyEvent`.
IanWood1
pushed a commit
to IanWood1/llvm-project
that referenced
this pull request
May 6, 2025
…lvm#137315) A couple of liboffload entry points were missed out from the tests, and unsurprisingly a crash in one of them made it in. Add the tests and fix the unchecked error in `olDestroyEvent`.
IanWood1
pushed a commit
to IanWood1/llvm-project
that referenced
this pull request
May 6, 2025
…lvm#137315) A couple of liboffload entry points were missed out from the tests, and unsurprisingly a crash in one of them made it in. Add the tests and fix the unchecked error in `olDestroyEvent`.
GeorgeARM
pushed a commit
to GeorgeARM/llvm-project
that referenced
this pull request
May 7, 2025
…lvm#137315) A couple of liboffload entry points were missed out from the tests, and unsurprisingly a crash in one of them made it in. Add the tests and fix the unchecked error in `olDestroyEvent`.
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.
A couple of liboffload entry points were missed out from the tests, and unsurprisingly a crash in one of them made it in. Add the tests and fix the unchecked error in
olDestroyEvent
.