From 09c2815f3cb6615b8b2d41a4eb05671f797df25a Mon Sep 17 00:00:00 2001 From: makslevental Date: Thu, 17 Oct 2024 13:16:34 -0400 Subject: [PATCH] remove exceptions --- .../xrt-lite/shim/linux/kmq/CMakeLists.txt | 3 +-- .../driver/xrt-lite/shim/linux/kmq/bo.cpp | 16 ++++------------ .../driver/xrt-lite/shim/linux/kmq/device.cpp | 16 +++++++--------- .../driver/xrt-lite/shim/linux/kmq/fence.cpp | 6 +----- .../driver/xrt-lite/shim/linux/kmq/hwctx.cpp | 6 +----- .../driver/xrt-lite/shim/linux/kmq/hwq.cpp | 13 ++++++++----- .../driver/xrt-lite/shim/linux/kmq/kernel.cpp | 7 +++---- .../driver/xrt-lite/shim/linux/kmq/shim_debug.h | 13 +++++-------- 8 files changed, 30 insertions(+), 50 deletions(-) diff --git a/runtime/src/iree-amd-aie/driver/xrt-lite/shim/linux/kmq/CMakeLists.txt b/runtime/src/iree-amd-aie/driver/xrt-lite/shim/linux/kmq/CMakeLists.txt index ca6cec933..e0757905f 100644 --- a/runtime/src/iree-amd-aie/driver/xrt-lite/shim/linux/kmq/CMakeLists.txt +++ b/runtime/src/iree-amd-aie/driver/xrt-lite/shim/linux/kmq/CMakeLists.txt @@ -27,8 +27,7 @@ iree_cc_library( shim_debug.h DEPS uuid - COPTS - $<$:-fexceptions -frtti> + LLVMSupport DEFINES $<$:SHIM_XDNA_DEBUG> PUBLIC diff --git a/runtime/src/iree-amd-aie/driver/xrt-lite/shim/linux/kmq/bo.cpp b/runtime/src/iree-amd-aie/driver/xrt-lite/shim/linux/kmq/bo.cpp index c2eec9fd9..2d266f729 100644 --- a/runtime/src/iree-amd-aie/driver/xrt-lite/shim/linux/kmq/bo.cpp +++ b/runtime/src/iree-amd-aie/driver/xrt-lite/shim/linux/kmq/bo.cpp @@ -181,11 +181,7 @@ drm_bo::drm_bo(bo &parent, const amdxdna_drm_get_bo_info &bo_info) drm_bo::~drm_bo() { if (m_handle == AMDXDNA_INVALID_BO_HANDLE) return; - try { - free_drm_bo(m_parent.m_pdev, m_handle); - } catch (const std::system_error &e) { - SHIM_DEBUG("Failed to free DRM BO: %s", e.what()); - } + free_drm_bo(m_parent.m_pdev, m_handle); } std::string bo::type_to_name() const { @@ -351,13 +347,9 @@ bo::~bo() { SHIM_DEBUG("Freeing KMQ BO, %s", describe().c_str()); munmap_bo(); - try { - detach_from_ctx(); - // If BO is in use, we should block and wait in driver - free_bo(); - } catch (const std::system_error &e) { - SHIM_DEBUG("Failed to free BO: %s", e.what()); - } + detach_from_ctx(); + // If BO is in use, we should block and wait in driver + free_bo(); } bo::bo(const pdev &p, size_t size, amdxdna_bo_type type) diff --git a/runtime/src/iree-amd-aie/driver/xrt-lite/shim/linux/kmq/device.cpp b/runtime/src/iree-amd-aie/driver/xrt-lite/shim/linux/kmq/device.cpp index 01c4a6bae..ae87fc0b3 100644 --- a/runtime/src/iree-amd-aie/driver/xrt-lite/shim/linux/kmq/device.cpp +++ b/runtime/src/iree-amd-aie/driver/xrt-lite/shim/linux/kmq/device.cpp @@ -16,6 +16,7 @@ #include "bo.h" #include "fence.h" #include "hwctx.h" +#include "llvm/Support/ErrorHandling.h" #include "shim_debug.h" #include "xrt_mem.h" @@ -26,29 +27,26 @@ int64_t import_fd(pid_t pid, int ehdl) { #if defined(SYS_pidfd_open) && defined(SYS_pidfd_getfd) auto pidfd = syscall(SYS_pidfd_open, pid, 0); - if (pidfd < 0) - throw std::system_error(errno, std::system_category(), "pidfd_open failed"); + if (pidfd < 0) shim_xdna::shim_err(errno, "pidfd_open failed"); int64_t fd = syscall(SYS_pidfd_getfd, pidfd, ehdl, 0); if (fd < 0) { if (errno == EPERM) { - throw std::system_error( - errno, std::system_category(), + shim_xdna::shim_err( + errno, "pidfd_getfd failed, check that ptrace access mode " "allows PTRACE_MODE_ATTACH_REALCREDS. For more details please " "check /etc/sysctl.d/10-ptrace.conf"); } - throw std::system_error(errno, std::system_category(), - "pidfd_getfd failed"); + shim_xdna::shim_err(errno, "pidfd_getfd failed"); } return fd; #else - throw std::system_error( - int(std::errc::not_supported), std::system_category(), + shim_xdna::shim_err( + int(std::errc::not_supported), "Importing buffer object from different process requires XRT " " built and installed on a system with 'pidfd' kernel support"); - return -1; #endif } diff --git a/runtime/src/iree-amd-aie/driver/xrt-lite/shim/linux/kmq/fence.cpp b/runtime/src/iree-amd-aie/driver/xrt-lite/shim/linux/kmq/fence.cpp index ba48b3f9e..06fd948fc 100644 --- a/runtime/src/iree-amd-aie/driver/xrt-lite/shim/linux/kmq/fence.cpp +++ b/runtime/src/iree-amd-aie/driver/xrt-lite/shim/linux/kmq/fence.cpp @@ -158,11 +158,7 @@ fence_handle::fence_handle(const fence_handle &f) fence_handle::~fence_handle() { SHIM_DEBUG("Fence going away: %d@%ld", m_syncobj_hdl, m_state); - try { - destroy_syncobj(m_pdev, m_syncobj_hdl); - } catch (const std::system_error &e) { - SHIM_DEBUG("Failed to destroy fence_handle"); - } + destroy_syncobj(m_pdev, m_syncobj_hdl); } std::unique_ptr fence_handle::share_handle() const { diff --git a/runtime/src/iree-amd-aie/driver/xrt-lite/shim/linux/kmq/hwctx.cpp b/runtime/src/iree-amd-aie/driver/xrt-lite/shim/linux/kmq/hwctx.cpp index c7fbc0e7e..8784c2cc8 100644 --- a/runtime/src/iree-amd-aie/driver/xrt-lite/shim/linux/kmq/hwctx.cpp +++ b/runtime/src/iree-amd-aie/driver/xrt-lite/shim/linux/kmq/hwctx.cpp @@ -82,11 +82,7 @@ hw_ctx::hw_ctx(device &device, const std::vector &pdi, } hw_ctx::~hw_ctx() { - try { - delete_ctx_on_device(); - } catch (const std::system_error &e) { - SHIM_DEBUG("Failed to delete context on device: %s", e.what()); - } + delete_ctx_on_device(); SHIM_DEBUG("Destroyed HW context (%d)...", m_handle); SHIM_DEBUG("Destroying KMQ HW context (%d)...", m_handle); } diff --git a/runtime/src/iree-amd-aie/driver/xrt-lite/shim/linux/kmq/hwq.cpp b/runtime/src/iree-amd-aie/driver/xrt-lite/shim/linux/kmq/hwq.cpp index 22a29549b..b3bcc6b2b 100644 --- a/runtime/src/iree-amd-aie/driver/xrt-lite/shim/linux/kmq/hwq.cpp +++ b/runtime/src/iree-amd-aie/driver/xrt-lite/shim/linux/kmq/hwq.cpp @@ -3,6 +3,8 @@ #include "hwq.h" +#include + #include "bo.h" #include "ert.h" #include "fence.h" @@ -28,11 +30,12 @@ int wait_cmd(const shim_xdna::pdev &pdev, const shim_xdna::hw_ctx *ctx, .seq = id, }; - try { - pdev.ioctl(DRM_IOCTL_AMDXDNA_WAIT_CMD, &wcmd); - } catch (const std::system_error &ex) { - if (ex.code().value() != ETIME) throw; - ret = 0; + if (::ioctl(pdev.m_dev_fd, DRM_IOCTL_AMDXDNA_WAIT_CMD, &wcmd) == -1) { + if (errno == ETIME) { + ret = 0; + } else { + shim_xdna::shim_err(errno, "DRM_IOCTL_AMDXDNA_WAIT_CMD IOCTL failed"); + } } return ret; } diff --git a/runtime/src/iree-amd-aie/driver/xrt-lite/shim/linux/kmq/kernel.cpp b/runtime/src/iree-amd-aie/driver/xrt-lite/shim/linux/kmq/kernel.cpp index b86da244a..f20b32dc5 100644 --- a/runtime/src/iree-amd-aie/driver/xrt-lite/shim/linux/kmq/kernel.cpp +++ b/runtime/src/iree-amd-aie/driver/xrt-lite/shim/linux/kmq/kernel.cpp @@ -10,6 +10,7 @@ #include "amdxdna_accel.h" #include "bo.h" #include "device.h" +#include "shim_debug.h" #define MAX_EXEC_BO_SIZE 4096 @@ -64,8 +65,7 @@ void kernel::add_ctrl_bo(bo &bo_ctrl) { break; } default: - throw std::runtime_error("Unknown exec buf op code: " + - std::to_string(m_op)); + shim_err(-1, "Unknown exec buf op code: %d", m_op); } } @@ -116,8 +116,7 @@ void kernel::inc_pkt_count(uint32_t n) const { m_cmd_pkt->count += n / sizeof(int32_t); if (m_cmd_size < sizeof(m_cmd_pkt->header) + m_cmd_pkt->count * sizeof(int32_t)) - throw std::runtime_error("Size of exec buf too small: " + - std::to_string(m_cmd_size)); + shim_err(-1, "Size of exec buf too small: %d", m_cmd_size); } bo *kernel::get_exec_buf_bo() const { return m_exec_buf_bo.get(); } diff --git a/runtime/src/iree-amd-aie/driver/xrt-lite/shim/linux/kmq/shim_debug.h b/runtime/src/iree-amd-aie/driver/xrt-lite/shim/linux/kmq/shim_debug.h index bf853312e..f9e5e1785 100644 --- a/runtime/src/iree-amd-aie/driver/xrt-lite/shim/linux/kmq/shim_debug.h +++ b/runtime/src/iree-amd-aie/driver/xrt-lite/shim/linux/kmq/shim_debug.h @@ -10,6 +10,8 @@ #include #include +#include "llvm/Support/ErrorHandling.h" + void debugf(const char *format, ...); namespace shim_xdna { @@ -19,18 +21,13 @@ template std::string format = std::string(fmt); format += " (err=%d)"; int sz = std::snprintf(nullptr, 0, format.c_str(), args..., err) + 1; - if (sz <= 0) - throw std::system_error(sz, std::system_category(), - "could not format error string"); + if (sz <= 0) llvm::report_fatal_error("could not format error string"); auto size = static_cast(sz); std::unique_ptr buf(new char[size]); std::snprintf(buf.get(), size, format.c_str(), args..., err); - throw std::system_error(err, std::system_category(), std::string(buf.get())); -} - -[[noreturn]] inline void shim_not_supported_err(const char *msg) { - shim_err(ENOTSUP, msg); + std::string err_str(buf.get()); + llvm::report_fatal_error(err_str.c_str()); } template