//
// ANeuralNetworksModel
//
-ANeuralNetworksModel::ANeuralNetworksModel() noexcept
- : _model{new neurun::model::Model}, _graph{nullptr}, _optional_operands{}, _operand_usages{}
+ANeuralNetworksModel::ANeuralNetworksModel() noexcept : _optional_operands{}, _operand_usages{}
{
- // DO NOTHING
+ auto model = nnfw::cpp14::make_unique<neurun::model::Model>();
+ _graph = std::make_shared<neurun::graph::Graph>(std::move(model));
}
bool ANeuralNetworksModel::addOperand(const ANeuralNetworksOperandType *type) noexcept
{
const auto shape = NNAPIConvert::getShape(type);
const auto typeInfo = NNAPIConvert::getTypeInfo(type);
- _model->operands.emplace(shape, typeInfo);
+ _graph->addOperand(shape, typeInfo);
_operand_usages.emplace_back(OperandUsage::NOT_DEFINED);
}
catch (const std::exception &e)
using ::neurun::model::ExternalData;
if (copy)
{
- _model->operands.at(ind).data(
+ _graph->operands().at(ind).data(
nnfw::cpp14::make_unique<CachedData>(reinterpret_cast<const uint8_t *>(buffer), length));
}
else
{
- _model->operands.at(ind).data(nnfw::cpp14::make_unique<ExternalData>(
+ _graph->operands().at(ind).data(nnfw::cpp14::make_unique<ExternalData>(
reinterpret_cast<const uint8_t *>(buffer), length));
}
}
auto &factory = OperationFactory::get();
OperationFactory::Param param{inputCount, inputs, outputCount, outputs};
- auto node = factory.create(type, param, _model->operands);
- _model->operations.push(std::unique_ptr<neurun::model::Operation>{node});
+ auto node = factory.create(type, param, _graph->operands());
+ _graph->addOperation(std::unique_ptr<neurun::model::Operation>{node});
}
catch (const std::exception &e)
{
auto &factory = OperationFactory::get();
OperationFactory::Param param{inputCount, inputs, outputCount, outputs};
- auto node = factory.create(type, param, _model->operands);
- _model->operations.push(std::unique_ptr<neurun::model::Operation>{node});
+ auto node = factory.create(type, param, _graph->operands());
+ _graph->addOperation(std::unique_ptr<neurun::model::Operation>{node});
}
catch (const std::exception &e)
{
_operand_usages[index] = OperandUsage::MODEL_INPUT;
const neurun::model::OperandIndex ind{index};
- _model->inputs.append(ind);
+ _graph->addInput(ind);
}
catch (const std::exception &e)
{
const neurun::model::OperandIndex ind{index};
// Duplicated output is not allowed
- if (_model->outputs.contains(ind))
+ if (_graph->getOutputs().contains(ind))
{
return false;
}
- _model->outputs.append(ind);
+ _graph->addOutput(ind);
}
catch (const std::exception &e)
{
{
fillOptionalOperand();
- _graph = std::make_shared<neurun::graph::Graph>(std::move(_model));
-
_graph->finishBuilding();
_operand_usages.clear();
return true;
}
-bool ANeuralNetworksModel::isFinished() noexcept { return _graph != nullptr; }
+bool ANeuralNetworksModel::isFinished() noexcept { return !_graph->isBuildingPhase(); }
bool ANeuralNetworksModel::isExistOperand(uint32_t index) noexcept
{
- return _model->operands.exist(neurun::model::OperandIndex{index});
+ return _graph->operands().exist(neurun::model::OperandIndex{index});
}
size_t ANeuralNetworksModel::operandSize(uint32_t index) noexcept
{
try
{
- return _model->operands.at(neurun::model::OperandIndex{index}).operandSize();
+ return _graph->operands().at(neurun::model::OperandIndex{index}).operandSize();
}
catch (const std::exception &e)
{
void ANeuralNetworksModel::fillOptionalOperand(void)
{
- _model->operations.iterate(
+ _graph->operations().iterate(
[&](const ::neurun::model::OperationIndex &, ::neurun::model::Operation &node) {
for (auto input : node.getInputs())
{