Skip to content

Commit 36e03ce

Browse files
tarun292facebook-github-bot
authored andcommitted
etdump schema and etrecord changes for intermediate tensor logging (#1255)
Summary: Pull Request resolved: #1255 All the schema changes needed for intermediate tensor logging in etdump. Reviewed By: Olivia-liu Differential Revision: D50900428 fbshipit-source-id: aaca12ef205f6123f32c21b7905fd19422cb1048
1 parent f4578fc commit 36e03ce

File tree

6 files changed

+66
-30
lines changed

6 files changed

+66
-30
lines changed

sdk/etdump/etdump_flatcc.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ void ETDumpGen::end_profiling_delegate(
131131
etdump_ProfileEvent_start(&builder);
132132
etdump_ProfileEvent_start_time_add(&builder, event_tracer_entry.start_time);
133133
etdump_ProfileEvent_end_time_add(&builder, end_time);
134-
etdump_ProfileEvent_chain_id_add(&builder, chain_id_);
134+
etdump_ProfileEvent_chain_index_add(&builder, chain_id_);
135135
etdump_ProfileEvent_instruction_id_add(&builder, debug_handle_);
136136
// Delegate debug identifier can either be of a string type or an integer
137137
// type. If it's a string type then it's a value of type
@@ -172,7 +172,7 @@ void ETDumpGen::log_profiling_delegate(
172172
etdump_ProfileEvent_start(&builder);
173173
etdump_ProfileEvent_start_time_add(&builder, start_time);
174174
etdump_ProfileEvent_end_time_add(&builder, end_time);
175-
etdump_ProfileEvent_chain_id_add(&builder, chain_id_);
175+
etdump_ProfileEvent_chain_index_add(&builder, chain_id_);
176176
etdump_ProfileEvent_instruction_id_add(&builder, debug_handle_);
177177
if (string_id == -1) {
178178
etdump_ProfileEvent_delegate_debug_id_int_add(
@@ -200,7 +200,7 @@ void ETDumpGen::end_profiling(EventTracerEntry prof_entry) {
200200
etdump_ProfileEvent_start(&builder);
201201
etdump_ProfileEvent_start_time_add(&builder, prof_entry.start_time);
202202
etdump_ProfileEvent_end_time_add(&builder, end_time);
203-
etdump_ProfileEvent_chain_id_add(&builder, prof_entry.chain_id);
203+
etdump_ProfileEvent_chain_index_add(&builder, prof_entry.chain_id);
204204
etdump_ProfileEvent_instruction_id_add(&builder, prof_entry.debug_handle);
205205
if (prof_entry.event_id != -1) {
206206
etdump_ProfileEvent_name_add(&builder, prof_entry.event_id);

sdk/etdump/etdump_schema_flatcc.fbs

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ table Tensor {
1313
scalar_type:executorch_flatbuffer.ScalarType;
1414
sizes:[int];
1515
strides:[int];
16-
data: [ubyte];
16+
offset:long;
1717
}
1818

1919
table Int {
@@ -24,6 +24,10 @@ table Bool {
2424
bool_val:bool;
2525
}
2626

27+
table Float {
28+
float_val:float;
29+
}
30+
2731
table Double {
2832
double_val:double;
2933
}
@@ -32,32 +36,35 @@ table String {
3236
string_val:string;
3337
}
3438

35-
enum ValueType : byte { Null, Int, Bool, Double, Tensor, String,}
39+
enum ValueType : byte { Null, Int, Bool, Float, Double, Tensor, String,}
3640

3741
// This table is only necessary because flatbuffer can't support a list of
3842
// union elements directly, they need to be wrapped in a table.
39-
struct Value {
43+
table Value {
4044
val:ValueType;
41-
offset:ulong;
45+
tensor:Tensor;
46+
int_value:Int;
47+
float_value:Float;
48+
double_value:Double;
49+
bool_value:Bool;
50+
output:Bool;
4251
}
4352

4453
// This table contains all the details that we store to debug an op executed in the
4554
// runtime. Each entry here reprsents an op executed in the runtime during inference.
4655
table DebugEvent {
4756
// The chain to which this instruction belongs to. For now it will always be 0,
4857
// as chains are not used, but left in place in case they are used in the future.
49-
chain_idx:ulong;
58+
chain_index:ulong;
5059

51-
// If this event corresponds to an operator execution then this is the debug
52-
// handle that was generated by the compiler that will help us map back this
53-
// operator to the source code.
54-
debug_handle:ulong;
60+
// Runtime instruction id to which this event corresponds to.
61+
instruction_id:int = -1;
5562

5663
// List of debug entries corresponding to this debug event. These could be
5764
// scalars, tensors etc.
5865
// The order of these entries is expected to be the same as the parameters
5966
// that are passed into a operator.
60-
debug_entries:[Value];
67+
debug_entry:Value;
6168
}
6269

6370
// All the details pertaining to an allocation done in the runtime. The main
@@ -82,7 +89,7 @@ table ProfileEvent {
8289

8390
// The chain to which this instruction belongs to. For now it will always be 0,
8491
// as chains are not used, but left in place in case they are used in the future.
85-
chain_id:int;
92+
chain_index:int;
8693

8794
// Runtime instruction id to which this event corresponds to.
8895
instruction_id:int = -1;
@@ -135,6 +142,11 @@ table Allocator {
135142
table RunData {
136143
name: string;
137144

145+
// If bundled input was used to run this model on device then this
146+
// entry will contain the index of the bundled input that was used
147+
// to run this specific block.
148+
bundled_input_index:int = -1;
149+
138150
// List of allocators on which profiling was enabled in the runtime.
139151
allocators:[Allocator];
140152

sdk/etdump/schema_flatcc.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class Tensor:
2323
scalar_type: ScalarType
2424
sizes: List[int]
2525
strides: List[int]
26-
data: bytes
26+
offset: Optional[int]
2727

2828

2929
@dataclass
@@ -46,6 +46,11 @@ class Double:
4646
double_val: float
4747

4848

49+
@dataclass
50+
class Float:
51+
float_val: float
52+
53+
4954
@dataclass
5055
class String:
5156
string_val: str
@@ -62,6 +67,7 @@ class ValueType(Enum):
6267
NULL = "Null"
6368
INT = "Int"
6469
BOOL = "Bool"
70+
FLOAT = "Float"
6571
DOUBLE = "Double"
6672
TENSOR = "Tensor"
6773
STRING = "String"
@@ -70,14 +76,19 @@ class ValueType(Enum):
7076
@dataclass
7177
class Value:
7278
val: str # Member of ValueType
73-
offset: int
79+
tensor: Optional[Tensor]
80+
int_value: Optional[Int]
81+
float_value: Optional[Float]
82+
double_value: Optional[Double]
83+
bool_value: Optional[Bool]
84+
output: Optional[Bool]
7485

7586

7687
@dataclass
7788
class DebugEvent:
78-
chain_idx: int
79-
debug_handle: int
80-
debug_entries: List[Value]
89+
chain_index: int
90+
instruction_id: int
91+
debug_entry: Value
8192

8293

8394
# Note the differing value style is a result of ETDump string
@@ -91,7 +102,7 @@ class PROFILE_EVENT_ENUM(Enum):
91102
@dataclass
92103
class ProfileEvent:
93104
name: Optional[str]
94-
chain_id: int
105+
chain_index: int
95106
instruction_id: int
96107
delegate_debug_id_int: Optional[int]
97108
delegate_debug_id_str: Optional[str]
@@ -122,6 +133,7 @@ class Event:
122133
@dataclass
123134
class RunData:
124135
name: str
136+
bundled_input_index: Optional[int]
125137
allocators: Optional[List[Allocator]]
126138
events: Optional[List[Event]]
127139

sdk/etdump/tests/etdump_test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ TEST_F(ProfilerETDumpTest, VerifyData) {
251251
etdump_ProfileEvent_name(single_prof_event),
252252
strlen(etdump_ProfileEvent_name(single_prof_event))),
253253
"test_event");
254-
EXPECT_EQ(etdump_ProfileEvent_chain_id(single_prof_event), 0);
254+
EXPECT_EQ(etdump_ProfileEvent_chain_index(single_prof_event), 0);
255255

256256
flatbuffers_string_t allocator_name =
257257
etdump_Allocator_name(etdump_Allocator_vec_at(allocator_vec, 0));

sdk/etdump/tests/serialize_test.py

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ def get_sample_etdump_flatcc() -> flatcc.ETDumpFlatCC:
3636
run_data=[
3737
flatcc.RunData(
3838
name="test_block",
39+
bundled_input_index=-1,
3940
allocators=[
4041
flatcc.Allocator(
4142
name="test_allocator",
@@ -45,7 +46,7 @@ def get_sample_etdump_flatcc() -> flatcc.ETDumpFlatCC:
4546
flatcc.Event(
4647
profile_event=flatcc.ProfileEvent(
4748
name="test_profile_event",
48-
chain_id=1,
49+
chain_index=1,
4950
instruction_id=1,
5051
delegate_debug_id_str="",
5152
delegate_debug_id_int=-1,
@@ -59,7 +60,7 @@ def get_sample_etdump_flatcc() -> flatcc.ETDumpFlatCC:
5960
flatcc.Event(
6061
profile_event=flatcc.ProfileEvent(
6162
name="test_profile_event_delegated",
62-
chain_id=1,
63+
chain_index=1,
6364
instruction_id=1,
6465
delegate_debug_id_str="",
6566
delegate_debug_id_int=13,
@@ -82,14 +83,22 @@ def get_sample_etdump_flatcc() -> flatcc.ETDumpFlatCC:
8283
profile_event=None,
8384
allocation_event=None,
8485
debug_event=flatcc.DebugEvent(
85-
chain_idx=1,
86-
debug_handle=0,
87-
debug_entries=[
88-
flatcc.Value(
89-
val=flatcc.ValueType.TENSOR.value,
86+
chain_index=1,
87+
instruction_id=0,
88+
debug_entry=flatcc.Value(
89+
val=flatcc.ValueType.TENSOR.value,
90+
tensor=flatcc.Tensor(
91+
scalar_type=flatcc.ScalarType.INT,
92+
sizes=[1],
93+
strides=[1],
9094
offset=12345,
91-
)
92-
],
95+
),
96+
int_value=flatcc.Int(1),
97+
float_value=flatcc.Float(1.0),
98+
double_value=flatcc.Double(1.0),
99+
bool_value=flatcc.Bool(False),
100+
output=flatcc.Bool(True),
101+
),
93102
),
94103
),
95104
],

sdk/inspector/tests/event_blocks_test.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ def _get_sample_etdump_flatcc() -> flatcc.ETDumpFlatCC:
6363
)
6464
run_data_1 = flatcc.RunData(
6565
name="run_data_1",
66+
bundled_input_index=-1,
6667
allocators=[],
6768
events=[
6869
flatcc.Event(
@@ -77,6 +78,7 @@ def _get_sample_etdump_flatcc() -> flatcc.ETDumpFlatCC:
7778
)
7879
run_data_2 = flatcc.RunData(
7980
name="run_data_2",
81+
bundled_input_index=-1,
8082
allocators=[],
8183
events=[
8284
flatcc.Event(
@@ -95,6 +97,7 @@ def _get_sample_etdump_flatcc() -> flatcc.ETDumpFlatCC:
9597
)
9698
run_data_3 = flatcc.RunData(
9799
name="run_data_3",
100+
bundled_input_index=-1,
98101
allocators=[],
99102
events=[
100103
flatcc.Event(

0 commit comments

Comments
 (0)