Skip to content

Commit 581a0d8

Browse files
committed
Add a workaround for the logger on windows
1 parent eeaa897 commit 581a0d8

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

source/adapters/level_zero/adapter.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,12 @@ ur_adapter_handle_t_ *GlobalAdapter = new ur_adapter_handle_t_();
2727
#else
2828
ur_adapter_handle_t_ *GlobalAdapter;
2929
#endif
30-
30+
// This is a temporary workaround on windows, where UR adapter is teardowned
31+
// before the UR loader, which will result in access violation when we use print
32+
// function as the overrided print function was already released with the UR
33+
// adapter.
34+
// TODO: Change adapters to use a common sink class in the loader instead of
35+
// using thier own sink class that inherit from logger::Sink.
3136
class ur_legacy_sink : public logger::Sink {
3237
public:
3338
ur_legacy_sink(std::string logger_name = "", bool skip_prefix = true)
@@ -40,7 +45,11 @@ class ur_legacy_sink : public logger::Sink {
4045
fprintf(stderr, "%s", msg.c_str());
4146
}
4247

43-
~ur_legacy_sink() = default;
48+
~ur_legacy_sink() {
49+
#if defined(_WIN32)
50+
logger::isTearDowned = true;
51+
#endif
52+
};
4453
};
4554

4655
ur_result_t initPlatforms(PlatformVec &platforms) noexcept try {

source/common/logger/ur_sinks.hpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717

1818
namespace logger {
1919

20+
#if defined(_WIN32)
21+
inline bool isTearDowned = false;
22+
#endif
23+
2024
class Sink {
2125
public:
2226
template <typename... Args>
@@ -28,7 +32,21 @@ class Sink {
2832
}
2933

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

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

0 commit comments

Comments
 (0)