Simpler workaround for gemmlowp profiling wrapper.

PiperOrigin-RevId: 284642626
Change-Id: I60b3fad294fc77f3e7fe4817f757c9b8d5d137a5
This commit is contained in:
Advait Jain 2019-12-09 15:02:49 -08:00 committed by TensorFlower Gardener
parent 22467f155c
commit 7480d49690
6 changed files with 30 additions and 85 deletions

View File

@ -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 = {

View File

@ -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

View File

@ -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_

View File

@ -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

View File

@ -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

View File

@ -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))