Skip to content

Commit 8e8324c

Browse files
authored
[UR][L0] Fixed issue where L0 Adapters unused were not calling teardown (#20642)
- L0 Static Loader "requires" teardown to be called before the adapter library exits otherwise the loader may call into the adapter during teardown to an invalid address. The "skipping" of L0 adapters failed to call the L0 teardown api required, which results in sporadic calls to invalid memory during teardown. - Added a function such that when an adapter is skipped, then the adapter calls the Loader teardown given static loader compile. Signed-off-by: Neil R. Spruit <[email protected]>
1 parent d10b37e commit 8e8324c

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,14 @@ static bool isBMGorNewer() {
288288
return urResult == UR_RESULT_SUCCESS;
289289
}
290290

291+
static void releaseStaticLoaderResourcesIfNeeded() {
292+
#ifdef UR_STATIC_LEVEL_ZERO
293+
// Given static linking of the L0 Loader, we must release the static loader
294+
// resources if the adapter is not used.
295+
zelLoaderContextTeardown();
296+
#endif
297+
}
298+
291299
// returns a pair indicating whether to use the V1 adapter and a string
292300
// indicating the reason for the decision.
293301
static std::pair<bool, std::string> shouldUseV1Adapter() {
@@ -525,12 +533,14 @@ ur_adapter_handle_t_::ur_adapter_handle_t_()
525533
auto [useV2, reason] = shouldUseV2Adapter();
526534
if (!useV2) {
527535
UR_LOG(INFO, "Skipping L0 V2 adapter: {}", reason);
536+
releaseStaticLoaderResourcesIfNeeded();
528537
return;
529538
}
530539
#else
531540
auto [useV1, reason] = shouldUseV1Adapter();
532541
if (!useV1) {
533542
UR_LOG(INFO, "Skipping L0 V1 adapter: {}", reason);
543+
releaseStaticLoaderResourcesIfNeeded();
534544
return;
535545
}
536546
#endif

0 commit comments

Comments
 (0)