Flexible input generation switch for RandomTestRunner (#1495)
author박종현/동작제어Lab(SR)/Staff Engineer/삼성전자 <jh1302.park@samsung.com>
Fri, 1 Jun 2018 03:17:53 +0000 (12:17 +0900)
committer서상민/동작제어Lab(SR)/Staff Engineer/삼성전자 <sangmin7.seo@samsung.com>
Fri, 1 Jun 2018 03:17:53 +0000 (12:17 +0900)
This commit revises RandomTestRunner to make it easy to extend supported
input type.

Signed-off-by: Jonghyun Park <jh1302.park@samsung.com>
libs/support/tflite/src/Diff.cpp

index 8355fc3..f2a86c9 100644 (file)
@@ -180,12 +180,7 @@ int RandomTestRunner::run(const nnfw::support::tflite::interp::Builder &builder)
 
   assert(pure->inputs() == nnapi->inputs());
 
-  // Fill IFM with random numbers
-  for (const auto id : pure->inputs())
-  {
-    assert(pure->tensor(id)->type == nnapi->tensor(id)->type);
-
-    // NOTE Float inputs are supported currently
+  auto floatgen = [&](int id, ::tflite::Interpreter *pure, ::tflite::Interpreter *nnapi) {
     assert(pure->tensor(id)->type == kTfLiteFloat32);
     assert(nnapi->tensor(id)->type == kTfLiteFloat32);
 
@@ -204,6 +199,24 @@ int RandomTestRunner::run(const nnfw::support::tflite::interp::Builder &builder)
       pure_view.at(ind) = value;
       nnapi_view.at(ind) = value;
     };
+  };
+
+  // Fill IFM with random numbers
+  for (const auto id : pure->inputs())
+  {
+    assert(pure->tensor(id)->type == nnapi->tensor(id)->type);
+    switch (pure->tensor(id)->type)
+    {
+      case kTfLiteFloat32:
+      {
+        floatgen(id, pure.get(), nnapi.get());
+        break;
+      }
+      default:
+      {
+        throw std::runtime_error{"Not supported input type"};
+      }
+    }
   }
 
   std::cout << "[NNAPI TEST] Run T/F Lite Interpreter without NNAPI" << std::endl;