Skip to content

Commit

Permalink
Fix SysMan driver pointers given no sysman env and no zesInit (#193)
Browse files Browse the repository at this point in the history
- To gracefully allow calls to zes* apis without setting the env nor
  calling zesinit, the drivers need to be defaulted to the zeDrivers and
have the zes ddi tables always updated unless ze or zes handles have
already been retrieved.

Signed-off-by: Neil R. Spruit <[email protected]>
  • Loading branch information
nrspruit authored Sep 4, 2024
1 parent 0f1a1de commit e3152a8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
8 changes: 6 additions & 2 deletions source/lib/ze_lib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ namespace ze_lib
ze_lib::context->zesDdiTable.exchange(&ze_lib::context->initialzesDdiTable);
}

// Given zesInit, then zesDrivers needs to be used as the sysmanInstanceDrivers;
if (sysmanOnly) {
loader::context->sysmanInstanceDrivers = &loader::context->zesDrivers;
}

// Always call the inits for all the ddi tables before checking which drivers are usable to enable Instrumentation correctly.

// Init the ZE DDI Tables
Expand Down Expand Up @@ -109,7 +114,6 @@ namespace ze_lib
// Check which drivers support the ze_driver_flag_t specified
// No need to check if only initializing sysman
bool requireDdiReinit = false;
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 (requireDdiReinit) {
Expand All @@ -131,7 +135,7 @@ namespace ze_lib
loader::context->intercept_enabled = false;
}
// 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)) {
if (!(ze_lib::context->zesInuse || ze_lib::context->zeInuse)) {
// reInit the ZES DDI Tables
if( ZE_RESULT_SUCCESS == result )
{
Expand Down
7 changes: 2 additions & 5 deletions source/loader/ze_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -449,12 +449,9 @@ namespace loader
}

forceIntercept = getenv_tobool( "ZE_ENABLE_LOADER_INTERCEPT" );
auto sysmanEnv = getenv_tobool( "ZES_ENABLE_SYSMAN" );

sysmanInstanceDrivers = &zesDrivers;
if (sysmanEnv) {
sysmanInstanceDrivers = &zeDrivers;
}
// Default sysmanInstance Drivers to be the zeDrivers list unless zesInit is called during init.
sysmanInstanceDrivers = &zeDrivers;

if(forceIntercept || allDrivers.size() > 1){
intercept_enabled = true;
Expand Down

0 comments on commit e3152a8

Please sign in to comment.