Use Kelvin Cycle Count for micro_time
Uses the Kelvin cycle count to indicate ticks. The ticks per second
is ommited (meaning profile.Log() won't work as expected) because
the values in device.h aren't set for the simulator.
Tested:
soundstream benchmark with profile=True/False
Change-Id: I65a29c06fb4dbc74393e892f5c192a325c87ab89
diff --git a/tensorflow/lite/micro/BUILD b/tensorflow/lite/micro/BUILD
index 475c541..13cb8de 100644
--- a/tensorflow/lite/micro/BUILD
+++ b/tensorflow/lite/micro/BUILD
@@ -298,8 +298,11 @@
hdrs = [
"micro_time.h",
],
- copts = micro_copts() + ["-DTF_LITE_USE_CTIME"],
- deps = ["//tensorflow/lite/c:common"],
+ copts = micro_copts(),
+ deps = [
+ "//tensorflow/lite/c:common",
+ "@kelvin_sw//benchmarks:cycle_count",
+ ],
)
cc_library(
diff --git a/tensorflow/lite/micro/micro_time.cc b/tensorflow/lite/micro/micro_time.cc
index 2d74fdb..d543820 100644
--- a/tensorflow/lite/micro/micro_time.cc
+++ b/tensorflow/lite/micro/micro_time.cc
@@ -26,6 +26,8 @@
#include "tensorflow/lite/micro/micro_time.h"
+#include "benchmarks/cycle_count.h"
+
#if defined(TF_LITE_USE_CTIME)
#include <ctime>
#endif
@@ -34,17 +36,10 @@
#if !defined(TF_LITE_USE_CTIME)
-// Reference implementation of the ticks_per_second() function that's required
-// for a platform to support Tensorflow Lite for Microcontrollers profiling.
-// This returns 0 by default because timing is an optional feature that builds
-// without errors on platforms that do not need it.
+// Currently disable ticks_per_second as it won't work for simulator targets.
uint32_t ticks_per_second() { return 0; }
-// Reference implementation of the GetCurrentTimeTicks() function that's
-// required for a platform to support Tensorflow Lite for Microcontrollers
-// profiling. This returns 0 by default because timing is an optional feature
-// that builds without errors on platforms that do not need it.
-uint32_t GetCurrentTimeTicks() { return 0; }
+uint32_t GetCurrentTimeTicks() { return static_cast<uint32_t>(mcycle_read()); }
#else // defined(TF_LITE_USE_CTIME)