aboutsummaryrefslogtreecommitdiffhomepage
path: root/tensorflow/contrib/lite/interpreter.cc
diff options
context:
space:
mode:
authorGravatar A. Unique TensorFlower <gardener@tensorflow.org>2018-07-03 13:17:19 -0700
committerGravatar TensorFlower Gardener <gardener@tensorflow.org>2018-07-03 13:20:38 -0700
commit3340c2da43f8b2313692aaad1a94da6c4a4e4106 (patch)
tree24f1f45d83c771c2324dec4f98b022faaca29849 /tensorflow/contrib/lite/interpreter.cc
parent02ed358a986496e387d5f2e52865b10606e52c0a (diff)
Remove framework's dependency on eigen and gemmlowp.
PiperOrigin-RevId: 203172717
Diffstat (limited to 'tensorflow/contrib/lite/interpreter.cc')
-rw-r--r--tensorflow/contrib/lite/interpreter.cc52
1 files changed, 40 insertions, 12 deletions
diff --git a/tensorflow/contrib/lite/interpreter.cc b/tensorflow/contrib/lite/interpreter.cc
index 3089a4c568..521216a4f1 100644
--- a/tensorflow/contrib/lite/interpreter.cc
+++ b/tensorflow/contrib/lite/interpreter.cc
@@ -25,10 +25,6 @@ limitations under the License.
#include "tensorflow/contrib/lite/context_util.h"
#include "tensorflow/contrib/lite/error_reporter.h"
#include "tensorflow/contrib/lite/graph_info.h"
-#ifndef TFLITE_MCU
-#include "tensorflow/contrib/lite/kernels/eigen_support.h"
-#include "tensorflow/contrib/lite/kernels/gemm_support.h"
-#endif
#include "tensorflow/contrib/lite/memory_planner.h"
#ifndef TFLITE_MCU
#include "tensorflow/contrib/lite/nnapi_delegate.h"
@@ -120,9 +116,9 @@ Interpreter::Interpreter(ErrorReporter* error_reporter)
context_.AddTensors = AddTensors;
context_.tensors = nullptr;
context_.tensors_size = 0;
- context_.eigen_context = nullptr;
- context_.gemm_context = nullptr;
context_.recommended_num_threads = -1;
+ context_.GetExternalContext = GetExternalContext;
+ context_.SetExternalContext = SetExternalContext;
// Invalid to call these these except from TfLiteDelegate
SetForbiddenContextFunction(&context_.GetNodeAndRegistration);
@@ -133,6 +129,11 @@ Interpreter::Interpreter(ErrorReporter* error_reporter)
tensors_.reserve(kTensorsReservedCapacity);
nodes_and_registration_.reserve(kTensorsReservedCapacity);
next_execution_plan_index_to_prepare_ = 0;
+
+ for (int i = 0; i < kTfLiteMaxExternalContexts; ++i) {
+ external_contexts_[i] = nullptr;
+ }
+
UseNNAPI(false);
}
@@ -290,6 +291,33 @@ TfLiteStatus Interpreter::ReplaceSubgraphsWithDelegateKernels(
return kTfLiteOk;
}
+TfLiteExternalContext* Interpreter::GetExternalContext(
+ TfLiteExternalContextType type) {
+ if (type >= 0 && type < kTfLiteMaxExternalContexts) {
+ return external_contexts_[type];
+ }
+ return nullptr;
+}
+
+TfLiteExternalContext* Interpreter::GetExternalContext(
+ struct TfLiteContext* context, TfLiteExternalContextType type) {
+ return static_cast<Interpreter*>(context->impl_)->GetExternalContext(type);
+}
+
+void Interpreter::SetExternalContext(TfLiteExternalContextType type,
+ TfLiteExternalContext* ctx) {
+ if (type >= 0 && type < kTfLiteMaxExternalContexts) {
+ external_contexts_[type] = ctx;
+ }
+}
+
+void Interpreter::SetExternalContext(struct TfLiteContext* context,
+ TfLiteExternalContextType type,
+ TfLiteExternalContext* ctx) {
+ return static_cast<Interpreter*>(context->impl_)
+ ->SetExternalContext(type, ctx);
+}
+
// Gets an TfLiteIntArray* representing the execution plan. The interpreter owns
// this memory and it is only guaranteed to exist during the invocation of the
// delegate prepare.
@@ -869,12 +897,12 @@ void Interpreter::UseNNAPI(bool enable) {
void Interpreter::SetNumThreads(int num_threads) {
context_.recommended_num_threads = num_threads;
- // TODO(ahentz): find a way to avoid this. It causes gemmlowp and eigen to
- // be required in order to compile the framework.
-#ifndef TFLITE_MCU
- gemm_support::SetNumThreads(&context_, num_threads);
- eigen_support::SetNumThreads(&context_, num_threads);
-#endif
+ for (int i = 0; i < kTfLiteMaxExternalContexts; ++i) {
+ auto* c = external_contexts_[i];
+ if (c && c->Refresh) {
+ c->Refresh(&context_);
+ }
+ }
}
TfLiteStatus Interpreter::ModifyGraphWithDelegate(TfLiteDelegate* delegate,