Skip to content

Commit

Permalink
Add event tracer for backend init (#7575)
Browse files Browse the repository at this point in the history
Summary:

Per request, backend would like to track model loading time

Reviewed By: tarun292, dbort

Differential Revision: D67987445
  • Loading branch information
cccclai authored and facebook-github-bot committed Jan 10, 2025
1 parent 478198b commit 2683e51
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
11 changes: 11 additions & 0 deletions runtime/backend/backend_init_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class BackendInitContext final {
public:
explicit BackendInitContext(
MemoryAllocator* runtime_allocator,
EventTracer* event_tracer = nullptr,
const char* method_name = nullptr)
: runtime_allocator_(runtime_allocator), method_name_(method_name) {}

Expand All @@ -31,6 +32,15 @@ class BackendInitContext final {
return runtime_allocator_;
}

/**
* Returns a pointer (null if not installed) to an instance of EventTracer to do profiling/debugging
* logging inside the delegate backend. Users will need access to this pointer
* to use any of the event tracer APIs.
*/
EventTracer* event_tracer() {
return event_tracer_;
}

/** Get the loaded method name from ExecuTorch runtime. Usually it's
* "forward", however, if there are multiple methods in the .pte file, it can
* be different. One example is that we may have prefill and decode methods in
Expand All @@ -44,6 +54,7 @@ class BackendInitContext final {

private:
MemoryAllocator* runtime_allocator_ = nullptr;
EventTracer* event_tracer_ = nullptr;
const char* method_name_ = nullptr;
};

Expand Down
1 change: 1 addition & 0 deletions runtime/executor/method.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,7 @@ Error Method::init(executorch_flatbuffer::ExecutionPlan* s_plan) {
const auto& delegate = *delegates->Get(i);
BackendInitContext backend_init_context(
method_allocator,
/*event_tracer=*/event_tracer_,
/*method_name=*/serialization_plan_->name()->c_str());
Error err = BackendDelegate::Init(
delegate, program_, backend_init_context, &delegates_[i]);
Expand Down

0 comments on commit 2683e51

Please sign in to comment.