Imported Upstream version 1.7.0
[platform/core/ml/nnfw.git] / runtime / onert / test / core / exec / ExecInstance.cc
index 7242486..cc04347 100644 (file)
@@ -71,22 +71,23 @@ public:
     graph->finishBuilding();
 
     // Compile
-    auto compiler = new onert::compiler::Compiler{graph};
-    compiler->compile();
-    compiler->release(executor);
+    auto subgs = std::make_shared<onert::ir::Subgraphs>();
+    subgs->push(onert::ir::SubgraphIndex{0}, graph);
+    auto compiler = new onert::compiler::Compiler{subgs};
+    executors = compiler->compile();
     delete compiler;
   }
 
 public:
   std::shared_ptr<Graph> graph;
-  std::shared_ptr<onert::exec::IExecutor> executor;
+  std::shared_ptr<onert::exec::ExecutorMap> executors;
 };
 
 TEST(ExecInstance, simple)
 {
   auto mockup = CompiledMockUpModel();
   auto graph = mockup.graph;
-  auto executor = mockup.executor;
+  auto executors = mockup.executors;
 
   auto input1 = IOIndex{0};
   auto input2 = IOIndex{1};
@@ -97,7 +98,7 @@ TEST(ExecInstance, simple)
   float output_buffer[4] = {};
   const float output_expected[4] = {5, -2, 0, -1};
 
-  auto execution = new onert::exec::Execution(executor);
+  auto execution = new onert::exec::Execution(executors);
 
   execution->setInput(input1, reinterpret_cast<const void *>(input1_buffer), 16);
   execution->setInput(input2, reinterpret_cast<const void *>(input2_buffer), 16);
@@ -116,8 +117,8 @@ TEST(ExecInstance, twoCompile)
 {
   auto mockup = CompiledMockUpModel();
   auto graph = mockup.graph;
-  auto executor1 = mockup.executor;
-  auto execution1 = new onert::exec::Execution(executor1);
+  auto executors1 = mockup.executors;
+  auto execution1 = new onert::exec::Execution(executors1);
 
   auto input1 = IOIndex{0};
   auto input2 = IOIndex{1};
@@ -133,11 +134,11 @@ TEST(ExecInstance, twoCompile)
   execution1->setOutput(output, reinterpret_cast<void *>(exe1_output_buffer), 16);
 
   // Make new executor: compile again
-  auto compiler = new onert::compiler::Compiler{graph};
-  compiler->compile();
-  std::shared_ptr<onert::exec::IExecutor> executor2;
-  compiler->release(executor2);
-  auto execution2 = new onert::exec::Execution(executor2);
+  auto subgs = std::make_shared<onert::ir::Subgraphs>();
+  subgs->push(onert::ir::SubgraphIndex{0}, graph);
+  auto compiler = new onert::compiler::Compiler{subgs};
+  std::shared_ptr<onert::exec::ExecutorMap> executors2 = compiler->compile();
+  auto execution2 = new onert::exec::Execution(executors2);
 
   const float exe2_input1_buffer[4] = {2, 1, -2, 0};
   const float exe2_input2_buffer[4] = {-3, 3, 1, 2};
@@ -166,7 +167,7 @@ TEST(ExecInstance, twoCompile)
 TEST(ExecInstance, twoExecution)
 {
   auto mockup = CompiledMockUpModel();
-  auto executor = mockup.executor;
+  auto executors = mockup.executors;
   auto input1 = IOIndex{0};
   auto input2 = IOIndex{1};
   auto output1 = IOIndex{0};
@@ -177,7 +178,7 @@ TEST(ExecInstance, twoExecution)
   const float exe1_output_expected[4] = {5, -2, 0, -1};
   const float exe2_output_expected[4] = {2, 5, -2, 7};
 
-  auto execution1 = new onert::exec::Execution(executor);
+  auto execution1 = new onert::exec::Execution(executors);
   execution1->setInput(input1, reinterpret_cast<const void *>(exe1_input1_buffer), 16);
   execution1->setInput(input2, reinterpret_cast<const void *>(exe1_input2_buffer), 16);
   execution1->setOutput(output1, reinterpret_cast<void *>(exe1_output_buffer), 16);
@@ -187,7 +188,7 @@ TEST(ExecInstance, twoExecution)
   float exe2_output_buffer[4] = {};
 
   // Make new execution
-  auto execution2 = new onert::exec::Execution(executor);
+  auto execution2 = new onert::exec::Execution(executors);
   execution2->setInput(input1, reinterpret_cast<const void *>(exe2_input1_buffer), 16);
   execution2->setInput(input2, reinterpret_cast<const void *>(exe2_input2_buffer), 16);
   execution2->setOutput(output1, reinterpret_cast<void *>(exe2_output_buffer), 16);
@@ -209,8 +210,8 @@ class Inference
 {
 public:
   Inference(const float (&input1)[4], const float (&input2)[4], float (&output)[4],
-            std::shared_ptr<onert::exec::IExecutor> &executor)
-      : _input1{input1}, _input2{input2}, _output{output}, _executor{executor}
+            std::shared_ptr<onert::exec::ExecutorMap> &executors)
+      : _input1{input1}, _input2{input2}, _output{output}, _executors{executors}
   {
     // DO NOTHING
   }
@@ -221,7 +222,7 @@ public:
     auto input2 = IOIndex{1};
     auto output1 = IOIndex{0};
 
-    auto execution = new onert::exec::Execution(_executor);
+    auto execution = new onert::exec::Execution(_executors);
     execution->setInput(input1, reinterpret_cast<const void *>(_input1), 16);
     execution->setInput(input2, reinterpret_cast<const void *>(_input2), 16);
     execution->setOutput(output1, reinterpret_cast<void *>(_output), 16);
@@ -235,28 +236,28 @@ private:
   const float (&_input1)[4];
   const float (&_input2)[4];
   float (&_output)[4];
-  std::shared_ptr<onert::exec::IExecutor> &_executor;
+  std::shared_ptr<onert::exec::ExecutorMap> &_executors;
 };
 
 // Support multi-thread execution
 TEST(ExecInstance, twoThreads)
 {
   auto mockup = CompiledMockUpModel();
-  auto executor = mockup.executor;
+  auto executors = mockup.executors;
 
   const float exe1_input1_buffer[4] = {1, 0, -1, -2};
   const float exe1_input2_buffer[4] = {1, -3, 2, -4};
   float exe1_output_buffer[4] = {};
   const float exe1_output_expected[4] = {5, -2, 0, -1};
 
-  Inference execution1{exe1_input1_buffer, exe1_input2_buffer, exe1_output_buffer, executor};
+  Inference execution1{exe1_input1_buffer, exe1_input2_buffer, exe1_output_buffer, executors};
 
   const float exe2_input1_buffer[4] = {2, 1, -2, 0};
   const float exe2_input2_buffer[4] = {-3, 3, 1, 2};
   float exe2_output_buffer[4] = {};
   const float exe2_output_expected[4] = {2, 5, -2, 7};
 
-  Inference execution2{exe2_input1_buffer, exe2_input2_buffer, exe2_output_buffer, executor};
+  Inference execution2{exe2_input1_buffer, exe2_input2_buffer, exe2_output_buffer, executors};
 
   std::thread t1{&Inference::inference, &execution1};
   std::thread t2{&Inference::inference, &execution2};
@@ -276,7 +277,7 @@ TEST(ExecInstance, async)
 {
   auto mockup = CompiledMockUpModel();
   auto graph = mockup.graph;
-  auto executor = mockup.executor;
+  auto executors = mockup.executors;
 
   auto input1 = IOIndex{0};
   auto input2 = IOIndex{1};
@@ -287,7 +288,7 @@ TEST(ExecInstance, async)
   float output_buffer[4] = {};
   const float output_expected[4] = {5, -2, 0, -1};
 
-  auto execution = new onert::exec::Execution(executor);
+  auto execution = new onert::exec::Execution(executors);
 
   execution->setInput(input1, reinterpret_cast<const void *>(input1_buffer), 16);
   execution->setInput(input2, reinterpret_cast<const void *>(input2_buffer), 16);