Skip to content

Commit eeaa897

Browse files
committed
Add umfInit/umfTearDown to urAdapterGet/urAdapterRelease
1 parent 608e918 commit eeaa897

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

source/adapters/level_zero/adapter.cpp

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@
1212
#include "ur_level_zero.hpp"
1313
#include <iomanip>
1414

15+
// As windows order of unloading dlls is reversed from linux, windows will call
16+
// umfTearDown before it could release umf objects in level_zero, so we call
17+
// umfInit on urAdapterGet and umfAdapterTearDown to enforce the teardown of umf
18+
// after umf objects are destructed.
19+
#if defined(_WIN32)
20+
#include <umf.h>
21+
#endif
22+
1523
// Due to multiple DLLMain definitions with SYCL, Global Adapter is init at
1624
// variable creation.
1725
#if defined(_WIN32)
@@ -74,7 +82,14 @@ ur_result_t initPlatforms(PlatformVec &platforms) noexcept try {
7482
return exceptionToResult(std::current_exception());
7583
}
7684

77-
ur_result_t adapterStateInit() { return UR_RESULT_SUCCESS; }
85+
ur_result_t adapterStateInit() {
86+
87+
#if defined(_WIN32)
88+
umfInit();
89+
#endif
90+
91+
return UR_RESULT_SUCCESS;
92+
}
7893

7994
ur_adapter_handle_t_::ur_adapter_handle_t_()
8095
: logger(logger::get_logger("level_zero")) {
@@ -258,6 +273,7 @@ ur_result_t adapterStateTeardown() {
258273
// Due to multiple DLLMain definitions with SYCL, register to cleanup the
259274
// Global Adapter after refcnt is 0
260275
#if defined(_WIN32)
276+
umfTearDown();
261277
std::atexit(globalAdapterOnDemandCleanup);
262278
#endif
263279

0 commit comments

Comments
 (0)