[llvm] [libsycl] Add device image registration & compatibility check (PR #187528)
Alexey Bader via llvm-commits
llvm-commits at lists.llvm.org
Sun Apr 5 17:54:13 PDT 2026
================
@@ -0,0 +1,95 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBSYCL_PROGRAM_MANAGER
+#define _LIBSYCL_PROGRAM_MANAGER
+
+#include <sycl/__impl/detail/config.hpp>
+
+#include <detail/device_binary_structures.hpp>
+#include <detail/device_image_wrapper.hpp>
+#include <detail/kernel_id.hpp>
+
+#include <mutex>
+#include <unordered_map>
+
+// +++ Entry points referenced by the offload wrapper object {
+
+/// Executed as a part of current module's (.exe, .dll) static initialization.
+/// Registers device executable images with the runtime.
+extern "C" _LIBSYCL_EXPORT void __sycl_register_lib(__sycl_tgt_bin_desc *desc);
+
+/// Executed as a part of current module's (.exe, .dll) static
+/// de-initialization.
+/// Unregisters device executable images with the runtime.
+extern "C" _LIBSYCL_EXPORT void
+__sycl_unregister_lib(__sycl_tgt_bin_desc *desc);
+
+// +++ }
+
+_LIBSYCL_BEGIN_NAMESPACE_SYCL
+
+namespace detail {
+
+class DeviceImpl;
+
+/// A class to manage programs and kernels.
+class ProgramManager {
+
+public:
+ static ProgramManager &getInstance() {
+ static ProgramManager PM{};
+ return PM;
+ }
+
+ /// Parses raw device images data and prepare internal structures for
+ /// effective kernel/program creation.
+ /// \param FatbinDesc a record of all the device code that may be offloaded
+ /// generated by compiler and offloading tools.
+ /// \throw sycl::exception with sycl::errc::runtime if device image descriptor
+ /// has incompatible version or if device image has incompatible
+ /// version/target/kind.
+ void addImages(__sycl_tgt_bin_desc *FatbinDesc);
+
+ /// Removes all entries of the data in FatbinDesc in internal structures.
+ /// \param FatbinDesc a record of all the device code that may be offloaded
+ /// generated by compiler and offloading tools. Must match the pointer and
+ /// data passed to addImages.
+ void removeImages(__sycl_tgt_bin_desc *FatbinDesc);
+
+private:
+ ProgramManager() = default;
+ ~ProgramManager() = default;
+ ProgramManager(ProgramManager const &) = delete;
+ ProgramManager &operator=(ProgramManager const &) = delete;
+
+ /// Searches for device image that contains requested kernel and is compatible
+ /// with requested device.
+ /// \param KernelName a null-terminated string representing the name of kernel
+ /// to obtain device image for.
+ /// \param KernelID a kernel id matching KernelName.
+ /// \param DeviceImpl a device that device image must be compatible with.
+ /// \throw sycl::exception with sycl::errc::runtime if device image validness
+ /// check failed in liboffload or if no compatible image was found.
+ DeviceImageWrapper *getDeviceImage(const char *KernelName, kernel_id KernelID,
+ DeviceImpl &Device);
+
+ // Filled by addImages(...).
----------------
bader wrote:
I agree that both versions are acceptable, but we can improve the name to describe what the function does more precisely than `addImages`. IMHO `addImages` is too vague.
https://github.com/llvm/llvm-project/pull/187528
More information about the llvm-commits
mailing list