From bf8af66a7d961c58c08131e48a31d12eabce3f37 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=EC=98=A4=ED=98=95=EC=84=9D/On-Device=20Lab=28SR=29/Staff?= =?utf8?q?=20Engineer/=EC=82=BC=EC=84=B1=EC=A0=84=EC=9E=90?= Date: Tue, 23 Apr 2019 13:20:20 +0900 Subject: [PATCH] Remove operand usage getter methods (#5038) - Remove unused isModelInput() method - Remove usage() method. Use hasData() and model's input/output Signed-off-by: Hyeongseok Oh --- runtimes/neurun/core/include/model/operand/Object.h | 2 -- runtimes/neurun/core/src/compiler/ConstantInitializer.cc | 2 +- runtimes/neurun/core/src/compiler/ParamChecker.cc | 4 +--- runtimes/neurun/core/src/compiler/SubTensorAnalyzer.cc | 2 +- runtimes/neurun/core/src/dumper/dot/DotDumper.cc | 6 ++---- runtimes/neurun/core/src/exec/interp/ExecManager.cc | 2 +- runtimes/neurun/core/src/graph/Graph.cc | 2 +- runtimes/neurun/core/src/linear/Linear.cc | 4 ++-- runtimes/neurun/core/src/model/operand/Object.cc | 2 +- runtimes/neurun/frontend/nnapi/wrapper/model.cc | 2 +- 10 files changed, 11 insertions(+), 17 deletions(-) diff --git a/runtimes/neurun/core/include/model/operand/Object.h b/runtimes/neurun/core/include/model/operand/Object.h index 151d112..fb4ba9e 100644 --- a/runtimes/neurun/core/include/model/operand/Object.h +++ b/runtimes/neurun/core/include/model/operand/Object.h @@ -59,8 +59,6 @@ public: const Info &info(void) const { return _info; } size_t operandSize(void) const; bool usageIsDefined(void) const { return _usage != Usage::NOT_DEFINED; } - bool isModelInput(void) const { return _usage == Usage::MODEL_INPUT; } - Usage usage() const { return _usage; } bool usage(Usage usage); const operation::IndexList &getUses() const { return _uses; } diff --git a/runtimes/neurun/core/src/compiler/ConstantInitializer.cc b/runtimes/neurun/core/src/compiler/ConstantInitializer.cc index 861c50a..51bbad4 100644 --- a/runtimes/neurun/core/src/compiler/ConstantInitializer.cc +++ b/runtimes/neurun/core/src/compiler/ConstantInitializer.cc @@ -172,7 +172,7 @@ void ConstantInitializer::operator()() const auto &model_obj = _graph.operands().at(index); // For only CONSTANTS - if (model_obj.usage() != neurun::model::operand::Usage::CONSTANT) + if (!model_obj.hasData()) return; auto type = model_obj.typeInfo().type(); diff --git a/runtimes/neurun/core/src/compiler/ParamChecker.cc b/runtimes/neurun/core/src/compiler/ParamChecker.cc index 28f877d..68452ec 100644 --- a/runtimes/neurun/core/src/compiler/ParamChecker.cc +++ b/runtimes/neurun/core/src/compiler/ParamChecker.cc @@ -23,8 +23,6 @@ namespace neurun namespace compiler { -using Usage = neurun::model::operand::Usage; - void ParamChecker::operator()() { _model->operations().iterate([&](const model::OperationIndex &, const model::Operation &node) { @@ -36,7 +34,7 @@ void ParamChecker::visit(const model::operation::AddNode &node) { const auto activation_index = node.param().activation_index; - if (_model->operands().at(activation_index).usage() != Usage::CONSTANT) + if (!_model->operands().at(activation_index).hasData()) { _nonConstParam = true; } diff --git a/runtimes/neurun/core/src/compiler/SubTensorAnalyzer.cc b/runtimes/neurun/core/src/compiler/SubTensorAnalyzer.cc index 9084add..b1a1c5a 100644 --- a/runtimes/neurun/core/src/compiler/SubTensorAnalyzer.cc +++ b/runtimes/neurun/core/src/compiler/SubTensorAnalyzer.cc @@ -38,7 +38,7 @@ void SubTensorAnalyzer::visit(const model::operation::ConcatNode &node) auto axis_index = node.param().axis_index; // To prepare concat elimination, axis should be constant - if (_ctx.at(axis_index).usage() != model::operand::Usage::CONSTANT) + if (!_ctx.at(axis_index).hasData()) { VERBOSE(SUBTENSOR) << "Cannot handle non-constant axis" << std::endl; return; diff --git a/runtimes/neurun/core/src/dumper/dot/DotDumper.cc b/runtimes/neurun/core/src/dumper/dot/DotDumper.cc index a590fd6..a03618f 100644 --- a/runtimes/neurun/core/src/dumper/dot/DotDumper.cc +++ b/runtimes/neurun/core/src/dumper/dot/DotDumper.cc @@ -56,17 +56,15 @@ void DotDumper::dumpIfNeeded(const std::string &tag) operands.iterate([&](const model::operand::Index &index, const model::operand::Object &object) { bool showing_cond = false; - auto usage = object.usage(); if (_option == OPTIONS::SHOW_CONSTANTS) { showing_cond = object.usageIsDefined(); } else { - showing_cond = (usage == model::operand::Usage::MODEL_INPUT) || - (usage == model::operand::Usage::OPERATION_OUTPUT); + showing_cond = !object.hasData(); } - if (usage != model::operand::Usage::OPERATION_OUTPUT) + if (object.hasData() || _graph.getInputs().contains(index)) { showing_cond = showing_cond && (object.getUses().size() > 0); } diff --git a/runtimes/neurun/core/src/exec/interp/ExecManager.cc b/runtimes/neurun/core/src/exec/interp/ExecManager.cc index e3d4c31..a941c7f 100644 --- a/runtimes/neurun/core/src/exec/interp/ExecManager.cc +++ b/runtimes/neurun/core/src/exec/interp/ExecManager.cc @@ -136,7 +136,7 @@ void ExecManager::execute(void) // Allocate constant tensor _model->operands.iterate([&](const model::operand::Index &ind, const model::operand::Object &obj) { - if (obj.usage() == model::operand::Usage::CONSTANT) + if (obj.hasData()) { VERBOSE(INTERPRETER) << "Allocate and assign constant tensor. operand index:" << ind.value() << std::endl; diff --git a/runtimes/neurun/core/src/graph/Graph.cc b/runtimes/neurun/core/src/graph/Graph.cc index bc52095..512a338 100644 --- a/runtimes/neurun/core/src/graph/Graph.cc +++ b/runtimes/neurun/core/src/graph/Graph.cc @@ -241,7 +241,7 @@ void Graph::lower(void) { // only valid_inputs const auto &operand = _model->operands.at(input); - if (operand.usage() == model::operand::Usage::CONSTANT) + if (operand.hasData()) continue; // This operand is input of operation, not weight or bias diff --git a/runtimes/neurun/core/src/linear/Linear.cc b/runtimes/neurun/core/src/linear/Linear.cc index 674808c..9659899 100644 --- a/runtimes/neurun/core/src/linear/Linear.cc +++ b/runtimes/neurun/core/src/linear/Linear.cc @@ -69,7 +69,7 @@ Linear::Linear(const std::shared_ptr &model, { // only valid_inputs const auto &operand = _model->operands.at(input); - if (operand.usage() == model::operand::Usage::CONSTANT) + if (operand.hasData()) continue; auto it = input_to_subgs.find(input); @@ -195,7 +195,7 @@ backend::TensorBuilderSet Linear::planTensors() // If a tensor is a constant, increase the use of the tensor. // It makes the tensor not be dealloced. - if (obj.usage() == model::operand::Usage::CONSTANT) + if (obj.hasData()) { constants.push_back(ind); uses_map[ind]++; diff --git a/runtimes/neurun/core/src/model/operand/Object.cc b/runtimes/neurun/core/src/model/operand/Object.cc index 8d0d000..1ff5d6f 100644 --- a/runtimes/neurun/core/src/model/operand/Object.cc +++ b/runtimes/neurun/core/src/model/operand/Object.cc @@ -71,7 +71,7 @@ void Object::removeUse(const ::neurun::model::OperationIndex &idx) void Object::appendDef(const ::neurun::model::OperationIndex &idx) { - assert(_usage != Usage::NOT_DEFINED && _usage != Usage::CONSTANT); + assert(_usage != Usage::NOT_DEFINED && !hasData()); assert(_def.size() == 0); _def.append(idx); diff --git a/runtimes/neurun/frontend/nnapi/wrapper/model.cc b/runtimes/neurun/frontend/nnapi/wrapper/model.cc index 9fb16e4..f3948ac 100644 --- a/runtimes/neurun/frontend/nnapi/wrapper/model.cc +++ b/runtimes/neurun/frontend/nnapi/wrapper/model.cc @@ -223,7 +223,7 @@ bool ANeuralNetworksModel::isUsageSet(uint32_t index) noexcept bool ANeuralNetworksModel::isOperationOutput(uint32_t index) noexcept { const neurun::model::operand::Index ind{index}; - return (_model->operands.at(ind).usage() == neurun::model::operand::Usage::OPERATION_OUTPUT); + return (!_model->operands.at(ind).hasData() && !_model->inputs.contains(ind)); } void ANeuralNetworksModel::setOptionalOperand(const neurun::model::operand::Index idx) -- 2.7.4