#include "Linear.h"
-#include "graph/Graph.h"
-
#include "graph/operation/LowerInfo.h"
#include "graph/operand/LowerInfo.h"
#include "backend/interface/IStageGenerator.h"
namespace linear
{
-Linear::Linear(const graph::Graph &graph,
+Linear::Linear(const std::shared_ptr<const model::Model> &model,
std::unique_ptr<std::vector<std::unique_ptr<model::operation::Subgraph>>> subg_set,
std::unique_ptr<graph::LowerInfoMap> lower_info_map)
- : _graph(graph), _subg_set(std::move(subg_set)), _lower_info_map(std::move(lower_info_map))
+ : _model(model), _subg_set(std::move(subg_set)), _lower_info_map(std::move(lower_info_map))
{
- assert(_subg_set && _lower_info_map);
+ assert(_model && _subg_set && _lower_info_map);
for (const auto &subg : *_subg_set)
{
// Assume that the lower_infos of all nodes on a subgraph are identified on the subgraph
using FnOnTensorBuilder =
std::function<void(const model::operand::Index &ind, ITensorBuilderPtr)>;
- const auto &graph = _graph;
- auto iterTensorBuilders = [this, &graph](const model::operand::Index &ind, FnOnTensorBuilder fn) {
+ auto iterTensorBuilders = [this](const model::operand::Index &ind, FnOnTensorBuilder fn) {
const auto lower_info = getLowerInfo(ind);
for (auto backend : lower_info->def_backends())
{
model::operand::IndexMap<uint32_t> uses_map;
std::vector<model::operand::Index> constants;
- _graph.operands().iterate(
+ _model->operands.iterate(
[&](const model::operand::Index &ind, const model::operand::Object &obj) {
const auto lower_info = getLowerInfo(ind);
uses_map[ind] = obj.getUses().size();
// If a tensor is model output, increase the use of the tensor.
// This aim is same to above one.
- for (const auto &ind : _graph.getOutputs())
+ // for (const auto &ind : _graph.getOutputs())
+ for (const auto &ind : _model->outputs)
{
uses_map[ind]++;
}
// Allocate Model's inputs
VERBOSE(LINEAR) << "TENSORS as MODEL INPUT" << std::endl;
- for (const auto &ind : _graph.getInputs())
+ for (const auto &ind : _model->inputs)
{
iterTensorBuilders(ind, [](const model::operand::Index &ind, ITensorBuilderPtr tensor_builder) {
tensor_builder->notifyFirstUse(ind);
// 1. Scan USE of inputs. Decrease the USE and deallocate if the USE is 0
// 2. Scan DEF of outputs. If the DEF, allocate it
VERBOSE(LINEAR) << "TENSORS" << std::endl;
- const auto &operands = _graph.operands();
+ const auto &operands = _model->operands;
for (const auto &e : _elements)
{
for (const auto &op : e.subgraph->operations())
}
// Now, model outputs should be not deallocated
- assert(std::all_of(_graph.getOutputs().begin(), _graph.getOutputs().end(),
+ assert(std::all_of(_model->outputs.begin(), _model->outputs.end(),
[&uses_map](const model::operand::Index &ind) { return uses_map[ind] > 0; }));
// Set subtensor information
#include <vector>
#include <memory>
+#include "model/Model.h"
#include "model/operation/Subgraph.h"
#include "backend/interface/ITensorBuilder.h"
#include "graph/LowerInfoMap.h"
namespace neurun
{
-namespace graph
-{
-class Graph;
-} // namespace graph
-} // namespace neurun
-
-namespace neurun
-{
namespace linear
{
class Linear
{
public:
- // TODO Change std::shared_ptr<Model> instead of Graph
- Linear(const graph::Graph &graph,
+ Linear(const std::shared_ptr<const model::Model> &model,
std::unique_ptr<std::vector<std::unique_ptr<model::operation::Subgraph>>> subg_set,
std::unique_ptr<graph::LowerInfoMap> lower_info_map);
const graph::operand::LowerInfo *getLowerInfo(const model::operand::Index &index) const;
private:
- const graph::Graph &_graph;
+ std::shared_ptr<const model::Model> _model;
std::unique_ptr<std::vector<std::unique_ptr<model::operation::Subgraph>>> _subg_set;
std::unique_ptr<graph::LowerInfoMap> _lower_info_map;
std::vector<Element> _elements;