summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author오형석/On-Device Lab(SR)/Staff Engineer/삼성전자 <hseok82.oh@samsung.com>2019-04-23 07:59:17 (GMT)
committerGitHub Enterprise <noreply-CODE@samsung.com>2019-04-23 07:59:17 (GMT)
commit4a04be82255eb76927674aaae8e8713e215b61c0 (patch)
treeb9317ee5168d62ff17fccee1f08e2f6188a53cfc
parent9df0eff70e680596f329dcf7ca097a914fe738ee (diff)
downloadnnfw-4a04be82255eb76927674aaae8e8713e215b61c0.zip
nnfw-4a04be82255eb76927674aaae8e8713e215b61c0.tar.gz
nnfw-4a04be82255eb76927674aaae8e8713e215b61c0.tar.bz2
Introduce operand usage vectorin frontend (#5039)
Collect operand usage info in frontend Clear when model building is finished Prepare removing nnapi-dependent usage info in neurun model operand Signed-off-by: Hyeongseok Oh <hseok82.oh@samsung.com>
-rw-r--r--runtimes/neurun/frontend/nnapi/wrapper/model.cc17
-rw-r--r--runtimes/neurun/frontend/nnapi/wrapper/model.h10
2 files changed, 26 insertions, 1 deletions
diff --git a/runtimes/neurun/frontend/nnapi/wrapper/model.cc b/runtimes/neurun/frontend/nnapi/wrapper/model.cc
index f3948ac..a15ac3e 100644
--- a/runtimes/neurun/frontend/nnapi/wrapper/model.cc
+++ b/runtimes/neurun/frontend/nnapi/wrapper/model.cc
@@ -27,7 +27,7 @@
// ANeuralNetworksModel
//
ANeuralNetworksModel::ANeuralNetworksModel() noexcept
- : _model{new neurun::model::Model}, _graph{nullptr}, _optional_operands{}
+ : _model{new neurun::model::Model}, _graph{nullptr}, _optional_operands{}, _operand_usages{}
{
// DO NOTHING
}
@@ -39,6 +39,7 @@ bool ANeuralNetworksModel::addOperand(const ANeuralNetworksOperandType *type) no
const auto shape = NNAPIConvert::getShape(type);
const auto typeInfo = NNAPIConvert::getTypeInfo(type);
_model->operands.append(shape, typeInfo);
+ _operand_usages.emplace_back(OperandUsage::NOT_DEFINED);
}
catch (const std::exception &e)
{
@@ -57,6 +58,9 @@ bool ANeuralNetworksModel::setOperandValue(uint32_t index, const void *buffer, s
try
{
+ // TODO remove usage setting in operand
+ _operand_usages[index] = OperandUsage::CONSTANT;
+
_model->operands.at(ind).usage(neurun::model::operand::Usage::CONSTANT);
// Remain operands.at(ind).data()->base() as nullptr for optional operand
@@ -97,6 +101,9 @@ bool ANeuralNetworksModel::addOperation(ANeuralNetworksOperationType type, uint3
{
for (uint32_t i = 0; i < outputCount; i++)
{
+ // TODO remove usage setting in operand
+ _operand_usages[outputs[i]] = OperandUsage::OPERATION_OUTPUT;
+
const neurun::model::operand::Index ind{outputs[i]};
_model->operands.at(ind).usage(neurun::model::operand::Usage::OPERATION_OUTPUT);
}
@@ -125,6 +132,9 @@ bool ANeuralNetworksModel::addOperationEx(ANeuralNetworksOperationTypeEx type, u
{
for (uint32_t i = 0; i < outputCount; i++)
{
+ // TODO remove usage setting in operand
+ _operand_usages[outputs[i]] = OperandUsage::OPERATION_OUTPUT;
+
const neurun::model::operand::Index ind{outputs[i]};
_model->operands.at(ind).usage(neurun::model::operand::Usage::OPERATION_OUTPUT);
}
@@ -146,6 +156,9 @@ bool ANeuralNetworksModel::addModelInput(uint32_t index) noexcept
{
try
{
+ // TODO remove usage setting in operand
+ _operand_usages[index] = OperandUsage::MODEL_INPUT;
+
const neurun::model::operand::Index ind{index};
_model->operands.at(ind).usage(neurun::model::operand::Usage::MODEL_INPUT);
_model->inputs.append(ind);
@@ -192,6 +205,8 @@ bool ANeuralNetworksModel::finish() noexcept
_graph = std::make_shared<neurun::graph::Graph>(std::move(_model));
_graph->finishBuilding();
+
+ _operand_usages.clear();
}
catch (const std::exception &e)
{
diff --git a/runtimes/neurun/frontend/nnapi/wrapper/model.h b/runtimes/neurun/frontend/nnapi/wrapper/model.h
index 0a25512..aee7efb 100644
--- a/runtimes/neurun/frontend/nnapi/wrapper/model.h
+++ b/runtimes/neurun/frontend/nnapi/wrapper/model.h
@@ -26,6 +26,15 @@
struct ANeuralNetworksModel
{
public:
+ enum class OperandUsage
+ {
+ NOT_DEFINED = 0,
+ MODEL_INPUT,
+ CONSTANT,
+ OPERATION_OUTPUT,
+ };
+
+public:
ANeuralNetworksModel() noexcept;
public:
@@ -57,6 +66,7 @@ private:
std::unique_ptr<neurun::model::Model> _model;
std::shared_ptr<neurun::graph::Graph> _graph;
std::unordered_set<neurun::model::operand::Index> _optional_operands;
+ std::vector<OperandUsage> _operand_usages;
};
#endif // __MODEL_H__