[llvm] [Offload] Introduce offload-tblgen and initial new API implementation (PR #108413)

Joseph Huber via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 30 07:14:32 PDT 2024


================
@@ -0,0 +1,37 @@
+//===------- Offload API tests - offloadDeviceGet -------------------------===//
+//
+// 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 <gtest/gtest.h>
+#include <offload_api.h>
+
+using offloadDeviceGetTest = offloadPlatformTest;
+
+TEST_F(offloadDeviceGetTest, Success) {
+  uint32_t Count = 0;
+  ASSERT_SUCCESS(offloadDeviceGetCount(Platform, &Count));
+  ASSERT_NE(Count, 0lu);
+  std::vector<offload_device_handle_t> Devices(Count);
+  ASSERT_SUCCESS(offloadDeviceGet(Platform, Count, Devices.data()));
+  for (auto Device : Devices) {
+    ASSERT_NE(nullptr, Device);
+  }
+}
+
+TEST_F(offloadDeviceGetTest, SuccessSubsetOfDevices) {
+  uint32_t Count;
+  ASSERT_SUCCESS(offloadDeviceGetCount(Platform, &Count));
+  if (Count < 2) {
+    GTEST_SKIP() << "Only one device is available on this platform.";
+  }
----------------
jhuber6 wrote:

nit, LLVM style shouldn't put braces around single lines.
```suggestion
  if (Count < 2)
    GTEST_SKIP() << "Only one device is available on this platform.";
```

https://github.com/llvm/llvm-project/pull/108413


More information about the llvm-commits mailing list