[llvm] [OFFLOAD] Add plugin with support for Intel oneAPI Level Zero (PR #158900)
Alexey Sachkov via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 16 04:35:52 PDT 2025
================
@@ -0,0 +1,189 @@
+//===--- 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 RTL Options support
+//
+//===----------------------------------------------------------------------===//
+
+#pragma once
+
+#include <level_zero/ze_api.h>
+
+#include "Shared/EnvironmentVar.h"
+
+#include "L0Defs.h"
+
+namespace llvm::omp::target::plugin {
+/// Command submission mode
+enum class CommandModeTy { Sync = 0, Async, AsyncOrdered };
+
+/// Specialization constants used for a module compilation.
+class SpecConstantsTy {
+ std::vector<uint32_t> ConstantIds;
+ std::vector<const void *> ConstantValues;
+
+public:
+ SpecConstantsTy() = default;
+ SpecConstantsTy(const SpecConstantsTy &) = delete;
+ SpecConstantsTy(SpecConstantsTy &&) = delete;
+ SpecConstantsTy &operator=(const SpecConstantsTy &) = delete;
+ SpecConstantsTy &operator=(const SpecConstantsTy &&) = delete;
+ SpecConstantsTy(const SpecConstantsTy &&Other)
+ : ConstantIds(std::move(Other.ConstantIds)),
+ ConstantValues(std::move(Other.ConstantValues)) {}
+
+ ~SpecConstantsTy() {
+ for (auto I : ConstantValues) {
+ const char *ValuePtr = reinterpret_cast<const char *>(I);
+ delete[] ValuePtr;
+ }
+ }
+
+ template <typename T> void addConstant(uint32_t Id, T Val) {
+ const size_t ValSize = sizeof(Val);
+ char *ValuePtr = new char[ValSize];
+ *reinterpret_cast<T *>(ValuePtr) = Val;
+
+ ConstantIds.push_back(Id);
+ ConstantValues.push_back(reinterpret_cast<void *>(ValuePtr));
+ }
+
+ ze_module_constants_t getModuleConstants() const {
+ ze_module_constants_t Tmp{static_cast<uint32_t>(ConstantValues.size()),
+ ConstantIds.data(),
+ // Unfortunately we have to const_cast it.
+ // L0 data type should probably be fixed.
+ const_cast<const void **>(ConstantValues.data())};
+ return Tmp;
+ }
+};
+#define FIXED static constexpr
----------------
AlexeySachkov wrote:
That is a weird naming choice I would say, is it an artifact from some earlier bugfix? Can it be inlined?
Oh, looking at the code below one more time, I guess the intent was to say "this is a constant", but in less words. To me, that is not worth the macro
https://github.com/llvm/llvm-project/pull/158900
More information about the llvm-commits
mailing list