Skip to content

Commit

Permalink
Split Ze and Zes Drivers and only release drivers at close (#184)
Browse files Browse the repository at this point in the history
- to allow for different sets of drivers supporting sysman vs core we
  now have two sets of drivers tracked in the instance allowing for
sysman to access different sets of drivers than core and vice versa.

Signed-off-by: Neil R. Spruit <neil.r.spruit@intel.com>
  • Loading branch information
nrspruit committed Aug 26, 2024
1 parent cace28e commit cba2c7d
Show file tree
Hide file tree
Showing 9 changed files with 429 additions and 325 deletions.
37 changes: 31 additions & 6 deletions scripts/templates/ldrddi.cpp.mako
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,11 @@ namespace loader

%if re.match(r"Init", obj['name']):
bool atLeastOneDriverValid = false;
for( auto& drv : context->drivers )
%if namespace != "zes":
for( auto& drv : loader::context->zeDrivers )
%else:
for( auto& drv : *loader::context->sysmanInstanceDrivers )
%endif
{
if(drv.initStatus != ZE_RESULT_SUCCESS)
continue;
Expand All @@ -55,7 +59,11 @@ namespace loader
%elif re.match(r"\w+DriverGet$", th.make_func_name(n, tags, obj)):
uint32_t total_driver_handle_count = 0;

for( auto& drv : context->drivers )
%if namespace != "zes":
for( auto& drv : loader::context->zeDrivers )
%else:
for( auto& drv : *loader::context->sysmanInstanceDrivers )
%endif
{
if(drv.initStatus != ZE_RESULT_SUCCESS)
continue;
Expand Down Expand Up @@ -293,7 +301,12 @@ ${tbl['export']['name']}(
%endfor
)
{
if( loader::context->drivers.size() < 1 )
%if namespace != "zes":
if( loader::context->zeDrivers.size() < 1 )
%else:
if( loader::context->sysmanInstanceDrivers->size() < 1 )
%endif

return ${X}_RESULT_ERROR_UNINITIALIZED;

if( nullptr == pDdiTable )
Expand All @@ -308,7 +321,11 @@ ${tbl['export']['name']}(
bool atLeastOneDriverValid = false;
%endif
// Load the device-driver DDI tables
for( auto& drv : loader::context->drivers )
%if namespace != "zes":
for( auto& drv : loader::context->zeDrivers )
%else:
for( auto& drv : *loader::context->sysmanInstanceDrivers )
%endif
{
if(drv.initStatus != ZE_RESULT_SUCCESS)
continue;
Expand Down Expand Up @@ -344,7 +361,11 @@ ${tbl['export']['name']}(

if( ${X}_RESULT_SUCCESS == result )
{
if( ( loader::context->drivers.size() > 1 ) || loader::context->forceIntercept )
%if namespace != "zes":
if( ( loader::context->zeDrivers.size() > 1 ) || loader::context->forceIntercept )
%else:
if( ( loader::context->sysmanInstanceDrivers->size() > 1 ) || loader::context->forceIntercept )
%endif
{
// return pointers to loader's DDIs
%for obj in tbl['functions']:
Expand All @@ -362,7 +383,11 @@ ${tbl['export']['name']}(
else
{
// return pointers directly to driver's DDIs
*pDdiTable = loader::context->drivers.front().dditable.${n}.${tbl['name']};
%if namespace != "zes":
*pDdiTable = loader::context->zeDrivers.front().dditable.${n}.${tbl['name']};
%else:
*pDdiTable = loader::context->sysmanInstanceDrivers->front().dditable.${n}.${tbl['name']};
%endif
}
}

Expand Down
35 changes: 19 additions & 16 deletions source/lib/ze_lib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,34 +104,37 @@ namespace ze_lib
// End DDI Table Inits

// Check which drivers and layers can be init on this system.
// If the driver check has already been called by zesInit or zeinit, then this is skipped.
if( ZE_RESULT_SUCCESS == result && !driverCheckCompleted)
if( ZE_RESULT_SUCCESS == result)
{
// 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 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) {
// reInit the ZE DDI Tables
if( ZE_RESULT_SUCCESS == result )
{
result = zeDdiTableInit();
if (!sysmanOnly) {
// reInit the ZE DDI Tables
if( ZE_RESULT_SUCCESS == result )
{
result = zeDdiTableInit();
}
// reInit the ZET DDI Tables
if( ZE_RESULT_SUCCESS == result )
{
result = zetDdiTableInit();
}
}
// reInit the ZET DDI Tables
if( ZE_RESULT_SUCCESS == result )
{
result = zetDdiTableInit();
}
// reInit the ZES DDI Tables
if( ZE_RESULT_SUCCESS == result )
{
result = zesDdiTableInit();
if (sysmanOnly || sysmanEnv) {
// reInit the ZES DDI Tables
if( ZE_RESULT_SUCCESS == result )
{
result = zesDdiTableInit();
}
}
}
driverCheckCompleted = true;
}

if( ZE_RESULT_SUCCESS == result )
Expand Down
1 change: 0 additions & 1 deletion source/lib/ze_lib.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ namespace ze_lib

std::once_flag initOnce;
std::once_flag initOnceSysMan;
bool driverCheckCompleted = false;

ze_result_t Init(ze_init_flags_t flags, bool sysmanOnly);

Expand Down
Loading

0 comments on commit cba2c7d

Please sign in to comment.