[llvm] [libsycl] Add liboffload kernel creation (PR #188794)
Sergey Semenov via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 14 06:43:37 PDT 2026
================
@@ -0,0 +1,80 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// This file contains the declaration of the class that aggregates information
+/// specific to device kernels (i.e. information that is uniform between
+/// different submissions of the same kernel).
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBSYCL_DEVICE_KERNEL_INFO
+#define _LIBSYCL_DEVICE_KERNEL_INFO
+
+#include <sycl/__impl/detail/config.hpp>
+
+#include <OffloadAPI.h>
+
+_LIBSYCL_BEGIN_NAMESPACE_SYCL
+namespace detail {
+
+class ProgramAndKernelManager;
+
+// Pointers to instances of this class are stored in header function templates
+// as a static variable to avoid repeated runtime lookup overhead.
+class DeviceKernelInfo {
+public:
+ /// Constructs device kernel info instance.
+ ///
+ /// \param KernelName a name of kernel.
+ /// \param DeviceImage a device image containing device code of this kernel.
+ DeviceKernelInfo(std::string_view KernelName, DeviceImageManager &DeviceImage)
+ : MName(KernelName), MDeviceImage(DeviceImage) {}
+
+ /// \return the name of this kernel.
+ std::string_view getName() { return MName; }
+
+private:
+ std::unordered_map<ol_device_handle_t, ol_symbol_handle_t> MBuiltKernels;
+
+ std::string_view MName;
+ DeviceImageManager &MDeviceImage;
+
+ /// Searches for the existing kernel handle compatible with the specified
+ /// device.
+ /// \param Device a device the kernel must be compatible with.
+ /// \return a liboffload kernel handle if and only if built kernel was found,
+ /// otherwise returns nullptr.
+ ol_symbol_handle_t getKernel(ol_device_handle_t Device) const {
+ if (auto KernelIt = MBuiltKernels.find(Device);
+ KernelIt != MBuiltKernels.end())
+ return KernelIt->second;
+ return nullptr;
+ }
+
+ /// \return device image which contains device code of this kernel.
+ DeviceImageManager &getDeviceImage() const { return MDeviceImage; }
+
+ /// Attaches liboffload kernel handle to this device kernel info object.
----------------
sergey-semenov wrote:
```suggestion
/// Attaches a liboffload kernel handle to this device kernel info object.
```
https://github.com/llvm/llvm-project/pull/188794
More information about the llvm-commits
mailing list