Skip to content

Commit d0aa228

Browse files
tarun292facebook-github-bot
authored andcommitted
Add event_tracer pointer to delegate backend context (#409)
Summary: Pull Request resolved: #409 Adding `event_tracer` pointer to delegate backend context which backend authors can access for logging/profiling in their backend. Reviewed By: chakriu, cccclai Differential Revision: D49422536 fbshipit-source-id: 7660ff2237b549776d57d0cac99602e76c87977b
1 parent 0ae7110 commit d0aa228

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

runtime/backend/backend_execution_context.h

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
#pragma once
1010

11+
#include <executorch/runtime/core/event_tracer.h>
12+
1113
namespace torch {
1214
namespace executor {
1315

@@ -16,7 +18,23 @@ namespace executor {
1618
* The current plan is to add temp allocator and event tracer (for profiling) as
1719
* part of the runtime context.
1820
*/
19-
class BackendExecutionContext final {};
21+
class BackendExecutionContext final {
22+
public:
23+
BackendExecutionContext(EventTracer* event_tracer = nullptr)
24+
: event_tracer_(event_tracer) {}
25+
26+
/**
27+
* Returns a pointer to an instance of EventTracer to do profiling/debugging
28+
* logging inside the delegate backend. Users will need access to this pointer
29+
* to use any of the event tracer APIs.
30+
*/
31+
EventTracer* event_tracer() {
32+
return event_tracer_;
33+
}
34+
35+
private:
36+
EventTracer* event_tracer_;
37+
};
2038

2139
} // namespace executor
2240
} // namespace torch

runtime/executor/method.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -952,7 +952,7 @@ Error Method::execute_instruction() {
952952
delegate_idx,
953953
n_delegate_,
954954
step_state_.instr_idx);
955-
BackendExecutionContext backend_execution_context;
955+
BackendExecutionContext backend_execution_context(event_tracer_);
956956
Error err = delegates_[delegate_idx].Execute(
957957
backend_execution_context,
958958
chain.argument_lists_[step_state_.instr_idx].data());

0 commit comments

Comments
 (0)