[nnc] Cleanup dead code in interpreter backend (#2734)
authorСергей Баранников/AI Tools Lab /SRR/Engineer/삼성전자 <s.barannikov@samsung.com>
Thu, 20 Dec 2018 12:04:42 +0000 (15:04 +0300)
committerРоман Михайлович Русяев/AI Tools Lab /SRR/Staff Engineer/삼성전자 <r.rusyaev@samsung.com>
Thu, 20 Dec 2018 12:04:42 +0000 (15:04 +0300)
Removed no longer used variable `_opByName` and methods working with it.

Signed-off-by: Sergei Barannikov <s.barannikov@samsung.com>
contrib/nnc/include/passes/interpreter/Interpreter.h
contrib/nnc/passes/interpreter/Interpreter.cpp

index e57d519..267ee28 100644 (file)
@@ -68,27 +68,15 @@ public:
 
   void setInput(const std::string &name, const TensorVariant& data);
   std::vector<TensorVariant> &getResult(Operation* op);
-  /**
-   * @brief Intermediate interpreter results getter
-   * @param nodeName - name of node
-   * @return vector of calculation result vectors
-   */
-  std::vector<TensorVariant> &getOperationResult(const std::string &nodeName);
 
   ~NNInterpreter() override = default;
 
 private:
   std::vector<TensorVariant> &var(size_t id);
-  /**
-   * @brief Used to collect nodes data for getting intermediate interpreter results
-   * @param op - reference to node
-   */
-  void mapByName(Operation* op);
 
 private:
   std::map<size_t, std::vector<TensorVariant>> vars;
   std::unordered_map<std::string, TensorVariant> data;
-  std::map<std::string, Operation*> _opByName;
 };
 
 } // namespace mir
index a6544e9..60731e9 100644 (file)
@@ -79,7 +79,6 @@ std::vector<TensorVariant> &NNInterpreter::var(size_t id) { return vars[id]; }
 void NNInterpreter::setInput(const std::string &name, const TensorVariant& t) { data.emplace(name, t); }
 
 void NNInterpreter::visit(ops::VariableOp& op) {
-  mapByName(&op);
   (void)op;
   auto it = data.find(op.getName());
   if( it == data.end() )
@@ -105,16 +104,7 @@ std::vector<TensorVariant> &NNInterpreter::getResult(Operation* op) {
   }
 }
 
-std::vector<TensorVariant> &NNInterpreter::getOperationResult(const std::string &nodeName) {
-  auto it = _opByName.find(nodeName);
-  if (it == _opByName.end())
-    throw std::runtime_error("Node not found <" + nodeName + ">");
-
-  return getResult(it->second);
-}
-
 void NNInterpreter::visit(ops::ConcatOp& op) {
-  mapByName(&op);
   auto &operands = op.getPrevNodes();
   std::vector<TensorVariant> ins;
   for (auto &in : operands)
@@ -125,20 +115,17 @@ void NNInterpreter::visit(ops::ConcatOp& op) {
 }
 
 void NNInterpreter::visit(ops::Conv2DOp& op) {
-  mapByName(&op);
   auto operand = op.getPrevNodes()[0];
   var(op.getId()) = Conv2D(var(operand.op->getId())[operand.index], op)();
 }
 
 void NNInterpreter::visit(ops::ReshapeOp& op) {
-  mapByName(&op);
   auto operand = op.getPrevNodes()[0];
   auto input = var(operand.op->getId())[operand.index];
   var(op.getId()) = Reshape<float>(input, op.getOutputShape(0))();
 }
 
 void NNInterpreter::visit(ops::ReluOp& op) {
-  mapByName(&op);
   auto operand = op.getPrevNodes()[0];
   Tensor<float> input(var(operand.op->getId())[operand.index]);
   var(op.getId()) = Fill<float>(
@@ -146,7 +133,6 @@ void NNInterpreter::visit(ops::ReluOp& op) {
 }
 
 void NNInterpreter::visit(ops::SigmoidOp& op) {
-  mapByName(&op);
   auto operand = op.getPrevNodes()[0];
   Tensor<float> input(var(operand.op->getId())[operand.index]);
   var(op.getId()) = Fill<float>(op.getOutputShape(0), [&input](const Index& id) {
@@ -155,35 +141,30 @@ void NNInterpreter::visit(ops::SigmoidOp& op) {
 }
 
 void NNInterpreter::visit(ops::SoftmaxOp& op) {
-  mapByName(&op);
   auto operand = op.getPrevNodes()[0];
   auto input = var(operand.op->getId())[operand.index];
   var(op.getId()) = Softmax(op.getInputShape(0), input, op.getAxis())();
 }
 
 void NNInterpreter::visit(ops::PoolOp& op) {
-  mapByName(&op);
   auto operand = op.getPrevNodes()[0];
   auto input = var(operand.op->getId())[operand.index];
   var(op.getId()) = Pool(input, op)();
 }
 
 void NNInterpreter::visit(ops::FullyConnectedOp& op) {
-  mapByName(&op);
   auto operand = op.getPrevNodes()[0];
   TensorVariant input = var(operand.op->getId())[operand.index];
   var(op.getId()) = FullyConnected<float>(input, op)();
 }
 
 void NNInterpreter::visit(ops::GemmOp& op) {
-  mapByName(&op);
   auto operand = op.getPrevNodes()[0];
   TensorVariant input = var(operand.op->getId())[operand.index];
   var(op.getId()) = Gemm<float>(input, op)();
 }
 
 void NNInterpreter::visit(ops::CappedReluOp& op) {
-  mapByName(&op);
   auto operand = op.getPrevNodes()[0];
   Tensor<float> input(var(operand.op->getId())[operand.index]);
   var(op.getId()) = Fill<float>(op.getOutputShape(0), [&input, &op](const Index &id) {
@@ -192,21 +173,18 @@ void NNInterpreter::visit(ops::CappedReluOp& op) {
 }
 
 void NNInterpreter::visit(ops::DepthwiseConv2DOp& op){
-  mapByName(&op);
   auto operand = op.getPrevNodes()[0];
   TensorVariant input(var(operand.op->getId())[operand.index]);
   var(op.getId()) = DepthwiseConv2D(input, op)();
 }
 
 void NNInterpreter::visit(ops::BiasAddOp& op) {
-  mapByName(&op);
   auto operand = op.getPrevNodes()[0];
   auto input = var(operand.op->getId())[operand.index];
   var(op.getId()) = BiasAdd(input, op.getWeights(), op.getOutputShape(0))();
 }
 
 void NNInterpreter::visit(ops::BatchNormOp& op) {
-  mapByName(&op);
   auto operand = op.getPrevNodes()[0];
   TensorVariant input(var(operand.op->getId())[operand.index]);
   // TODO implement this
@@ -214,7 +192,6 @@ void NNInterpreter::visit(ops::BatchNormOp& op) {
 }
 
 void NNInterpreter::visit(ops::ScaleOp& op) {
-  mapByName(&op);
   auto operand = op.getPrevNodes()[0];
   TensorVariant input(var(operand.op->getId())[operand.index]);
   // TODO implement this
@@ -223,7 +200,6 @@ void NNInterpreter::visit(ops::ScaleOp& op) {
 
 
 void NNInterpreter::visit(ops::SliceOp& op) {
-  mapByName(&op);
   auto operand = op.getPrevNodes()[0];
   auto input = Tensor<float>(var(operand.op->getId())[operand.index]);
   var(op.getId()) = Fill<float>(op.getOutputShape(0), [&input, &op](const Index& id) {
@@ -233,27 +209,13 @@ void NNInterpreter::visit(ops::SliceOp& op) {
 }
 
 void NNInterpreter::visit(ops::DropoutOp& op) {
-  mapByName(&op);
   auto operand = op.getPrevNodes()[0];
   TensorVariant input(var(operand.op->getId())[operand.index]);
   // TODO implement this
    var(op.getId()) = Dropout<float>(input, op)();
 }
 
-void NNInterpreter::mapByName(Operation* op) {
-  auto &nodeName = op->getName();
-  if (_opByName.find(nodeName) != _opByName.end())
-  {
-    // TODO use common debug macro
-    // std::cout << "Warning: duplicate node name <" + nodeName + "> ignore node." << std::endl;
-    return;
-  }
-
-  _opByName[nodeName] = op;
-}
-
 void NNInterpreter::visit(ops::TanhOp& op) {
-  mapByName(&op);
   auto operand = op.getPrevNodes()[0];
   Tensor<float> input(var(operand.op->getId())[operand.index]);
   var(op.getId()) = Fill<float>(op.getOutputShape(0), [&input, &op](const Index &id) {
@@ -262,7 +224,6 @@ void NNInterpreter::visit(ops::TanhOp& op) {
 }
 
 void NNInterpreter::visit(ops::ElementwiseOp& op) {
-  mapByName(&op);
   auto operands = op.getPrevNodes();
   std::vector<Tensor<float>> ins;
   // Reserve space for tensor variants to avoid reference invalidation when pushing into vector
@@ -306,13 +267,11 @@ void NNInterpreter::visit(ops::ElementwiseOp& op) {
 }
 
 void NNInterpreter::visit(ops::DeConv2DOp& op) {
-  mapByName(&op);
   auto operand = op.getPrevNodes()[0];
   var(op.getId()) = DeConv2D(var(operand.op->getId())[operand.index], op)();
 }
 
 void NNInterpreter::visit(ops::EluOp& op) {
-  mapByName(&op);
   auto operand = op.getPrevNodes()[0];
   Tensor<float> input(var(operand.op->getId())[operand.index]);
   var(op.getId()) = Fill<float>(op.getOutputShape(0), [&input, &op](const Index &id) {
@@ -324,7 +283,6 @@ void NNInterpreter::visit(ops::EluOp& op) {
 }
 
 void NNInterpreter::visit(ops::SqueezeOp& op) {
-  mapByName(&op);
   auto operand = op.getPrevNodes()[0];
   auto& input = var(operand.op->getId())[operand.index];
   //Squeeze is just a special case of reshape
@@ -332,14 +290,12 @@ void NNInterpreter::visit(ops::SqueezeOp& op) {
 }
 
 void NNInterpreter::visit(ops::PadOp& op) {
-  mapByName(&op);
   auto operand = op.getPrevNodes()[0];
   auto& input = var(operand.op->getId())[operand.index];
   var(op.getId()) = Pad(input, op)();
 }
 
 void NNInterpreter::visit(ops::SqrtOp& op) {
-  mapByName(&op);
   auto operand = op.getPrevNodes()[0];
   auto input = Tensor<float>(var(operand.op->getId())[operand.index]);
   var(op.getId()) = Fill<float>(op.getOutputShape(0), [&input](const Index id) {
@@ -348,7 +304,6 @@ void NNInterpreter::visit(ops::SqrtOp& op) {
 }
 
 void NNInterpreter::visit(ops::ResizeOp& op) {
-  mapByName(&op);
   auto operand = op.getPrevNodes()[0];
   Tensor<float> input(var(operand.op->getId())[operand.index]);
   switch (op.getMode()) {
@@ -371,7 +326,6 @@ void NNInterpreter::visit(ops::ResizeOp& op) {
 }
 
 void NNInterpreter::visit(ops::ReduceFOp& op) {
-  mapByName(&op);
   // should always be an integer in a float
   const float reduction_area =
     static_cast<float>(op.getInputShape(0).numElements() / op.getOutputShape(0).numElements());
@@ -398,14 +352,12 @@ void NNInterpreter::visit(ops::ReduceFOp& op) {
 }
 
 void NNInterpreter::visit(ops::TransposeOp& op) {
-  mapByName(&op);
   auto operand = op.getPrevNodes()[0];
   auto& input = var(operand.op->getId())[operand.index];
   var(op.getId()) = Transpose(input, op)();
 }
 
 void NNInterpreter::visit(ops::GatherOp& op) {
-  mapByName(&op);
   auto data_descr = op.getPrevNodes()[0];
   auto indices_descr = op.getPrevNodes()[1];
   const auto& data = var(data_descr.op->getId())[data_descr.index];