[llvm] [OFFLOAD] Add plugin with support for Intel oneAPI Level Zero (PR #158900)
Kevin Sala Penades via llvm-commits
llvm-commits at lists.llvm.org
Fri Oct 31 14:14:46 PDT 2025
================
@@ -0,0 +1,194 @@
+//===--- 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
+//
+//===----------------------------------------------------------------------===//
+//
+// Code for tracing L0
+//
+//===----------------------------------------------------------------------===//
+// clang-format off
+#ifndef OPENMP_LIBOMPTARGET_PLUGINS_NEXTGEN_LEVEL_ZERO_L0TRACE_H
+#define OPENMP_LIBOMPTARGET_PLUGINS_NEXTGEN_LEVEL_ZERO_L0TRACE_H
+
+#include "Shared/Debug.h"
+#include "omptarget.h"
+#include <string>
+#include <level_zero/ze_api.h>
+
+#define STR(x) #x
+#define TO_STRING(x) STR(x)
+
+#define DPCALL(...) \
+ do { \
+ if (getDebugLevel() > 1) \
+ DP(__VA_ARGS__); \
+ } while (0)
+
+#define WARNING(...) \
+ do { \
+ fprintf(stderr, "%s --> ", DEBUG_PREFIX); \
+ fprintf(stderr, "Warning: " __VA_ARGS__); \
+ } while (0)
+
+#define INVALID_OPTION(Name, Value) \
+ WARNING("Ignoring invalid option " #Name "=%s\n", Value)
+
+#define CALL_ZE(Rc, Fn, ...) \
+ do { \
+ Rc = Fn(__VA_ARGS__); \
+ } while (0)
+
+#define CALL_ZE_RC(Rc, Fn, ...) \
+ do { \
+ CALL_ZE(Rc, Fn, __VA_ARGS__); \
+ if (Rc != ZE_RESULT_SUCCESS) { \
+ DP("Error: %s:%s failed with error code %d, %s\n", __func__, #Fn, Rc, \
+ getZeErrorName(Rc)); \
+ } \
+ } while(0)
+
+/// For non-thread-safe functions
+#define CALL_ZE_RET_MTX(Ret, Fn, Mtx, ...) \
+ do { \
+ Mtx.lock(); \
+ ze_result_t rc; \
+ CALL_ZE(rc, Fn, __VA_ARGS__); \
+ Mtx.unlock(); \
+ if (rc != ZE_RESULT_SUCCESS) { \
+ DP("Error: %s:%s failed with error code %d, %s\n", __func__, #Fn, rc, \
+ getZeErrorName(rc)); \
+ return Ret; \
+ } \
+ } while (0)
+
+#define CALL_ZE_RET_FAIL_MTX(Fn, Mtx, ...) \
+ CALL_ZE_RET_MTX(OFFLOAD_FAIL, Fn, Mtx, __VA_ARGS__)
+#define CALL_ZE_RET_NULL_MTX(Fn, Mtx, ...) \
+ CALL_ZE_RET_MTX(NULL, Fn, Mtx, __VA_ARGS__)
+#define CALL_ZE_RET_ZERO_MTX(Fn, Mtx, ...) \
+ CALL_ZE_RET_MTX(0, Fn, Mtx, __VA_ARGS__)
+#define CALL_ZE_RET_ERROR_MTX(Fn, Mtx, ...) \
+ CALL_ZE_RET_MTX( \
+ Plugin::error(ErrorCode::UNKNOWN, "%s failed with error %d, %s", \
+ STR(Fn), rc, getZeErrorName(rc)), Fn, Mtx, __VA_ARGS__)
+
+
+/// For thread-safe functions
+#define CALL_ZE_RET(Ret, Fn, ...) \
+ do { \
+ ze_result_t rc; \
+ CALL_ZE(rc, Fn, __VA_ARGS__); \
+ if (rc != ZE_RESULT_SUCCESS) { \
+ DP("Error: %s:%s failed with error code %d, %s\n", __func__, #Fn, rc, \
+ getZeErrorName(rc)); \
+ return Ret; \
+ } \
+ } while (0)
+
+#define CALL_ZE_RET_FAIL(Fn, ...) CALL_ZE_RET(OFFLOAD_FAIL, Fn, __VA_ARGS__)
----------------
kevinsala wrote:
Not used.
https://github.com/llvm/llvm-project/pull/158900
More information about the llvm-commits
mailing list