From 3ed53c13e583b540a2681949ef090112d7d26df0 Mon Sep 17 00:00:00 2001 From: Sergei Barannikov/AI Tools Lab /SRR/Engineer/Samsung Electronics Date: Thu, 14 Nov 2019 08:33:41 +0300 Subject: [PATCH] [neurun] Eliminate OperandIndex in TopKV2::Param (#8930) Make `k` static attribute of the operation. Signed-off-by: Sergei Barannikov --- runtime/neurun/backend/acl_cl/KernelGenerator.cc | 3 +-- runtime/neurun/core/include/model/operation/TopKV2.h | 2 +- runtime/neurun/frontend/nnapi/wrapper/OperationFactory.cc | 4 ++-- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/runtime/neurun/backend/acl_cl/KernelGenerator.cc b/runtime/neurun/backend/acl_cl/KernelGenerator.cc index fb90819..9c0382e 100644 --- a/runtime/neurun/backend/acl_cl/KernelGenerator.cc +++ b/runtime/neurun/backend/acl_cl/KernelGenerator.cc @@ -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(); + const auto k = node.param().k; auto values_alloc = _tensor_builder->at(outputValues_index).get(); auto indices_alloc = _tensor_builder->at(outputIndices_index).get(); diff --git a/runtime/neurun/core/include/model/operation/TopKV2.h b/runtime/neurun/core/include/model/operation/TopKV2.h index aa494b9..f36a491 100644 --- a/runtime/neurun/core/include/model/operation/TopKV2.h +++ b/runtime/neurun/core/include/model/operation/TopKV2.h @@ -44,7 +44,7 @@ public: struct Param { - OperandIndex k_index; + std::int32_t k; }; public: diff --git a/runtime/neurun/frontend/nnapi/wrapper/OperationFactory.cc b/runtime/neurun/frontend/nnapi/wrapper/OperationFactory.cc index 7b306b6..e8cdb12 100644 --- a/runtime/neurun/frontend/nnapi/wrapper/OperationFactory.cc +++ b/runtime/neurun/frontend/nnapi/wrapper/OperationFactory.cc @@ -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(); return new operation::TopKV2{inputs, outputs, param}; }; -- 2.7.4