Skip to content

Commit

Permalink
Add a workaround for the logger on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
omarahmed1111 committed Aug 27, 2024
1 parent 6c1617d commit 40e68b8
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
13 changes: 11 additions & 2 deletions source/adapters/level_zero/adapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,12 @@ ur_adapter_handle_t_ *GlobalAdapter = new ur_adapter_handle_t_();
#else
ur_adapter_handle_t_ *GlobalAdapter;
#endif

// This is a temporary workaround on windows, where UR adapter is teardowned
// before the UR loader, which will result in access violation when we use print
// function as the overrided print function was already released with the UR
// adapter.
// TODO: Change adapters to use a common sink class in the loader instead of
// using thier own sink class that inherit from logger::Sink.
class ur_legacy_sink : public logger::Sink {
public:
ur_legacy_sink(std::string logger_name = "", bool skip_prefix = true)
Expand All @@ -40,7 +45,11 @@ class ur_legacy_sink : public logger::Sink {
fprintf(stderr, "%s", msg.c_str());
}

~ur_legacy_sink() = default;
~ur_legacy_sink() {
#if defined(_WIN32)
logger::isTearDowned = true;
#endif
};
};

ur_result_t initPlatforms(PlatformVec &platforms) noexcept try {
Expand Down
18 changes: 18 additions & 0 deletions source/common/logger/ur_sinks.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@

namespace logger {

#if defined(_WIN32)
inline bool isTearDowned = false;
#endif

class Sink {
public:
template <typename... Args>
Expand All @@ -28,7 +32,21 @@ class Sink {
}

format(buffer, fmt, std::forward<Args &&>(args)...);
// This is a temporary workaround on windows, where UR adapter is teardowned
// before the UR loader, which will result in access violation when we use print
// function as the overrided print function was already released with the UR
// adapter.
// TODO: Change adapters to use a common sink class in the loader instead of
// using thier own sink class that inherit from logger::Sink.
#if defined(_WIN32)
if (isTearDowned) {
std::cerr << buffer.str() << "\n";
} else {
print(level, buffer.str());
}
#else
print(level, buffer.str());
#endif
}

void setFlushLevel(logger::Level level) { this->flush_level = level; }
Expand Down

0 comments on commit 40e68b8

Please sign in to comment.