summaryrefslogtreecommitdiff
path: root/offload/unittests/OffloadAPI/device
diff options
context:
space:
mode:
authorCallum Fare <callum@codeplay.com>2025-04-22 19:27:50 +0100
committerGitHub <noreply@github.com>2025-04-22 13:27:50 -0500
commit800d949bb315349a116a980e99d0f36645ffefd3 (patch)
treee13178e6c2d33cbe0235274e43a278d9b85e89d7 /offload/unittests/OffloadAPI/device
parentfcb309715e4bd46d96dda7bdf99291ebf394d130 (diff)
[Offload] Implement the remaining initial Offload API (#122106)
Implement the complete initial version of the Offload API, to the extent that is usable for simple offloading programs. Tested with a basic SYCL program. As far as possible, these are simple wrappers over existing functionality in the plugins. * Allocating and freeing memory (host, device, shared). * Creating a program * Creating a queue (wrapper over asynchronous stream resource) * Enqueuing memcpy operations * Enqueuing kernel executions * Waiting on (optional) output events from the enqueue operations * Waiting on a queue to finish Objects created with the API have reference counting semantics to handle their lifetime. They are created with an initial reference count of 1, which can be incremented and decremented with retain and release functions. They are freed when their reference count reaches 0. Platform and device objects are not reference counted, as they are expected to persist as long as the library is in use, and it's not meaningful for users to create or destroy them. Tests have been added to `offload.unittests`, including device code for testing program and kernel related functionality. The API should still be considered unstable and it's very likely we will need to change the existing entry points.
Diffstat (limited to 'offload/unittests/OffloadAPI/device')
-rw-r--r--offload/unittests/OffloadAPI/device/olGetDevice.cpp39
-rw-r--r--offload/unittests/OffloadAPI/device/olGetDeviceCount.cpp28
-rw-r--r--offload/unittests/OffloadAPI/device/olGetDeviceInfo.cpp6
-rw-r--r--offload/unittests/OffloadAPI/device/olGetDeviceInfoSize.cpp4
-rw-r--r--offload/unittests/OffloadAPI/device/olIterateDevices.cpp45
5 files changed, 50 insertions, 72 deletions
diff --git a/offload/unittests/OffloadAPI/device/olGetDevice.cpp b/offload/unittests/OffloadAPI/device/olGetDevice.cpp
deleted file mode 100644
index 68d4682dd335..000000000000
--- a/offload/unittests/OffloadAPI/device/olGetDevice.cpp
+++ /dev/null
@@ -1,39 +0,0 @@
-//===------- Offload API tests - olGetDevice -------------------------===//
-//
-// 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 olGetDeviceTest = offloadPlatformTest;
-
-TEST_F(olGetDeviceTest, Success) {
- uint32_t Count = 0;
- ASSERT_SUCCESS(olGetDeviceCount(Platform, &Count));
- if (Count == 0)
- GTEST_SKIP() << "No available devices on this platform.";
-
- std::vector<ol_device_handle_t> Devices(Count);
- ASSERT_SUCCESS(olGetDevice(Platform, Count, Devices.data()));
- for (auto Device : Devices) {
- ASSERT_NE(nullptr, Device);
- }
-}
-
-TEST_F(olGetDeviceTest, SuccessSubsetOfDevices) {
- uint32_t Count;
- ASSERT_SUCCESS(olGetDeviceCount(Platform, &Count));
- if (Count < 2)
- GTEST_SKIP() << "Only one device is available on this platform.";
-
- std::vector<ol_device_handle_t> Devices(Count - 1);
- ASSERT_SUCCESS(olGetDevice(Platform, Count - 1, Devices.data()));
- for (auto Device : Devices) {
- ASSERT_NE(nullptr, Device);
- }
-}
diff --git a/offload/unittests/OffloadAPI/device/olGetDeviceCount.cpp b/offload/unittests/OffloadAPI/device/olGetDeviceCount.cpp
deleted file mode 100644
index ef377d671bf6..000000000000
--- a/offload/unittests/OffloadAPI/device/olGetDeviceCount.cpp
+++ /dev/null
@@ -1,28 +0,0 @@
-//===------- Offload API tests - olGetDeviceCount --------------------===//
-//
-// 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 olGetDeviceCountTest = offloadPlatformTest;
-
-TEST_F(olGetDeviceCountTest, Success) {
- uint32_t Count = 0;
- ASSERT_SUCCESS(olGetDeviceCount(Platform, &Count));
-}
-
-TEST_F(olGetDeviceCountTest, InvalidNullPlatform) {
- uint32_t Count = 0;
- ASSERT_ERROR(OL_ERRC_INVALID_NULL_HANDLE, olGetDeviceCount(nullptr, &Count));
-}
-
-TEST_F(olGetDeviceCountTest, InvalidNullPointer) {
- ASSERT_ERROR(OL_ERRC_INVALID_NULL_POINTER,
- olGetDeviceCount(Platform, nullptr));
-}
diff --git a/offload/unittests/OffloadAPI/device/olGetDeviceInfo.cpp b/offload/unittests/OffloadAPI/device/olGetDeviceInfo.cpp
index c936802fb1e4..f71f60a2c057 100644
--- a/offload/unittests/OffloadAPI/device/olGetDeviceInfo.cpp
+++ b/offload/unittests/OffloadAPI/device/olGetDeviceInfo.cpp
@@ -11,10 +11,10 @@
#include <OffloadAPI.h>
#include <gtest/gtest.h>
-struct olGetDeviceInfoTest : offloadDeviceTest,
+struct olGetDeviceInfoTest : OffloadDeviceTest,
::testing::WithParamInterface<ol_device_info_t> {
- void SetUp() override { RETURN_ON_FATAL_FAILURE(offloadDeviceTest::SetUp()); }
+ void SetUp() override { RETURN_ON_FATAL_FAILURE(OffloadDeviceTest::SetUp()); }
};
INSTANTIATE_TEST_SUITE_P(
@@ -37,7 +37,7 @@ TEST_P(olGetDeviceInfoTest, Success) {
if (InfoType == OL_DEVICE_INFO_PLATFORM) {
auto *ReturnedPlatform =
reinterpret_cast<ol_platform_handle_t *>(InfoData.data());
- ASSERT_EQ(Platform, *ReturnedPlatform);
+ ASSERT_NE(nullptr, *ReturnedPlatform);
}
}
diff --git a/offload/unittests/OffloadAPI/device/olGetDeviceInfoSize.cpp b/offload/unittests/OffloadAPI/device/olGetDeviceInfoSize.cpp
index 9e792d1c3e25..b4b5042dbfd8 100644
--- a/offload/unittests/OffloadAPI/device/olGetDeviceInfoSize.cpp
+++ b/offload/unittests/OffloadAPI/device/olGetDeviceInfoSize.cpp
@@ -12,10 +12,10 @@
#include "olDeviceInfo.hpp"
struct olGetDeviceInfoSizeTest
- : offloadDeviceTest,
+ : OffloadDeviceTest,
::testing::WithParamInterface<ol_device_info_t> {
- void SetUp() override { RETURN_ON_FATAL_FAILURE(offloadDeviceTest::SetUp()); }
+ void SetUp() override { RETURN_ON_FATAL_FAILURE(OffloadDeviceTest::SetUp()); }
};
// TODO: We could autogenerate the list of enum values
diff --git a/offload/unittests/OffloadAPI/device/olIterateDevices.cpp b/offload/unittests/OffloadAPI/device/olIterateDevices.cpp
new file mode 100644
index 000000000000..5bdbd17e9e97
--- /dev/null
+++ b/offload/unittests/OffloadAPI/device/olIterateDevices.cpp
@@ -0,0 +1,45 @@
+//===------- Offload API tests - olIterateDevices -------------------------===//
+//
+// 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 olIterateDevicesTest = OffloadTest;
+
+TEST_F(olIterateDevicesTest, SuccessEmptyCallback) {
+ ASSERT_SUCCESS(olIterateDevices(
+ [](ol_device_handle_t, void *) { return false; }, nullptr));
+}
+
+TEST_F(olIterateDevicesTest, SuccessGetDevice) {
+ uint32_t DeviceCount = 0;
+ ol_device_handle_t Device = nullptr;
+
+ ASSERT_SUCCESS(olIterateDevices(
+ [](ol_device_handle_t, void *Data) {
+ auto Count = static_cast<uint32_t *>(Data);
+ *Count += 1;
+ return false;
+ },
+ &DeviceCount));
+
+ if (DeviceCount == 0) {
+ GTEST_SKIP() << "No available devices.";
+ }
+
+ ASSERT_SUCCESS(olIterateDevices(
+ [](ol_device_handle_t D, void *Data) {
+ auto DevicePtr = static_cast<ol_device_handle_t *>(Data);
+ *DevicePtr = D;
+ return true;
+ },
+ &Device));
+
+ ASSERT_NE(Device, nullptr);
+}