enable use of <ctime> for profiling via -DTF_LITE_USE_CTIME

This commit is contained in:
Advait Jain 2020-11-05 14:29:12 -08:00
parent ac56fe8f94
commit ab21c0fbb8
8 changed files with 25 additions and 86 deletions

View File

@ -158,12 +158,12 @@ cc_library(
cc_library(
name = "micro_time",
srcs = [
"posix/micro_time.cc",
"micro_time.cc",
],
hdrs = [
"micro_time.h",
],
copts = micro_copts(),
copts = micro_copts() + ["-DTF_LITE_USE_CTIME"],
deps = ["//tensorflow/lite/c:common"],
)

View File

@ -1,28 +0,0 @@
/* Copyright 2020 The TensorFlow Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/
// Hexagon timer implementation.
// To include this with make, add TARGET=hexagon.
#include "tensorflow/lite/micro/micro_time.h"
#include <time.h>
namespace tflite {
int32_t ticks_per_second() { return CLOCKS_PER_SEC; }
int32_t GetCurrentTimeTicks() { return clock(); }
} // namespace tflite

View File

@ -27,8 +27,14 @@ limitations under the License.
#include "tensorflow/lite/micro/micro_time.h"
#if defined(TF_LITE_USE_CTIME)
#include <ctime>
#endif
namespace tflite {
#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
@ -41,4 +47,13 @@ int32_t ticks_per_second() { return 0; }
// that builds without errors on platforms that do not need it.
int32_t GetCurrentTimeTicks() { return 0; }
#else // defined(TF_LITE_USE_CTIME)
// For platforms that support ctime, we implment the micro_time interface in
// this central location.
int32_t ticks_per_second() { return CLOCKS_PER_SEC; }
int32_t GetCurrentTimeTicks() { return clock(); }
#endif
} // namespace tflite

View File

@ -1,28 +0,0 @@
/* Copyright 2019 The TensorFlow Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/
// Posix implementation of micro_timer.
// To include this with make, add TAGS=posix.
#include "tensorflow/lite/micro/micro_time.h"
#include <time.h>
namespace tflite {
int32_t ticks_per_second() { return CLOCKS_PER_SEC; }
int32_t GetCurrentTimeTicks() { return clock(); }
} // namespace tflite

View File

@ -137,6 +137,12 @@ COMMON_FLAGS := \
$(OPTIMIZED_KERNEL_DEFINES) \
$(TAG_DEFINES)
ifeq ($(TARGET), $(HOST_OS))
# If we are not doing a cross-compilation then -DTF_LITE_USE_CTIME is what we
# want to have by default.
COMMON_FLAGS += -DTF_LITE_USE_CTIME
endif
CXXFLAGS := \
-std=c++11 \
-fno-rtti \

View File

@ -39,6 +39,7 @@ ifeq ($(TARGET), hexagon)
PLATFORM_ARGS = \
-DTF_LITE_MCU_DEBUG_LOG \
-DTF_LITE_USE_CTIME \
-DHEXAGON_ASM \
-DMALLOC_IN_STDLIB \
-DPTHREAD_STUBS \

View File

@ -24,6 +24,7 @@ endif
PLATFORM_FLAGS = \
-DTF_LITE_MCU_DEBUG_LOG \
-DTF_LITE_USE_CTIME \
--xtensa-core=$(XTENSA_CORE) \
-mcoproc \
-DXTENSA \

View File

@ -1,28 +0,0 @@
/* Copyright 2020 The TensorFlow Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/
// Xtensa timer implementation.
// To include this with make, add TARGET=xtensa_hifimini.
#include "tensorflow/lite/micro/micro_time.h"
#include <time.h>
namespace tflite {
int32_t ticks_per_second() { return CLOCKS_PER_SEC; }
int32_t GetCurrentTimeTicks() { return clock(); }
} // namespace tflite