[AIMIGRAPHX-911] Add callback function to eval()#4780
[AIMIGRAPHX-911] Add callback function to eval()#4780
Conversation
There was a problem hiding this comment.
Pull request overview
Adds a per-instruction evaluation callback to MIGraphX program execution so callers can inspect operator outputs as the graph runs.
Changes:
- Introduces
migraphx::eval_callbackand a newprogram::eval(..., eval_callback, ...)overload to invoke a callback during evaluation. - Exposes the feature through the C API / C++ API wrapper (
migraphx_program_run_callback,program::eval(pparams, F callback)). - Adds unit tests plus a C++ example (
examples/migraphx/cpp_eval_callback) demonstrating filtering options.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
src/program.cpp |
Implements program::eval overload and wires callback invocation + host-copy behavior into the eval path. |
src/include/migraphx/program.hpp |
Declares new eval overload taking eval_callback. |
src/include/migraphx/eval_callback.hpp |
Adds the new callback type with name/instruction filtering helpers. |
src/api/api.cpp |
Adds C API entrypoint migraphx_program_run_callback and bridges to eval_callback. |
src/api/include/migraphx/migraphx.h |
Declares the C API callback typedef + function. |
src/api/include/migraphx/migraphx.hpp |
Adds a C++ convenience wrapper overload to register a per-instruction callback. |
test/eval_test.cpp |
Adds tests validating callback enablement, firing, and filtering behavior. |
examples/migraphx/cpp_eval_callback/eval_callback_example.cpp |
Provides a runnable example demonstrating callback usage + filtering. |
examples/migraphx/cpp_eval_callback/README.md |
Documents building/running the example and filter modes. |
examples/migraphx/cpp_eval_callback/CMakeLists.txt |
Build configuration for the new example. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| void* data); | ||
|
|
||
| MIGRAPHX_C_EXPORT migraphx_status | ||
| migraphx_program_run_callback(migraphx_arguments_t* out, |
There was a problem hiding this comment.
This should be called migraphx_program_run_trace to make it clear its enabling the trace.
There was a problem hiding this comment.
Or maybe we should not expose another overload and expose the execution_environment.
There was a problem hiding this comment.
I've left it exposed through the API for now since I believe it's cleaner than just giving users the execution_environment; I've modified the example as well to show usage of this in trace_callback_example.cpp.
There was a problem hiding this comment.
It just starts create more complicated combinations that user might want to do. What if they want to pass a stream and do trace callback? I think for these more advance cases it makes sense to have the user do it through an execution_environment which we they can use the full options for execution.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #4780 +/- ##
===========================================
+ Coverage 92.29% 92.45% +0.16%
===========================================
Files 580 584 +4
Lines 28688 29598 +910
===========================================
+ Hits 26475 27362 +887
- Misses 2213 2236 +23
🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 9 out of 9 changed files in this pull request and generated 6 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| { | ||
| ret = generic_eval(*this, contexts, params, [&](auto&&, auto f) { return f(); }); | ||
| auto trace_level = value_of(MIGRAPHX_TRACE_EVAL{}); | ||
| if(trace_level > 0) |
There was a problem hiding this comment.
So I dont think we need two paths for the tracing. Instead when MIGRAPHX_TRACE_EVAL is set, then we set the trace callback and run the same trace code.
There was a problem hiding this comment.
Are you suggesting that MIGRAPHX_TRACE_EVAL should overwrite any callback function the user passes in with the current trace callback? Or do we want to support multiple callbacks at once (i.e. both trace and user callback at the same time).
Co-authored-by: anisha-amd <anisha.sankar@amd.com>
shivadbhavsar
left a comment
There was a problem hiding this comment.
LGTM. You can unify the trace_eval here if that's decided, or the unification can done after in a separate PR too. Re-request if you decide to do it in this pr
pfultz2
left a comment
There was a problem hiding this comment.
Tests needed to be added for the API calls.
Motivation
Allow users to inspect data from each instruction.
Technical Details
Adds a callback function to eval() that can be used to get data from specific instructions in the compiled graph. See
examples/migraphx/cpp_trace_callbackfor an implementation of a basic callback function.Changelog Category
Add a
CHANGELOG.mdentry for any option other thanNot Applicable