[llvm] [SYCL] Add platform enumeration and info query using liboffload (PR #166927)
Tom Honermann via llvm-commits
llvm-commits at lists.llvm.org
Fri Jan 16 13:08:23 PST 2026
================
@@ -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
----------------
tahonermann wrote:
Yes, good, that is inline with what I was thinking. How do you feel about adding a TODO comment for this?
```suggestion
// olIterateDevices() calls the lambda for each device. Devices that fail
// probes or that report unknown backends are silently ignored.
// TODO: Investigate a reporting mechanism to facilitate debugging
// of errors or unrecognized backends during device discovery.
```
https://github.com/llvm/llvm-project/pull/166927
More information about the llvm-commits
mailing list