[llvm] [OFFLOAD] Add plugin with support for Intel oneAPI Level Zero (PR #158900)
Alex Duran via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 16 14:01:38 PDT 2025
================
@@ -0,0 +1,135 @@
+//===--- Level Zero Target RTL Implementation -----------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+//
+// Level Zero Program abstraction
+//
+//===----------------------------------------------------------------------===//
+
+#pragma once
+
+#include "L0Kernel.h"
+
+namespace llvm::omp::target::plugin {
+
+class L0DeviceTy;
+
+/// Program data to be initialized by plugin
+struct ProgramDataTy {
+ int Initialized = 0;
+ int NumDevices = 0;
+ int DeviceNum = -1;
+ uint32_t TotalEUs = 0;
+ uint32_t HWThreadsPerEU = 0;
+ uintptr_t DynamicMemoryLB = 0;
+ uintptr_t DynamicMemoryUB = 0;
+ int DeviceType = 0;
+ void *DynamicMemPool = nullptr;
+ int TeamsThreadLimit = 0;
+};
+
+/// Level Zero program that can contain multiple modules.
+class L0ProgramTy : public DeviceImageTy {
+ /// Handle multiple modules within a single target image
+ llvm::SmallVector<ze_module_handle_t> Modules;
+
+ /// Map of kernel names to Modules
+ std::unordered_map<std::string, ze_module_handle_t> KernelsToModuleMap;
+
+ /// List of kernels built for this image
+ /// We need to delete them ourselves as the main library is not doing
+ /// that right now
+ std::list<L0KernelTy *> Kernels;
+
+ /// Module that contains global data including device RTL
+ ze_module_handle_t GlobalModule = nullptr;
+
+ /// Requires module link
+ bool RequiresModuleLink = false;
+
+ /// Is this module library
+ bool IsLibModule = false;
+
+ /// Build a single module with the given image, build option, and format.
+ int32_t addModule(const size_t Size, const uint8_t *Image,
+ const std::string &BuildOption, ze_module_format_t Format);
+ /// Read file and return the size of the binary if successful.
+ size_t readFile(const char *FileName, std::vector<uint8_t> &OutFile) const;
+ int32_t readSPVFile(const char *FileName, std::vector<uint8_t> &OutSPV) const;
+ void replaceDriverOptsWithBackendOpts(const L0DeviceTy &Device,
+ std::string &Options) const;
+
+ /// Check if the image should be handled as a library module
+ void setLibModule();
+
+ L0DeviceTy &getL0Device() const;
+
+public:
+ L0ProgramTy() = delete;
+
+ L0ProgramTy(int32_t ImageId, GenericDeviceTy &Device,
+ const __tgt_device_image *Image)
----------------
adurang wrote:
do you have a link to where you did that as reference?
https://github.com/llvm/llvm-project/pull/158900
More information about the llvm-commits
mailing list