Replace shared libtflite dependency with static library.
This allows us to only include the ops required to run the model and
have the linker strip the rest out, reducing memory overhead.
Bug: 267050081
Test: atest libinput_tests
Change-Id: I4055a0c8971ed4308ccfa425ab5e5ba560deb58c
diff --git a/libs/input/TfLiteMotionPredictor.cpp b/libs/input/TfLiteMotionPredictor.cpp
index 40653d3..fbb7106 100644
--- a/libs/input/TfLiteMotionPredictor.cpp
+++ b/libs/input/TfLiteMotionPredictor.cpp
@@ -35,9 +35,11 @@
#include <log/log.h>
#include "tensorflow/lite/core/api/error_reporter.h"
+#include "tensorflow/lite/core/api/op_resolver.h"
#include "tensorflow/lite/interpreter.h"
-#include "tensorflow/lite/kernels/register.h"
+#include "tensorflow/lite/kernels/builtin_op_kernels.h"
#include "tensorflow/lite/model.h"
+#include "tensorflow/lite/mutable_op_resolver.h"
namespace android {
namespace {
@@ -102,6 +104,15 @@
LOG_ALWAYS_FATAL_IF(buffer.empty(), "No buffer for tensor '%s'", tensor->name);
}
+std::unique_ptr<tflite::OpResolver> createOpResolver() {
+ auto resolver = std::make_unique<tflite::MutableOpResolver>();
+ resolver->AddBuiltin(::tflite::BuiltinOperator_CONCATENATION,
+ ::tflite::ops::builtin::Register_CONCATENATION());
+ resolver->AddBuiltin(::tflite::BuiltinOperator_FULLY_CONNECTED,
+ ::tflite::ops::builtin::Register_FULLY_CONNECTED());
+ return resolver;
+}
+
} // namespace
TfLiteMotionPredictorBuffers::TfLiteMotionPredictorBuffers(size_t inputLength)
@@ -214,8 +225,8 @@
mErrorReporter.get());
LOG_ALWAYS_FATAL_IF(!mModel);
- tflite::ops::builtin::BuiltinOpResolver resolver;
- tflite::InterpreterBuilder builder(*mModel, resolver);
+ auto resolver = createOpResolver();
+ tflite::InterpreterBuilder builder(*mModel, *resolver);
if (builder(&mInterpreter) != kTfLiteOk || !mInterpreter) {
LOG_ALWAYS_FATAL("Failed to build interpreter");
@@ -227,6 +238,8 @@
allocateTensors();
}
+TfLiteMotionPredictorModel::~TfLiteMotionPredictorModel() {}
+
void TfLiteMotionPredictorModel::allocateTensors() {
if (mRunner->AllocateTensors() != kTfLiteOk) {
LOG_ALWAYS_FATAL("Failed to allocate tensors");