Skip to content

Increase kMaxEvents and error out when it's exceeded #1835

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion tensorflow/lite/micro/docs/profiling.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,14 @@ from within operator kernels and other TFLite Micro routines.

## API

The MicroInterpreter class constructor contains and optional profiler argument.
The MicroInterpreter class constructor contains an optional profiler argument.
This profiler must be an instance of the tflite::Profiler class, and should
implement the BeginEvent and EndEvent methods. There is a default implementation
in tensorflow/lite/micro/micro_profiler.cc which can be used for most purposes.

The best practice for profiling across multiple invocations is to reset or call
`ClearEvents()` in between invocations.

## Per-Op Profiling

There is a feature in the MicroInterpreter to enable per-op profiling. To enable
Expand Down
6 changes: 5 additions & 1 deletion tensorflow/lite/micro/micro_profiler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@ namespace tflite {

uint32_t MicroProfiler::BeginEvent(const char* tag) {
if (num_events_ == kMaxEvents) {
num_events_ = 0;
MicroPrintf(
"MicroProfiler errored out because total number of events exceeded the "
"maximum of %d.",
kMaxEvents);
TFLITE_ASSERT_FALSE;
}

tags_[num_events_] = tag;
Expand Down
2 changes: 1 addition & 1 deletion tensorflow/lite/micro/micro_profiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class MicroProfiler : public MicroProfilerInterface {
// Maximum number of events that this class can keep track of. If we call
// AddEvent more than kMaxEvents number of times, then the oldest event's
// profiling information will be overwritten.
static constexpr int kMaxEvents = 1024;
static constexpr int kMaxEvents = 4096;

const char* tags_[kMaxEvents];
uint32_t start_ticks_[kMaxEvents];
Expand Down