[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:49:43 PST 2025


================
@@ -0,0 +1,68 @@
+//===----------------------------------------------------------------------===//
+//
+// 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/platform_impl.hpp>
+
+#ifdef _WIN32
+#  include <windows.h>
+#endif
+
+#include <vector>
+
+_LIBSYCL_BEGIN_NAMESPACE_SYCL
+namespace detail {
+
+std::vector<detail::OffloadTopology> &getOffloadTopologies() {
+  static std::vector<detail::OffloadTopology> Topologies(
+      OL_PLATFORM_BACKEND_LAST);
+  return Topologies;
+}
+
+std::vector<PlatformImplUPtr> &getPlatformCache() {
+  static std::vector<PlatformImplUPtr> PlatformCache{};
+  return PlatformCache;
+}
+
+void shutdown() {
+  // No error reporting in shutdown
+  std::ignore = olShutDown();
+}
+
+#ifdef _WIN32
+extern "C" _LIBSYCL_EXPORT BOOL WINAPI DllMain(HINSTANCE hinstDLL,
+                                               DWORD fdwReason,
+                                               LPVOID lpReserved) {
+  // Perform actions based on the reason for calling.
+  switch (fdwReason) {
+  case DLL_PROCESS_DETACH:
+    try {
+      shutdown();
+    } catch (std::exception &e) {
+      // report
+    }
+
+    break;
+  case DLL_PROCESS_ATTACH:
+    break;
+  case DLL_THREAD_ATTACH:
+    break;
+  case DLL_THREAD_DETACH:
+    break;
+  }
+  return TRUE; // Successful DLL_PROCESS_ATTACH.
+}
+#else
+// Setting low priority on destructor ensures it runs after all other global
+// destructors. Priorities 0-100 are reserved by the compiler. The priority
+// value 110 allows SYCL users to run their destructors after runtime library
+// deinitialization.
----------------
KseniyaTikhomirova wrote:

I changed "runtime library" to "libsycl" now.
The comment explains the reasoning behind value == 110. 
The majority of application global destructors will run before libsycl destruction but there are a few numbers that also allow users to run destructors after.

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


More information about the llvm-commits mailing list