Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent reinit when zes/ze handles have already been retrieved #192

Merged
merged 1 commit into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions scripts/templates/libapi.cpp.mako
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,9 @@ ${th.make_func_name(n, tags, obj)}(
else
return ${X}_RESULT_ERROR_UNSUPPORTED_FEATURE;
}
%if re.match(r"\w+DriverGet$", th.make_func_name(n, tags, obj)):
ze_lib::context->${n}Inuse = true;
%endif

return ${th.make_pfn_name(n, tags, obj)}( ${", ".join(th.make_param_lines(n, tags, obj, format=["name"]))} );
}
Expand Down
10 changes: 5 additions & 5 deletions source/lib/ze_lib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,9 @@ namespace ze_lib
auto sysmanEnv = getenv_tobool( "ZES_ENABLE_SYSMAN" );
result = zelLoaderDriverCheck(flags, &ze_lib::context->initialzeDdiTable.Global, &ze_lib::context->initialzesDdiTable.Global, &requireDdiReinit, sysmanOnly);
// If a driver was removed from the driver list, then the ddi tables need to be reinit to allow for passthru directly to the driver.
// If ZET_ENABLE_PROGRAM_INSTRUMENTATION is enabled, then reInit is not possible due to the functions being intercepted with the previous ddi tables.
auto programInstrumentationEnabled = getenv_tobool( "ZET_ENABLE_PROGRAM_INSTRUMENTATION" );
if (requireDdiReinit && !programInstrumentationEnabled) {
if (!sysmanOnly) {
if (requireDdiReinit) {
// If a user has already called the core apis, then ddi table reinit is not possible due to handles already being read by the user.
if (!sysmanOnly && !ze_lib::context->zeInuse) {
// reInit the ZE DDI Tables
if( ZE_RESULT_SUCCESS == result )
{
Expand All @@ -131,7 +130,8 @@ namespace ze_lib
// Translation is only required if the intercept layer is enabled for the ZE handle types.
loader::context->intercept_enabled = false;
}
if (sysmanOnly || sysmanEnv) {
// If a user has already called the zes/ze apis, then ddi table reinit is not possible due to handles already being read by the user.
if ((sysmanOnly || sysmanEnv) && !(ze_lib::context->zesInuse || ze_lib::context->zeInuse)) {
// reInit the ZES DDI Tables
if( ZE_RESULT_SUCCESS == result )
{
Expand Down
2 changes: 2 additions & 0 deletions source/lib/ze_lib.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ namespace ze_lib
HMODULE tracing_lib = nullptr;
bool isInitialized = false;
bool inTeardown = false;
bool zesInuse = false;
bool zeInuse = false;
};

extern context_t *context;
Expand Down
1 change: 1 addition & 0 deletions source/lib/ze_libapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ zeDriverGet(
else
return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE;
}
ze_lib::context->zeInuse = true;

return pfnGet( pCount, phDrivers );
}
Expand Down
1 change: 1 addition & 0 deletions source/lib/zes_libapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ zesDriverGet(
else
return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE;
}
ze_lib::context->zesInuse = true;

return pfnGet( pCount, phDrivers );
}
Expand Down
Loading