From: 이한종/동작제어Lab(SR)/Engineer/삼성전자 Date: Wed, 21 Nov 2018 08:00:55 +0000 (+0900) Subject: [neurun] Graph holds Model as pointer (#3663) X-Git-Tag: 0.3~367 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=7b87e08dc8dc897af16493ce8c3c976349efbd9f;p=platform%2Fcore%2Fml%2Fnnfw.git [neurun] Graph holds Model as pointer (#3663) Graph holds Model as pointer. This is for the next work that `_model` is moved to Linear. Signed-off-by: Hanjoung Lee --- diff --git a/runtimes/neurun/src/graph/Graph.cc b/runtimes/neurun/src/graph/Graph.cc index d263fed..cf2d00c 100644 --- a/runtimes/neurun/src/graph/Graph.cc +++ b/runtimes/neurun/src/graph/Graph.cc @@ -42,32 +42,32 @@ Graph::~Graph(void) = default; operand::Index Graph::addOperand(const operand::Shape &shape, const operand::TypeInfo &type) { - return _model.operands.append(shape, type); + return _model->operands.append(shape, type); } operation::Index Graph::addOperation(std::unique_ptr &&node) { assert(isBuildingPhase()); - return _model.operations.append(std::move(node)); + return _model->operations.append(std::move(node)); } void Graph::setOperandValue(const operand::Index &ind, std::unique_ptr &&data) { assert(isBuildingPhase()); - assert(_model.operands.exist(ind)); - _model.operands.at(ind).data(std::move(data)); + assert(_model->operands.exist(ind)); + _model->operands.at(ind).data(std::move(data)); } void Graph::addInput(const operand::Index &ind) { assert(isBuildingPhase()); - _model.inputs.append(ind); + _model->inputs.append(ind); } void Graph::addOutput(const operand::Index &ind) { assert(isBuildingPhase()); - _model.outputs.append(ind); + _model->outputs.append(ind); } void Graph::finishBuilding(void) @@ -94,14 +94,14 @@ void Graph::lower(void) // operand::LowerInfo holder std::unordered_map> operands_lower_info; - _model.operands.iterate([&](const operand::Index &index, const operand::Object &object) { + _model->operands.iterate([&](const operand::Index &index, const operand::Object &object) { operands_lower_info[index] = nnfw::make_unique(operand::asShape4D(object.shape())); }); - _backend_resolver = nnfw::make_unique(_model.operands); + _backend_resolver = nnfw::make_unique(_model->operands); - _model.operations.iterate([&](const operation::Index &, operation::Node &node) { + _model->operations.iterate([&](const operation::Index &, operation::Node &node) { auto backend = _backend_resolver->getBackend(typeid(node)); // Operation LowerInfo @@ -135,7 +135,7 @@ void Graph::lower(void) // Add DefBackend constants same as UseBackend // NOTE This assumes a constant operand is used by only one operation - _model.operations.iterate([&](const operation::Index &, operation::Node &node) { + _model->operations.iterate([&](const operation::Index &, operation::Node &node) { // LowerInfo for input operands for (auto operand : node.getInputs()) { @@ -148,7 +148,7 @@ void Graph::lower(void) }); // Set LowerInfo for each operand from the operand::LowerInfo holder - _model.operands.iterate([&](const operand::Index &index, operand::Object &object) { + _model->operands.iterate([&](const operand::Index &index, operand::Object &object) { object.lower_info(std::move(operands_lower_info[index])); // Dump operand LowerInfo diff --git a/runtimes/neurun/src/graph/Graph.h b/runtimes/neurun/src/graph/Graph.h index e5ca1ec..3b82a6c 100644 --- a/runtimes/neurun/src/graph/Graph.h +++ b/runtimes/neurun/src/graph/Graph.h @@ -114,18 +114,18 @@ private: // Accessors public: - const operand::IndexSet &getInputs() const { return _model.inputs; } - const operand::IndexSet &getOutputs() const { return _model.outputs; } - operand::IndexSet &getOutputs() { return _model.outputs; } - const operand::Set &operands() const { return _model.operands; } - operand::Set &operands() { return _model.operands; } // TODO Remove this non-const accessor - const operation::Set &operations() const { return _model.operations; } - operation::Set &operations() { return _model.operations; } + const operand::IndexSet &getInputs() const { return _model->inputs; } + const operand::IndexSet &getOutputs() const { return _model->outputs; } + operand::IndexSet &getOutputs() { return _model->outputs; } + const operand::Set &operands() const { return _model->operands; } + operand::Set &operands() { return _model->operands; } // TODO Remove this non-const accessor + const operation::Set &operations() const { return _model->operations; } + operation::Set &operations() { return _model->operations; } const codegen::BackendResolver *backend_resolver() const { return _backend_resolver.get(); } private: Phase _phase{Phase::BUILDING}; - Model _model; + std::unique_ptr _model{new Model}; // For LOWERED phase private: