Minor update on TF_AcquireFlexDelegate()

- Use TFL_CAPI_EXPORT with tflite_copts()
- Add a LINT.IfChange rule.
- Add TF_AcquireFlexDelegate test.

PiperOrigin-RevId: 332152174
Change-Id: I1c84bad98eb48ff876ea6745fd6c17110f63de08
This commit is contained in:
Terry Heo 2020-09-16 21:04:23 -07:00 committed by TensorFlower Gardener
parent df7facd634
commit 58fcfb1e55
3 changed files with 22 additions and 6 deletions

View File

@ -1,4 +1,5 @@
load("//tensorflow:tensorflow.bzl", "tf_cc_test", "tf_opts_nortti_if_lite_protos")
load("//tensorflow/lite:build_def.bzl", "tflite_copts")
load("//tensorflow/lite/delegates/flex:build_def.bzl", "tflite_flex_cc_library")
#
@ -84,6 +85,7 @@ cc_library(
hdrs = [
"delegate.h",
],
copts = tflite_copts(),
visibility = ["//visibility:public"],
deps = [
":buffer_map",
@ -128,6 +130,7 @@ tf_cc_test(
deps = [
":delegate",
":test_util",
"//tensorflow/lite:shared_library",
"//tensorflow/lite/kernels:test_util",
"@com_google_googletest//:gtest",
],

View File

@ -19,6 +19,7 @@ limitations under the License.
#include "absl/strings/str_cat.h"
#include "tensorflow/core/lib/core/status.h"
#include "tensorflow/lite/c/common.h"
#include "tensorflow/lite/context_util.h"
#include "tensorflow/lite/core/macros.h"
#include "tensorflow/lite/delegates/flex/buffer_map.h"
@ -142,16 +143,16 @@ TfLiteStatus FlexDelegate::CopyFromBufferHandle(
} // namespace tflite
// LINT.IfChange
// Exported C interface function which is used by AcquireFlexDelegate() at
// interpreter_build.cc. To export the function name globally, the function name
// must be matched with patterns in tf_version_script.lds
// interpreter_builder.cc. To export the function name globally, the function
// name must be matched with patterns in tf_version_script.lds. In Android, we
// don't use this feature so skip building.
#if !defined(__ANDROID__)
extern "C" {
#if defined(_WIN32)
__declspec(dllexport)
#endif
tflite::TfLiteDelegateUniquePtr TF_AcquireFlexDelegate() {
TFL_CAPI_EXPORT tflite::TfLiteDelegateUniquePtr TF_AcquireFlexDelegate() {
return tflite::FlexDelegate::Create();
}
} // extern "C"
#endif // !defined(__ANDROID__)
// LINT.ThenChange(//tensorflow/lite/interpreter_builder.cc)

View File

@ -17,6 +17,7 @@ limitations under the License.
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include "tensorflow/lite/delegates/flex/test_util.h"
#include "tensorflow/lite/shared_library.h"
namespace tflite {
namespace flex {
@ -301,6 +302,17 @@ TEST_F(DelegateTest, MultiThreaded) {
ASSERT_EQ(GetType(8), kTfLiteFloat32);
}
#if !defined(__ANDROID__)
TEST_F(DelegateTest, TF_AcquireFlexDelegate) {
auto TF_AcquireFlexDelegate =
reinterpret_cast<Interpreter::TfLiteDelegatePtr (*)()>(
SharedLibrary::GetLibrarySymbol(nullptr, "TF_AcquireFlexDelegate"));
ASSERT_TRUE(TF_AcquireFlexDelegate);
auto delegate_ptr = TF_AcquireFlexDelegate();
ASSERT_TRUE(delegate_ptr != nullptr);
}
#endif // !defined(__ANDROID__)
} // namespace
} // namespace flex
} // namespace tflite