xref: /aosp_15_r20/external/executorch/devtools/etdump/etdump_schema_flatcc.fbs (revision 523fa7a60841cd1ecfb9cc4201f1ca8b03ed023a)
1include "scalar_type.fbs";
2
3namespace etdump;
4
5// Identifier of a valid executor schema.
6file_identifier "ED00";
7// Extension of written files.
8file_extension "etdp";
9
10table Null {}
11
12table Tensor {
13  scalar_type:executorch_flatbuffer.ScalarType;
14  sizes:[long];
15  strides:[long];
16  offset:long;
17}
18
19table Int {
20  int_val:long;
21}
22
23table Bool {
24  bool_val:bool;
25}
26
27table Float {
28  float_val:float;
29}
30
31table Double {
32  double_val:double;
33}
34
35table String {
36  string_val:string;
37}
38
39table TensorList {
40  tensors:[Tensor];
41}
42
43enum ValueType : byte { Null, Int, Bool, Float, Double, Tensor, TensorList, String,}
44
45// This table is only necessary because flatbuffer can't support a list of
46// union elements directly, they need to be wrapped in a table.
47table Value {
48    val:ValueType;
49    tensor:Tensor;
50    tensor_list:TensorList;
51    int_value:Int;
52    float_value:Float;
53    double_value:Double;
54    bool_value:Bool;
55    output:Bool;
56}
57
58// This table contains all the details that we store to debug an op executed in the
59// runtime. Each entry here reprsents an op executed in the runtime during inference.
60table DebugEvent {
61  // The chain to which this instruction belongs to. For now it will always be 0,
62  // as chains are not used, but left in place in case they are used in the future.
63  chain_index:ulong;
64
65  // Runtime instruction id to which this event corresponds to.
66  instruction_id:int = -1;
67
68  // List of debug entries corresponding to this debug event. These could be
69  // scalars, tensors etc.
70  // The order of these entries is expected to be the same as the parameters
71  // that are passed into a operator.
72  debug_entry:Value;
73
74  // Integer based delegate debug identifier.
75  delegate_debug_id_int:int = -1;
76
77  // String based delegate debug identifier.
78  delegate_debug_id_str:string;
79
80  // Name assigned to this debug event by the runtime. If it is an operator
81  // call this will just be the name of the operator that was executed.
82  name:string;
83}
84
85// All the details pertaining to an allocation done in the runtime. The main
86// details that we care about currently are the allocator id (which directly maps
87// to the allocators stored in the RunData.allocators vector) and the size of the
88// allocation done from it.
89table AllocationEvent {
90  // Allocator id of the allocator from which this memory was allocated.
91  allocator_id:int;
92
93  // Size of allocation in bytes.
94  allocation_size:ulong;
95}
96
97// This table contains all the details we need to represent a profiling event that
98// has occurred in the runtime. These could be an operator profiling event or something
99// more generic like the total time taken to execute an inference loop.
100table ProfileEvent {
101  // Name assigned to this profiling event by the runtime. If it is an operator
102  // call this will just be the name of the operator that was executed.
103  name:string;
104
105  // The chain to which this instruction belongs to. For now it will always be 0,
106  // as chains are not used, but left in place in case they are used in the future.
107  chain_index:int;
108
109  // Runtime instruction id to which this event corresponds to.
110  instruction_id:int = -1;
111
112  // If this is a delegate event then these will be the corresponding delegate
113  // debug identifiers of the event which occurred in the delegate backend. This
114  // should be the same delegate debug identifier that was generated AOT.
115
116  // Integer based delegate debug identifier.
117  delegate_debug_id_int:int = -1;
118
119  // String based delegate debug identifier.
120  delegate_debug_id_str:string;
121
122  // Delegate debug metadata bytes.
123  delegate_debug_metadata:[ubyte];
124
125  // Time at which this event started. Could be in units of time or CPU cycles.
126  start_time:ulong;
127
128  // Time at which this event ended. Could be in units of time or CPU cycles.
129  end_time:ulong;
130}
131
132// This table contains all the details we need to represent a profiling, allocation, or
133// debug event that has occurred in the runtime. These could be an operator profiling
134// event or something more generic like the total time taken to execute an inference loop.
135// Since we can only keep one vector open at a time when building the flatbuffer, using a
136// generic Event type (as opposed to separate arrays for each type) allows us to add
137// different events as they occur.
138//
139// Exactly one of these fields must be non-null, and the rest must be set to null.
140table Event {
141  profile_event: ProfileEvent;
142
143  allocation_event: AllocationEvent;
144
145  debug_event: DebugEvent;
146}
147
148// Representation of an ExecuTorch memory allocator that is used in the runtime.
149table Allocator {
150  // Name of the allocator.
151  name:string;
152}
153
154// This table contains the total set of debug and profiling data that was
155// collected for a single run. It's not always necessary that the profiling
156// data and debug data map 1:1.
157table RunData {
158  name: string;
159
160  // If bundled input was used to run this model on device then this
161  // entry will contain the index of the bundled input that was used
162  // to run this specific block.
163  bundled_input_index:int = -1;
164
165  // List of allocators on which profiling was enabled in the runtime.
166  allocators:[Allocator];
167
168  events: [Event];
169}
170
171table ETDump {
172  // Schema version.
173  version:uint;
174
175  // This is the base level abstraction. One entry here will correspond
176  // to one run.
177  run_data:[RunData];
178
179}
180
181root_type ETDump;
182