-
Notifications
You must be signed in to change notification settings - Fork 96
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[DO_NOT_MERGE] Static L0 Loader Support #224
Draft
nrspruit
wants to merge
2
commits into
oneapi-src:master
Choose a base branch
from
nrspruit:static_loader
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,19 +8,26 @@ | |
* | ||
*/ | ||
#include "ze_lib.h" | ||
#ifndef DYNAMIC_LOAD_LOADER | ||
#include "../loader/ze_loader_api.h" | ||
#endif | ||
|
||
namespace ze_lib | ||
{ | ||
/////////////////////////////////////////////////////////////////////////////// | ||
#ifndef DYNAMIC_LOAD_LOADER | ||
context_t *context; | ||
#else | ||
context_t *context = new context_t; | ||
#endif | ||
bool destruction = false; | ||
|
||
/////////////////////////////////////////////////////////////////////////////// | ||
context_t::context_t() | ||
{ | ||
#ifdef DYNAMIC_LOAD_LOADER | ||
printf("Context created static\n"); | ||
#else | ||
printf("Context created dynamic\n"); | ||
#endif | ||
}; | ||
|
||
/////////////////////////////////////////////////////////////////////////////// | ||
|
@@ -46,19 +53,48 @@ namespace ze_lib | |
std::string loaderFullLibraryPath = create_library_path(MAKE_LIBRARY_NAME( "ze_loader", L0_LOADER_VERSION), loaderLibraryPath.c_str()); | ||
loader = LOAD_DRIVER_LIBRARY(loaderFullLibraryPath.c_str()); | ||
|
||
if( NULL == loader ) | ||
if( NULL == loader ) { | ||
printf("loader load failed\n"); | ||
return ZE_RESULT_ERROR_UNINITIALIZED; | ||
} | ||
|
||
typedef ze_result_t (ZE_APICALL *loaderInit_t)(); | ||
auto loaderInit = reinterpret_cast<loaderInit_t>( | ||
GET_FUNCTION_PTR(loader, "zeLoaderInit") ); | ||
printf("calling loader init static\n"); | ||
result = loaderInit(); | ||
if( ZE_RESULT_SUCCESS == result ) { | ||
typedef HMODULE (ZE_APICALL *getTracing_t)(); | ||
auto getTracing = reinterpret_cast<getTracing_t>( | ||
GET_FUNCTION_PTR(loader, "zeLoaderGetTracingHandle") ); | ||
tracing_lib = getTracing(); | ||
if( ZE_RESULT_SUCCESS != result ) { | ||
return result; | ||
} | ||
typedef HMODULE (ZE_APICALL *getTracing_t)(); | ||
auto getTracing = reinterpret_cast<getTracing_t>( | ||
GET_FUNCTION_PTR(loader, "zeLoaderGetTracingHandle") ); | ||
if (getTracing == nullptr) { | ||
printf("missing getTracing\n"); | ||
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<zelLoaderDriverCheck_t>( | ||
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<ze_dditable_t *> &zeDdiTable); | ||
auto loaderTracingLayerInit = reinterpret_cast<zelLoaderTracingLayerInit_t>( | ||
GET_FUNCTION_PTR(loader, "zelLoaderTracingLayerInit") ); | ||
if (loaderTracingLayerInit == nullptr) { | ||
printf("missing loaderTracingLayerInit\n"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think these should be going to stderr There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. agreed, I was going to convert the printfs to debug trace logs for the ones we determine useful. |
||
return ZE_RESULT_ERROR_UNINITIALIZED; | ||
} | ||
typedef loader::context_t * (ZE_APICALL *zelLoaderGetContext_t)(); | ||
auto loaderGetContext = reinterpret_cast<zelLoaderGetContext_t>( | ||
GET_FUNCTION_PTR(loader, "zelLoaderGetContext") ); | ||
if (loaderGetContext == nullptr) { | ||
printf("missing zelLoaderGetContext\n"); | ||
} | ||
printf("done loading functions\n"); | ||
#else | ||
result = zeLoaderInit(); | ||
if( ZE_RESULT_SUCCESS == result ) { | ||
|
@@ -75,7 +111,15 @@ namespace ze_lib | |
} | ||
|
||
// Given zesInit, then zesDrivers needs to be used as the sysmanInstanceDrivers; | ||
if (sysmanOnly) { | ||
bool loaderContextAccessAllowed = true; | ||
#ifdef DYNAMIC_LOAD_LOADER | ||
if (loaderGetContext == nullptr) { | ||
loaderContextAccessAllowed = false; | ||
} else { | ||
loader::context = loaderGetContext(); | ||
} | ||
#endif | ||
if (sysmanOnly && loaderContextAccessAllowed) { | ||
loader::context->sysmanInstanceDrivers = &loader::context->zesDrivers; | ||
} | ||
|
||
|
@@ -104,7 +148,11 @@ namespace ze_lib | |
// Init the stored ddi tables for the tracing layer | ||
if( ZE_RESULT_SUCCESS == result ) | ||
{ | ||
#ifdef DYNAMIC_LOAD_LOADER | ||
result = loaderTracingLayerInit(this->pTracingZeDdiTable); | ||
#else | ||
result = zelLoaderTracingLayerInit(this->pTracingZeDdiTable); | ||
#endif | ||
} | ||
// End DDI Table Inits | ||
|
||
|
@@ -114,9 +162,13 @@ 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 | ||
result = loaderDriverCheck(flags, desc, &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 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) { | ||
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. | ||
if (!sysmanOnly && !ze_lib::context->zeInuse) { | ||
// reInit the ZE DDI Tables | ||
|
@@ -165,7 +217,7 @@ zelLoaderGetVersions( | |
{ | ||
#ifdef DYNAMIC_LOAD_LOADER | ||
if(nullptr == ze_lib::context->loader) | ||
return ZE_RESULT_ERROR; | ||
return ZE_RESULT_ERROR_UNINITIALIZED; | ||
typedef ze_result_t (ZE_APICALL *zelLoaderGetVersions_t)(size_t *num_elems, zel_component_version_t *versions); | ||
auto getVersions = reinterpret_cast<zelLoaderGetVersions_t>( | ||
GET_FUNCTION_PTR(ze_lib::context->loader, "zelLoaderGetVersionsInternal") ); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Recommend the top level cmake option be named after the result rather than the behavior, like
BUILD_STATIC
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good point, that would differentiate.