Skip to content

Commit

Permalink
remove exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
makslevental committed Oct 17, 2024
1 parent 626057f commit 09c2815
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ iree_cc_library(
shim_debug.h
DEPS
uuid
COPTS
$<$<PLATFORM_ID:Linux>:-fexceptions -frtti>
LLVMSupport
DEFINES
$<$<CONFIG:Debug>:SHIM_XDNA_DEBUG>
PUBLIC
Expand Down
16 changes: 4 additions & 12 deletions runtime/src/iree-amd-aie/driver/xrt-lite/shim/linux/kmq/bo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<shared_handle> fence_handle::share_handle() const {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,7 @@ hw_ctx::hw_ctx(device &device, const std::vector<uint8_t> &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);
}
Expand Down
13 changes: 8 additions & 5 deletions runtime/src/iree-amd-aie/driver/xrt-lite/shim/linux/kmq/hwq.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

#include "hwq.h"

#include <sys/ioctl.h>

#include "bo.h"
#include "ert.h"
#include "fence.h"
Expand All @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "amdxdna_accel.h"
#include "bo.h"
#include "device.h"
#include "shim_debug.h"

#define MAX_EXEC_BO_SIZE 4096

Expand Down Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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(); }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
#include <memory>
#include <system_error>

#include "llvm/Support/ErrorHandling.h"

void debugf(const char *format, ...);

namespace shim_xdna {
Expand All @@ -19,18 +21,13 @@ template <typename... Args>
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<size_t>(sz);
std::unique_ptr<char[]> 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 <typename... Args>
Expand Down

0 comments on commit 09c2815

Please sign in to comment.