Hi Aakash,
I was able to get the profiler working a little while back so I can share how I did it. The way to set up the profiler will be microprocessor dependent. You will need to have access to a function that gives you the system time. Basically, the profiler relies on two functions which have been stubbed out in
micro_time.cc. One is
ticks_per_second and the other is
GetCurrentTimeTicks. You may need to create a version of `micro_time.cc` that implements these functions for your hardware. Versions of `micro_time.cc` have already been implemented for a variety of different kinds of microprocessors in the different subdirectories in `tflite-micro/tensorflow/lite/micro/`. If your microprocessor is already there, you just need to link to the correct version of `micro_time.cc` when you compile TFLM.
If your microprocessor is not there, you will need to add the appropriate `microe_time.cc` file yourself. What I did was to implement this through some callbacks. So in a file called `tflite-micro/tensorflow/lite/micro/<my_microprocessor>/micro_time.cc` I have:
static CurrentTimeCallback current_time_callback = nullptr;
static TicksPerSecondCallback ticks_per_second_callback = nullptr;
void RegisterCurrentTimeCallback(CurrentTimeCallback cb) {
current_time_callback = cb;
}
void RegisterTicksPerSecondCallback(TicksPerSecondCallback cb) {
ticks_per_second_callback = cb;
}
int32_t ticks_per_second() {
return (int32_t)ticks_per_second_callback();
}
int32_t GetCurrentTimeTicks() {
return (int32_t)current_time_callback();
}
Once you've done that, in your main function you can then do something like this:
#include "tensorflow/lite/micro/<my_microprocessor>/micro_time_callback.h"
// Register the callbacks with the appropriate timer calls on your system
// (May not be needed if model_time.cc can already find the right functions.)
tflite::RegisterCurrentTimeCallback(<my_microprocessors_timer_function>);
tflite::RegisterTicksPerSecondCallback(<my_microprocessors_clock_frequency_function>);
// Create a profiler
tflite::MicroProfiler profiler;
// Include it when you create your interpreter.
tflite::MicroInterpreter interpreter = MicroInterpreter(model, ..., &profiler);
// Invoke your model as normal.
interpreter.Invoke();
// Now you can just do this and it will print out the per-layer times.
profiler.Log();
Hope that helps!
Best,
Joe Antognini