[nnc] Remove unnecessary heap allocs in interpreter test (#916)
authorDmitry Mozolev/AI Tools Lab /SRR/Engineer/삼성전자 <d.mozolev@samsung.com>
Tue, 7 Aug 2018 07:34:25 +0000 (10:34 +0300)
committerSergey Vostokov/AI Tools Lab /SRR/Staff Engineer/삼성전자 <s.vostokov@samsung.com>
Tue, 7 Aug 2018 07:34:25 +0000 (10:34 +0300)
Changed unnecessary heap allocation for Interpreter and
ShapeInference objects to stack allocations.

Signed-off-by: Dmitry Mozolev <d.mozolev@samsung.com>
contrib/nnc/libs/backend/interpreter/test/src/graph_creator.cpp
contrib/nnc/libs/backend/interpreter/test/src/op_test.cpp

index 746b3f5..9d81ca3 100644 (file)
@@ -135,9 +135,8 @@ std::unique_ptr<Graph> make_graph(const opinfo::OperatorInfo* opInfo)
   g->markOutput(opNode);
 
   // Run shape inference
-  auto shapeInferencer = new ShapeInference();
-  g->accept(shapeInferencer);
-  delete shapeInferencer;
+  ShapeInference shapeInferencer;
+  g->accept(&shapeInferencer);
 
   return g;
 }
index 6ffe62a..dd69e68 100644 (file)
@@ -24,21 +24,19 @@ TEST_P(InterpTestFixture, InterpTest)
   const OperatorInfo* opInfo = GetParam();
   std::unique_ptr<Graph> g = make_graph(opInfo);
 
-  auto interpreter = new core::NNInterpreter();
+  core::NNInterpreter interpreter;
 
   for (unsigned int i = 0; i < opInfo->inputs()->size(); ++i)
   {
-    interpreter->setInput("x" + std::to_string(i), *getTensor(opInfo->inputs()->Get(i)));
+    interpreter.setInput("x" + std::to_string(i), *getTensor(opInfo->inputs()->Get(i)));
   }
 
-  g->accept(interpreter);
+  g->accept(&interpreter);
 
   // TODO: Get and check equality for multiple outputs and results.
-  auto res = interpreter->getResult(g->getOutput("y"))[0];
+  auto res = interpreter.getResult(g->getOutput("y"))[0];
 
   assertTensorEq(res, *getTensor(opInfo->results()->Get(0)));
-
-  delete interpreter;
 }
 
 INSTANTIATE_TEST_CASE_P(InterpTestSuite, InterpTestFixture,