File tree Expand file tree Collapse file tree 2 files changed +29
-2
lines changed Expand file tree Collapse file tree 2 files changed +29
-2
lines changed Original file line number Diff line number Diff line change @@ -27,7 +27,12 @@ ur_adapter_handle_t_ *GlobalAdapter = new ur_adapter_handle_t_();
2727#else
2828ur_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.
3136class ur_legacy_sink : public logger ::Sink {
3237public:
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
4655ur_result_t initPlatforms (PlatformVec &platforms) noexcept try {
Original file line number Diff line number Diff line change 1717
1818namespace logger {
1919
20+ #if defined(_WIN32)
21+ inline bool isTearDowned = false ;
22+ #endif
23+
2024class 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; }
You can’t perform that action at this time.
0 commit comments