Make default number of threads trigger the default behavior for both eigen
authorA. Unique TensorFlower <gardener@tensorflow.org>
Mon, 12 Mar 2018 17:34:34 +0000 (10:34 -0700)
committerTensorFlower Gardener <gardener@tensorflow.org>
Mon, 12 Mar 2018 17:38:25 +0000 (10:38 -0700)
and gemmlowp. In gemmlowp the default is '1', while in eigen it is 'number of
processors'.

PiperOrigin-RevId: 188742087

tensorflow/contrib/lite/interpreter.cc
tensorflow/contrib/lite/kernels/eigen_support.cc
tensorflow/contrib/lite/kernels/gemm_support.cc

index 831cfaf..bbcd318 100644 (file)
@@ -94,7 +94,7 @@ Interpreter::Interpreter(ErrorReporter* error_reporter)
   context_.tensors_size = 0;
   context_.eigen_context = nullptr;
   context_.gemm_context = nullptr;
-  context_.recommended_num_threads = 0;
+  context_.recommended_num_threads = -1;
 
   // Invalid to call these these except from TfLiteDelegate
   SetForbiddenContextFunction(&context_.GetNodeAndRegistration);
index 1435a45..213e465 100644 (file)
@@ -27,8 +27,9 @@ struct RefCountedEigenContext {
 void IncrementUsageCounter(TfLiteContext* context) {
   auto* ptr = reinterpret_cast<RefCountedEigenContext*>(context->eigen_context);
   if (ptr == nullptr) {
-    Eigen::setNbThreads(context->recommended_num_threads);
-
+    if (context->recommended_num_threads != -1) {
+      Eigen::setNbThreads(context->recommended_num_threads);
+    }
     ptr = new RefCountedEigenContext;
     ptr->num_references = 0;
     context->eigen_context = ptr;
index df8a9c8..76a5165 100644 (file)
@@ -29,7 +29,9 @@ void IncrementUsageCounter(TfLiteContext* context) {
   if (ptr == nullptr) {
     ptr = new RefCountedGemmContext;
     ptr->gemm_context_ = new gemmlowp::GemmContext();
-    ptr->gemm_context_->set_max_num_threads(context->recommended_num_threads);
+    if (context->recommended_num_threads != -1) {
+      ptr->gemm_context_->set_max_num_threads(context->recommended_num_threads);
+    }
     ptr->num_references_ = 0;
     context->gemm_context = ptr;
   }