[tfliite_benchmark] Allow Thread configuration (#1473)
author박종현/동작제어Lab(SR)/Staff Engineer/삼성전자 <jh1302.park@samsung.com>
Thu, 31 May 2018 06:22:47 +0000 (15:22 +0900)
committer서상민/동작제어Lab(SR)/Staff Engineer/삼성전자 <sangmin7.seo@samsung.com>
Thu, 31 May 2018 06:22:47 +0000 (15:22 +0900)
This commit revises tflite_benchmark to read thread configuration from
THREAD environment variable.

This commit also changes the default configuration as -1 to enable
multi-threading.

Signed-off-by: Jonghyun Park <jh1302.park@samsung.com>
tools/tflite_benchmark/src/tflite_benchmark.cc

index 91e22e7..4f1f32d 100644 (file)
 using namespace tflite;
 using namespace tflite::ops::builtin;
 
+class Thread
+{
+public:
+  // Use threads as much as possible
+  Thread() : _value(-1)
+  {
+    auto env = std::getenv("THREAD");
+
+    if (env)
+    {
+      _value = atoi(env);
+    }
+  }
+
+public:
+  int32_t value(void) const { return _value; }
+
+private:
+  int32_t _value;
+};
+
 class Count
 {
 public:
@@ -55,6 +76,8 @@ private:
 
 int main(const int argc, char **argv)
 {
+  const Thread thread{};
+
   const auto filename = argv[1];
 
   bool use_nnapi = false;
@@ -76,7 +99,7 @@ int main(const int argc, char **argv)
 
   TFLITE_ENSURE(builder(&interpreter));
 
-  interpreter->SetNumThreads(1);
+  interpreter->SetNumThreads(thread.value());
 
   std::shared_ptr<nnfw::support::tflite::Session> sess;