[llvm] [Offload] Use new error code handling mechanism (PR #139275)

via llvm-commits llvm-commits at lists.llvm.org
Fri May 9 07:52:46 PDT 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-backend-amdgpu

@llvm/pr-subscribers-offload

Author: Ross Brunton (RossBrunton)

<details>
<summary>Changes</summary>

[Offload] Use new error code handling mechanism

This removes the old ErrorCode-less error method and requires
every user to provide a concrete error code. All calls have been
updated.

Depends on https://github.com/llvm/llvm-project/pull/138258 ignore the first 4 commits of this MR.

---

Patch is 68.77 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/139275.diff


25 Files Affected:

- (added) offload/include/Shared/OffloadErrcodes.inc (+51) 
- (modified) offload/liboffload/API/CMakeLists.txt (+7-3) 
- (modified) offload/liboffload/API/Common.td (+21-11) 
- (modified) offload/liboffload/CMakeLists.txt (+2) 
- (modified) offload/liboffload/include/OffloadImpl.hpp (+11-3) 
- (modified) offload/liboffload/include/generated/OffloadAPI.h (+56-42) 
- (modified) offload/liboffload/include/generated/OffloadPrint.hpp (+45-27) 
- (modified) offload/liboffload/src/OffloadImpl.cpp (+1-1) 
- (modified) offload/plugins-nextgen/amdgpu/dynamic_hsa/hsa.h (+1) 
- (modified) offload/plugins-nextgen/amdgpu/src/rtl.cpp (+61-27) 
- (modified) offload/plugins-nextgen/common/CMakeLists.txt (+1) 
- (added) offload/plugins-nextgen/common/include/OffloadError.h (+64) 
- (modified) offload/plugins-nextgen/common/include/PluginInterface.h (+10-3) 
- (modified) offload/plugins-nextgen/common/src/GlobalHandler.cpp (+24-11) 
- (modified) offload/plugins-nextgen/common/src/JIT.cpp (+1-1) 
- (added) offload/plugins-nextgen/common/src/OffloadError.cpp (+40) 
- (modified) offload/plugins-nextgen/common/src/PluginInterface.cpp (+45-21) 
- (modified) offload/plugins-nextgen/common/src/RPC.cpp (+1) 
- (modified) offload/plugins-nextgen/cuda/src/rtl.cpp (+47-23) 
- (modified) offload/plugins-nextgen/host/src/rtl.cpp (+24-12) 
- (modified) offload/tools/offload-tblgen/CMakeLists.txt (+1-2) 
- (modified) offload/tools/offload-tblgen/Generators.hpp (+2) 
- (renamed) offload/tools/offload-tblgen/MiscGen.cpp (+21) 
- (modified) offload/tools/offload-tblgen/offload-tblgen.cpp (+8-2) 
- (modified) offload/unittests/OffloadAPI/kernel/olGetKernel.cpp (+2-2) 


``````````diff
diff --git a/offload/include/Shared/OffloadErrcodes.inc b/offload/include/Shared/OffloadErrcodes.inc
new file mode 100644
index 0000000000000..e0797e2bac194
--- /dev/null
+++ b/offload/include/Shared/OffloadErrcodes.inc
@@ -0,0 +1,51 @@
+//===- 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(HOST_IO, "I/O error on host", 2)
+OFFLOAD_ERRC(INVALID_BINARY, "A provided binary image is malformed", 3)
+OFFLOAD_ERRC(INVALID_NULL_POINTER,
+             "A pointer argument is null when it should not be", 4)
+OFFLOAD_ERRC(INVALID_ARGUMENT, "An argument is invalid", 5)
+OFFLOAD_ERRC(NOT_FOUND, "Requested object was not found in the binary image", 6)
+OFFLOAD_ERRC(OUT_OF_RESOURCES, "Out of resources", 7)
+OFFLOAD_ERRC(
+    INVALID_SIZE,
+    "invalid size or dimensions (e.g., must not be zero, or is out of bounds)",
+    8)
+OFFLOAD_ERRC(INVALID_ENUMERATION, "enumerator argument is not valid", 9)
+OFFLOAD_ERRC(HOST_TOOL_NOT_FOUND,
+             "A required binary (linker, etc.) was not found on the host", 10)
+OFFLOAD_ERRC(INVALID_VALUE, "Invalid Value", 11)
+OFFLOAD_ERRC(UNIMPLEMENTED,
+             "Generic error code for features currently unimplemented by the "
+             "device/backend",
+             12)
+OFFLOAD_ERRC(
+    UNSUPPORTED,
+    "Generic error code for features unsupported by the device/backend", 13)
+OFFLOAD_ERRC(ASSEMBLE_FAILURE,
+             "Assembler failure while processing binary image", 14)
+OFFLOAD_ERRC(LINK_FAILURE, "Linker failure while processing binary image", 15)
+OFFLOAD_ERRC(BACKEND_FAILURE,
+             "The plugin backend is in an invalid or unsupported state", 16)
+OFFLOAD_ERRC(INVALID_NULL_HANDLE,
+             "A handle argument is null when it should not be", 17)
+OFFLOAD_ERRC(INVALID_PLATFORM, "Invalid platform", 18)
+OFFLOAD_ERRC(INVALID_DEVICE, "Invalid device", 19)
+OFFLOAD_ERRC(INVALID_QUEUE, "Invalid queue", 20)
+OFFLOAD_ERRC(INVALID_EVENT, "Invalid event", 21)
diff --git a/offload/liboffload/API/CMakeLists.txt b/offload/liboffload/API/CMakeLists.txt
index 8fd6cb539374a..5f8d1435d141f 100644
--- a/offload/liboffload/API/CMakeLists.txt
+++ b/offload/liboffload/API/CMakeLists.txt
@@ -11,13 +11,17 @@ if (CLANG_FORMAT)
     tablegen(OFFLOAD OffloadFuncs.inc -gen-func-names)
     tablegen(OFFLOAD OffloadImplFuncDecls.inc -gen-impl-func-decls)
     tablegen(OFFLOAD OffloadPrint.hpp -gen-print-header)
+    tablegen(OFFLOAD OffloadErrcodes.inc -gen-errcodes)
 
-    set(OFFLOAD_GENERATED_FILES ${TABLEGEN_OUTPUT})
+    set(FILES_TO_COPY "OffloadAPI.h;OffloadEntryPoints.inc;OffloadFuncs.inc;OffloadImplFuncDecls.inc;OffloadPrint.hpp")
+    set(GEN_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../include/generated)
     add_public_tablegen_target(OffloadGenerate)
     add_custom_command(TARGET OffloadGenerate POST_BUILD COMMAND ${CLANG_FORMAT}
-        -i ${OFFLOAD_GENERATED_FILES})
+        -i ${TABLEGEN_OUTPUT})
     add_custom_command(TARGET OffloadGenerate POST_BUILD COMMAND ${CMAKE_COMMAND}
-        -E copy_if_different ${OFFLOAD_GENERATED_FILES} "${CMAKE_CURRENT_SOURCE_DIR}/../include/generated")
+        -E copy_if_different ${FILES_TO_COPY} ${GEN_DIR})
+    add_custom_command(TARGET OffloadGenerate POST_BUILD COMMAND ${CMAKE_COMMAND}
+        -E copy_if_different OffloadErrcodes.inc "${LIBOMPTARGET_INCLUDE_DIR}/Shared/OffloadErrcodes.inc")
 else()
     message(WARNING "clang-format was not found, so the OffloadGenerate target\
         will not be available. Offload will still build, but you will not be\
diff --git a/offload/liboffload/API/Common.td b/offload/liboffload/API/Common.td
index de7502b540618..71079420a210f 100644
--- a/offload/liboffload/API/Common.td
+++ b/offload/liboffload/API/Common.td
@@ -83,26 +83,36 @@ def : Typedef {
   let value = "void *";
 }
 
-def : Enum {
+def ErrorCode : Enum {
   let name = "ol_errc_t";
   let desc = "Defines Return/Error codes";
   let etors =[
     Etor<"SUCCESS", "Success">,
+
+    // Universal errors
+    Etor<"UNKNOWN", "Unknown or internal error">,
+    Etor<"HOST_IO", "I/O error on host">,
+    Etor<"INVALID_BINARY", "A provided binary image is malformed">,
+    Etor<"INVALID_NULL_POINTER", "A pointer argument is null when it should not be">,
+    Etor<"INVALID_ARGUMENT", "An argument is invalid">,
+    Etor<"NOT_FOUND", "Requested object was not found in the binary image">,
+    Etor<"OUT_OF_RESOURCES", "Out of resources">,
+    Etor<"INVALID_SIZE", "invalid size or dimensions (e.g., must not be zero, or is out of bounds)">,
+    Etor<"INVALID_ENUMERATION", "enumerator argument is not valid">,
+    Etor<"HOST_TOOL_NOT_FOUND", "A required binary (linker, etc.) was not found on the host">,
     Etor<"INVALID_VALUE", "Invalid Value">,
+    Etor<"UNIMPLEMENTED", "Generic error code for features currently unimplemented by the device/backend">,
+    Etor<"UNSUPPORTED", "Generic error code for features unsupported by the device/backend">,
+    Etor<"ASSEMBLE_FAILURE", "Assembler failure while processing binary image">,
+    Etor<"LINK_FAILURE", "Linker failure while processing binary image">,
+    Etor<"BACKEND_FAILURE", "The plugin backend is in an invalid or unsupported state">,
+
+    // Handle related errors - only makes sense for liboffload
+    Etor<"INVALID_NULL_HANDLE", "A handle argument is null when it should not be">,
     Etor<"INVALID_PLATFORM", "Invalid platform">,
     Etor<"INVALID_DEVICE", "Invalid device">,
     Etor<"INVALID_QUEUE", "Invalid queue">,
     Etor<"INVALID_EVENT", "Invalid event">,
-    Etor<"INVALID_KERNEL_NAME", "Named kernel not found in the program binary">,
-    Etor<"OUT_OF_RESOURCES", "Out of resources">,
-    Etor<"UNSUPPORTED_FEATURE", "generic error code for unsupported features">,
-    Etor<"INVALID_ARGUMENT", "generic error code for invalid arguments">,
-    Etor<"INVALID_NULL_HANDLE", "handle argument is not valid">,
-    Etor<"INVALID_NULL_POINTER", "pointer argument may not be nullptr">,
-    Etor<"INVALID_SIZE", "invalid size or dimensions (e.g., must not be zero, or is out of bounds)">,
-    Etor<"INVALID_ENUMERATION", "enumerator argument is not valid">,
-    Etor<"UNSUPPORTED_ENUMERATION", "enumerator argument is not supported by the device">,
-    Etor<"UNKNOWN", "Unknown or internal error">
   ];
 }
 
diff --git a/offload/liboffload/CMakeLists.txt b/offload/liboffload/CMakeLists.txt
index db12236ddfc7f..9927fa3c3400a 100644
--- a/offload/liboffload/CMakeLists.txt
+++ b/offload/liboffload/CMakeLists.txt
@@ -1,3 +1,5 @@
+set(LIBOFFLOAD_ROOT "${CMAKE_CURRENT_SOURCE_DIR}")
+
 add_subdirectory(API)
 
 add_llvm_library(
diff --git a/offload/liboffload/include/OffloadImpl.hpp b/offload/liboffload/include/OffloadImpl.hpp
index 48fdc2b884199..7d2c0c53fc85b 100644
--- a/offload/liboffload/include/OffloadImpl.hpp
+++ b/offload/liboffload/include/OffloadImpl.hpp
@@ -7,6 +7,7 @@
 //===----------------------------------------------------------------------===//
 #pragma once
 
+#include "PluginInterface.h"
 #include <OffloadAPI.h>
 #include <iostream>
 #include <memory>
@@ -93,9 +94,7 @@ struct ol_impl_result_t {
     ol_errc_t ErrCode;
     llvm::StringRef Details;
     llvm::handleAllErrors(std::move(Error), [&](llvm::StringError &Err) {
-      // TODO: PluginInterface doesn't yet have a way to communicate offload
-      // error codes
-      ErrCode = OL_ERRC_UNKNOWN;
+      ErrCode = GetErrorCode(Err.convertToErrorCode());
       Details = errorStrs().insert(Err.getMessage()).first->getKeyData();
     });
 
@@ -105,5 +104,14 @@ struct ol_impl_result_t {
   operator ol_result_t() { return Result; }
 
 private:
+  static ol_errc_t GetErrorCode(std::error_code Code) {
+    if (Code.category() == llvm::omp::target::plugin::make_error_code(
+                               llvm::omp::target::plugin::ErrorCode::SUCCESS)
+                               .category()) {
+      return static_cast<ol_errc_t>(Code.value());
+    }
+    return OL_ERRC_UNKNOWN;
+  }
+
   ol_result_t Result;
 };
diff --git a/offload/liboffload/include/generated/OffloadAPI.h b/offload/liboffload/include/generated/OffloadAPI.h
index ace31c57cf2f8..d38ed06b91559 100644
--- a/offload/liboffload/include/generated/OffloadAPI.h
+++ b/offload/liboffload/include/generated/OffloadAPI.h
@@ -17,6 +17,60 @@
 extern "C" {
 #endif
 
+///////////////////////////////////////////////////////////////////////////////
+/// @brief Defines Return/Error codes
+typedef enum ol_errc_t {
+  /// Success
+  OL_ERRC_SUCCESS = 0,
+  /// Unknown or internal error
+  OL_ERRC_UNKNOWN = 1,
+  /// I/O error on host
+  OL_ERRC_HOST_IO = 2,
+  /// A provided binary image is malformed
+  OL_ERRC_INVALID_BINARY = 3,
+  /// A pointer argument is null when it should not be
+  OL_ERRC_INVALID_NULL_POINTER = 4,
+  /// An argument is invalid
+  OL_ERRC_INVALID_ARGUMENT = 5,
+  /// Requested object was not found in the binary image
+  OL_ERRC_NOT_FOUND = 6,
+  /// Out of resources
+  OL_ERRC_OUT_OF_RESOURCES = 7,
+  /// invalid size or dimensions (e.g., must not be zero, or is out of bounds)
+  OL_ERRC_INVALID_SIZE = 8,
+  /// enumerator argument is not valid
+  OL_ERRC_INVALID_ENUMERATION = 9,
+  /// A required binary (linker, etc.) was not found on the host
+  OL_ERRC_HOST_TOOL_NOT_FOUND = 10,
+  /// Invalid Value
+  OL_ERRC_INVALID_VALUE = 11,
+  /// Generic error code for features currently unimplemented by the
+  /// device/backend
+  OL_ERRC_UNIMPLEMENTED = 12,
+  /// Generic error code for features unsupported by the device/backend
+  OL_ERRC_UNSUPPORTED = 13,
+  /// Assembler failure while processing binary image
+  OL_ERRC_ASSEMBLE_FAILURE = 14,
+  /// Linker failure while processing binary image
+  OL_ERRC_LINK_FAILURE = 15,
+  /// The plugin backend is in an invalid or unsupported state
+  OL_ERRC_BACKEND_FAILURE = 16,
+  /// A handle argument is null when it should not be
+  OL_ERRC_INVALID_NULL_HANDLE = 17,
+  /// Invalid platform
+  OL_ERRC_INVALID_PLATFORM = 18,
+  /// Invalid device
+  OL_ERRC_INVALID_DEVICE = 19,
+  /// Invalid queue
+  OL_ERRC_INVALID_QUEUE = 20,
+  /// Invalid event
+  OL_ERRC_INVALID_EVENT = 21,
+  /// @cond
+  OL_ERRC_FORCE_UINT32 = 0x7fffffff
+  /// @endcond
+
+} ol_errc_t;
+
 ///////////////////////////////////////////////////////////////////////////////
 #ifndef OL_VERSION_MAJOR
 /// @brief Major version of the Offload API
@@ -101,47 +155,6 @@ typedef struct ol_program_impl_t *ol_program_handle_t;
 /// @brief Handle of kernel object
 typedef void *ol_kernel_handle_t;
 
-///////////////////////////////////////////////////////////////////////////////
-/// @brief Defines Return/Error codes
-typedef enum ol_errc_t {
-  /// Success
-  OL_ERRC_SUCCESS = 0,
-  /// Invalid Value
-  OL_ERRC_INVALID_VALUE = 1,
-  /// Invalid platform
-  OL_ERRC_INVALID_PLATFORM = 2,
-  /// Invalid device
-  OL_ERRC_INVALID_DEVICE = 3,
-  /// Invalid queue
-  OL_ERRC_INVALID_QUEUE = 4,
-  /// Invalid event
-  OL_ERRC_INVALID_EVENT = 5,
-  /// Named kernel not found in the program binary
-  OL_ERRC_INVALID_KERNEL_NAME = 6,
-  /// Out of resources
-  OL_ERRC_OUT_OF_RESOURCES = 7,
-  /// generic error code for unsupported features
-  OL_ERRC_UNSUPPORTED_FEATURE = 8,
-  /// generic error code for invalid arguments
-  OL_ERRC_INVALID_ARGUMENT = 9,
-  /// handle argument is not valid
-  OL_ERRC_INVALID_NULL_HANDLE = 10,
-  /// pointer argument may not be nullptr
-  OL_ERRC_INVALID_NULL_POINTER = 11,
-  /// invalid size or dimensions (e.g., must not be zero, or is out of bounds)
-  OL_ERRC_INVALID_SIZE = 12,
-  /// enumerator argument is not valid
-  OL_ERRC_INVALID_ENUMERATION = 13,
-  /// enumerator argument is not supported by the device
-  OL_ERRC_UNSUPPORTED_ENUMERATION = 14,
-  /// Unknown or internal error
-  OL_ERRC_UNKNOWN = 15,
-  /// @cond
-  OL_ERRC_FORCE_UINT32 = 0x7fffffff
-  /// @endcond
-
-} ol_errc_t;
-
 ///////////////////////////////////////////////////////////////////////////////
 /// @brief Details of the error condition returned by an API call
 typedef struct ol_error_struct_t {
@@ -477,7 +490,8 @@ OL_APIEXPORT ol_result_t OL_APICALL olMemFree(
 /// @brief Enqueue a memcpy operation.
 ///
 /// @details
-///    - For host pointers, use the device returned by olGetHostDevice
+///    - For host pointers, use the host device belonging to the
+///    OL_PLATFORM_BACKEND_HOST platform.
 ///    - If a queue is specified, at least one device must be a non-host device
 ///    - If a queue is not specified, the memcpy happens synchronously
 ///
diff --git a/offload/liboffload/include/generated/OffloadPrint.hpp b/offload/liboffload/include/generated/OffloadPrint.hpp
index 7f5e33aea6f73..9b916543eec0d 100644
--- a/offload/liboffload/include/generated/OffloadPrint.hpp
+++ b/offload/liboffload/include/generated/OffloadPrint.hpp
@@ -49,50 +49,68 @@ inline llvm::raw_ostream &operator<<(llvm::raw_ostream &os,
   case OL_ERRC_SUCCESS:
     os << "OL_ERRC_SUCCESS";
     break;
-  case OL_ERRC_INVALID_VALUE:
-    os << "OL_ERRC_INVALID_VALUE";
+  case OL_ERRC_UNKNOWN:
+    os << "OL_ERRC_UNKNOWN";
     break;
-  case OL_ERRC_INVALID_PLATFORM:
-    os << "OL_ERRC_INVALID_PLATFORM";
+  case OL_ERRC_HOST_IO:
+    os << "OL_ERRC_HOST_IO";
     break;
-  case OL_ERRC_INVALID_DEVICE:
-    os << "OL_ERRC_INVALID_DEVICE";
+  case OL_ERRC_INVALID_BINARY:
+    os << "OL_ERRC_INVALID_BINARY";
     break;
-  case OL_ERRC_INVALID_QUEUE:
-    os << "OL_ERRC_INVALID_QUEUE";
+  case OL_ERRC_INVALID_NULL_POINTER:
+    os << "OL_ERRC_INVALID_NULL_POINTER";
     break;
-  case OL_ERRC_INVALID_EVENT:
-    os << "OL_ERRC_INVALID_EVENT";
+  case OL_ERRC_INVALID_ARGUMENT:
+    os << "OL_ERRC_INVALID_ARGUMENT";
     break;
-  case OL_ERRC_INVALID_KERNEL_NAME:
-    os << "OL_ERRC_INVALID_KERNEL_NAME";
+  case OL_ERRC_NOT_FOUND:
+    os << "OL_ERRC_NOT_FOUND";
     break;
   case OL_ERRC_OUT_OF_RESOURCES:
     os << "OL_ERRC_OUT_OF_RESOURCES";
     break;
-  case OL_ERRC_UNSUPPORTED_FEATURE:
-    os << "OL_ERRC_UNSUPPORTED_FEATURE";
+  case OL_ERRC_INVALID_SIZE:
+    os << "OL_ERRC_INVALID_SIZE";
+    break;
+  case OL_ERRC_INVALID_ENUMERATION:
+    os << "OL_ERRC_INVALID_ENUMERATION";
+    break;
+  case OL_ERRC_HOST_TOOL_NOT_FOUND:
+    os << "OL_ERRC_HOST_TOOL_NOT_FOUND";
     break;
-  case OL_ERRC_INVALID_ARGUMENT:
-    os << "OL_ERRC_INVALID_ARGUMENT";
+  case OL_ERRC_INVALID_VALUE:
+    os << "OL_ERRC_INVALID_VALUE";
+    break;
+  case OL_ERRC_UNIMPLEMENTED:
+    os << "OL_ERRC_UNIMPLEMENTED";
+    break;
+  case OL_ERRC_UNSUPPORTED:
+    os << "OL_ERRC_UNSUPPORTED";
+    break;
+  case OL_ERRC_ASSEMBLE_FAILURE:
+    os << "OL_ERRC_ASSEMBLE_FAILURE";
+    break;
+  case OL_ERRC_LINK_FAILURE:
+    os << "OL_ERRC_LINK_FAILURE";
+    break;
+  case OL_ERRC_BACKEND_FAILURE:
+    os << "OL_ERRC_BACKEND_FAILURE";
     break;
   case OL_ERRC_INVALID_NULL_HANDLE:
     os << "OL_ERRC_INVALID_NULL_HANDLE";
     break;
-  case OL_ERRC_INVALID_NULL_POINTER:
-    os << "OL_ERRC_INVALID_NULL_POINTER";
-    break;
-  case OL_ERRC_INVALID_SIZE:
-    os << "OL_ERRC_INVALID_SIZE";
+  case OL_ERRC_INVALID_PLATFORM:
+    os << "OL_ERRC_INVALID_PLATFORM";
     break;
-  case OL_ERRC_INVALID_ENUMERATION:
-    os << "OL_ERRC_INVALID_ENUMERATION";
+  case OL_ERRC_INVALID_DEVICE:
+    os << "OL_ERRC_INVALID_DEVICE";
     break;
-  case OL_ERRC_UNSUPPORTED_ENUMERATION:
-    os << "OL_ERRC_UNSUPPORTED_ENUMERATION";
+  case OL_ERRC_INVALID_QUEUE:
+    os << "OL_ERRC_INVALID_QUEUE";
     break;
-  case OL_ERRC_UNKNOWN:
-    os << "OL_ERRC_UNKNOWN";
+  case OL_ERRC_INVALID_EVENT:
+    os << "OL_ERRC_INVALID_EVENT";
     break;
   default:
     os << "unknown enumerator";
diff --git a/offload/liboffload/src/OffloadImpl.cpp b/offload/liboffload/src/OffloadImpl.cpp
index b50c7e0f87b7c..ea65282e3ba52 100644
--- a/offload/liboffload/src/OffloadImpl.cpp
+++ b/offload/liboffload/src/OffloadImpl.cpp
@@ -482,7 +482,7 @@ ol_impl_result_t olGetKernel_impl(ol_program_handle_t Program,
   auto &Device = Program->Image->getDevice();
   auto KernelImpl = Device.constructKernel(KernelName);
   if (!KernelImpl)
-    return OL_ERRC_INVALID_KERNEL_NAME;
+    return ol_impl_result_t::fromError(KernelImpl.takeError());
 
   auto Err = KernelImpl->init(Device, *Program->Image);
   if (Err)
diff --git a/offload/plugins-nextgen/amdgpu/dynamic_hsa/hsa.h b/offload/plugins-nextgen/amdgpu/dynamic_hsa/hsa.h
index 27e4541481301..61f680bab3a07 100644
--- a/offload/plugins-nextgen/amdgpu/dynamic_hsa/hsa.h
+++ b/offload/plugins-nextgen/amdgpu/dynamic_hsa/hsa.h
@@ -30,6 +30,7 @@ typedef enum {
   HSA_STATUS_INFO_BREAK = 0x1,
   HSA_STATUS_ERROR = 0x1000,
   HSA_STATUS_ERROR_INVALID_CODE_OBJECT = 0x1010,
+  HSA_STATUS_ERROR_INVALID_SYMBOL_NAME = 0x1013,
   HSA_STATUS_ERROR_NOT_INITIALIZED = 0x100B,
   HSA_STATUS_ERROR_EXCEPTION = 0x1016,
 } hsa_status_t;
diff --git a/offload/plugins-nextgen/amdgpu/src/rtl.cpp b/offload/plugins-nextgen/amdgpu/src/rtl.cpp
index ed575f2213f28..8cd1187e83eb1 100644
--- a/offload/plugins-nextgen/amdgpu/src/rtl.cpp
+++ b/offload/plugins-nextgen/amdgpu/src/rtl.cpp
@@ -167,7 +167,8 @@ Error asyncMemCopy(bool UseMultipleSdmaEngines, void *Dst, hsa_agent_t DstAgent,
 // This solution is probably not the best
 #if !(HSA_AMD_INTERFACE_VERSION_MAJOR >= 1 &&                                  \
       HSA_AMD_INTERFACE_VERSION_MINOR >= 2)
-  return Plugin::error("Async copy on selected SDMA requires ROCm 5.7");
+  return Plugin::error(ErrorCode::UNSUPPORTED,
+                       "Async copy on selected SDMA requires ROCm 5.7");
 #else
   static std::atomic<int> SdmaEngine{1};
 
@@ -237,7 +238,8 @@ struct AMDGPUResourceRef : public GenericDeviceResourceRef {
   /// reference must be to a valid resource before calling to this function.
   Error destroy(GenericDeviceTy &Device) override {
     if (!Resource)
-      return Plugin::error("Destroying an invalid resource");
+      return Plugin::error(ErrorCode::INVALID_ARGUMENT,
+                           "Destroying an invalid resource");
 
     if (auto Err = Resource->deinit())
       return Err;
@@ -335,7 +337,8 @@ struct AMDGPUMemoryPoolTy {
       // The agent is not allowed to access the memory pool in any case. Do not
       // continue because otherwise it result in undefined behavior.
       if (Access == HSA_AMD_MEMORY_POOL_ACCESS_NEVER_ALLOWED)
-        return Plugin::error("An agent is not allowed to access a memory pool");
+        return Plugin::error(ErrorCode::INVALID_VALUE,
+                             "An agent is not allowed to access a memory pool");
     }
 #endif
 
@@ -416,7 +419,8 @@ struct AMDGPUMemoryManagerTy : public DeviceAllocatorTy {
 
     *PtrStorage = MemoryManager->allocate(Size, nullptr);
     if (*PtrStorage == nullptr)
-      return Plugin::error("Failure to allocate from AMDGPU memory manager");
+      return Plugin::error(ErrorCode::OUT_OF_RESOURCES,
+                           "Failure to allocate from AMDGPU memory manager");
 
     return Plugin::success();
   }
@@ -426,7 +430,8 @@ struct AMDGPUMemoryManagerTy : public DeviceAllocatorTy {
     assert(Ptr && "Invalid pointer");
 
     if (MemoryManager->free(Ptr))
-      return Plugin::error("Failure to deallocate from AMDGPU memory manager");
+      return Plugin::error(ErrorCode::UNKNOWN,
+                           "Failure to deallocate from AMDGPU memory manager");
 
     return Plugin::success();
   }
@@ -540,7 +545,8 @@ struct AMDGPUKernelTy : public GenericKernelTy {
 
     // Make sure it is a kernel symbol.
     if (SymbolType != HSA_SYMBOL_KIND_KERNEL)
-      return Plugin::error("Symbol %s is not a kernel function");
+      return Plugin::error(ErrorCode::INVALID_BINARY,
+                           "Symbol %s is not a kernel function");
 
     // TODO: Read the kernel descriptor for the max threads per block. May be
     // read from the image.
@@ -1115,7 +1121,8...
[truncated]

``````````

</details>


https://github.com/llvm/llvm-project/pull/139275


More information about the llvm-commits mailing list