Skip to content

Commit

Permalink
Prevent reinit when zes/ze handles have already been retrieved (#192)
Browse files Browse the repository at this point in the history
- Given ze or zes driver get has been called, then one cannot allow for
  the ddi table to be reinit to avoid breaking the user's existing
handles.

Signed-off-by: Neil R. Spruit <neil.r.spruit@intel.com>
  • Loading branch information
nrspruit authored Sep 4, 2024
1 parent 519eed2 commit 0f1a1de
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 5 deletions.
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

0 comments on commit 0f1a1de

Please sign in to comment.