@@ -107,7 +107,7 @@ static uint8_t* alignPointer(void* ptr, size_t alignment) {
107
107
} // namespace
108
108
109
109
// Constructor implementation
110
- ETDumpGen::ETDumpGen (Span<uint8_t > buffer) {
110
+ ETDumpGenBase::ETDumpGenBase (Span<uint8_t > buffer) {
111
111
constexpr size_t max_alloc_buf_size = 128 * 1024 ;
112
112
113
113
// Initialize the flatcc builder_ using the buffer and buffer size.
@@ -140,14 +140,14 @@ ETDumpGen::ETDumpGen(Span<uint8_t> buffer) {
140
140
reset ();
141
141
}
142
142
143
- ETDumpGen ::~ETDumpGen () {
143
+ ETDumpGenBase ::~ETDumpGenBase () {
144
144
flatcc_builder_clear (builder_);
145
145
if (!is_static_etdump ()) {
146
146
free (builder_);
147
147
}
148
148
}
149
149
150
- void ETDumpGen ::reset () {
150
+ void ETDumpGenBase ::reset () {
151
151
state_ = State::Init;
152
152
num_blocks_ = 0 ;
153
153
flatcc_builder_reset (builder_);
@@ -158,7 +158,7 @@ void ETDumpGen::reset() {
158
158
etdump_ETDump_run_data_push_start (builder_);
159
159
}
160
160
161
- void ETDumpGen ::create_event_block (const char * name) {
161
+ void ETDumpGenBase ::create_event_block (const char * name) {
162
162
if (state_ == State::AddingEvents) {
163
163
etdump_RunData_events_end (builder_);
164
164
} else if (state_ == State::Done) {
@@ -176,24 +176,24 @@ void ETDumpGen::create_event_block(const char* name) {
176
176
state_ = State::BlockCreated;
177
177
}
178
178
179
- int64_t ETDumpGen ::create_string_entry (const char * name) {
179
+ int64_t ETDumpGenBase ::create_string_entry (const char * name) {
180
180
return flatbuffers_string_create_str (builder_, name);
181
181
}
182
182
183
- // ETDumpGen has the following possible states, ETDumpGen_Init ,
184
- // ETDumpGen_Block_Created, ETDumpGen_Adding_Allocators,
183
+ // ETDumpGenBase family classes has the following possible states,
184
+ // ETDumpGen_Init, ETDumpGen_Block_Created, ETDumpGen_Adding_Allocators,
185
185
// ETDumpGen_Adding_Events. Right after boot-up the state of ETDump will be
186
186
// ETDumpGen_Init. At this point we have an option of adding allocators that
187
187
// we want to track. Once we've completed adding the allocators we want to track
188
- // we will close the allocators table and move ETDumpGen to the
189
- // ETDumpGen_Adding_Events state. After this point we can start adding events to
190
- // ETDump as we wish.
191
- // The reason we need to maintain this state machine inside of ETDumpGen is
192
- // because, once a table of one type has been closed and another table of a
193
- // different type is opened after it we cannot open another table of the first
194
- // type again. In this case once we close the allocators table and start pushing
195
- // to the events table we cannot push to the allocators table again.
196
- void ETDumpGen ::check_ready_to_add_events () {
188
+ // we will close the allocators table and move ETDumpGenBase family classes to
189
+ // the ETDumpGen_Adding_Events state. After this point we can start adding
190
+ // events to ETDump as we wish. The reason we need to maintain this state
191
+ // machine inside of ETDumpGenBase family classes is because, once a table of
192
+ // one type has been closed and another table of a different type is opened
193
+ // after it we cannot open another table of the first type again. In this case
194
+ // once we close the allocators table and start pushing to the events table we
195
+ // cannot push to the allocators table again.
196
+ void ETDumpGenBase ::check_ready_to_add_events () {
197
197
if (state_ != State::AddingEvents) {
198
198
ET_CHECK_MSG (
199
199
(state_ == State::AddingAllocators || state_ == State::BlockCreated),
@@ -206,7 +206,7 @@ void ETDumpGen::check_ready_to_add_events() {
206
206
}
207
207
}
208
208
209
- EventTracerEntry ETDumpGen ::start_profiling (
209
+ EventTracerEntry ETDumpGenBase ::start_profiling (
210
210
const char * name,
211
211
ChainID chain_id,
212
212
DebugHandle debug_handle) {
@@ -227,7 +227,7 @@ EventTracerEntry ETDumpGen::start_profiling(
227
227
228
228
// TODO: Update all occurrences of the ProfileEvent calls once the
229
229
// EventTracerEntry struct is updated.
230
- EventTracerEntry ETDumpGen ::start_profiling_delegate (
230
+ EventTracerEntry ETDumpGenBase ::start_profiling_delegate (
231
231
const char * name,
232
232
DebugHandle delegate_debug_index) {
233
233
ET_CHECK_MSG (
@@ -247,7 +247,7 @@ EventTracerEntry ETDumpGen::start_profiling_delegate(
247
247
return prof_entry;
248
248
}
249
249
250
- void ETDumpGen ::end_profiling_delegate (
250
+ void ETDumpGenBase ::end_profiling_delegate (
251
251
EventTracerEntry event_tracer_entry,
252
252
const void * metadata,
253
253
size_t metadata_len) {
@@ -280,7 +280,7 @@ void ETDumpGen::end_profiling_delegate(
280
280
etdump_RunData_events_push_end (builder_);
281
281
}
282
282
283
- void ETDumpGen ::log_profiling_delegate (
283
+ void ETDumpGenBase ::log_profiling_delegate (
284
284
const char * name,
285
285
DebugHandle delegate_debug_index,
286
286
et_timestamp_t start_time,
@@ -312,43 +312,43 @@ void ETDumpGen::log_profiling_delegate(
312
312
etdump_RunData_events_push_end (builder_);
313
313
}
314
314
315
- void ETDumpGen ::log_intermediate_output_delegate (
315
+ void ETDumpGenBase ::log_intermediate_output_delegate (
316
316
const char * name,
317
317
DebugHandle delegate_debug_index,
318
318
const Tensor& output) {
319
319
log_intermediate_output_delegate_helper (name, delegate_debug_index, output);
320
320
}
321
321
322
- void ETDumpGen ::log_intermediate_output_delegate (
322
+ void ETDumpGenBase ::log_intermediate_output_delegate (
323
323
const char * name,
324
324
DebugHandle delegate_debug_index,
325
325
const ArrayRef<Tensor> output) {
326
326
log_intermediate_output_delegate_helper (name, delegate_debug_index, output);
327
327
}
328
328
329
- void ETDumpGen ::log_intermediate_output_delegate (
329
+ void ETDumpGenBase ::log_intermediate_output_delegate (
330
330
const char * name,
331
331
DebugHandle delegate_debug_index,
332
332
const int & output) {
333
333
log_intermediate_output_delegate_helper (name, delegate_debug_index, output);
334
334
}
335
335
336
- void ETDumpGen ::log_intermediate_output_delegate (
336
+ void ETDumpGenBase ::log_intermediate_output_delegate (
337
337
const char * name,
338
338
DebugHandle delegate_debug_index,
339
339
const bool & output) {
340
340
log_intermediate_output_delegate_helper (name, delegate_debug_index, output);
341
341
}
342
342
343
- void ETDumpGen ::log_intermediate_output_delegate (
343
+ void ETDumpGenBase ::log_intermediate_output_delegate (
344
344
const char * name,
345
345
DebugHandle delegate_debug_index,
346
346
const double & output) {
347
347
log_intermediate_output_delegate_helper (name, delegate_debug_index, output);
348
348
}
349
349
350
350
template <typename T>
351
- void ETDumpGen ::log_intermediate_output_delegate_helper (
351
+ void ETDumpGenBase ::log_intermediate_output_delegate_helper (
352
352
const char * name,
353
353
DebugHandle delegate_debug_index,
354
354
const T& output) {
@@ -430,7 +430,7 @@ void ETDumpGen::log_intermediate_output_delegate_helper(
430
430
etdump_RunData_events_push_end (builder_);
431
431
}
432
432
433
- void ETDumpGen ::end_profiling (EventTracerEntry prof_entry) {
433
+ void ETDumpGenBase ::end_profiling (EventTracerEntry prof_entry) {
434
434
et_timestamp_t end_time = et_pal_current_ticks ();
435
435
ET_CHECK_MSG (
436
436
prof_entry.delegate_event_id_type == DelegateDebugIdType::kNone ,
@@ -451,7 +451,7 @@ void ETDumpGen::end_profiling(EventTracerEntry prof_entry) {
451
451
etdump_RunData_events_push_end (builder_);
452
452
}
453
453
454
- AllocatorID ETDumpGen ::track_allocator (const char * name) {
454
+ AllocatorID ETDumpGenBase ::track_allocator (const char * name) {
455
455
ET_CHECK_MSG (
456
456
(state_ == State::BlockCreated || state_ == State::AddingAllocators),
457
457
" Allocators can only be added immediately after a new block is created and before any events are added." );
@@ -464,7 +464,7 @@ AllocatorID ETDumpGen::track_allocator(const char* name) {
464
464
return etdump_RunData_allocators_reserved_len (builder_);
465
465
}
466
466
467
- void ETDumpGen ::track_allocation (
467
+ void ETDumpGenBase ::track_allocation (
468
468
AllocatorID allocator_id,
469
469
size_t allocation_size) {
470
470
check_ready_to_add_events ();
@@ -474,7 +474,7 @@ void ETDumpGen::track_allocation(
474
474
etdump_RunData_events_push_end (builder_);
475
475
}
476
476
477
- ETDumpResult ETDumpGen ::get_etdump_data () {
477
+ ETDumpResult ETDumpGenBase ::get_etdump_data () {
478
478
ETDumpResult result;
479
479
if (state_ == State::AddingEvents) {
480
480
etdump_RunData_events_end (builder_);
@@ -504,25 +504,13 @@ ETDumpResult ETDumpGen::get_etdump_data() {
504
504
return result;
505
505
}
506
506
507
- void ETDumpGen ::set_debug_buffer (Span<uint8_t > buffer) {
507
+ void ETDumpGenBase ::set_debug_buffer (Span<uint8_t > buffer) {
508
508
debug_buffer_ = buffer;
509
509
}
510
510
511
- size_t ETDumpGen::copy_tensor_to_debug_buffer (executorch::aten::Tensor tensor) {
512
- if (tensor.nbytes () == 0 ) {
513
- return static_cast <size_t >(-1 );
514
- }
515
- uint8_t * offset_ptr =
516
- alignPointer (debug_buffer_.data () + debug_buffer_offset_, 64 );
517
- debug_buffer_offset_ = (offset_ptr - debug_buffer_.data ()) + tensor.nbytes ();
518
- ET_CHECK_MSG (
519
- debug_buffer_offset_ <= debug_buffer_.size (),
520
- " Ran out of space to store intermediate outputs." );
521
- memcpy (offset_ptr, tensor.const_data_ptr (), tensor.nbytes ());
522
- return (size_t )(offset_ptr - debug_buffer_.data ());
523
- }
524
-
525
- void ETDumpGen::log_evalue (const EValue& evalue, LoggedEValueType evalue_type) {
511
+ void ETDumpGenBase::log_evalue (
512
+ const EValue& evalue,
513
+ LoggedEValueType evalue_type) {
526
514
if (debug_buffer_.empty ()) {
527
515
return ;
528
516
}
@@ -635,17 +623,32 @@ void ETDumpGen::log_evalue(const EValue& evalue, LoggedEValueType evalue_type) {
635
623
etdump_RunData_events_push_end (builder_);
636
624
}
637
625
638
- size_t ETDumpGen ::get_num_blocks () {
626
+ size_t ETDumpGenBase ::get_num_blocks () {
639
627
return num_blocks_;
640
628
}
641
629
642
- bool ETDumpGen ::is_static_etdump () {
630
+ bool ETDumpGenBase ::is_static_etdump () {
643
631
return alloc_.data != nullptr ;
644
632
}
645
633
646
- size_t ETDumpGen ::get_debug_buffer_size () const {
634
+ size_t ETDumpGenBase ::get_debug_buffer_size () const {
647
635
return debug_buffer_.size ();
648
636
}
649
637
638
+ size_t ETDumpGen::copy_tensor_to_debug_buffer (
639
+ const executorch::aten::Tensor& tensor) {
640
+ if (tensor.nbytes () == 0 ) {
641
+ return static_cast <size_t >(-1 );
642
+ }
643
+ uint8_t * offset_ptr =
644
+ alignPointer (debug_buffer_.data () + debug_buffer_offset_, 64 );
645
+ debug_buffer_offset_ = (offset_ptr - debug_buffer_.data ()) + tensor.nbytes ();
646
+ ET_CHECK_MSG (
647
+ debug_buffer_offset_ <= debug_buffer_.size (),
648
+ " Ran out of space to store intermediate outputs." );
649
+ memcpy (offset_ptr, tensor.const_data_ptr (), tensor.nbytes ());
650
+ return (size_t )(offset_ptr - debug_buffer_.data ());
651
+ }
652
+
650
653
} // namespace etdump
651
654
} // namespace executorch
0 commit comments