Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions unified-runtime/source/adapters/level_zero/v2/memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ void ur_integrated_buffer_handle_t::copyBackToHostIfNeeded() {
if (result2 == UR_RESULT_SUCCESS) {
writeBackPtr = nullptr;
} else {
UR_LOG(ERR, "Failed to copy-back buffer data: {}", result2);
UR_LOG_SAFE(ERR, "Failed to copy-back buffer data: {}", result2);
}
}
}
Expand Down Expand Up @@ -326,8 +326,11 @@ ur_discrete_buffer_handle_t::~ur_discrete_buffer_handle_t() {
return;

auto srcPtr = getActiveDeviceAlloc();
synchronousZeCopy(hContext, activeAllocationDevice, writeBackPtr, srcPtr,
getSize());
auto ret = synchronousZeCopy(hContext, activeAllocationDevice, writeBackPtr,
srcPtr, getSize());
if (ret != UR_RESULT_SUCCESS) {
UR_LOG_SAFE(ERR, "Failed to copy-back buffer data: {}", ret);
}
}

void *ur_discrete_buffer_handle_t::getActiveDeviceAlloc(size_t offset) {
Expand Down
12 changes: 12 additions & 0 deletions unified-runtime/source/common/logger/ur_logger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,18 @@ inline void init(const std::string &name) { get_logger(name.c_str()); }
URLOG_L_(::logger::get_logger(), level, legacy_message, __VA_ARGS__)
#define UR_LOG_L(logger, level, ...) URLOG_(logger, level, __VA_ARGS__)

// safe version of UR_LOG that catches exceptions from the logger
#define UR_LOG_SAFE(level, ...) \
{ \
try { \
UR_LOG(level, __VA_ARGS__); \
} catch (const std::exception &e) { \
std::fprintf(stderr, "Error during logging: %s\n", e.what()); \
} catch (...) { \
std::fprintf(stderr, "Unknown error during logging\n"); \
} \
}

inline void setLevel(ur_logger_level_t level) { get_logger().setLevel(level); }

inline void setFlushLevel(ur_logger_level_t level) {
Expand Down
Loading