Skip to content

Commit

Permalink
Fix layer init with multiple drivers and ensure init for instrumentat…
Browse files Browse the repository at this point in the history
…ion support

-Fix potential race condition when initializing the layers
 with multiple drivers by verifying the usable drivers and layers
 before init of the final ddi tables.
-Document the reasons for requiring ddi table init before driver init
 checks can be done.

Signed-off-by: Neil R. Spruit <[email protected]>
  • Loading branch information
nrspruit committed Jun 28, 2024
1 parent 07527e6 commit af648e1
Showing 1 changed file with 21 additions and 13 deletions.
34 changes: 21 additions & 13 deletions source/lib/ze_lib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,40 +74,48 @@ namespace ze_lib
ze_lib::context->zesDdiTable.exchange(&ze_lib::context->initialzesDdiTable);
}

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

// Check which drivers and layers are functional by checking which can be loaded.
// This check needs to be done before all inits to avoid overwriting the layer ddi table pointers.
if( ZE_RESULT_SUCCESS == result && !sysmanOnly)
{
//Check which drivers support the ze_driver_flag_t specified
//No need to check if only initializing sysman
result = zelLoaderDriverCheck(flags);
}

// Init the ZE DDI Tables
if( ZE_RESULT_SUCCESS == result )
{
result = zeInit();
}

// Init the ZET DDI Tables
if( ZE_RESULT_SUCCESS == result )
{
result = zetInit();
}

// Init the ZES DDI Tables
if( ZE_RESULT_SUCCESS == result )
{
result = zesInit();
}

// Init the Tracing API DDI Tables
if( ZE_RESULT_SUCCESS == result )
{
result = zelTracingInit();
}

// Init the stored ddi tables for the tracing layer
if( ZE_RESULT_SUCCESS == result )
{
result = zelLoaderTracingLayerInit(this->pTracingZeDdiTable, this->pTracingZetDdiTable, this->pTracingZesDdiTable);
}
// End DDI Table Inits

// Check which drivers and layers can be init on this system.
if( ZE_RESULT_SUCCESS == result && !sysmanOnly)
{
// Check which drivers support the ze_driver_flag_t specified
// No need to check if only initializing sysman
result = zelLoaderDriverCheck(flags);
// reInit the ze ddi tables after verifying the zeInit() with dummy tables.
// This ensures the tracing and validation layers are pointing to the correct function pointers after init.
if( ZE_RESULT_SUCCESS == result )
{
result = zeInit();
}
}

if( ZE_RESULT_SUCCESS == result )
{
Expand Down

0 comments on commit af648e1

Please sign in to comment.