diff --git a/tensorflow/lite/BUILD b/tensorflow/lite/BUILD index 32ff4a2dde2..84150546353 100644 --- a/tensorflow/lite/BUILD +++ b/tensorflow/lite/BUILD @@ -15,14 +15,6 @@ exports_files(glob([ "models/testdata/*", ])) -# Config setting to determine if we are building for embedded platforms. -config_setting( - name = "micro", - define_values = { - "micro": "true", - }, -) - config_setting( name = "mips", values = { diff --git a/tensorflow/lite/kernels/internal/BUILD b/tensorflow/lite/kernels/internal/BUILD index 671ed96f5fc..43b6a50cf5a 100644 --- a/tensorflow/lite/kernels/internal/BUILD +++ b/tensorflow/lite/kernels/internal/BUILD @@ -49,10 +49,6 @@ cc_library( cc_library( name = "scoped_profiling_label_wrapper", - srcs = select({ - "//tensorflow/lite:micro": ["scoped_profiling_label_wrapper_stub.cc"], - "//conditions:default": ["scoped_profiling_label_wrapper_gemmlowp.cc"], - }), hdrs = ["scoped_profiling_label_wrapper.h"], copts = tflite_copts(), # TODO(b/145820877): Add in a select statement once we can figure out a way diff --git a/tensorflow/lite/kernels/internal/scoped_profiling_label_wrapper.h b/tensorflow/lite/kernels/internal/scoped_profiling_label_wrapper.h index f1f21aafe14..ed883b1c0b5 100644 --- a/tensorflow/lite/kernels/internal/scoped_profiling_label_wrapper.h +++ b/tensorflow/lite/kernels/internal/scoped_profiling_label_wrapper.h @@ -15,23 +15,42 @@ limitations under the License. #ifndef TENSORFLOW_LITE_KERNELS_INTERNAL_SCOPED_PROFILING_LABEL_WRAPPER_H_ #define TENSORFLOW_LITE_KERNELS_INTERNAL_SCOPED_PROFILING_LABEL_WRAPPER_H_ -namespace tflite { +// gemmlowp itself defines an empty class for ScopedProfilingLabel when +// GEMMLOWP_PROFILING is not defined. However, that does not work for embedded +// builds because instrumentation.h depends on pthread and defines a few Mutex +// classes independent of GEMMLOWP_PROFILING. +// +// As a result, we are using GEMMLOWP_PROFILING to either pull in the +// gemmlowp implementation or use our own empty class. +// +// The downside with this approach is that we are using a gemmlowp macro from +// the TFLite codebase. The upside is that it is much simpler than the +// alternatives (see history of this file). -// This class uses the PIMPL pattern to enable a stub implementation for micro -// platforms and a full gemlowp implementation otherwise. +#ifdef GEMMLOWP_PROFILING + +#include "profiling/instrumentation.h" + +namespace tflite { class ScopedProfilingLabelWrapper { public: - explicit ScopedProfilingLabelWrapper(const char* label); - - ~ScopedProfilingLabelWrapper(); + explicit ScopedProfilingLabelWrapper(const char* label) + : scoped_profiling_label_(label) {} private: - class ScopedProfilingLabelImpl; - // Using a raw pointer instead of unique_ptr because we need to also build for - // embedded platforms. - ScopedProfilingLabelImpl* impl_; + gemmlowp::ScopedProfilingLabel scoped_profiling_label_; }; - } // namespace tflite +#else // GEMMLOWP_PROFILING + +namespace tflite { +class ScopedProfilingLabelWrapper { + public: + explicit ScopedProfilingLabelWrapper(const char* label) {} +}; +} // namespace tflite + +#endif // GEMMLOWP_PROFILING + #endif // TENSORFLOW_LITE_KERNELS_INTERNAL_SCOPED_PROFILING_LABEL_WRAPPER_H_ diff --git a/tensorflow/lite/kernels/internal/scoped_profiling_label_wrapper_gemmlowp.cc b/tensorflow/lite/kernels/internal/scoped_profiling_label_wrapper_gemmlowp.cc deleted file mode 100644 index b3eb118704a..00000000000 --- a/tensorflow/lite/kernels/internal/scoped_profiling_label_wrapper_gemmlowp.cc +++ /dev/null @@ -1,34 +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. -==============================================================================*/ - -#include "profiling/instrumentation.h" -#include "tensorflow/lite/kernels/internal/scoped_profiling_label_wrapper.h" - -namespace tflite { - -class ScopedProfilingLabelWrapper::ScopedProfilingLabelImpl { - public: - explicit ScopedProfilingLabelImpl(const char* label) : gemmlowp_(label) {} - - private: - gemmlowp::ScopedProfilingLabel gemmlowp_; -}; - -ScopedProfilingLabelWrapper::ScopedProfilingLabelWrapper(const char* label) - : impl_(new ScopedProfilingLabelImpl(label)) {} - -ScopedProfilingLabelWrapper::~ScopedProfilingLabelWrapper() { delete impl_; } - -} // namespace tflite diff --git a/tensorflow/lite/kernels/internal/scoped_profiling_label_wrapper_stub.cc b/tensorflow/lite/kernels/internal/scoped_profiling_label_wrapper_stub.cc deleted file mode 100644 index 6946155d1cf..00000000000 --- a/tensorflow/lite/kernels/internal/scoped_profiling_label_wrapper_stub.cc +++ /dev/null @@ -1,27 +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. -==============================================================================*/ - -#include "tensorflow/lite/kernels/internal/scoped_profiling_label_wrapper.h" - -namespace tflite { - -class ScopedProfilingLabelWrapper::ScopedProfilingLabelImpl {}; - -ScopedProfilingLabelWrapper::ScopedProfilingLabelWrapper(const char* label) - : impl_(nullptr) {} - -ScopedProfilingLabelWrapper::~ScopedProfilingLabelWrapper() = default; - -} // namespace tflite diff --git a/tensorflow/lite/micro/tools/make/Makefile b/tensorflow/lite/micro/tools/make/Makefile index a3c1c378547..2c7295ef4f0 100644 --- a/tensorflow/lite/micro/tools/make/Makefile +++ b/tensorflow/lite/micro/tools/make/Makefile @@ -99,7 +99,6 @@ tensorflow/lite/core/api/flatbuffer_conversions.cc \ tensorflow/lite/core/api/op_resolver.cc \ tensorflow/lite/core/api/tensor_utils.cc \ tensorflow/lite/kernels/internal/quantization_util.cc \ -tensorflow/lite/kernels/internal/scoped_profiling_label_wrapper_stub.cc \ tensorflow/lite/kernels/kernel_util.cc MICROLITE_CC_SRCS := $(filter-out $(MICROLITE_TEST_SRCS), $(MICROLITE_CC_BASE_SRCS))