Skip to content

Add ability to Register a TeardownCallback to notify release of L0 resources#333

Merged
nrspruit merged 10 commits into
oneapi-src:masterfrom
nrspruit:teardown_notifications
May 16, 2025
Merged

Add ability to Register a TeardownCallback to notify release of L0 resources#333
nrspruit merged 10 commits into
oneapi-src:masterfrom
nrspruit:teardown_notifications

Conversation

@nrspruit
Copy link
Copy Markdown
Contributor

@nrspruit nrspruit commented May 15, 2025

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:

  • Added a new API function, zelRegisterTeardownCallback, allowing applications to register teardown callbacks. This includes defining the function prototype and its implementation in both ze_loader.h and ze_lib.cpp (zelRegisterTeardownCallback) [1] [2].
  • Introduced new data structures in ze_lib.h, such as teardownCallbacks (a map) and teardownCallbacksCount (an atomic counter), to manage registered callbacks and their indices (teardownCallbacks, teardownCallbacksCount).

Loader Teardown Handling:

  • Implemented logic in the context_t destructor to invoke registered teardown callbacks and clear the callback registry during loader teardown (teardownCallbacks.clear()) [1] [2].
  • Added staticLoaderTeardownCallback and applicationTeardownCallback functions to handle loader teardown events and remove callbacks from the registry (staticLoaderTeardownCallback, applicationTeardownCallback).

Initialization and Registration:

  • Updated ze_lib context initialization to dynamically load the zelRegisterTeardownCallback function and register the static loader callback if available (zelRegisterTeardownCallback).

Stability Check Removal:

  • Removed the old stability check mechanism, including the stabilityCheck function and related code, replacing it with the new teardown callback system [1] [2].

Debugging and Logging Enhancements:

  • Enhanced debug tracing to log messages when teardown callbacks are registered, invoked, or when the loader enters a teardown state (debug_trace_message) [1] [2].

@nrspruit nrspruit force-pushed the teardown_notifications branch 2 times, most recently from 6360fe9 to 97f544b Compare May 15, 2025 00:31
@nrspruit nrspruit changed the title Add ability to Register a TeardownCallback to notify release of L0 re… Add ability to Register a TeardownCallback to notify release of L0 resources May 15, 2025
@nrspruit nrspruit marked this pull request as ready for review May 15, 2025 04:25
@nrspruit nrspruit requested a review from rwmcguir May 15, 2025 04:25
@nrspruit nrspruit force-pushed the teardown_notifications branch 2 times, most recently from 8e72f36 to 2c5bc54 Compare May 15, 2025 20:05
nrspruit added 7 commits May 15, 2025 14:46
…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>
nrspruit added 2 commits May 15, 2025 14:58
Signed-off-by: Neil R. Spruit <neil.r.spruit@intel.com>
Signed-off-by: Neil R. Spruit <neil.r.spruit@intel.com>
@nrspruit nrspruit requested a review from Copilot May 15, 2025 23:52
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
aravindksg previously approved these changes May 16, 2025
Comment thread source/lib/ze_lib.cpp
Signed-off-by: Neil R. Spruit <neil.r.spruit@intel.com>
@nrspruit nrspruit merged commit 35c037c into oneapi-src:master May 16, 2025
50 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants