[neurun] Eliminate OperandIndex in TopKV2::Param (#8930)
authorSergei Barannikov/AI Tools Lab /SRR/Engineer/Samsung Electronics <s.barannikov@samsung.com>
Thu, 14 Nov 2019 05:33:41 +0000 (08:33 +0300)
committer이한종/On-Device Lab(SR)/Engineer/삼성전자 <hanjoung.lee@samsung.com>
Thu, 14 Nov 2019 05:33:41 +0000 (14:33 +0900)
Make `k` static attribute of the operation.

Signed-off-by: Sergei Barannikov <s.barannikov@samsung.com>
runtime/neurun/backend/acl_cl/KernelGenerator.cc
runtime/neurun/core/include/model/operation/TopKV2.h
runtime/neurun/frontend/nnapi/wrapper/OperationFactory.cc

index fb90819..9c0382e 100644 (file)
@@ -1700,13 +1700,12 @@ void KernelGenerator::visit(const model::operation::TopKV2 &node)
       node.getOutputs().at(model::operation::TopKV2::Output::OUTPUT_INDICES)};
 
   const auto inputData_index{node.getInputs().at(model::operation::TopKV2::Input::INPUT)};
-  const auto k_index{node.param().k_index};
 
   // Currently, we only support the vector input.
   assert(_ctx.at(inputData_index).shape().rank() == 1 ||
          _ctx.at(inputData_index).shape().rank() == 2);
 
-  const auto k = _ctx.at(k_index).asScalar<int32_t>();
+  const auto k = node.param().k;
 
   auto values_alloc = _tensor_builder->at(outputValues_index).get();
   auto indices_alloc = _tensor_builder->at(outputIndices_index).get();
index aa494b9..f36a491 100644 (file)
@@ -44,7 +44,7 @@ public:
 
   struct Param
   {
-    OperandIndex k_index;
+    std::int32_t k;
   };
 
 public:
index 7b306b6..e8cdb12 100644 (file)
@@ -1333,7 +1333,7 @@ OperationFactory::OperationFactory()
   };
 
   _map[ANEURALNETWORKS_TOPK_V2_EX] = [](const OperationFactory::Param &init_param,
-                                        neurun::model::Operands &) {
+                                        neurun::model::Operands &operands) {
     assert(init_param.input_count == 2 && init_param.output_count == 2);
 
     // Each output should be interpreted as follows:
@@ -1349,7 +1349,7 @@ OperationFactory::OperationFactory()
     OperandIndexSequence inputs{init_param.inputs[0]};
 
     operation::TopKV2::Param param;
-    param.k_index = OperandIndex{init_param.inputs[1]};
+    param.k = operands.at(OperandIndex{init_param.inputs[1]}).asScalar<std::int32_t>();
 
     return new operation::TopKV2{inputs, outputs, param};
   };