diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt index 458546d6..92cc7734 100644 --- a/source/CMakeLists.txt +++ b/source/CMakeLists.txt @@ -12,7 +12,7 @@ configure_file( @ONLY) include(GNUInstallDirs) -if (DYNAMIC_LOAD_LOADER) +if (BUILD_STATIC) message(STATUS "Building loader as static library") add_library(${TARGET_LOADER_NAME} STATIC diff --git a/source/lib/linux/lib_init.cpp b/source/lib/linux/lib_init.cpp index 66500f26..399736c7 100644 --- a/source/lib/linux/lib_init.cpp +++ b/source/lib/linux/lib_init.cpp @@ -12,11 +12,9 @@ namespace ze_lib { #ifndef DYNAMIC_LOAD_LOADER void __attribute__((constructor)) createLibContext() { - printf("Context created context lib dynamic\n"); context = new context_t; } void __attribute__((destructor)) deleteLibContext() { - printf("Context destroyed context lib dynamic\n"); delete context; } #endif diff --git a/source/lib/ze_lib.cpp b/source/lib/ze_lib.cpp index c7707830..126d0bbc 100644 --- a/source/lib/ze_lib.cpp +++ b/source/lib/ze_lib.cpp @@ -22,13 +22,7 @@ namespace ze_lib /////////////////////////////////////////////////////////////////////////////// context_t::context_t() - { - #ifdef DYNAMIC_LOAD_LOADER - printf("Context created static\n"); - #else - printf("Context created dynamic\n"); - #endif - }; + {}; /////////////////////////////////////////////////////////////////////////////// context_t::~context_t() @@ -41,10 +35,17 @@ namespace ze_lib ze_lib::destruction = true; }; + ////////////////////////////////////////////////////////////////////////// + void debug_trace_message(const std::string &message, const std::string &extra) + { + std::cerr << message << " " << extra << std::endl; + } + ////////////////////////////////////////////////////////////////////////// __zedlllocal ze_result_t context_t::Init(ze_init_flags_t flags, bool sysmanOnly, ze_init_driver_type_desc_t* desc) { ze_result_t result; + ze_api_version_t version = ZE_API_VERSION_CURRENT; #ifdef DYNAMIC_LOAD_LOADER std::string loaderLibraryPath; #ifdef _WIN32 @@ -54,47 +55,78 @@ namespace ze_lib loader = LOAD_DRIVER_LIBRARY(loaderFullLibraryPath.c_str()); if( NULL == loader ) { - printf("loader load failed\n"); + std::string message = "ze_lib Context Init() Loader Library Load Failed"; + debug_trace_message(message, ""); return ZE_RESULT_ERROR_UNINITIALIZED; } typedef ze_result_t (ZE_APICALL *loaderInit_t)(); auto loaderInit = reinterpret_cast( GET_FUNCTION_PTR(loader, "zeLoaderInit") ); - printf("calling loader init static\n"); result = loaderInit(); if( ZE_RESULT_SUCCESS != result ) { + std::string message = "ze_lib Context Init() Loader Init Failed"; + debug_trace_message(message, ""); return result; } typedef HMODULE (ZE_APICALL *getTracing_t)(); auto getTracing = reinterpret_cast( GET_FUNCTION_PTR(loader, "zeLoaderGetTracingHandle") ); if (getTracing == nullptr) { - printf("missing getTracing\n"); + std::string message = "ze_lib Context Init() zeLoaderGetTracingHandle missing"; + debug_trace_message(message, ""); return ZE_RESULT_ERROR_UNINITIALIZED; } tracing_lib = getTracing(); - 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( - GET_FUNCTION_PTR(loader, "zelLoaderDriverCheck") ); - if (loaderDriverCheck == nullptr) { - printf("missing loaderDriverCheck\n"); - return ZE_RESULT_ERROR_UNINITIALIZED; - } typedef ze_result_t (ZE_APICALL *zelLoaderTracingLayerInit_t)(std::atomic &zeDdiTable); auto loaderTracingLayerInit = reinterpret_cast( GET_FUNCTION_PTR(loader, "zelLoaderTracingLayerInit") ); if (loaderTracingLayerInit == nullptr) { - printf("missing loaderTracingLayerInit\n"); + std::string message = "ze_lib Context Init() zelLoaderTracingLayerInit missing"; + debug_trace_message(message, ""); return ZE_RESULT_ERROR_UNINITIALIZED; } typedef loader::context_t * (ZE_APICALL *zelLoaderGetContext_t)(); auto loaderGetContext = reinterpret_cast( GET_FUNCTION_PTR(loader, "zelLoaderGetContext") ); if (loaderGetContext == nullptr) { - printf("missing zelLoaderGetContext\n"); + std::string message = "ze_lib Context Init() zelLoaderGetContext missing"; + debug_trace_message(message, ""); + } + + size_t size = 0; + result = zelLoaderGetVersions(&size, nullptr); + if (ZE_RESULT_SUCCESS != result) { + std::string message = "ze_lib Context Init() zelLoaderGetVersions Failed"; + debug_trace_message(message, ""); + return result; + } + + std::vector versions(size); + result = zelLoaderGetVersions(&size, versions.data()); + if (ZE_RESULT_SUCCESS != result) { + std::string message = "ze_lib Context Init() zelLoaderGetVersions Failed to read component versions"; + debug_trace_message(message, ""); + return result; + } + bool zeInitDriversSupport = true; + const std::string loader_name = "loader"; + for (auto &component : versions) { + if (loader_name == component.component_name) { + version = component.spec_version; + if(component.component_lib_version.major == 1) { + if (component.component_lib_version.minor < 18) { + std::string message = "ze_lib Context Init() Version Does not support zeInitDrivers"; + debug_trace_message(message, ""); + zeInitDriversSupport = false; + } + } else { + std::string message = "ze_lib Context Init() Loader version is too new"; + debug_trace_message(message, ""); + return ZE_RESULT_ERROR_UNSUPPORTED_VERSION; + } + } } - printf("done loading functions\n"); #else result = zeLoaderInit(); if( ZE_RESULT_SUCCESS == result ) { @@ -128,22 +160,38 @@ namespace ze_lib // Init the ZE DDI Tables if( ZE_RESULT_SUCCESS == result ) { - result = zeDdiTableInit(); + result = zeDdiTableInit(version); + if (result != ZE_RESULT_SUCCESS) { + std::string message = "ze_lib Context Init() zeDdiTableInit failed"; + debug_trace_message(message, ""); + } } // Init the ZET DDI Tables if( ZE_RESULT_SUCCESS == result ) { - result = zetDdiTableInit(); + result = zetDdiTableInit(version); + if( ZE_RESULT_SUCCESS != result ) { + std::string message = "ze_lib Context Init() zetDdiTableInit failed"; + debug_trace_message(message, ""); + } } // Init the ZES DDI Tables if( ZE_RESULT_SUCCESS == result ) { - result = zesDdiTableInit(); + result = zesDdiTableInit(version); + if (result != ZE_RESULT_SUCCESS) { + std::string message = "ze_lib Context Init() zesDdiTableInit failed"; + debug_trace_message(message, ""); + } } // Init the Tracing API DDI Tables if( ZE_RESULT_SUCCESS == result ) { - result = zelTracingDdiTableInit(); + result = zelTracingDdiTableInit(version); + if (result != ZE_RESULT_SUCCESS) { + std::string message = "ze_lib Context Init() zelTracingDdiTableInit failed"; + debug_trace_message(message, ""); + } } // Init the stored ddi tables for the tracing layer if( ZE_RESULT_SUCCESS == result ) @@ -163,10 +211,34 @@ namespace ze_lib // No need to check if only initializing sysman bool requireDdiReinit = false; #ifdef DYNAMIC_LOAD_LOADER - result = loaderDriverCheck(flags, desc, &ze_lib::context->initialzeDdiTable.Global, &ze_lib::context->initialzesDdiTable.Global, &requireDdiReinit, sysmanOnly); + 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( + GET_FUNCTION_PTR(loader, "zelLoaderDriverCheck") ); + if (loaderDriverCheck == nullptr) { + std::string message = "ze_lib Context Init() zelLoaderDriverCheck missing"; + debug_trace_message(message, ""); + return ZE_RESULT_ERROR_UNINITIALIZED; + } + result = loaderDriverCheck(flags, desc, &ze_lib::context->initialzeDdiTable.Global, &ze_lib::context->initialzesDdiTable.Global, &requireDdiReinit, sysmanOnly); + } else { + typedef ze_result_t (ZE_APICALL *zelLoaderDriverCheck_t)(ze_init_flags_t flags, ze_global_dditable_t *globalInitStored, zes_global_dditable_t *sysmanGlobalInitStored, bool *requireDdiReinit, bool sysmanOnly); + auto loaderDriverCheck = reinterpret_cast( + GET_FUNCTION_PTR(loader, "zelLoaderDriverCheck") ); + if (loaderDriverCheck == nullptr) { + std::string message = "ze_lib Context Init() zelLoaderDriverCheck missing"; + debug_trace_message(message, ""); + return ZE_RESULT_ERROR_UNINITIALIZED; + } + result = loaderDriverCheck(flags, &ze_lib::context->initialzeDdiTable.Global, &ze_lib::context->initialzesDdiTable.Global, &requireDdiReinit, sysmanOnly); + } #else result = zelLoaderDriverCheck(flags, desc, &ze_lib::context->initialzeDdiTable.Global, &ze_lib::context->initialzesDdiTable.Global, &requireDdiReinit, sysmanOnly); #endif + if (result != ZE_RESULT_SUCCESS) { + std::string message = "ze_lib Context Init() zelLoaderDriverCheck failed"; + debug_trace_message(message, ""); + } // 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 && loaderContextAccessAllowed) { // 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. @@ -174,12 +246,12 @@ namespace ze_lib // reInit the ZE DDI Tables if( ZE_RESULT_SUCCESS == result ) { - result = zeDdiTableInit(); + result = zeDdiTableInit(version); } // reInit the ZET DDI Tables if( ZE_RESULT_SUCCESS == result ) { - result = zetDdiTableInit(); + result = zetDdiTableInit(version); } // If ze/zet ddi tables have been reinit and no longer use the intercept layer, then handles passed to zelLoaderTranslateHandleInternal do not require translation. // Setting intercept_enabled==false changes the behavior of zelLoaderTranslateHandleInternal to avoid translation. @@ -191,7 +263,7 @@ namespace ze_lib // reInit the ZES DDI Tables if( ZE_RESULT_SUCCESS == result ) { - result = zesDdiTableInit(); + result = zesDdiTableInit(version); } } } diff --git a/source/lib/ze_lib.h b/source/lib/ze_lib.h index 73589936..93af3e5d 100644 --- a/source/lib/ze_lib.h +++ b/source/lib/ze_lib.h @@ -34,22 +34,31 @@ namespace ze_lib context_t(); ~context_t(); + /////////////////////////////////////////////////////////////////////////////// + template + ze_result_t getTableWithCheck(T getTable, ze_api_version_t version, TableType* table) { + if (getTable == nullptr) { + return ZE_RESULT_ERROR_UNINITIALIZED; + } + return getTable(version, table); + } + std::once_flag initOnce; std::once_flag initOnceDrivers; std::once_flag initOnceSysMan; ze_result_t Init(ze_init_flags_t flags, bool sysmanOnly, ze_init_driver_type_desc_t* desc); - ze_result_t zeDdiTableInit(); + ze_result_t zeDdiTableInit(ze_api_version_t version); std::atomic zeDdiTable = {nullptr}; - ze_result_t zetDdiTableInit(); + ze_result_t zetDdiTableInit(ze_api_version_t version); std::atomic zetDdiTable = {nullptr}; - ze_result_t zesDdiTableInit(); + ze_result_t zesDdiTableInit(ze_api_version_t version); std::atomic zesDdiTable = {nullptr}; - ze_result_t zelTracingDdiTableInit(); + ze_result_t zelTracingDdiTableInit(ze_api_version_t version); zel_tracing_dditable_t zelTracingDdiTable = {}; std::atomic pTracingZeDdiTable = {nullptr}; ze_dditable_t initialzeDdiTable; diff --git a/source/lib/ze_libddi.cpp b/source/lib/ze_libddi.cpp index b73d815c..bf8db69d 100644 --- a/source/lib/ze_libddi.cpp +++ b/source/lib/ze_libddi.cpp @@ -17,15 +17,14 @@ namespace ze_lib /////////////////////////////////////////////////////////////////////////////// #ifdef DYNAMIC_LOAD_LOADER - __zedlllocal ze_result_t context_t::zeDdiTableInit() + __zedlllocal ze_result_t context_t::zeDdiTableInit(ze_api_version_t version) { ze_result_t result = ZE_RESULT_SUCCESS; - printf("calling static loader ddi init\n"); if( ZE_RESULT_SUCCESS == result ) { auto getTable = reinterpret_cast( GET_FUNCTION_PTR(loader, "zeGetGlobalProcAddrTable") ); - result = getTable( ZE_API_VERSION_CURRENT, &initialzeDdiTable.Global ); + result = getTableWithCheck(getTable, version, &initialzeDdiTable.Global ); } if( ZE_RESULT_SUCCESS == result ) @@ -33,7 +32,7 @@ namespace ze_lib // Optional auto getTable = reinterpret_cast( GET_FUNCTION_PTR(loader, "zeGetRTASBuilderExpProcAddrTable") ); - getTable( ZE_API_VERSION_CURRENT, &initialzeDdiTable.RTASBuilderExp ); + getTableWithCheck(getTable, version, &initialzeDdiTable.RTASBuilderExp ); } if( ZE_RESULT_SUCCESS == result ) @@ -41,14 +40,14 @@ namespace ze_lib // Optional auto getTable = reinterpret_cast( GET_FUNCTION_PTR(loader, "zeGetRTASParallelOperationExpProcAddrTable") ); - getTable( ZE_API_VERSION_CURRENT, &initialzeDdiTable.RTASParallelOperationExp ); + getTableWithCheck(getTable, version, &initialzeDdiTable.RTASParallelOperationExp ); } if( ZE_RESULT_SUCCESS == result ) { auto getTable = reinterpret_cast( GET_FUNCTION_PTR(loader, "zeGetDriverProcAddrTable") ); - result = getTable( ZE_API_VERSION_CURRENT, &initialzeDdiTable.Driver ); + result = getTableWithCheck(getTable, version, &initialzeDdiTable.Driver ); } if( ZE_RESULT_SUCCESS == result ) @@ -56,14 +55,14 @@ namespace ze_lib // Optional auto getTable = reinterpret_cast( GET_FUNCTION_PTR(loader, "zeGetDriverExpProcAddrTable") ); - getTable( ZE_API_VERSION_CURRENT, &initialzeDdiTable.DriverExp ); + getTableWithCheck(getTable, version, &initialzeDdiTable.DriverExp ); } if( ZE_RESULT_SUCCESS == result ) { auto getTable = reinterpret_cast( GET_FUNCTION_PTR(loader, "zeGetDeviceProcAddrTable") ); - result = getTable( ZE_API_VERSION_CURRENT, &initialzeDdiTable.Device ); + result = getTableWithCheck(getTable, version, &initialzeDdiTable.Device ); } if( ZE_RESULT_SUCCESS == result ) @@ -71,28 +70,28 @@ namespace ze_lib // Optional auto getTable = reinterpret_cast( GET_FUNCTION_PTR(loader, "zeGetDeviceExpProcAddrTable") ); - getTable( ZE_API_VERSION_CURRENT, &initialzeDdiTable.DeviceExp ); + getTableWithCheck(getTable, version, &initialzeDdiTable.DeviceExp ); } if( ZE_RESULT_SUCCESS == result ) { auto getTable = reinterpret_cast( GET_FUNCTION_PTR(loader, "zeGetContextProcAddrTable") ); - result = getTable( ZE_API_VERSION_CURRENT, &initialzeDdiTable.Context ); + result = getTableWithCheck(getTable, version, &initialzeDdiTable.Context ); } if( ZE_RESULT_SUCCESS == result ) { auto getTable = reinterpret_cast( GET_FUNCTION_PTR(loader, "zeGetCommandQueueProcAddrTable") ); - result = getTable( ZE_API_VERSION_CURRENT, &initialzeDdiTable.CommandQueue ); + result = getTableWithCheck(getTable, version, &initialzeDdiTable.CommandQueue ); } if( ZE_RESULT_SUCCESS == result ) { auto getTable = reinterpret_cast( GET_FUNCTION_PTR(loader, "zeGetCommandListProcAddrTable") ); - result = getTable( ZE_API_VERSION_CURRENT, &initialzeDdiTable.CommandList ); + result = getTableWithCheck(getTable, version, &initialzeDdiTable.CommandList ); } if( ZE_RESULT_SUCCESS == result ) @@ -100,14 +99,14 @@ namespace ze_lib // Optional auto getTable = reinterpret_cast( GET_FUNCTION_PTR(loader, "zeGetCommandListExpProcAddrTable") ); - getTable( ZE_API_VERSION_CURRENT, &initialzeDdiTable.CommandListExp ); + getTableWithCheck(getTable, version, &initialzeDdiTable.CommandListExp ); } if( ZE_RESULT_SUCCESS == result ) { auto getTable = reinterpret_cast( GET_FUNCTION_PTR(loader, "zeGetEventProcAddrTable") ); - result = getTable( ZE_API_VERSION_CURRENT, &initialzeDdiTable.Event ); + result = getTableWithCheck(getTable, version, &initialzeDdiTable.Event ); } if( ZE_RESULT_SUCCESS == result ) @@ -115,28 +114,28 @@ namespace ze_lib // Optional auto getTable = reinterpret_cast( GET_FUNCTION_PTR(loader, "zeGetEventExpProcAddrTable") ); - getTable( ZE_API_VERSION_CURRENT, &initialzeDdiTable.EventExp ); + getTableWithCheck(getTable, version, &initialzeDdiTable.EventExp ); } if( ZE_RESULT_SUCCESS == result ) { auto getTable = reinterpret_cast( GET_FUNCTION_PTR(loader, "zeGetEventPoolProcAddrTable") ); - result = getTable( ZE_API_VERSION_CURRENT, &initialzeDdiTable.EventPool ); + result = getTableWithCheck(getTable, version, &initialzeDdiTable.EventPool ); } if( ZE_RESULT_SUCCESS == result ) { auto getTable = reinterpret_cast( GET_FUNCTION_PTR(loader, "zeGetFenceProcAddrTable") ); - result = getTable( ZE_API_VERSION_CURRENT, &initialzeDdiTable.Fence ); + result = getTableWithCheck(getTable, version, &initialzeDdiTable.Fence ); } if( ZE_RESULT_SUCCESS == result ) { auto getTable = reinterpret_cast( GET_FUNCTION_PTR(loader, "zeGetImageProcAddrTable") ); - result = getTable( ZE_API_VERSION_CURRENT, &initialzeDdiTable.Image ); + result = getTableWithCheck(getTable, version, &initialzeDdiTable.Image ); } if( ZE_RESULT_SUCCESS == result ) @@ -144,14 +143,14 @@ namespace ze_lib // Optional auto getTable = reinterpret_cast( GET_FUNCTION_PTR(loader, "zeGetImageExpProcAddrTable") ); - getTable( ZE_API_VERSION_CURRENT, &initialzeDdiTable.ImageExp ); + getTableWithCheck(getTable, version, &initialzeDdiTable.ImageExp ); } if( ZE_RESULT_SUCCESS == result ) { auto getTable = reinterpret_cast( GET_FUNCTION_PTR(loader, "zeGetKernelProcAddrTable") ); - result = getTable( ZE_API_VERSION_CURRENT, &initialzeDdiTable.Kernel ); + result = getTableWithCheck(getTable, version, &initialzeDdiTable.Kernel ); } if( ZE_RESULT_SUCCESS == result ) @@ -159,14 +158,14 @@ namespace ze_lib // Optional auto getTable = reinterpret_cast( GET_FUNCTION_PTR(loader, "zeGetKernelExpProcAddrTable") ); - getTable( ZE_API_VERSION_CURRENT, &initialzeDdiTable.KernelExp ); + getTableWithCheck(getTable, version, &initialzeDdiTable.KernelExp ); } if( ZE_RESULT_SUCCESS == result ) { auto getTable = reinterpret_cast( GET_FUNCTION_PTR(loader, "zeGetMemProcAddrTable") ); - result = getTable( ZE_API_VERSION_CURRENT, &initialzeDdiTable.Mem ); + result = getTableWithCheck(getTable, version, &initialzeDdiTable.Mem ); } if( ZE_RESULT_SUCCESS == result ) @@ -174,42 +173,42 @@ namespace ze_lib // Optional auto getTable = reinterpret_cast( GET_FUNCTION_PTR(loader, "zeGetMemExpProcAddrTable") ); - getTable( ZE_API_VERSION_CURRENT, &initialzeDdiTable.MemExp ); + getTableWithCheck(getTable, version, &initialzeDdiTable.MemExp ); } if( ZE_RESULT_SUCCESS == result ) { auto getTable = reinterpret_cast( GET_FUNCTION_PTR(loader, "zeGetModuleProcAddrTable") ); - result = getTable( ZE_API_VERSION_CURRENT, &initialzeDdiTable.Module ); + result = getTableWithCheck(getTable, version, &initialzeDdiTable.Module ); } if( ZE_RESULT_SUCCESS == result ) { auto getTable = reinterpret_cast( GET_FUNCTION_PTR(loader, "zeGetModuleBuildLogProcAddrTable") ); - result = getTable( ZE_API_VERSION_CURRENT, &initialzeDdiTable.ModuleBuildLog ); + result = getTableWithCheck(getTable, version, &initialzeDdiTable.ModuleBuildLog ); } if( ZE_RESULT_SUCCESS == result ) { auto getTable = reinterpret_cast( GET_FUNCTION_PTR(loader, "zeGetPhysicalMemProcAddrTable") ); - result = getTable( ZE_API_VERSION_CURRENT, &initialzeDdiTable.PhysicalMem ); + result = getTableWithCheck(getTable, version, &initialzeDdiTable.PhysicalMem ); } if( ZE_RESULT_SUCCESS == result ) { auto getTable = reinterpret_cast( GET_FUNCTION_PTR(loader, "zeGetSamplerProcAddrTable") ); - result = getTable( ZE_API_VERSION_CURRENT, &initialzeDdiTable.Sampler ); + result = getTableWithCheck(getTable, version, &initialzeDdiTable.Sampler ); } if( ZE_RESULT_SUCCESS == result ) { auto getTable = reinterpret_cast( GET_FUNCTION_PTR(loader, "zeGetVirtualMemProcAddrTable") ); - result = getTable( ZE_API_VERSION_CURRENT, &initialzeDdiTable.VirtualMem ); + result = getTableWithCheck(getTable, version, &initialzeDdiTable.VirtualMem ); } if( ZE_RESULT_SUCCESS == result ) @@ -217,7 +216,7 @@ namespace ze_lib // Optional auto getTable = reinterpret_cast( GET_FUNCTION_PTR(loader, "zeGetFabricEdgeExpProcAddrTable") ); - getTable( ZE_API_VERSION_CURRENT, &initialzeDdiTable.FabricEdgeExp ); + getTableWithCheck(getTable, version, &initialzeDdiTable.FabricEdgeExp ); } if( ZE_RESULT_SUCCESS == result ) @@ -225,13 +224,13 @@ namespace ze_lib // Optional auto getTable = reinterpret_cast( GET_FUNCTION_PTR(loader, "zeGetFabricVertexExpProcAddrTable") ); - getTable( ZE_API_VERSION_CURRENT, &initialzeDdiTable.FabricVertexExp ); + getTableWithCheck(getTable, version, &initialzeDdiTable.FabricVertexExp ); } return result; } #else - __zedlllocal ze_result_t context_t::zeDdiTableInit() + __zedlllocal ze_result_t context_t::zeDdiTableInit(ze_api_version_t version) { ze_result_t result = ZE_RESULT_SUCCESS; diff --git a/source/lib/zel_tracing_libddi.cpp b/source/lib/zel_tracing_libddi.cpp index cb481951..f20b75bb 100644 --- a/source/lib/zel_tracing_libddi.cpp +++ b/source/lib/zel_tracing_libddi.cpp @@ -15,7 +15,7 @@ namespace ze_lib /////////////////////////////////////////////////////////////////////////////// #ifdef DYNAMIC_LOAD_LOADER - __zedlllocal ze_result_t context_t::zelTracingDdiTableInit() + __zedlllocal ze_result_t context_t::zelTracingDdiTableInit(ze_api_version_t version) { ze_result_t result = ZE_RESULT_SUCCESS; @@ -23,13 +23,13 @@ namespace ze_lib { auto getTable = reinterpret_cast( GET_FUNCTION_PTR(loader, "zelGetTracerApiProcAddrTable") ); - result = getTable( ZE_API_VERSION_CURRENT, &zelTracingDdiTable.Tracer); + result = getTableWithCheck(getTable, version, &zelTracingDdiTable.Tracer); } return result; } #else - __zedlllocal ze_result_t context_t::zelTracingDdiTableInit() + __zedlllocal ze_result_t context_t::zelTracingDdiTableInit(ze_api_version_t version) { ze_result_t result; result = zelGetTracerApiProcAddrTable( ZE_API_VERSION_CURRENT, &zelTracingDdiTable.Tracer); diff --git a/source/lib/zes_libddi.cpp b/source/lib/zes_libddi.cpp index 4159a931..7c51ee89 100644 --- a/source/lib/zes_libddi.cpp +++ b/source/lib/zes_libddi.cpp @@ -17,7 +17,7 @@ namespace ze_lib /////////////////////////////////////////////////////////////////////////////// #ifdef DYNAMIC_LOAD_LOADER - __zedlllocal ze_result_t context_t::zesDdiTableInit() + __zedlllocal ze_result_t context_t::zesDdiTableInit(ze_api_version_t version) { ze_result_t result = ZE_RESULT_SUCCESS; @@ -26,14 +26,14 @@ namespace ze_lib // Optional auto getTable = reinterpret_cast( GET_FUNCTION_PTR(loader, "zesGetGlobalProcAddrTable") ); - getTable( ZE_API_VERSION_CURRENT, &initialzesDdiTable.Global ); + getTableWithCheck(getTable, version, &initialzesDdiTable.Global ); } if( ZE_RESULT_SUCCESS == result ) { auto getTable = reinterpret_cast( GET_FUNCTION_PTR(loader, "zesGetDeviceProcAddrTable") ); - result = getTable( ZE_API_VERSION_CURRENT, &initialzesDdiTable.Device ); + result = getTableWithCheck(getTable, version, &initialzesDdiTable.Device ); } if( ZE_RESULT_SUCCESS == result ) @@ -41,14 +41,14 @@ namespace ze_lib // Optional auto getTable = reinterpret_cast( GET_FUNCTION_PTR(loader, "zesGetDeviceExpProcAddrTable") ); - getTable( ZE_API_VERSION_CURRENT, &initialzesDdiTable.DeviceExp ); + getTableWithCheck(getTable, version, &initialzesDdiTable.DeviceExp ); } if( ZE_RESULT_SUCCESS == result ) { auto getTable = reinterpret_cast( GET_FUNCTION_PTR(loader, "zesGetDriverProcAddrTable") ); - result = getTable( ZE_API_VERSION_CURRENT, &initialzesDdiTable.Driver ); + result = getTableWithCheck(getTable, version, &initialzesDdiTable.Driver ); } if( ZE_RESULT_SUCCESS == result ) @@ -56,42 +56,42 @@ namespace ze_lib // Optional auto getTable = reinterpret_cast( GET_FUNCTION_PTR(loader, "zesGetDriverExpProcAddrTable") ); - getTable( ZE_API_VERSION_CURRENT, &initialzesDdiTable.DriverExp ); + getTableWithCheck(getTable, version, &initialzesDdiTable.DriverExp ); } if( ZE_RESULT_SUCCESS == result ) { auto getTable = reinterpret_cast( GET_FUNCTION_PTR(loader, "zesGetDiagnosticsProcAddrTable") ); - result = getTable( ZE_API_VERSION_CURRENT, &initialzesDdiTable.Diagnostics ); + result = getTableWithCheck(getTable, version, &initialzesDdiTable.Diagnostics ); } if( ZE_RESULT_SUCCESS == result ) { auto getTable = reinterpret_cast( GET_FUNCTION_PTR(loader, "zesGetEngineProcAddrTable") ); - result = getTable( ZE_API_VERSION_CURRENT, &initialzesDdiTable.Engine ); + result = getTableWithCheck(getTable, version, &initialzesDdiTable.Engine ); } if( ZE_RESULT_SUCCESS == result ) { auto getTable = reinterpret_cast( GET_FUNCTION_PTR(loader, "zesGetFabricPortProcAddrTable") ); - result = getTable( ZE_API_VERSION_CURRENT, &initialzesDdiTable.FabricPort ); + result = getTableWithCheck(getTable, version, &initialzesDdiTable.FabricPort ); } if( ZE_RESULT_SUCCESS == result ) { auto getTable = reinterpret_cast( GET_FUNCTION_PTR(loader, "zesGetFanProcAddrTable") ); - result = getTable( ZE_API_VERSION_CURRENT, &initialzesDdiTable.Fan ); + result = getTableWithCheck(getTable, version, &initialzesDdiTable.Fan ); } if( ZE_RESULT_SUCCESS == result ) { auto getTable = reinterpret_cast( GET_FUNCTION_PTR(loader, "zesGetFirmwareProcAddrTable") ); - result = getTable( ZE_API_VERSION_CURRENT, &initialzesDdiTable.Firmware ); + result = getTableWithCheck(getTable, version, &initialzesDdiTable.Firmware ); } if( ZE_RESULT_SUCCESS == result ) @@ -99,28 +99,28 @@ namespace ze_lib // Optional auto getTable = reinterpret_cast( GET_FUNCTION_PTR(loader, "zesGetFirmwareExpProcAddrTable") ); - getTable( ZE_API_VERSION_CURRENT, &initialzesDdiTable.FirmwareExp ); + getTableWithCheck(getTable, version, &initialzesDdiTable.FirmwareExp ); } if( ZE_RESULT_SUCCESS == result ) { auto getTable = reinterpret_cast( GET_FUNCTION_PTR(loader, "zesGetFrequencyProcAddrTable") ); - result = getTable( ZE_API_VERSION_CURRENT, &initialzesDdiTable.Frequency ); + result = getTableWithCheck(getTable, version, &initialzesDdiTable.Frequency ); } if( ZE_RESULT_SUCCESS == result ) { auto getTable = reinterpret_cast( GET_FUNCTION_PTR(loader, "zesGetLedProcAddrTable") ); - result = getTable( ZE_API_VERSION_CURRENT, &initialzesDdiTable.Led ); + result = getTableWithCheck(getTable, version, &initialzesDdiTable.Led ); } if( ZE_RESULT_SUCCESS == result ) { auto getTable = reinterpret_cast( GET_FUNCTION_PTR(loader, "zesGetMemoryProcAddrTable") ); - result = getTable( ZE_API_VERSION_CURRENT, &initialzesDdiTable.Memory ); + result = getTableWithCheck(getTable, version, &initialzesDdiTable.Memory ); } if( ZE_RESULT_SUCCESS == result ) @@ -128,35 +128,35 @@ namespace ze_lib // Optional auto getTable = reinterpret_cast( GET_FUNCTION_PTR(loader, "zesGetOverclockProcAddrTable") ); - getTable( ZE_API_VERSION_CURRENT, &initialzesDdiTable.Overclock ); + getTableWithCheck(getTable, version, &initialzesDdiTable.Overclock ); } if( ZE_RESULT_SUCCESS == result ) { auto getTable = reinterpret_cast( GET_FUNCTION_PTR(loader, "zesGetPerformanceFactorProcAddrTable") ); - result = getTable( ZE_API_VERSION_CURRENT, &initialzesDdiTable.PerformanceFactor ); + result = getTableWithCheck(getTable, version, &initialzesDdiTable.PerformanceFactor ); } if( ZE_RESULT_SUCCESS == result ) { auto getTable = reinterpret_cast( GET_FUNCTION_PTR(loader, "zesGetPowerProcAddrTable") ); - result = getTable( ZE_API_VERSION_CURRENT, &initialzesDdiTable.Power ); + result = getTableWithCheck(getTable, version, &initialzesDdiTable.Power ); } if( ZE_RESULT_SUCCESS == result ) { auto getTable = reinterpret_cast( GET_FUNCTION_PTR(loader, "zesGetPsuProcAddrTable") ); - result = getTable( ZE_API_VERSION_CURRENT, &initialzesDdiTable.Psu ); + result = getTableWithCheck(getTable, version, &initialzesDdiTable.Psu ); } if( ZE_RESULT_SUCCESS == result ) { auto getTable = reinterpret_cast( GET_FUNCTION_PTR(loader, "zesGetRasProcAddrTable") ); - result = getTable( ZE_API_VERSION_CURRENT, &initialzesDdiTable.Ras ); + result = getTableWithCheck(getTable, version, &initialzesDdiTable.Ras ); } if( ZE_RESULT_SUCCESS == result ) @@ -164,28 +164,28 @@ namespace ze_lib // Optional auto getTable = reinterpret_cast( GET_FUNCTION_PTR(loader, "zesGetRasExpProcAddrTable") ); - getTable( ZE_API_VERSION_CURRENT, &initialzesDdiTable.RasExp ); + getTableWithCheck(getTable, version, &initialzesDdiTable.RasExp ); } if( ZE_RESULT_SUCCESS == result ) { auto getTable = reinterpret_cast( GET_FUNCTION_PTR(loader, "zesGetSchedulerProcAddrTable") ); - result = getTable( ZE_API_VERSION_CURRENT, &initialzesDdiTable.Scheduler ); + result = getTableWithCheck(getTable, version, &initialzesDdiTable.Scheduler ); } if( ZE_RESULT_SUCCESS == result ) { auto getTable = reinterpret_cast( GET_FUNCTION_PTR(loader, "zesGetStandbyProcAddrTable") ); - result = getTable( ZE_API_VERSION_CURRENT, &initialzesDdiTable.Standby ); + result = getTableWithCheck(getTable, version, &initialzesDdiTable.Standby ); } if( ZE_RESULT_SUCCESS == result ) { auto getTable = reinterpret_cast( GET_FUNCTION_PTR(loader, "zesGetTemperatureProcAddrTable") ); - result = getTable( ZE_API_VERSION_CURRENT, &initialzesDdiTable.Temperature ); + result = getTableWithCheck(getTable, version, &initialzesDdiTable.Temperature ); } if( ZE_RESULT_SUCCESS == result ) @@ -193,13 +193,13 @@ namespace ze_lib // Optional auto getTable = reinterpret_cast( GET_FUNCTION_PTR(loader, "zesGetVFManagementExpProcAddrTable") ); - getTable( ZE_API_VERSION_CURRENT, &initialzesDdiTable.VFManagementExp ); + getTableWithCheck(getTable, version, &initialzesDdiTable.VFManagementExp ); } return result; } #else - __zedlllocal ze_result_t context_t::zesDdiTableInit() + __zedlllocal ze_result_t context_t::zesDdiTableInit(ze_api_version_t version) { ze_result_t result = ZE_RESULT_SUCCESS; diff --git a/source/lib/zet_libddi.cpp b/source/lib/zet_libddi.cpp index 5a6595b6..e3b90f65 100644 --- a/source/lib/zet_libddi.cpp +++ b/source/lib/zet_libddi.cpp @@ -14,10 +14,9 @@ namespace ze_lib { - /////////////////////////////////////////////////////////////////////////////// #ifdef DYNAMIC_LOAD_LOADER - __zedlllocal ze_result_t context_t::zetDdiTableInit() + __zedlllocal ze_result_t context_t::zetDdiTableInit(ze_api_version_t version) { ze_result_t result = ZE_RESULT_SUCCESS; @@ -26,7 +25,7 @@ namespace ze_lib // Optional auto getTable = reinterpret_cast( GET_FUNCTION_PTR(loader, "zetGetMetricDecoderExpProcAddrTable") ); - getTable( ZE_API_VERSION_CURRENT, &initialzetDdiTable.MetricDecoderExp ); + getTableWithCheck(getTable, version, &initialzetDdiTable.MetricDecoderExp ); } if( ZE_RESULT_SUCCESS == result ) @@ -34,7 +33,7 @@ namespace ze_lib // Optional auto getTable = reinterpret_cast( GET_FUNCTION_PTR(loader, "zetGetMetricProgrammableExpProcAddrTable") ); - getTable( ZE_API_VERSION_CURRENT, &initialzetDdiTable.MetricProgrammableExp ); + getTableWithCheck(getTable, version, &initialzetDdiTable.MetricProgrammableExp ); } if( ZE_RESULT_SUCCESS == result ) @@ -42,14 +41,14 @@ namespace ze_lib // Optional auto getTable = reinterpret_cast( GET_FUNCTION_PTR(loader, "zetGetMetricTracerExpProcAddrTable") ); - getTable( ZE_API_VERSION_CURRENT, &initialzetDdiTable.MetricTracerExp ); + getTableWithCheck(getTable, version, &initialzetDdiTable.MetricTracerExp ); } if( ZE_RESULT_SUCCESS == result ) { auto getTable = reinterpret_cast( GET_FUNCTION_PTR(loader, "zetGetDeviceProcAddrTable") ); - result = getTable( ZE_API_VERSION_CURRENT, &initialzetDdiTable.Device ); + result = getTableWithCheck(getTable, version, &initialzetDdiTable.Device ); } if( ZE_RESULT_SUCCESS == result ) @@ -57,49 +56,49 @@ namespace ze_lib // Optional auto getTable = reinterpret_cast( GET_FUNCTION_PTR(loader, "zetGetDeviceExpProcAddrTable") ); - getTable( ZE_API_VERSION_CURRENT, &initialzetDdiTable.DeviceExp ); + getTableWithCheck(getTable, version, &initialzetDdiTable.DeviceExp ); } if( ZE_RESULT_SUCCESS == result ) { auto getTable = reinterpret_cast( GET_FUNCTION_PTR(loader, "zetGetContextProcAddrTable") ); - result = getTable( ZE_API_VERSION_CURRENT, &initialzetDdiTable.Context ); + result = getTableWithCheck(getTable, version, &initialzetDdiTable.Context ); } if( ZE_RESULT_SUCCESS == result ) { auto getTable = reinterpret_cast( GET_FUNCTION_PTR(loader, "zetGetCommandListProcAddrTable") ); - result = getTable( ZE_API_VERSION_CURRENT, &initialzetDdiTable.CommandList ); + result = getTableWithCheck(getTable, version, &initialzetDdiTable.CommandList ); } if( ZE_RESULT_SUCCESS == result ) { auto getTable = reinterpret_cast( GET_FUNCTION_PTR(loader, "zetGetKernelProcAddrTable") ); - result = getTable( ZE_API_VERSION_CURRENT, &initialzetDdiTable.Kernel ); + result = getTableWithCheck(getTable, version, &initialzetDdiTable.Kernel ); } if( ZE_RESULT_SUCCESS == result ) { auto getTable = reinterpret_cast( GET_FUNCTION_PTR(loader, "zetGetModuleProcAddrTable") ); - result = getTable( ZE_API_VERSION_CURRENT, &initialzetDdiTable.Module ); + result = getTableWithCheck(getTable, version, &initialzetDdiTable.Module ); } if( ZE_RESULT_SUCCESS == result ) { auto getTable = reinterpret_cast( GET_FUNCTION_PTR(loader, "zetGetDebugProcAddrTable") ); - result = getTable( ZE_API_VERSION_CURRENT, &initialzetDdiTable.Debug ); + result = getTableWithCheck(getTable, version, &initialzetDdiTable.Debug ); } if( ZE_RESULT_SUCCESS == result ) { auto getTable = reinterpret_cast( GET_FUNCTION_PTR(loader, "zetGetMetricProcAddrTable") ); - result = getTable( ZE_API_VERSION_CURRENT, &initialzetDdiTable.Metric ); + result = getTableWithCheck(getTable, version, &initialzetDdiTable.Metric ); } if( ZE_RESULT_SUCCESS == result ) @@ -107,14 +106,14 @@ namespace ze_lib // Optional auto getTable = reinterpret_cast( GET_FUNCTION_PTR(loader, "zetGetMetricExpProcAddrTable") ); - getTable( ZE_API_VERSION_CURRENT, &initialzetDdiTable.MetricExp ); + getTableWithCheck(getTable, version, &initialzetDdiTable.MetricExp ); } if( ZE_RESULT_SUCCESS == result ) { auto getTable = reinterpret_cast( GET_FUNCTION_PTR(loader, "zetGetMetricGroupProcAddrTable") ); - result = getTable( ZE_API_VERSION_CURRENT, &initialzetDdiTable.MetricGroup ); + result = getTableWithCheck(getTable, version, &initialzetDdiTable.MetricGroup ); } if( ZE_RESULT_SUCCESS == result ) @@ -122,41 +121,41 @@ namespace ze_lib // Optional auto getTable = reinterpret_cast( GET_FUNCTION_PTR(loader, "zetGetMetricGroupExpProcAddrTable") ); - getTable( ZE_API_VERSION_CURRENT, &initialzetDdiTable.MetricGroupExp ); + getTableWithCheck(getTable, version, &initialzetDdiTable.MetricGroupExp ); } if( ZE_RESULT_SUCCESS == result ) { auto getTable = reinterpret_cast( GET_FUNCTION_PTR(loader, "zetGetMetricQueryProcAddrTable") ); - result = getTable( ZE_API_VERSION_CURRENT, &initialzetDdiTable.MetricQuery ); + result = getTableWithCheck(getTable, version, &initialzetDdiTable.MetricQuery ); } if( ZE_RESULT_SUCCESS == result ) { auto getTable = reinterpret_cast( GET_FUNCTION_PTR(loader, "zetGetMetricQueryPoolProcAddrTable") ); - result = getTable( ZE_API_VERSION_CURRENT, &initialzetDdiTable.MetricQueryPool ); + result = getTableWithCheck(getTable, version, &initialzetDdiTable.MetricQueryPool ); } if( ZE_RESULT_SUCCESS == result ) { auto getTable = reinterpret_cast( GET_FUNCTION_PTR(loader, "zetGetMetricStreamerProcAddrTable") ); - result = getTable( ZE_API_VERSION_CURRENT, &initialzetDdiTable.MetricStreamer ); + result = getTableWithCheck(getTable, version, &initialzetDdiTable.MetricStreamer ); } if( ZE_RESULT_SUCCESS == result ) { auto getTable = reinterpret_cast( GET_FUNCTION_PTR(loader, "zetGetTracerExpProcAddrTable") ); - result = getTable( ZE_API_VERSION_CURRENT, &initialzetDdiTable.TracerExp ); + result = getTableWithCheck(getTable, version, &initialzetDdiTable.TracerExp ); } return result; } #else - __zedlllocal ze_result_t context_t::zetDdiTableInit() + __zedlllocal ze_result_t context_t::zetDdiTableInit(ze_api_version_t version) { ze_result_t result = ZE_RESULT_SUCCESS; diff --git a/source/loader/linux/loader_init.cpp b/source/loader/linux/loader_init.cpp index e3d322ac..aa9f57ba 100644 --- a/source/loader/linux/loader_init.cpp +++ b/source/loader/linux/loader_init.cpp @@ -12,12 +12,10 @@ namespace loader { #ifndef DYNAMIC_LOAD_LOADER void __attribute__((constructor)) createLoaderContext() { - printf("loader created context lib dynamic\n"); context = new context_t; } void __attribute__((destructor)) deleteLoaderContext() { - printf("loader destroyed context lib dynamic\n"); delete context; } #endif diff --git a/source/loader/ze_loader_api.cpp b/source/loader/ze_loader_api.cpp index 4ab76f77..3c1c8902 100644 --- a/source/loader/ze_loader_api.cpp +++ b/source/loader/ze_loader_api.cpp @@ -56,7 +56,6 @@ zeLoaderGetTracingHandle() /// - ::Pointer to the Loader's Context ZE_DLLEXPORT loader::context_t *ZE_APICALL zelLoaderGetContext() { - printf("zelLoaderGetContext\n"); return loader::context; }