summaryrefslogtreecommitdiff
path: root/offload/include
diff options
context:
space:
mode:
authorRoss Brunton <ross@codeplay.com>2025-05-19 15:38:34 +0100
committerGitHub <noreply@github.com>2025-05-19 09:38:34 -0500
commit1532ee6916ef16627bafddced391c0b5a31390fe (patch)
tree2a68b73bd4cc4e959e4ee4acd8be0286bc725e2b /offload/include
parent4bdd116b80670cf74ced3e36def6ca09169ff7ac (diff)
[Offload] Add Error Codes to PluginInterface (#138258)
A new ErrorCode enumeration is present in PluginInterface which can be used when returning an llvm::Error from offload and PluginInterface functions. This enum must be kept up to sync with liboffload's ol_errc_t enum, so both are automatically generated from liboffload's enum definition. Some error codes have also been shuffled around to allow for future work. Note that this patch only adds the machinery; actual error codes will be added in a future patch. ~~Depends on #137339 , please ignore first commit of this MR.~~ This has been merged.
Diffstat (limited to 'offload/include')
-rw-r--r--offload/include/Shared/OffloadErrcodes.inc37
-rw-r--r--offload/include/Shared/OffloadError.h51
2 files changed, 88 insertions, 0 deletions
diff --git a/offload/include/Shared/OffloadErrcodes.inc b/offload/include/Shared/OffloadErrcodes.inc
new file mode 100644
index 000000000000..217565647c4e
--- /dev/null
+++ b/offload/include/Shared/OffloadErrcodes.inc
@@ -0,0 +1,37 @@
+//===- Auto-generated file, part of the LLVM/Offload project --------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef OFFLOAD_ERRC
+#error Please define the macro OFFLOAD_ERRCODE(Name, Desc, Value)
+#endif
+
+// Error codes are shared between PluginInterface and liboffload.
+// To add new error codes, add them to offload/liboffload/API/Common.td and run
+// the GenerateOffload target.
+
+OFFLOAD_ERRC(SUCCESS, "Success", 0)
+OFFLOAD_ERRC(UNKNOWN, "Unknown or internal error", 1)
+OFFLOAD_ERRC(INVALID_NULL_POINTER,
+ "A pointer argument is null when it should not be", 2)
+OFFLOAD_ERRC(INVALID_ARGUMENT, "An argument is invalid", 3)
+OFFLOAD_ERRC(OUT_OF_RESOURCES, "Out of resources", 4)
+OFFLOAD_ERRC(UNSUPPORTED,
+ "generic error code for unsupported features and enums", 5)
+OFFLOAD_ERRC(
+ INVALID_SIZE,
+ "invalid size or dimensions (e.g., must not be zero, or is out of bounds)",
+ 6)
+OFFLOAD_ERRC(INVALID_ENUMERATION, "enumerator argument is not valid", 7)
+OFFLOAD_ERRC(INVALID_KERNEL_NAME,
+ "Named kernel not found in the program binary", 8)
+OFFLOAD_ERRC(INVALID_VALUE, "Invalid Value", 9)
+OFFLOAD_ERRC(INVALID_PLATFORM, "Invalid platform", 10)
+OFFLOAD_ERRC(INVALID_DEVICE, "Invalid device", 11)
+OFFLOAD_ERRC(INVALID_QUEUE, "Invalid queue", 12)
+OFFLOAD_ERRC(INVALID_EVENT, "Invalid event", 13)
+OFFLOAD_ERRC(INVALID_NULL_HANDLE, "handle argument is not valid", 14)
diff --git a/offload/include/Shared/OffloadError.h b/offload/include/Shared/OffloadError.h
new file mode 100644
index 000000000000..b999705893ad
--- /dev/null
+++ b/offload/include/Shared/OffloadError.h
@@ -0,0 +1,51 @@
+//===- OffloadError.h - Definition of error class -------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef OPENMP_LIBOMPTARGET_PLUGINS_NEXTGEN_COMMON_OFFLOAD_ERROR_H
+#define OPENMP_LIBOMPTARGET_PLUGINS_NEXTGEN_COMMON_OFFLOAD_ERROR_H
+
+#include "llvm/Support/Error.h"
+#include "llvm/Support/ErrorHandling.h"
+
+namespace error {
+
+enum class ErrorCode {
+#define OFFLOAD_ERRC(Name, _, Value) Name = Value,
+#include "Shared/OffloadErrcodes.inc"
+#undef OFFLOAD_ERRC
+};
+
+} // namespace error
+
+namespace std {
+template <> struct is_error_code_enum<error::ErrorCode> : std::true_type {};
+} // namespace std
+
+namespace error {
+
+const std::error_category &OffloadErrCategory();
+
+inline std::error_code make_error_code(ErrorCode E) {
+ return std::error_code(static_cast<int>(E), OffloadErrCategory());
+}
+
+/// Base class for errors originating in DIA SDK, e.g. COM calls
+class OffloadError : public llvm::ErrorInfo<OffloadError, llvm::StringError> {
+public:
+ using ErrorInfo<OffloadError, StringError>::ErrorInfo;
+
+ OffloadError(const llvm::Twine &S) : ErrorInfo(S, ErrorCode::UNKNOWN) {}
+
+ // The definition for this resides in the plugin static library
+ static char ID;
+};
+} // namespace error
+
+#endif