Skip to content

feature: Add zelTracerSetResultReturnValue to override traced API return values - #525

Open
rwmcguir wants to merge 6 commits into
oneapi-src:masterfrom
rwmcguir:russ_tracing_retval
Open

rwmcguir wants to merge 6 commits into
oneapi-src:masterfrom
rwmcguir:russ_tracing_retval

Conversation

@rwmcguir

@rwmcguir rwmcguir commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

So this adds zelTracerSetResultReturnValue(ze_result_t), which lets an epilogue
callback replace the value a traced API returns to the application. The main use
is a progress hook, i.e. an epilogue on zeEventHostSynchronize that drives
progress while the result is ZE_RESULT_NOT_READY, then reports the final result.

The requestors have tested this and confirmed it works for them.

How it works..

  • Loader-only, no change to the spec or the ze_api.h params structs.
  • A thread-local slot points at the in-flight result while the epilogues run.
    Epilogues run in registration order, each one sees the previous override,
    last write wins.
  • Outside an epilogue, or for an API that does not return ze_result_t, it
    returns ZE_RESULT_ERROR_INVALID_ARGUMENT and changes nothing.
  • A static loader on top of an older runtime loader returns
    ZE_RESULT_ERROR_UNSUPPORTED_FEATURE.
  • Available in loader v1.37.0 and later, apps can check with
    zelLoaderGetVersions.

Not supported (documented in the README)

  • Driver extension functions, the driver owns that return value. May be
    supported in the future.
  • Sysman and Tools APIs are not traced at all.

On logging, I decided not to log overrides. A log without the API name is not
much use, and with the API name it costs a store on every traced call. Instead
the README has a warning section on how an override can hide real errors, and
how to debug with it disabled.

Tests cover core, runtime and extension APIs, static and dynamic tracing,
multiple tracers, thread isolation, and the rejected cases.

@rwmcguir
rwmcguir requested a review from aravindksg October 1, 2026 22:39
@rwmcguir
rwmcguir force-pushed the russ_tracing_retval branch from c700f9b to 5051a60 Compare October 8, 2026 05:00
@rwmcguir
rwmcguir force-pushed the russ_tracing_retval branch from 5051a60 to c4ccce7 Compare October 31, 2026 00:26
@github-actions

github-actions Bot commented Oct 31, 2026 •

Copy link
Copy Markdown

Level Zero loader ABI check

last-release (v1.36.0): ✅ no ABI problems. Report

Creating compatibility report ...
Binary compatibility: 100%
Source compatibility: 100%
Total binary compatibility problems: 0, warnings: 0
Total source compatibility problems: 0, warnings: 0

master (master): ✅ no ABI problems. Report

Creating compatibility report ...
Binary compatibility: 100%
Source compatibility: 100%
Total binary compatibility problems: 0, warnings: 0
Total source compatibility problems: 0, warnings: 0

Workflow run

If an ABI change is intended, a reviewer with write access can accept it: leave an approval review on the PR head commit with the keyword abi-failure-approved in the review body. That re-runs the check.

Signed-off-by: Russell McGuire <russell.w.mcguire@intel.com>
Signed-off-by: Russell McGuire <russell.w.mcguire@intel.com>
@rwmcguir
rwmcguir force-pushed the russ_tracing_retval branch from c4ccce7 to 14a392a Compare December 3, 2026 22:04
Add tests for zelTracerSetResultReturnValue on a runtime API returning
ze_result_t, an extension API in the DDI table, and per-thread isolation
of the override slot.

Document and test that driver extension function epilogues cannot
override the return value: the driver owns it and passes it by value,
so the call returns ZE_RESULT_ERROR_INVALID_ARGUMENT. This may be
supported in the future.

Signed-off-by: Russell McGuire <russell.w.mcguire@intel.com>
@rwmcguir rwmcguir changed the title Add tracing layer feature to modify return values feature: Add zelTracerSetResultReturnValue to override traced API return values Dec 3, 2026
Signed-off-by: Russell McGuire <russell.w.mcguire@intel.com>
Signed-off-by: Russell McGuire <russell.w.mcguire@intel.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

The documentation incorrectly describes epilogue ordering as registration order rather than enablement order, which can change which override wins after a tracer is disabled and re-enabled.

1 open issue
What changed in this PR

Adds zelTracerSetResultReturnValue so tracing epilogues can override API results, supporting progress hooks without changing API parameter structures.

Changes:

  • Implements thread-local result overrides and static-loader forwarding.
  • Documents usage, compatibility, limitations, and error-masking risks.
  • Adds tests for overrides, callback ordering, rejected calls, and thread isolation.
File Description
test/​loader_tracing_layer.cpp Tests result overrides and isolation.
test/​loader_ext_fn_callback.cpp Tests rejection in driver-extension callbacks.
test/​CMakeLists.txt Registers override tests.
source/​lib/​zel_tracing_libapi.cpp Forwards calls with compatibility checks.
source/​layers/​tracing/​ze_tracing.cpp Implements the override entry point.
source/​layers/​tracing/​tracing_imp.h Exposes results during epilogues.
source/​layers/​tracing/​tracing_imp.cpp Defines thread-local result storage.
source/​layers/​tracing/​README.md Documents usage and safety considerations.
include/​layers/​zel_tracing_api.h Declares and documents the public API.

Review effort: Balanced

Comment thread include/layers/zel_tracing_api.h Resolved
aravindksg
aravindksg previously approved these changes Dec 4, 2026
@stwhite91

Copy link
Copy Markdown

IMPI device-initiated RMA is now working again based on this PR (I tested again this morning on the rebased version)- thanks for your work on this!

Epilogues run in the order tracers were enabled, not registered.
Disabling and re-enabling a tracer moves it to the end, which changes
which override wins. Fix the header and README, and add a test.

Signed-off-by: Russell McGuire <russell.w.mcguire@intel.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues block the tracing return-value override change.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

This branch has not been deployed

No deployments
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