![]() |
ONNX Runtime
|
Struct that an EP implements for profiling support. More...
#include <onnxruntime_ep_c_api.h>
Public Member Functions | |
| OrtStatus * | StartProfiling (OrtEpProfilerImpl *this_ptr, int64_t ep_profiling_start_offset_ns) |
| Called when profiling starts. | |
| OrtStatus * | StartEvent (OrtEpProfilerImpl *this_ptr, uint64_t ort_event_correlation_id) |
| Called when an ORT event (e.g., session initialization, node kernel execution, etc.) begins. | |
| OrtStatus * | StopEvent (OrtEpProfilerImpl *this_ptr, uint64_t ort_event_correlation_id, const OrtProfilingEvent *ort_event) |
| Called when a profiled ORT event (e.g., session initialization, node kernel execution, etc.) ends. | |
| OrtStatus * | EndProfiling (OrtEpProfilerImpl *this_ptr, OrtProfilingEventsContainer *events_container) |
| Called when profiling ends to collect the EP's new profiling events since the call to StartProfiling. | |
Public Attributes | |
| uint32_t | ort_version_supported |
| Must be initialized to ORT_API_VERSION. | |
| void(* | Release )(OrtEpProfilerImpl *this_ptr) |
| Release the OrtEpProfilerImpl instance. | |
Struct that an EP implements for profiling support.
An execution provider optionally implements this struct to participate in ONNX Runtime's profiling system. The EP creates and returns an instance of this struct via OrtEp::CreateProfiler.
ORT calls the function pointers at appropriate times during a profiling session:
Profiling scenarios:
| OrtStatus * OrtEpProfilerImpl::EndProfiling | ( | OrtEpProfilerImpl * | this_ptr, |
| OrtProfilingEventsContainer * | events_container | ||
| ) |
Called when profiling ends to collect the EP's new profiling events since the call to StartProfiling.
An EP profiler converts its events to OrtProfilingEvent instances and adds them into the provided OrtProfilingEventsContainer container. Call OrtEpApi::CreateProfilingEvent to create a new OrtProfilingEvent instance. Then call OrtEpApi::ProfilingEventsContainer_AddEvents to add one or more events to the container.
After this function returns, ORT appends the EP's events to the profiling timeline.
| [in] | this_ptr | The OrtEpProfilerImpl instance. |
| [in] | events_container | Event container to which the EP profiler adds its new events. |
| OrtStatus * OrtEpProfilerImpl::StartEvent | ( | OrtEpProfilerImpl * | this_ptr, |
| uint64_t | ort_event_correlation_id | ||
| ) |
Called when an ORT event (e.g., session initialization, node kernel execution, etc.) begins.
ORT pairs every StartEvent call with a corresponding call to StopEvent with the same ORT event correlation ID. EP profiler implementations may use the calls to StartEvent and StopEvent to maintain a stack of ORT event correlation IDs that can be correlated with EP events (e.g., GPU kernel events). For example:
OrtEpProfilerImpl::StartEvent(x) -> EP ort event stack: [x] <- top of stack [EP events are tagged with 'x'] OrtEpProfilerImpl::StartEvent(y) -> EP ort event stack: [x, y] <- top of stack [EP events are tagged with 'y'] OrtEpProfilerImpl::StopEvent(y) -> EP ort event stack: [x] <- top of stack OrtEpProfilerImpl::StartEvent(z) -> EP ort event stack: [x, z] <- top of stack [EP events are tagged with 'z'] OrtEpProfilerImpl::StopEvent(z) -> EP ort event stack: [x] <- top of stack OrtEpProfilerImpl::StopEvent(x) -> EP ort event stack: [ ] <- top of stack
Tagging EP events with the ORT event correlation ID enables the EP to annotate its own events with metadata from the parent ORT event (e.g., operator name).
| [in] | this_ptr | Pointer to the OrtEpProfilerImpl instance. |
| [in] | ort_event_correlation_id | Absolute, epoch-based correlation ID for the ORT event that is starting. The same value is passed to the corresponding StopEvent call. |
| OrtStatus * OrtEpProfilerImpl::StartProfiling | ( | OrtEpProfilerImpl * | this_ptr, |
| int64_t | ep_profiling_start_offset_ns | ||
| ) |
Called when profiling starts.
Allows the EP profiler to initialize profiling utilities and record the profiling start time.
An EP profiler should record its own clock's current time when this function is called. This allows the EP to later compute ORT-relative event timestamps by combining ep_profiling_start_offset_ns with the EP's own elapsed time since this call. The formula is:
event_timestamp_us = (ep_profiling_start_offset_ns + (ep_event_time_ns - ep_profiling_start_time_ns)) / 1000
where ep_event_time_ns and ep_profiling_start_time_ns are measured using the EP's own clock.
| [in] | this_ptr | Pointer to the OrtEpProfilerImpl instance. |
| [in] | ep_profiling_start_offset_ns | The elapsed time in nanoseconds (using ORT's profiling clock) between ORT's profiling start and this call to StartProfiling. |
| OrtStatus * OrtEpProfilerImpl::StopEvent | ( | OrtEpProfilerImpl * | this_ptr, |
| uint64_t | ort_event_correlation_id, | ||
| const OrtProfilingEvent * | ort_event | ||
| ) |
Called when a profiled ORT event (e.g., session initialization, node kernel execution, etc.) ends.
ORT pairs every StartEvent call with a corresponding call to StopEvent with the same ORT event correlation ID. EP profiler implementations may use the calls to StartEvent and StopEvent to maintain a stack of ORT event correlation IDs that can be correlated with EP events (e.g., GPU kernel events). For example:
OrtEpProfilerImpl::StartEvent(x) -> EP ort event stack: [x] <- top of stack [EP events are tagged with 'x'] OrtEpProfilerImpl::StartEvent(y) -> EP ort event stack: [x, y] <- top of stack [EP events are tagged with 'y'] OrtEpProfilerImpl::StopEvent(y) -> EP ort event stack: [x] <- top of stack OrtEpProfilerImpl::StartEvent(z) -> EP ort event stack: [x, z] <- top of stack [EP events are tagged with 'z'] OrtEpProfilerImpl::StopEvent(z) -> EP ort event stack: [x] <- top of stack OrtEpProfilerImpl::StopEvent(x) -> EP ort event stack: [ ] <- top of stack
Tagging EP events with the ORT event correlation ID enables the EP to annotate its own events with metadata from the parent ORT event (e.g., operator name).
| [in] | this_ptr | Pointer to the OrtEpProfilerImpl instance. |
| [in] | ort_event_correlation_id | Absolute, epoch-based correlation ID for the ORT event that is ending. The same value was passed to the corresponding StartEvent call. |
| [in] | ort_event | Opaque pointer to the ORT profiling event. Valid only during this call. Use OrtEpApi accessor functions to read event fields. |
| uint32_t OrtEpProfilerImpl::ort_version_supported |
Must be initialized to ORT_API_VERSION.
| void( * OrtEpProfilerImpl::Release) (OrtEpProfilerImpl *this_ptr) |
Release the OrtEpProfilerImpl instance.
Called by ORT when the profiler is no longer needed. The implementation should release any resources held by the instance.
| [in] | this_ptr | Pointer to the OrtEpProfilerImpl instance. |