Skip to content

Commit 106fa9a

Browse files
committed
[Loader] Supress system errors when loading adapters on Windows.
1 parent d50a59e commit 106fa9a

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

source/loader/ur_loader.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,18 @@ context_t *getContext() { return context_t::get_direct(); }
1515

1616
///////////////////////////////////////////////////////////////////////////////
1717
ur_result_t context_t::init() {
18+
#ifdef _WIN32
19+
// Suppress system errors.
20+
// Tells the system to not display the critical-error-handler message box.
21+
// Instead, the system sends the error to the calling process.
22+
// This is crucial for graceful handling of plugins that couldn't be
23+
// loaded, e.g. due to missing native run-times.
24+
// Sometimes affects L0 or the unified runtime.
25+
// TODO: add reporting in case of an error.
26+
// NOTE: we restore the old mode to not affect user app behavior.
27+
// See https://github.com/intel/llvm/blob/sycl/sycl/ur_win_proxy_loader/ur_win_proxy_loader.cpp (preloadLibraries())
28+
UINT SavedMode = SetErrorMode(SEM_FAILCRITICALERRORS);
29+
#endif
1830
for (const auto &adapterPaths : adapter_registry) {
1931
for (const auto &path : adapterPaths) {
2032
auto handle = LibLoader::loadAdapterLibrary(path.string().c_str());
@@ -24,6 +36,10 @@ ur_result_t context_t::init() {
2436
}
2537
}
2638
}
39+
#ifdef _WIN32
40+
// Restore system error handling.
41+
(void)SetErrorMode(SavedMode);
42+
#endif
2743

2844
forceIntercept = getenv_tobool("UR_ENABLE_LOADER_INTERCEPT");
2945

0 commit comments

Comments
 (0)