// 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));
// 1st add operands (result1 <= lhs + rhs1)
Shape shape{1, 2, 2, 1};
TypeInfo type{DataType::FLOAT32};
static float rhs2_data[4] = {3, 1, -1, 5};
- auto operand_lhs = model->operands.emplace(shape, type);
- auto operand_rhs1 = model->operands.emplace(shape, type);
- auto operand_result1 = model->operands.emplace(shape, type);
- auto operand_rhs2 = model->operands.emplace(shape, type);
- auto operand_result2 = model->operands.emplace(shape, type);
- model->operands.at(operand_rhs2)
+ auto operand_lhs = graph->addOperand(shape, type);
+ auto operand_rhs1 = graph->addOperand(shape, type);
+ auto operand_result1 = graph->addOperand(shape, type);
+ auto operand_rhs2 = graph->addOperand(shape, type);
+ auto operand_result2 = graph->addOperand(shape, type);
+ graph->operands()
+ .at(operand_rhs2)
.data(nnfw::cpp14::make_unique<CachedData>(reinterpret_cast<const uint8_t *>(&rhs2_data),
16));
// 2nd add operations (result2 <= result1 + rhs2)
param1.activation = neurun::model::Activation::NONE;
auto input_set1 = OperandIndexSequence{operand_lhs, operand_rhs1};
auto output_set1 = OperandIndexSequence{operand_result1};
- model->operations.push(
- nnfw::cpp14::make_unique<operation::Add>(input_set1, output_set1, param1));
+ graph->addOperation(nnfw::cpp14::make_unique<operation::Add>(input_set1, output_set1, param1));
operation::Add::Param param2;
param2.activation = neurun::model::Activation::NONE;
auto input_set2 = OperandIndexSequence{operand_result1, operand_rhs2};
auto output_set2 = OperandIndexSequence{operand_result2};
- model->operations.push(
- nnfw::cpp14::make_unique<operation::Add>(input_set2, output_set2, param2));
+ graph->addOperation(nnfw::cpp14::make_unique<operation::Add>(input_set2, output_set2, param2));
// Identify model inputs and outputs
- model->inputs.append(operand_lhs);
- model->inputs.append(operand_rhs1);
- model->outputs.append(operand_result2);
- graph = std::make_shared<::neurun::graph::Graph>(std::move(model));
+ graph->addInput(operand_lhs);
+ graph->addInput(operand_rhs1);
+ graph->addOutput(operand_result2);
graph->finishBuilding();
// Compile
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::verifier::DAGChecker verifier;
neurun::model::Shape shape(3);
neurun::model::TypeInfo type{neurun::model::DataType::INT32};
// Model Input/Output
- auto input_operand = model->operands.emplace(shape, type);
- auto output_operand = model->operands.emplace(shape, type);
+ auto input_operand = graph.addOperand(shape, type);
+ auto output_operand = graph.addOperand(shape, type);
- model->inputs.append(input_operand);
- model->outputs.append(output_operand);
+ graph.addInput(input_operand);
+ graph.addOutput(output_operand);
// MockNode1
- auto operand_index1 = model->operands.emplace(shape, type);
- auto mocknode_index1 = model->operations.push(
+ auto operand_index1 = graph.addOperand(shape, type);
+ auto mocknode_index1 = graph.addOperation(
nnfw::cpp14::make_unique<Mock>(IndexSet{input_operand}, IndexSet{operand_index1}));
// MockNode2
- auto operand_index2 = model->operands.emplace(shape, type);
- auto mocknode_index2 = model->operations.push(
+ auto operand_index2 = graph.addOperand(shape, type);
+ auto mocknode_index2 = graph.addOperation(
nnfw::cpp14::make_unique<Mock>(IndexSet{input_operand}, IndexSet{operand_index2}));
// MockNode3(two input)
- auto multiinput_index = model->operations.push(nnfw::cpp14::make_unique<Mock>(
+ auto multiinput_index = graph.addOperation(nnfw::cpp14::make_unique<Mock>(
IndexSet{operand_index1, operand_index2}, IndexSet{output_operand}));
- neurun::graph::Graph graph{std::move(model)};
graph.finishBuilding();
ASSERT_EQ(verifier.verify(graph), true);
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::model::Shape shape{3};
::neurun::model::TypeInfo type{neurun::model::DataType::INT32};
- auto operand1 = model->operands.emplace(shape, type);
- auto operand2 = model->operands.emplace(shape, type);
+ auto operand1 = graph.addOperand(shape, type);
+ auto operand2 = graph.addOperand(shape, type);
- model->inputs.append(operand1);
- model->outputs.append(operand2);
+ graph.addInput(operand1);
+ graph.addOutput(operand2);
- model->operations.push(nnfw::cpp14::make_unique<Mock>(IndexSet{operand1}, IndexSet{operand2}));
+ graph.addOperation(nnfw::cpp14::make_unique<Mock>(IndexSet{operand1}, IndexSet{operand2}));
- neurun::graph::Graph graph{std::move(model)};
graph.finishBuilding();
neurun::graph::verifier::DAGChecker verifier;