[neurun] Use Graph instead of Model in tests (#9288)
authorSergei Barannikov/AI Tools Lab /SRR/Engineer/Samsung Electronics <s.barannikov@samsung.com>
Fri, 29 Nov 2019 07:00:53 +0000 (10:00 +0300)
committer이한종/On-Device Lab(SR)/Engineer/삼성전자 <hanjoung.lee@samsung.com>
Fri, 29 Nov 2019 07:00:53 +0000 (16:00 +0900)
Replace uses of `Model` class with equivalent uses of `Graph` class.

Signed-off-by: Sergei Barannikov <s.barannikov@samsung.com>
runtime/neurun/test/core/exec/ExecInstance.cc
runtime/neurun/test/graph/operand/UseDef.cc
runtime/neurun/test/graph/verifier/Verifier.cc

index 804f1da..0805e7f 100644 (file)
@@ -44,16 +44,18 @@ public:
     // lhs, rhs1, rh2, result1, result2 shape: {1, 2, 2, 1}
     // activation: none (constant)
     std::unique_ptr<neurun::model::Model> model = nnfw::cpp14::make_unique<neurun::model::Model>();
+    graph = std::make_shared<::neurun::graph::Graph>(std::move(model));
     // 1st add operands (result1 <= lhs + rhs1)
     Shape shape{1, 2, 2, 1};
     TypeInfo type{DataType::FLOAT32};
     static float rhs2_data[4] = {3, 1, -1, 5};
-    auto operand_lhs = model->operands.emplace(shape, type);
-    auto operand_rhs1 = model->operands.emplace(shape, type);
-    auto operand_result1 = model->operands.emplace(shape, type);
-    auto operand_rhs2 = model->operands.emplace(shape, type);
-    auto operand_result2 = model->operands.emplace(shape, type);
-    model->operands.at(operand_rhs2)
+    auto operand_lhs = graph->addOperand(shape, type);
+    auto operand_rhs1 = graph->addOperand(shape, type);
+    auto operand_result1 = graph->addOperand(shape, type);
+    auto operand_rhs2 = graph->addOperand(shape, type);
+    auto operand_result2 = graph->addOperand(shape, type);
+    graph->operands()
+        .at(operand_rhs2)
         .data(nnfw::cpp14::make_unique<CachedData>(reinterpret_cast<const uint8_t *>(&rhs2_data),
                                                    16));
     // 2nd add operations (result2 <= result1 + rhs2)
@@ -61,19 +63,16 @@ public:
     param1.activation = neurun::model::Activation::NONE;
     auto input_set1 = OperandIndexSequence{operand_lhs, operand_rhs1};
     auto output_set1 = OperandIndexSequence{operand_result1};
-    model->operations.push(
-        nnfw::cpp14::make_unique<operation::Add>(input_set1, output_set1, param1));
+    graph->addOperation(nnfw::cpp14::make_unique<operation::Add>(input_set1, output_set1, param1));
     operation::Add::Param param2;
     param2.activation = neurun::model::Activation::NONE;
     auto input_set2 = OperandIndexSequence{operand_result1, operand_rhs2};
     auto output_set2 = OperandIndexSequence{operand_result2};
-    model->operations.push(
-        nnfw::cpp14::make_unique<operation::Add>(input_set2, output_set2, param2));
+    graph->addOperation(nnfw::cpp14::make_unique<operation::Add>(input_set2, output_set2, param2));
     // Identify model inputs and outputs
-    model->inputs.append(operand_lhs);
-    model->inputs.append(operand_rhs1);
-    model->outputs.append(operand_result2);
-    graph = std::make_shared<::neurun::graph::Graph>(std::move(model));
+    graph->addInput(operand_lhs);
+    graph->addInput(operand_rhs1);
+    graph->addOutput(operand_result2);
     graph->finishBuilding();
 
     // Compile
index f291b8e..e5eb2c4 100644 (file)
@@ -35,33 +35,33 @@ using Mock = neurun_test::graph::SimpleMock;
 TEST(graph_operand_usedef, usedef_test)
 {
   std::unique_ptr<neurun::model::Model> model = nnfw::cpp14::make_unique<neurun::model::Model>();
+  neurun::graph::Graph graph(std::move(model));
   neurun::graph::verifier::DAGChecker verifier;
 
   neurun::model::Shape shape(3);
   neurun::model::TypeInfo type{neurun::model::DataType::INT32};
 
   // Model Input/Output
-  auto input_operand = model->operands.emplace(shape, type);
-  auto output_operand = model->operands.emplace(shape, type);
+  auto input_operand = graph.addOperand(shape, type);
+  auto output_operand = graph.addOperand(shape, type);
 
-  model->inputs.append(input_operand);
-  model->outputs.append(output_operand);
+  graph.addInput(input_operand);
+  graph.addOutput(output_operand);
 
   // MockNode1
-  auto operand_index1 = model->operands.emplace(shape, type);
-  auto mocknode_index1 = model->operations.push(
+  auto operand_index1 = graph.addOperand(shape, type);
+  auto mocknode_index1 = graph.addOperation(
       nnfw::cpp14::make_unique<Mock>(IndexSet{input_operand}, IndexSet{operand_index1}));
 
   // MockNode2
-  auto operand_index2 = model->operands.emplace(shape, type);
-  auto mocknode_index2 = model->operations.push(
+  auto operand_index2 = graph.addOperand(shape, type);
+  auto mocknode_index2 = graph.addOperation(
       nnfw::cpp14::make_unique<Mock>(IndexSet{input_operand}, IndexSet{operand_index2}));
 
   // MockNode3(two input)
-  auto multiinput_index = model->operations.push(nnfw::cpp14::make_unique<Mock>(
+  auto multiinput_index = graph.addOperation(nnfw::cpp14::make_unique<Mock>(
       IndexSet{operand_index1, operand_index2}, IndexSet{output_operand}));
 
-  neurun::graph::Graph graph{std::move(model)};
   graph.finishBuilding();
 
   ASSERT_EQ(verifier.verify(graph), true);
index cf2b3c5..54d212d 100644 (file)
@@ -30,19 +30,19 @@ using Mock = neurun_test::graph::SimpleMock;
 TEST(Verifier, dag_checker)
 {
   std::unique_ptr<neurun::model::Model> model = nnfw::cpp14::make_unique<neurun::model::Model>();
+  neurun::graph::Graph graph(std::move(model));
 
   ::neurun::model::Shape shape{3};
   ::neurun::model::TypeInfo type{neurun::model::DataType::INT32};
 
-  auto operand1 = model->operands.emplace(shape, type);
-  auto operand2 = model->operands.emplace(shape, type);
+  auto operand1 = graph.addOperand(shape, type);
+  auto operand2 = graph.addOperand(shape, type);
 
-  model->inputs.append(operand1);
-  model->outputs.append(operand2);
+  graph.addInput(operand1);
+  graph.addOutput(operand2);
 
-  model->operations.push(nnfw::cpp14::make_unique<Mock>(IndexSet{operand1}, IndexSet{operand2}));
+  graph.addOperation(nnfw::cpp14::make_unique<Mock>(IndexSet{operand1}, IndexSet{operand2}));
 
-  neurun::graph::Graph graph{std::move(model)};
   graph.finishBuilding();
 
   neurun::graph::verifier::DAGChecker verifier;