diff --git a/scripts/templates/libapi.cpp.mako b/scripts/templates/libapi.cpp.mako index d0b377ee..f61ae4a0 100644 --- a/scripts/templates/libapi.cpp.mako +++ b/scripts/templates/libapi.cpp.mako @@ -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"]))} ); } diff --git a/source/lib/ze_lib.cpp b/source/lib/ze_lib.cpp index 2f93997b..1e4f755a 100644 --- a/source/lib/ze_lib.cpp +++ b/source/lib/ze_lib.cpp @@ -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 ) { @@ -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 ) { diff --git a/source/lib/ze_lib.h b/source/lib/ze_lib.h index c5fd487d..77f53c45 100644 --- a/source/lib/ze_lib.h +++ b/source/lib/ze_lib.h @@ -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; diff --git a/source/lib/ze_libapi.cpp b/source/lib/ze_libapi.cpp index d4d5bc76..fca47e35 100644 --- a/source/lib/ze_libapi.cpp +++ b/source/lib/ze_libapi.cpp @@ -125,6 +125,7 @@ zeDriverGet( else return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE; } + ze_lib::context->zeInuse = true; return pfnGet( pCount, phDrivers ); } diff --git a/source/lib/zes_libapi.cpp b/source/lib/zes_libapi.cpp index 522cd1ca..f3151164 100644 --- a/source/lib/zes_libapi.cpp +++ b/source/lib/zes_libapi.cpp @@ -120,6 +120,7 @@ zesDriverGet( else return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE; } + ze_lib::context->zesInuse = true; return pfnGet( pCount, phDrivers ); }