[neurun] Replace Execution::model with Execution::graph (#9289)
authorSergei Barannikov/AI Tools Lab /SRR/Engineer/Samsung Electronics <s.barannikov@samsung.com>
Mon, 2 Dec 2019 06:27:00 +0000 (09:27 +0300)
committer이한종/On-Device Lab(SR)/Engineer/삼성전자 <hanjoung.lee@samsung.com>
Mon, 2 Dec 2019 06:27:00 +0000 (15:27 +0900)
Replace `model()` method of `Execution` class with `graph()` method.

Signed-off-by: Sergei Barannikov <s.barannikov@samsung.com>
runtime/neurun/core/include/exec/Execution.h
runtime/neurun/core/src/exec/Execution.cc
runtime/neurun/frontend/nnapi/wrapper/ANeuralNetworksExecution.cc

index b23841f..d5c6c3f 100644 (file)
@@ -48,10 +48,10 @@ public:
 
 public:
   /**
-   * @brief   Returns model object
-   * @return  Model object
+   * @brief   Returns graph object
+   * @return  Graph object
    */
-  const model::Model &model() const { return *_executor->graph().shareModel(); }
+  const graph::Graph &graph() const { return _executor->graph(); }
   /**
    * @brief     Set input data's information
    * @param[in] index   Input index
index 29eb7c7..2921599 100644 (file)
@@ -33,8 +33,8 @@ Execution::Execution(const std::shared_ptr<IExecutor> &executor) : _executor{exe
 void Execution::setInput(const model::IOIndex &index, const void *buffer, size_t length,
                          model::Layout layout)
 {
-  const auto input_index = model().inputs.at(index);
-  const auto info = model().operands.at(input_index).info();
+  const auto input_index = graph().getInputs().at(index);
+  const auto info = graph().operands().at(input_index).info();
 
   if (length < info.total_size())
   {
@@ -65,8 +65,8 @@ void Execution::setInput(const model::IOIndex &index, const model::TypeInfo &typ
 void Execution::setOutput(const model::IOIndex &index, void *buffer, size_t length,
                           model::Layout layout)
 {
-  const auto output_index = model().outputs.at(index);
-  const auto info = model().operands.at(output_index).info();
+  const auto output_index = graph().getOutputs().at(index);
+  const auto info = graph().operands().at(output_index).info();
 
   if (length < info.total_size())
   {
index 61dc0fc..7b580f1 100644 (file)
@@ -28,14 +28,14 @@ ANeuralNetworksExecution::getInputOperandIndex(int32_t index) noexcept
   }
 
   uint32_t cast_index = static_cast<uint32_t>(index);
-  if (cast_index >= _execution->model().inputs.size())
+  if (cast_index >= _execution->graph().getInputs().size())
   {
     // Return invalid index
     return neurun::model::OperandIndex{};
   }
 
   neurun::model::IOIndex input_index{cast_index};
-  const auto operand_index = _execution->model().inputs.at(input_index);
+  const auto operand_index = _execution->graph().getInputs().at(input_index);
   return operand_index;
 }
 
@@ -49,14 +49,14 @@ ANeuralNetworksExecution::getOutputOperandIndex(int32_t index) noexcept
   }
 
   uint32_t cast_index = static_cast<uint32_t>(index);
-  if (cast_index >= _execution->model().outputs.size())
+  if (cast_index >= _execution->graph().getOutputs().size())
   {
     // Return invalid index
     return neurun::model::OperandIndex{};
   }
 
   neurun::model::IOIndex output_index{cast_index};
-  const auto operand_index = _execution->model().outputs.at(output_index);
+  const auto operand_index = _execution->graph().getOutputs().at(output_index);
   return operand_index;
 }
 
@@ -65,7 +65,7 @@ bool ANeuralNetworksExecution::compareDataType(const ANeuralNetworksOperandType
 {
   try
   {
-    const auto operand_type = _execution->model().operands.at(index).typeInfo();
+    const auto operand_type = _execution->graph().operands().at(index).typeInfo();
     const auto typeInfo = NNAPIConvert::getTypeInfo(type);
 
     if (operand_type != typeInfo)
@@ -93,7 +93,7 @@ bool ANeuralNetworksExecution::compareShape(const ANeuralNetworksOperandType *ty
     return false;
   }
 
-  const auto &operand_shape = _execution->model().operands.at(index).shape();
+  const auto &operand_shape = _execution->graph().operands().at(index).shape();
   const auto &shape_from_type = NNAPIConvert::getShape(type);
 
   return operand_shape == shape_from_type;
@@ -101,7 +101,7 @@ bool ANeuralNetworksExecution::compareShape(const ANeuralNetworksOperandType *ty
 
 bool ANeuralNetworksExecution::haveUnspecifiedDims(const neurun::model::OperandIndex index) noexcept
 {
-  const auto operand_shape = _execution->model().operands.at(index).shape();
+  const auto operand_shape = _execution->graph().operands().at(index).shape();
 
   return operand_shape.num_elements() == 0;
 }
@@ -110,7 +110,7 @@ size_t ANeuralNetworksExecution::getOperandSize(const neurun::model::OperandInde
 {
   try
   {
-    return _execution->model().operands.at(index).operandSize();
+    return _execution->graph().operands().at(index).operandSize();
   }
   catch (const std::exception &e)
   {
@@ -128,9 +128,9 @@ bool ANeuralNetworksExecution::setInput(uint32_t index, const ANeuralNetworksOpe
     neurun::model::IOIndex input_index{index};
     const auto operand_index = getInputOperandIndex(index);
 
-    const auto type_info = _execution->model().operands.at(operand_index).typeInfo();
-    const auto shape = ((type != nullptr) ? NNAPIConvert::getShape(type)
-                                          : _execution->model().operands.at(operand_index).shape());
+    const auto type_info = _execution->graph().operands().at(operand_index).typeInfo();
+    const auto shape = (type != nullptr) ? NNAPIConvert::getShape(type)
+                                         : _execution->graph().operands().at(operand_index).shape();
 
     // NOTE The nnapi does not provide setting io_layout and not support changing layout. In other
     // words, we can assume that io_layout from nnapi always is the same as layout of the used
@@ -157,9 +157,9 @@ bool ANeuralNetworksExecution::setOutput(uint32_t index, const ANeuralNetworksOp
     neurun::model::IOIndex output_index{index};
     const auto operand_index = getOutputOperandIndex(index);
 
-    const auto type_info = _execution->model().operands.at(operand_index).typeInfo();
-    const auto shape = ((type != nullptr) ? NNAPIConvert::getShape(type)
-                                          : _execution->model().operands.at(operand_index).shape());
+    const auto type_info = _execution->graph().operands().at(operand_index).typeInfo();
+    const auto shape = (type != nullptr) ? NNAPIConvert::getShape(type)
+                                         : _execution->graph().operands().at(operand_index).shape();
 
     // NOTE The nnapi does not provide setting io_layout and not support changing layout. In other
     // words, we can assume that io_layout from nnapi always is the same as layout of the used
@@ -236,7 +236,7 @@ bool ANeuralNetworksExecution::getOutputOperandRank(uint32_t index, uint32_t *ra
       return false;
     }
 
-    *rank = _execution->model().operands.at(operand_index).shape().rank();
+    *rank = _execution->graph().operands().at(operand_index).shape().rank();
   }
   catch (const std::exception &e)
   {
@@ -267,7 +267,7 @@ bool ANeuralNetworksExecution::getOutputOperandDimensions(uint32_t index, uint32
       return false;
     }
 
-    auto shape = _execution->model().operands.at(operand_index).shape();
+    auto shape = _execution->graph().operands().at(operand_index).shape();
     for (int i = 0; i < shape.rank(); i++)
     {
       auto dim = shape.dim(i);