[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 Oct 21 06:01:05 PDT 2025
================
@@ -0,0 +1,138 @@
+//===--- 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
+//
+//===----------------------------------------------------------------------===//
+//
+// Plugin interface for SPIR-V/Xe machine
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef OPENMP_LIBOMPTARGET_PLUGINS_NEXTGEN_LEVEL_ZERO_L0PLUGIN_H
+#define OPENMP_LIBOMPTARGET_PLUGINS_NEXTGEN_LEVEL_ZERO_L0PLUGIN_H
+
+#include "AsyncQueue.h"
+#include "L0Defs.h"
+#include "L0Device.h"
+#include "L0Memory.h"
+#include "L0Options.h"
+#include "L0Program.h"
+#include "TLS.h"
+
+namespace llvm::omp::target::plugin {
+
+/// Class implementing the LevelZero specific functionalities of the plugin.
+class LevelZeroPluginTy final : public GenericPluginTy {
+private:
+ /// Number of devices available including subdevices
+ uint32_t NumDevices = 0;
+
+ /// Context (and Driver) specific data
+ std::list<L0ContextTy> ContextList;
+
+ /// L0 device used by each OpenMP device
+ using DeviceContainerTy = llvm::SmallVector<L0DeviceTy *>;
+ DeviceContainerTy L0Devices;
+
+ // Table containing per-thread information using TLS
+ L0ThreadTblTy ThreadTLSTable;
+ // Table containing per-thread information for each device using TLS
+ L0DeviceTLSTableTy DeviceTLSTable;
+ // Table containing per-thread information for each Context using TLS
+ L0ContextTLSTableTy ContextTLSTable;
+
+ /// L0 plugin global options
+ static L0OptionsTy Options;
+
+ std::mutex GlobalMutex;
+
+ /// Common pool of AsyncQueue
+ AsyncQueuePoolTy AsyncQueuePool;
+
+ auto &getTLS() { return ThreadTLSTable.get(); }
+
+public:
+ LevelZeroPluginTy() : GenericPluginTy(getTripleArch()) {}
+ virtual ~LevelZeroPluginTy() {}
+
+ auto &getDeviceTLS(int32_t DeviceId) { return DeviceTLSTable.get(DeviceId); }
+ auto &getContextTLS(ze_context_handle_t Context) {
+ return ContextTLSTable.get(Context);
+ }
+
+ static const auto &getOptions() { return Options; }
+
+ auto &getGlobalMutex() { return GlobalMutex; }
+
+ struct DevicesRangeTy {
+ using iterator = DeviceContainerTy::iterator;
+
+ iterator BeginIt;
+ iterator EndIt;
+
+ DevicesRangeTy(iterator BeginIt, iterator EndIt)
+ : BeginIt(BeginIt), EndIt(EndIt) {}
+
+ auto &begin() { return BeginIt; }
+ auto &end() { return EndIt; }
+ };
+
+ auto getDevicesRange() {
+ return DevicesRangeTy(L0Devices.begin(), L0Devices.end());
+ }
+
+ /// Clean-up routine to be invoked by the destructor or
+ /// LevelZeroPluginTy::deinit.
+ void closeRTL();
+
+ /// Find L0 devices and initialize device properties.
+ /// Returns number of devices reported to omptarget.
+ int32_t findDevices();
+
+ L0DeviceTy &getDeviceFromId(int32_t DeviceId) const {
----------------
adurang wrote:
These are all related, answer again "because subdevices" :) Will change with others if possible.
https://github.com/llvm/llvm-project/pull/158900
More information about the llvm-commits
mailing list