[llvm] [SYCL] Add platform enumeration and info query using liboffload (PR #166927)

Kseniya Tikhomirova via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 18 03:55:58 PST 2025


================
@@ -0,0 +1,74 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 <detail/global_objects.hpp>
+#include <detail/offload/offload_topology.hpp>
+#include <detail/offload/offload_utils.hpp>
+
+#include <array>
+#include <unordered_map>
+
+_LIBSYCL_BEGIN_NAMESPACE_SYCL
+
+namespace detail {
+
+void discoverOffloadDevices() {
+  call_and_throw(olInit);
+
+  using PerBackendDataType =
+      std::array<std::pair<PlatformWithDevStorageType, size_t /*DevCount*/>,
+                 OL_PLATFORM_BACKEND_LAST>;
+
+  PerBackendDataType Mapping;
+  // olIterateDevices calls lambda for every device.
+  // Returning early means jump to next iteration/next device.
+  call_nocheck(
+      olIterateDevices,
+      [](ol_device_handle_t Dev, void *User) -> bool {
+        auto *Data = static_cast<PerBackendDataType *>(User);
+        ol_platform_handle_t Plat = nullptr;
+        ol_result_t Res = call_nocheck(
+            olGetDeviceInfo, Dev, OL_DEVICE_INFO_PLATFORM, sizeof(Plat), &Plat);
+        // If error occurs, ignore platform and continue iteration
----------------
KseniyaTikhomirova wrote:

`// If error occurs, ignore platform and continue iteration`

It supposed to mean that when we iterate devices we just ignore devices that behave wrong for some reason and try to get other devices. 
by the way how this API is designed there are two ways to go:
1) abort iteration on the first failure and throw exception.
2) ignore "incorrect" devices and try to get the healthy ones.


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


More information about the llvm-commits mailing list