Add ability to Register a TeardownCallback to notify release of L0 resources#333
Merged
Merged
Conversation
6360fe9 to
97f544b
Compare
8e72f36 to
2c5bc54
Compare
…sources Signed-off-by: Neil R. Spruit <neil.r.spruit@intel.com>
…allback Signed-off-by: Neil R. Spruit <neil.r.spruit@intel.com>
Signed-off-by: Neil R. Spruit <neil.r.spruit@intel.com>
Signed-off-by: Neil R. Spruit <neil.r.spruit@intel.com>
Signed-off-by: Neil R. Spruit <neil.r.spruit@intel.com>
Signed-off-by: Neil R. Spruit <neil.r.spruit@intel.com>
Signed-off-by: Neil R. Spruit <neil.r.spruit@intel.com>
c629333 to
dbdd143
Compare
Signed-off-by: Neil R. Spruit <neil.r.spruit@intel.com>
Signed-off-by: Neil R. Spruit <neil.r.spruit@intel.com>
There was a problem hiding this comment.
Pull Request Overview
This pull request introduces a new teardown callback mechanism in the Level Zero loader that enables applications to register callbacks during loader teardown. The key changes include:
- Implementation of the new API function zelRegisterTeardownCallback and its declaration in both the header and source files.
- Introduction of new data structures (atomic counter, map, mutex) in the context for managing registered callbacks.
- Updates to the loader teardown handling logic in the context destructor and in the zelCheckIsLoaderInTearDown function.
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| source/lib/ze_lib.h | Added new data structures and included ze_loader.h for teardown callback support. |
| source/lib/ze_lib.cpp | Implemented callback invocation logic in the context destructor, defined static and application teardown callbacks, and updated registration and teardown state checks. |
| include/loader/ze_loader.h | Declared the new API functions and callback type definitions for teardown handling. |
Comments suppressed due to low confidence (1)
source/lib/ze_lib.cpp:73
- Before invoking loaderTeardownCallback, consider adding an explicit null-check to ensure that the callback pointer is valid to prevent potential null pointer dereference issues.
if (loaderTeardownRegistrationEnabled && !loaderTeardownCallbackReceived) { loaderTeardownCallback(loaderTeardownCallbackIndex); }
aravindksg
previously approved these changes
May 16, 2025
rwmcguir
reviewed
May 16, 2025
Signed-off-by: Neil R. Spruit <neil.r.spruit@intel.com>
rwmcguir
approved these changes
May 16, 2025
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This pull request introduces a new teardown callback mechanism for the Level Zero loader, enabling applications to register and handle callbacks during the loader teardown process. It also removes the old stability check mechanism and replaces it with a more robust teardown notification system. Below are the most important changes grouped by themes:
Teardown Callback Mechanism:
zelRegisterTeardownCallback, allowing applications to register teardown callbacks. This includes defining the function prototype and its implementation in bothze_loader.handze_lib.cpp(zelRegisterTeardownCallback) [1] [2].ze_lib.h, such asteardownCallbacks(a map) andteardownCallbacksCount(an atomic counter), to manage registered callbacks and their indices (teardownCallbacks,teardownCallbacksCount).Loader Teardown Handling:
context_tdestructor to invoke registered teardown callbacks and clear the callback registry during loader teardown (teardownCallbacks.clear()) [1] [2].staticLoaderTeardownCallbackandapplicationTeardownCallbackfunctions to handle loader teardown events and remove callbacks from the registry (staticLoaderTeardownCallback,applicationTeardownCallback).Initialization and Registration:
ze_libcontext initialization to dynamically load thezelRegisterTeardownCallbackfunction and register the static loader callback if available (zelRegisterTeardownCallback).Stability Check Removal:
stabilityCheckfunction and related code, replacing it with the new teardown callback system [1] [2].Debugging and Logging Enhancements:
debug_trace_message) [1] [2].