[llvm] [Offload] Adding missing Offload unit tests for event entry points (PR #137315)
Callum Fare via llvm-commits
llvm-commits at lists.llvm.org
Fri Apr 25 04:17:20 PDT 2025
https://github.com/callumfare created https://github.com/llvm/llvm-project/pull/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`.
>From 7541da370a7665a9bf7ef574e61404408bda9779 Mon Sep 17 00:00:00 2001
From: Callum Fare <callum at codeplay.com>
Date: Wed, 23 Apr 2025 16:40:51 +0100
Subject: [PATCH] Adding missing Offload unit tests for event entry points
---
offload/liboffload/src/OffloadImpl.cpp | 5 ++-
offload/unittests/OffloadAPI/CMakeLists.txt | 2 ++
.../OffloadAPI/event/olDestroyEvent.cpp | 31 +++++++++++++++++++
.../OffloadAPI/event/olWaitEvent.cpp | 31 +++++++++++++++++++
4 files changed, 68 insertions(+), 1 deletion(-)
create mode 100644 offload/unittests/OffloadAPI/event/olDestroyEvent.cpp
create mode 100644 offload/unittests/OffloadAPI/event/olWaitEvent.cpp
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));
+}
More information about the llvm-commits
mailing list