xref: /aosp_15_r20/external/pytorch/test/edge/event_tracer_hooks.h (revision da0073e96a02ea20f0ac840b70461e3646d07c45)
1 /*
2  * Copyright (c) Meta Platforms, Inc. and affiliates.
3  * All rights reserved.
4  *
5  * This source code is licensed under the BSD-style license found in the
6  * LICENSE file in the root directory of this source tree.
7  */
8 
9 #pragma once
10 
11 #include <event_tracer.h>
12 
13 /**
14  * @file
15  *
16  * This file contains the hooks that are inserted across various parts of the
17  * core runtime code to call into the EventTracer class for logging of profiling
18  * and debugging events. Any calls made to the EventTracer from the runtime must
19  * be made via these hooks.
20  * Users shouldn't directly add these hooks in their code and it's meant only
21  * for usage in ExecuTorch internal code.
22  *
23  * The benefit of defining these hooks is that we can easily control whether or
24  * not we want to compile in the EventTracer code based on the status of the
25  * ET_EVENT_TRACER_ENABLED flag.
26  */
27 
28 namespace torch {
29 namespace executor {
30 namespace internal {
31 
32 /**
33  * This class enables scope based profiling where needed using RAII.
34  * Profiling will be started when the object is created and will end
35  * when the object goes out of scope.
36  */
37 class EventTracerProfileScope final {
38  public:
EventTracerProfileScope(EventTracer * event_tracer,const char * name)39   EventTracerProfileScope(EventTracer* event_tracer, const char* name) {};
40 
~EventTracerProfileScope()41   ~EventTracerProfileScope() {};
42 
43  private:
44   EventTracer* event_tracer_;
45   EventTracerEntry event_entry_;
46 };
47 
48 /**
49  * This class helps us set and then clear out the chain id and debug handle
50  * values stored in the event tracer class using RAII. This is typically called
51  * in the executor loop before entering the codegen layer to configure the chain
52  * id and debug handle of the current instruction being executed.
53  * After we return from the kernel execution we can then reset the chain id and
54  * debug handle to defaults when this object goes out of scope.
55  */
56 class EventTracerProfileInstructionScope final {
57  public:
EventTracerProfileInstructionScope(EventTracer * event_tracer,ChainID chain_idx,DebugHandle debug_handle)58   EventTracerProfileInstructionScope(
59       EventTracer* event_tracer,
60       ChainID chain_idx,
61       DebugHandle debug_handle) {};
62 
~EventTracerProfileInstructionScope()63   ~EventTracerProfileInstructionScope() {};
64 
65  private:
66   EventTracer* event_tracer_;
67 };
68 
event_tracer_log_evalue(EventTracer * event_tracer,EValue & evalue)69 void event_tracer_log_evalue(EventTracer* event_tracer, EValue& evalue) {
70   (void)evalue;
71 }
72 
73 } // namespace internal
74 } // namespace executor
75 } // namespace torch
76