Skip to content

Commit fe0d8a5

Browse files
committed
Delay L0 loader destruction and fix ZeCommandListImmediateAppendExt init
Signed-off-by: Neil R. Spruit <[email protected]>
1 parent 076dc68 commit fe0d8a5

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

unified-runtime/cmake/FetchLevelZero.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ if (NOT DEFINED LEVEL_ZERO_LIBRARY OR NOT DEFINED LEVEL_ZERO_INCLUDE_DIR)
4343
set(UR_LEVEL_ZERO_LOADER_REPO "https://github.com/oneapi-src/level-zero.git")
4444
endif()
4545
if (UR_LEVEL_ZERO_LOADER_TAG STREQUAL "")
46-
set(UR_LEVEL_ZERO_LOADER_TAG c4892da92dab13a2d276a18975f9fff4268c2daf)
46+
set(UR_LEVEL_ZERO_LOADER_TAG v1.21.1)
4747
endif()
4848

4949
# Disable due to a bug https://github.com/oneapi-src/level-zero/issues/104

unified-runtime/source/adapters/level_zero/adapter.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,12 @@ ur_adapter_handle_t_::ur_adapter_handle_t_()
300300
ZeInitResult = ZE_RESULT_ERROR_UNINITIALIZED;
301301
ZesResult = ZE_RESULT_ERROR_UNINITIALIZED;
302302

303+
#ifdef UR_STATIC_LEVEL_ZERO
304+
// Given static linking of the L0 Loader, we must delay the loader's
305+
// destruction of its context until after the UR Adapter is destroyed.
306+
zelSetDelayLoaderContextTeardown();
307+
#endif
308+
303309
if (UrL0Debug & UR_L0_DEBUG_BASIC) {
304310
logger.setLegacySink(std::make_unique<ur_legacy_sink>());
305311
};
@@ -672,7 +678,13 @@ ur_result_t urAdapterRelease(ur_adapter_handle_t) {
672678
if (GlobalAdapter) {
673679
std::lock_guard<std::mutex> Lock{GlobalAdapter->Mutex};
674680
if (--GlobalAdapter->RefCount == 0) {
675-
return adapterStateTeardown();
681+
auto result = adapterStateTeardown();
682+
#ifdef UR_STATIC_LEVEL_ZERO
683+
// Given static linking of the L0 Loader, we must delay the loader's
684+
// destruction of its context until after the UR Adapter is destroyed.
685+
zelLoaderContextTeardown();
686+
#endif
687+
return result;
676688
}
677689
}
678690

unified-runtime/source/adapters/level_zero/platform.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,12 +470,18 @@ ur_result_t ur_platform_handle_t_::initialize() {
470470
// Check if ImmediateAppendCommandList is supported and initialize the
471471
// function pointer.
472472
if (ZeImmediateCommandListAppendExtensionFound) {
473+
#ifdef UR_STATIC_LEVEL_ZERO
474+
ZeCommandListImmediateAppendExt
475+
.zeCommandListImmediateAppendCommandListsExp =
476+
zeCommandListImmediateAppendCommandListsExp;
477+
#else
473478
ZeCommandListImmediateAppendExt
474479
.zeCommandListImmediateAppendCommandListsExp =
475480
(ze_pfnCommandListImmediateAppendCommandListsExp_t)
476481
ur_loader::LibLoader::getFunctionPtr(
477482
GlobalAdapter->processHandle,
478483
"zeCommandListImmediateAppendCommandListsExp");
484+
#endif
479485
ZeCommandListImmediateAppendExt.Supported =
480486
ZeCommandListImmediateAppendExt
481487
.zeCommandListImmediateAppendCommandListsExp != nullptr;

0 commit comments

Comments
 (0)