Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions scripts/templates/libapi.cpp.mako
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ ${th.make_func_name(n, tags, obj)}(
{
%if re.match("Init", obj['name']):
%if re.match("zes", n):
#ifdef DYNAMIC_LOAD_LOADER
#ifdef L0_STATIC_LOADER_BUILD
if (!${x}_lib::context) {
${x}_lib::context = new ${x}_lib::context_t;
}
Expand Down Expand Up @@ -87,7 +87,7 @@ ${th.make_func_name(n, tags, obj)}(
%else:
%if re.match("InitDrivers", obj['name']):
${x}_result_t result = ${X}_RESULT_SUCCESS;
#ifdef DYNAMIC_LOAD_LOADER
#ifdef L0_STATIC_LOADER_BUILD
if (!${x}_lib::context) {
${x}_lib::context = new ${x}_lib::context_t;
}
Expand Down Expand Up @@ -124,7 +124,7 @@ ${th.make_func_name(n, tags, obj)}(
return result;
%else:
static ${x}_result_t result = ${X}_RESULT_SUCCESS;
#ifdef DYNAMIC_LOAD_LOADER
#ifdef L0_STATIC_LOADER_BUILD
if (!${x}_lib::context) {
${x}_lib::context = new ${x}_lib::context_t;
}
Expand Down Expand Up @@ -160,7 +160,7 @@ ${th.make_func_name(n, tags, obj)}(
}
%endif
%else:
#ifdef DYNAMIC_LOAD_LOADER
#ifdef L0_STATIC_LOADER_BUILD
ze_result_t result = ${X}_RESULT_SUCCESS;
if(ze_lib::destruction) {
return ${X}_RESULT_ERROR_UNINITIALIZED;
Expand Down
4 changes: 2 additions & 2 deletions scripts/templates/libddi.cpp.mako
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ from templates import helper as th
*
*/
#include "${x}_lib.h"
#ifndef DYNAMIC_LOAD_LOADER
#ifndef L0_STATIC_LOADER_BUILD
#include "${n}_ddi.h"
#endif

namespace ${x}_lib
{
///////////////////////////////////////////////////////////////////////////////

#ifdef DYNAMIC_LOAD_LOADER
#ifdef L0_STATIC_LOADER_BUILD
__zedlllocal ${x}_result_t context_t::${n}DdiTableInit(ze_api_version_t version)
{
${x}_result_t result = ${X}_RESULT_SUCCESS;
Expand Down
2 changes: 1 addition & 1 deletion source/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ if (BUILD_STATIC)
""
${CMAKE_CURRENT_BINARY_DIR}/ZeLoaderVersion.rc
)
add_definitions(-DDYNAMIC_LOAD_LOADER="1")
add_definitions(-DL0_STATIC_LOADER_BUILD="1")
else()
message(STATUS "Building loader as dynamic library")
add_library(${TARGET_LOADER_NAME}
Expand Down
2 changes: 1 addition & 1 deletion source/lib/linux/lib_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

namespace ze_lib
{
#ifndef DYNAMIC_LOAD_LOADER
#ifndef L0_STATIC_LOADER_BUILD
void __attribute__((constructor)) createLibContext() {
context = new context_t;
}
Expand Down
4 changes: 2 additions & 2 deletions source/lib/windows/lib_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
*/

#include "../ze_lib.h"
#ifndef DYNAMIC_LOAD_LOADER
#ifndef L0_STATIC_LOADER_BUILD
#include "../loader/ze_loader_internal.h"
#endif

namespace ze_lib
{
#ifndef DYNAMIC_LOAD_LOADER
#ifndef L0_STATIC_LOADER_BUILD
extern "C" BOOL APIENTRY DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) {
if (fdwReason == DLL_PROCESS_DETACH) {
delete context;
Expand Down
30 changes: 15 additions & 15 deletions source/lib/ze_lib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace ze_lib
{
///////////////////////////////////////////////////////////////////////////////
context_t *context = nullptr;
#ifdef DYNAMIC_LOAD_LOADER
#ifdef L0_STATIC_LOADER_BUILD
void context_at_exit_destructor()
{
if (ze_lib::context) {
Expand Down Expand Up @@ -69,7 +69,7 @@ namespace ze_lib
///////////////////////////////////////////////////////////////////////////////
__zedlllocal context_t::~context_t()
{
#ifdef DYNAMIC_LOAD_LOADER
#ifdef L0_STATIC_LOADER_BUILD
if (loaderTeardownRegistrationEnabled && !loaderTeardownCallbackReceived) {
loaderTeardownCallback(loaderTeardownCallbackIndex);
}
Expand All @@ -92,7 +92,7 @@ namespace ze_lib
{
ze_result_t result;
ze_api_version_t version = ZE_API_VERSION_CURRENT;
#ifdef DYNAMIC_LOAD_LOADER
#ifdef L0_STATIC_LOADER_BUILD
std::string loaderLibraryPath;
auto loaderLibraryPathEnv = getenv_string("ZEL_LIBRARY_PATH");
if (!loaderLibraryPathEnv.empty()) {
Expand Down Expand Up @@ -213,7 +213,7 @@ namespace ze_lib

// Given zesInit, then zesDrivers needs to be used as the sysmanInstanceDrivers;
bool loaderContextAccessAllowed = true;
#ifdef DYNAMIC_LOAD_LOADER
#ifdef L0_STATIC_LOADER_BUILD
loaderContextAccessAllowed = false;
loader::context_t *loaderContext = nullptr;
#else
Expand Down Expand Up @@ -264,7 +264,7 @@ namespace ze_lib
// Init the stored ddi tables for the tracing layer
if( ZE_RESULT_SUCCESS == result )
{
#ifdef DYNAMIC_LOAD_LOADER
#ifdef L0_STATIC_LOADER_BUILD
if (loaderTracingLayerInit) {
result = loaderTracingLayerInit(this->pTracingZeDdiTable);
}
Expand All @@ -280,7 +280,7 @@ namespace ze_lib
// Check which drivers support the ze_driver_flag_t specified
// No need to check if only initializing sysman
bool requireDdiReinit = false;
#ifdef DYNAMIC_LOAD_LOADER
#ifdef L0_STATIC_LOADER_BUILD
if (zeInitDriversSupport) {
typedef ze_result_t (ZE_APICALL *zelLoaderDriverCheck_t)(ze_init_flags_t flags, ze_init_driver_type_desc_t* desc, ze_global_dditable_t *globalInitStored, zes_global_dditable_t *sysmanGlobalInitStored, bool *requireDdiReinit, bool sysmanOnly);
auto loaderDriverCheck = reinterpret_cast<zelLoaderDriverCheck_t>(
Expand Down Expand Up @@ -341,7 +341,7 @@ namespace ze_lib

if( ZE_RESULT_SUCCESS == result )
{
#ifdef DYNAMIC_LOAD_LOADER
#ifdef L0_STATIC_LOADER_BUILD
// Init Dynamic Loader's Lib Context:
auto initDriversLoader = reinterpret_cast<ze_pfnInitDrivers_t>(
GET_FUNCTION_PTR(loader, "zeInitDrivers") );
Expand Down Expand Up @@ -378,7 +378,7 @@ namespace ze_lib
#endif
isInitialized = true;
}
#ifdef DYNAMIC_LOAD_LOADER
#ifdef L0_STATIC_LOADER_BUILD
std::call_once(ze_lib::context->initTeardownCallbacksOnce, [this]() {
if (!delayContextDestruction) {
std::atexit(context_at_exit_destructor);
Expand Down Expand Up @@ -416,7 +416,7 @@ zelLoaderGetVersions(
size_t *num_elems, //Pointer to num versions to get.
zel_component_version_t *versions) //Pointer to array of versions. If set to NULL, num_elems is returned
{
#ifdef DYNAMIC_LOAD_LOADER
#ifdef L0_STATIC_LOADER_BUILD
if(nullptr == ze_lib::context->loader)
return ZE_RESULT_ERROR_UNINITIALIZED;
typedef ze_result_t (ZE_APICALL *zelLoaderGetVersions_t)(size_t *num_elems, zel_component_version_t *versions);
Expand All @@ -436,7 +436,7 @@ zelLoaderTranslateHandle(
void **handleOut)

{
#ifdef DYNAMIC_LOAD_LOADER
#ifdef L0_STATIC_LOADER_BUILD
if(nullptr == ze_lib::context->loader)
return ZE_RESULT_ERROR_UNINITIALIZED;
typedef ze_result_t (ZE_APICALL *zelLoaderTranslateHandleInternal_t)(zel_handle_type_t handleType, void *handleIn, void **handleOut);
Expand Down Expand Up @@ -470,7 +470,7 @@ zelSetDriverTeardown()
void ZE_APICALL
zelSetDelayLoaderContextTeardown()
{
#ifdef DYNAMIC_LOAD_LOADER
#ifdef L0_STATIC_LOADER_BUILD
if (!ze_lib::delayContextDestruction) {
ze_lib::delayContextDestruction = true;
}
Expand Down Expand Up @@ -539,7 +539,7 @@ zelCheckIsLoaderInTearDown() {
if (ze_lib::destruction || ze_lib::context == nullptr) {
return true;
}
#if defined(DYNAMIC_LOAD_LOADER) && defined(_WIN32)
#if defined(L0_STATIC_LOADER_BUILD) && defined(_WIN32)
static bool loaderIsStable = true;
if (!loaderIsStable) {
if (ze_lib::context->debugTraceEnabled) {
Expand Down Expand Up @@ -594,7 +594,7 @@ zelCheckIsLoaderInTearDown() {
void ZE_APICALL
zelLoaderContextTeardown()
{
#ifdef DYNAMIC_LOAD_LOADER
#ifdef L0_STATIC_LOADER_BUILD
if (ze_lib::delayContextDestruction && ze_lib::context) {
delete ze_lib::context;
ze_lib::context = nullptr;
Expand All @@ -605,7 +605,7 @@ zelLoaderContextTeardown()
ze_result_t ZE_APICALL
zelEnableTracingLayer()
{
#ifdef DYNAMIC_LOAD_LOADER
#ifdef L0_STATIC_LOADER_BUILD
if(nullptr == ze_lib::context->loader)
return ZE_RESULT_ERROR_UNINITIALIZED;
typedef ze_result_t (ZE_APICALL *zelEnableTracingLayerInternal_t)();
Expand All @@ -626,7 +626,7 @@ zelEnableTracingLayer()
ze_result_t ZE_APICALL
zelDisableTracingLayer()
{
#ifdef DYNAMIC_LOAD_LOADER
#ifdef L0_STATIC_LOADER_BUILD
if(nullptr == ze_lib::context->loader)
return ZE_RESULT_ERROR_UNINITIALIZED;
typedef ze_result_t (ZE_APICALL *zelDisableTracingLayerInternal_t)();
Expand Down
6 changes: 3 additions & 3 deletions source/lib/ze_lib.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ namespace ze_lib
class __zedlllocal context_t
{
public:
#ifdef DYNAMIC_LOAD_LOADER
#ifdef L0_STATIC_LOADER_BUILD
HMODULE loader = nullptr;
#endif

Expand Down Expand Up @@ -179,7 +179,7 @@ namespace ze_lib
std::atomic<uint32_t> teardownCallbacksCount{0};
std::map<uint32_t, zel_loader_teardown_callback_t> teardownCallbacks;
std::mutex teardownCallbacksMutex;
#ifdef DYNAMIC_LOAD_LOADER
#ifdef L0_STATIC_LOADER_BUILD
std::once_flag initTeardownCallbacksOnce;
zel_application_teardown_callback_t loaderTeardownCallback = nullptr;
uint32_t loaderTeardownCallbackIndex = 0;
Expand All @@ -188,7 +188,7 @@ namespace ze_lib

extern bool destruction;
extern context_t *context;
#ifdef DYNAMIC_LOAD_LOADER
#ifdef L0_STATIC_LOADER_BUILD
extern bool delayContextDestruction;
extern bool loaderTeardownCallbackReceived;
extern bool loaderTeardownRegistrationEnabled;
Expand Down
Loading
Loading