Skip to content

Commit 1232c2a

Browse files
tarun292facebook-github-bot
authored andcommitted
Add option to disable operator profiling (#136838)
Summary: X-link: pytorch/executorch#5720 For smaller models the overhead of profiling ops might be prohibitively large (distorting the inference execution time significantly) so we provide users an option to disable op profiling and essentially only profile the important events such as inference execution time. To disable operator profiling users need to do: ``` etdump_gen.set_event_tracer_profiling_level(executorch::runtime::EventTracerProfilingLevel::kNoOperatorProfiling); ``` Test Plan: Added test case. Reviewed By: dbort Differential Revision: D61883224
1 parent adc48a5 commit 1232c2a

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

test/edge/event_tracer_hooks.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,22 @@ class EventTracerProfileScope final {
4545
EventTracerEntry event_entry_;
4646
};
4747

48+
/**
49+
* This class enables scope based profiling where needed using RAII.
50+
* Profiling will be started when the object is created and will end
51+
* when the object goes out of scope.
52+
*/
53+
class EventTracerProfileOpScope final {
54+
public:
55+
EventTracerProfileOpScope(EventTracer* event_tracer, const char* name) {};
56+
57+
~EventTracerProfileOpScope() {};
58+
59+
private:
60+
EventTracer* event_tracer_;
61+
EventTracerEntry event_entry_;
62+
};
63+
4864
/**
4965
* This class helps us set and then clear out the chain id and debug handle
5066
* values stored in the event tracer class using RAII. This is typically called

tools/test/test_executorch_gen.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ def test_codegen_unboxed_specialized(self) -> None:
503503
"""
504504
+ """
505505
506-
internal::EventTracerProfileScope event_tracer_scope(context.internal_event_tracer(), "native_call_op_1");
506+
internal::EventTracerProfileOpScope event_tracer_op_scope(context.internal_event_tracer(), "native_call_op_1");
507507
EXECUTORCH_SCOPE_PROF("native_call_op_1");
508508
bool result_ = at::native::default_kernel(context, );
509509
internal::event_tracer_log_evalue(context.internal_event_tracer(), *stack[0]);
@@ -590,7 +590,7 @@ def test_codegen_unboxed_default(self) -> None:
590590
"""
591591
+ """
592592
593-
internal::EventTracerProfileScope event_tracer_scope(context.internal_event_tracer(), "native_call_op_1");
593+
internal::EventTracerProfileOpScope event_tracer_op_scope(context.internal_event_tracer(), "native_call_op_1");
594594
EXECUTORCH_SCOPE_PROF("native_call_op_1");
595595
bool result_ = at::native::default_kernel(context, );
596596
internal::event_tracer_log_evalue(context.internal_event_tracer(), *stack[0]);
@@ -626,7 +626,7 @@ def test_codegen_unboxed_default_kernel_key_selected(self) -> None:
626626
"""
627627
+ """
628628
629-
internal::EventTracerProfileScope event_tracer_scope(context.internal_event_tracer(), "native_call_op_1");
629+
internal::EventTracerProfileOpScope event_tracer_op_scope(context.internal_event_tracer(), "native_call_op_1");
630630
EXECUTORCH_SCOPE_PROF("native_call_op_1");
631631
bool result_ = at::native::default_kernel(context, );
632632
internal::event_tracer_log_evalue(context.internal_event_tracer(), *stack[0]);

torchgen/gen_executorch.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ def __call__(
271271
[]({contextArg.defn()}, EValue** stack) {{
272272
{code_connector.join(code_list)}
273273
274-
internal::EventTracerProfileScope event_tracer_scope(context.internal_event_tracer(), "native_call_{f.func.name}");
274+
internal::EventTracerProfileOpScope event_tracer_op_scope(context.internal_event_tracer(), "native_call_{f.func.name}");
275275
EXECUTORCH_SCOPE_PROF("native_call_{f.func.name}");
276276
{ret_prefix}{kernel_call}(context, {args_str});
277277
{event_tracer_output_logging}

0 commit comments

Comments
 (0)