Move `Model` fields into `Graph` and remove `Model`.
Signed-off-by: Sergei Barannikov <s.barannikov@samsung.com>
#include <functional>
-#include "model/Operation.h"
-#include "model/Model.h"
+#include "model/Operands.h"
+#include "model/Operations.h"
#include "graph/LowerInfoMap.h"
#include "model/Subgraph.h"
#include "model/Subgraphs.h"
using PostDfsConstIterator = PostDfsIterator<true>;
public:
- Graph(void) = delete;
- Graph(std::unique_ptr<model::Model> &&model);
+ Graph(void);
~Graph(void);
// Graph Building
void addOutput(const model::OperandIndex &ind);
void finishBuilding(void);
void lower(void);
- void removeOperand(const model::OperandIndex &ind) { _model->operands.remove(ind); }
+ void removeOperand(const model::OperandIndex &ind) { _operands.remove(ind); }
bool isBuildingPhase(void) const { return _phase == Phase::BUILDING; }
- std::shared_ptr<const model::Model> shareModel() const { return _model; }
private:
void initializeUseDef();
// Accessors
public:
- const model::OperandIndexSequence &getInputs() const { return _model->inputs; }
- model::OperandIndexSequence &getInputs() { return _model->inputs; }
- const model::OperandIndexSequence &getOutputs() const { return _model->outputs; }
- model::OperandIndexSequence &getOutputs() { return _model->outputs; }
- const model::Operands &operands() const { return _model->operands; }
- model::Operands &operands() { return _model->operands; } // TODO Remove this non-const accessor
- const model::Operations &operations() const { return _model->operations; }
- model::Operations &operations() { return _model->operations; }
+ const model::OperandIndexSequence &getInputs() const { return _inputs; }
+ model::OperandIndexSequence &getInputs() { return _inputs; }
+ const model::OperandIndexSequence &getOutputs() const { return _outputs; }
+ model::OperandIndexSequence &getOutputs() { return _outputs; }
+ const model::Operands &operands() const { return _operands; }
+ model::Operands &operands() { return _operands; } // TODO Remove this non-const accessor
+ const model::Operations &operations() const { return _operations; }
+ model::Operations &operations() { return _operations; }
const compiler::BackendResolver *backend_resolver() const { return _backend_resolver.get(); }
private:
Phase _phase{Phase::BUILDING};
- std::shared_ptr<model::Model> _model;
+ model::Operations _operations;
+ model::Operands _operands;
+ model::OperandIndexSequence _inputs;
+ model::OperandIndexSequence _outputs;
// For LOWERED phase
public:
+++ /dev/null
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef __NEURUN_MODEL_MODEL_H__
-#define __NEURUN_MODEL_MODEL_H__
-
-#include "model/Operations.h"
-#include "model/OperandIndexSequence.h"
-#include "model/Operands.h"
-
-namespace neurun
-{
-namespace model
-{
-
-struct Model
-{
- model::Operations operations;
- model::Operands operands;
- model::OperandIndexSequence inputs;
- model::OperandIndexSequence outputs;
-};
-
-} // namespace model
-} // namespace neurun
-
-#endif // __NEURUN_MODEL_MODEL_H__
#include <vector>
#include <memory>
-#include "model/Model.h"
#include "model/Subgraphs.h"
#include "backend/ITensorBuilder.h"
#include "graph/Graph.h"
#include "Job.h"
#include "model/OperandIndexSequence.h"
#include "model/Index.h"
-#include "model/Model.h"
#include "cpp14/memory.h"
#include "exec/ExecutorBase.h"
#include "Job.h"
#include "model/OperandIndexSequence.h"
#include "model/Index.h"
-#include "model/Model.h"
#include "cpp14/memory.h"
#include "exec/DataflowExecutor.h"
#include "ParallelScheduler.h"
namespace graph
{
-Graph::Graph(std::unique_ptr<model::Model> &&model) : _model{std::move(model)}
-{
- // DO NOTHING
-}
+Graph::Graph() = default;
Graph::~Graph(void) = default;
model::OperandIndex Graph::addOperand(const model::Shape &shape, const model::TypeInfo &type)
{
- return _model->operands.emplace(shape, type);
+ return _operands.emplace(shape, type);
}
model::OperationIndex Graph::addOperation(std::unique_ptr<model::Operation> &&node)
{
assert(isBuildingPhase());
- return _model->operations.push(std::move(node));
+ return _operations.push(std::move(node));
}
void Graph::setOperandValue(const model::OperandIndex &ind, std::unique_ptr<model::Data> &&data)
{
assert(isBuildingPhase());
- assert(_model->operands.exist(ind));
- _model->operands.at(ind).data(std::move(data));
+ assert(_operands.exist(ind));
+ _operands.at(ind).data(std::move(data));
}
void Graph::addInput(const model::OperandIndex &ind)
{
assert(isBuildingPhase());
- _model->inputs.append(ind);
+ _inputs.append(ind);
}
void Graph::addOutput(const model::OperandIndex &ind)
{
assert(isBuildingPhase());
- _model->outputs.append(ind);
+ _outputs.append(ind);
}
void Graph::finishBuilding(void)
// operand::LowerInfo holder
model::OperandIndexMap<std::unique_ptr<operand::LowerInfo>> operands_lower_info;
- _model->operands.iterate([&](const model::OperandIndex &index, const model::Operand &object) {
+ _operands.iterate([&](const model::OperandIndex &index, const model::Operand &object) {
operands_lower_info[index] =
nnfw::cpp14::make_unique<operand::LowerInfo>(graph::operand::asShape4D(object.shape()));
});
for (auto input : node.getInputs())
{
// only valid_inputs
- const auto &operand = _model->operands.at(input);
+ const auto &operand = _operands.at(input);
if (operand.isConstant())
continue;
model::OperandIndexMap<std::unique_ptr<operand::LowerInfo>> &operands_lower_info)
{
const auto default_backend = backend::BackendManager::get().getDefault();
- for (auto index : _model->inputs)
+ for (auto index : _inputs)
{
// Pick just any one from the uses, here the first one is chosen
// For the other uses, Permute operations will be inserted later
assert(lower_info->use_factors().size() > 0);
lower_info->addDefPermuteFactor(*lower_info->use_factors().begin());
}
- for (auto index : _model->outputs)
+ for (auto index : _outputs)
{
auto &&lower_info = operands_lower_info.at(index);
- if (_model->operands.at(index).isConstant())
+ if (_operands.at(index).isConstant())
{
lower_info->addDefPermuteFactor(operand::PermuteFactor{
default_backend,
}
// Set LowerInfo for each operand from the operand::LowerInfo holder
- _model->operands.iterate([&](const model::OperandIndex &index, model::Operand &) {
+ _operands.iterate([&](const model::OperandIndex &index, model::Operand &) {
setLowerInfo(index, std::move(operands_lower_info[index]));
});
}
std::map<uint32_t, std::string> dumps;
- _model->operands.iterate([&](const model::OperandIndex &index, model::Operand &object) {
+ _operands.iterate([&](const model::OperandIndex &index, model::Operand &object) {
std::stringstream sstream;
if (!getLowerInfo(index)->def_factors().empty() || !getLowerInfo(index)->use_factors().empty())
{
// 1. the same backend id and layout?
// 2. if 1 is true, the subg and a node are connected?
const auto &subg = _subgraphs->at(subg_index);
- const auto &node = _model->operations.at(node_index);
+ const auto &node = _operations.at(node_index);
// The same backend id and layout?
{
std::unique_ptr<neurun::graph::Graph> loadModel(const char *filename)
{
- auto model = nnfw::cpp14::make_unique<model::Model>();
- auto graph = nnfw::cpp14::make_unique<graph::Graph>(std::move(model));
+ auto graph = nnfw::cpp14::make_unique<graph::Graph>();
CircleLoader loader(*graph);
loader.loadFromFile(filename);
return graph;
//
ANeuralNetworksModel::ANeuralNetworksModel() noexcept : _optional_operands{}, _operand_usages{}
{
- auto model = nnfw::cpp14::make_unique<neurun::model::Model>();
- _graph = std::make_shared<neurun::graph::Graph>(std::move(model));
+ _graph = std::make_shared<neurun::graph::Graph>();
}
bool ANeuralNetworksModel::addOperand(const ANeuralNetworksOperandType *type) noexcept
std::unique_ptr<graph::Graph> loadModel(const char *filename)
{
- auto model = nnfw::cpp14::make_unique<model::Model>();
- auto graph = nnfw::cpp14::make_unique<graph::Graph>(std::move(model));
+ auto graph = nnfw::cpp14::make_unique<graph::Graph>();
TFLiteLoader loader(*graph);
loader.loadFromFile(filename);
return graph;
#include <backend/ExecTime.h>
#include <backend/IShapeFixer.h>
-#include <model/Model.h>
#include <model/Shape.h>
#include <model/InternalType.h>
#include <model/TypeInfo.h>
// Create straight graph: Add->Sub->Mul
std::shared_ptr<graph::Graph> createStraightGraph()
{
- auto graph = std::make_shared<graph::Graph>(nnfw::cpp14::make_unique<Model>());
+ auto graph = std::make_shared<graph::Graph>();
const TypeInfo float_op(DataType::FLOAT32);
// Create add node
*/
std::shared_ptr<graph::Graph> createBranchedGraph()
{
- auto graph = std::make_shared<graph::Graph>(nnfw::cpp14::make_unique<Model>());
+ auto graph = std::make_shared<graph::Graph>();
const TypeInfo float_op(DataType::FLOAT32);
// Create add node
#include <thread>
#include "graph/Graph.h"
-#include "model/Model.h"
#include "compiler/Compiler.h"
#include "exec/Execution.h"
#include "model/operation/Add.h"
using namespace neurun::model;
using DataType = neurun::model::DataType;
-using Model = neurun::model::Model;
class CompiledMockUpModel
{
// result2 <= (result1 + rhs2)
// lhs, rhs1, rh2, result1, result2 shape: {1, 2, 2, 1}
// activation: none (constant)
- std::unique_ptr<neurun::model::Model> model = nnfw::cpp14::make_unique<neurun::model::Model>();
- graph = std::make_shared<::neurun::graph::Graph>(std::move(model));
+ graph = std::make_shared<::neurun::graph::Graph>();
// 1st add operands (result1 <= lhs + rhs1)
Shape shape{1, 2, 2, 1};
TypeInfo type{DataType::FLOAT32};
#include "graph/Graph.h"
#include "exec/interp/ExecManager.h"
#include "exec/Execution.h"
-#include "model/Model.h"
#include "model/operation/Add.h"
namespace
using DataType = neurun::model::DataType;
using ExecManager = neurun::exec::interp::ExecManager;
using Execution = neurun::exec::Execution;
-using Model = neurun::model::Model;
class InterpExecManagerTest : public ::testing::Test
{
// model output: add result
// lhs, rhs, result shape: {1, 2, 2, 1}
// activation: none (constant)
- auto model = nnfw::cpp14::make_unique<neurun::model::Model>();
- _graph = nnfw::cpp14::make_unique<neurun::graph::Graph>(std::move(model));
+ _graph = nnfw::cpp14::make_unique<neurun::graph::Graph>();
// Add operands
// result2 <= (result1 + rhs2)
// lhs, rhs1, rh2, result1, result2 shape: {1, 2, 2, 1}
// activation: none (constant)
- auto model = nnfw::cpp14::make_unique<neurun::model::Model>();
- _graph = nnfw::cpp14::make_unique<neurun::graph::Graph>(std::move(model));
+ _graph = nnfw::cpp14::make_unique<neurun::graph::Graph>();
// 1st add operands (result1 <= lhs + rhs1)
// model output: add result
// lhs, rhs, result shape: {1, unknown, 2, 1}
// activation: none (constant)
- auto model = nnfw::cpp14::make_unique<neurun::model::Model>();
- _graph = nnfw::cpp14::make_unique<neurun::graph::Graph>(std::move(model));
+ _graph = nnfw::cpp14::make_unique<neurun::graph::Graph>();
// Add operands
TEST_F(InterpExecManagerTest, create_empty)
{
- neurun::graph::Graph graph(nnfw::cpp14::make_unique<Model>());
+ neurun::graph::Graph graph;
graph.finishBuilding();
_executor = nnfw::cpp14::make_unique<ExecManager>(graph);
ASSERT_NE(_executor, nullptr);
#include <gtest/gtest.h>
-#include "model/Model.h"
+#include "graph/Graph.h"
-// TODO Change name to Model
TEST(Graph, inputs_and_outputs)
{
- ::neurun::model::Model model;
+ ::neurun::graph::Graph graph;
::neurun::model::OperandIndex index0{0u};
::neurun::model::OperandIndex index1{1u};
- model.inputs.append({index0});
- model.inputs.append({index1});
+ graph.addInput({index0});
+ graph.addInput({index1});
::neurun::model::OperandIndex index10{10u};
::neurun::model::OperandIndex index11{11u};
::neurun::model::OperandIndex index12{12u};
- model.outputs.append({index10});
- model.outputs.append({index11});
- model.outputs.append({index12});
+ graph.addOutput({index10});
+ graph.addOutput({index11});
+ graph.addOutput({index12});
- ASSERT_EQ(model.inputs.size(), 2);
- ASSERT_EQ(model.outputs.size(), 3);
+ ASSERT_EQ(graph.getInputs().size(), 2);
+ ASSERT_EQ(graph.getOutputs().size(), 3);
::neurun::model::IOIndex io_index0{0};
::neurun::model::IOIndex io_index1{1};
::neurun::model::IOIndex io_index2{2};
- ASSERT_EQ(model.inputs.at(io_index0), 0);
- ASSERT_EQ(model.inputs.at(io_index1), 1);
+ ASSERT_EQ(graph.getInputs().at(io_index0), 0);
+ ASSERT_EQ(graph.getInputs().at(io_index1), 1);
- ASSERT_EQ(model.outputs.at(io_index0), 10);
- ASSERT_EQ(model.outputs.at(io_index1), 11);
- ASSERT_EQ(model.outputs.at(io_index2), 12);
+ ASSERT_EQ(graph.getOutputs().at(io_index0), 10);
+ ASSERT_EQ(graph.getOutputs().at(io_index1), 11);
+ ASSERT_EQ(graph.getOutputs().at(io_index2), 12);
}
#include "graph/verifier/Verifier.h"
#include "cpp14/memory.h"
#include "../MockNode.h"
-#include "model/Model.h"
#include <typeindex>
TEST(graph_operand_usedef, usedef_test)
{
- std::unique_ptr<neurun::model::Model> model = nnfw::cpp14::make_unique<neurun::model::Model>();
- neurun::graph::Graph graph(std::move(model));
+ neurun::graph::Graph graph;
neurun::graph::verifier::DAGChecker verifier;
neurun::model::Shape shape(3);
#include <gtest/gtest.h>
#include "graph/Graph.h"
-#include "model/Model.h"
#include "model/Index.h"
#include "model/OperandIndexSequence.h"
#include "model/operation/Conv2D.h"
TEST(graph_operation_setIO, operation_setIO_conv)
{
- neurun::model::Model model;
+ neurun::graph::Graph graph;
neurun::model::Shape shape{3};
neurun::model::TypeInfo type{neurun::model::DataType::INT32};
// Add Conv
using Graph = neurun::model::operation::Conv2D;
- auto input_operand = model.operands.emplace(shape, type);
- auto kernel_operand = model.operands.emplace(shape, type);
- auto bias_operand = model.operands.emplace(shape, type);
+ auto input_operand = graph.addOperand(shape, type);
+ auto kernel_operand = graph.addOperand(shape, type);
+ auto bias_operand = graph.addOperand(shape, type);
IndexSet inputs{input_operand, kernel_operand, bias_operand};
Graph::Param conv_params;
conv_params.stride.vertical = 1;
conv_params.activation = neurun::model::Activation::NONE;
- auto output_operand = model.operands.emplace(shape, type).value();
+ auto output_operand = graph.addOperand(shape, type).value();
IndexSet outputs{output_operand};
auto conv = nnfw::cpp14::make_unique<Graph>(inputs, outputs, conv_params);
TEST(graph_operation_setIO, operation_setIO_concat)
{
- neurun::model::Model model;
+ neurun::graph::Graph graph;
neurun::model::Shape shape{3};
IndexSet inputs;
for (int i = 0; i < 6; ++i)
{
- inputs.append(model.operands.emplace(shape, type));
+ inputs.append(graph.addOperand(shape, type));
}
Graph::Param concat_params{0};
- auto output_operand = model.operands.emplace(shape, type).value();
+ auto output_operand = graph.addOperand(shape, type).value();
IndexSet outputs{output_operand};
auto concat = nnfw::cpp14::make_unique<Graph>(inputs, outputs, concat_params);
#include "graph/Graph.h"
#include "graph/verifier/Verifier.h"
#include "cpp14/memory.h"
-#include "model/Model.h"
#include "model/Operand.h"
#include "../MockNode.h"
TEST(Verifier, dag_checker)
{
- std::unique_ptr<neurun::model::Model> model = nnfw::cpp14::make_unique<neurun::model::Model>();
- neurun::graph::Graph graph(std::move(model));
+ neurun::graph::Graph graph;
::neurun::model::Shape shape{3};
::neurun::model::TypeInfo type{neurun::model::DataType::INT32};