}
}
-Backend BackendManager::get(const std::string &key) { return _gen_map.at(key); }
+Backend *BackendManager::get(const std::string &key) { return &_gen_map.at(key); }
} // namespace backend
} // namespace neurun
public:
BackendManager(const neurun::graph::operand::Set &operands);
- Backend get(const std::string &key);
+ Backend *get(const std::string &key);
private:
std::map<std::string, Backend> _gen_map;
}
public:
- const backend::Backend &getBackend(const std::type_index &type) { return _gen_map[type]; }
+ const backend::Backend *getBackend(const std::type_index &type) { return _gen_map[type]; }
+ const backend::Backend *getDefaultBackend()
+ {
+ static backend::Backend *default_backend = _backend_manager->get("cpu");
+ return default_backend;
+ }
private:
- std::unordered_map<std::type_index, backend::Backend> _gen_map;
+ std::unordered_map<std::type_index, backend::Backend *> _gen_map;
std::shared_ptr<backend::BackendManager> _backend_manager;
};
auto backend = node.lower_info()->backend();
// Generate Initializers
- auto init_gen = backend.initializer_gen();
+ auto init_gen = backend->initializer_gen();
_builder.addInitializer(ker_index, init_gen->generateWeight(node));
_builder.addInitializer(bias_index, init_gen->generateBias(node));
// Generate Stage
- auto stage_gen = backend.stage_gen();
+ auto stage_gen = backend->stage_gen();
_builder.addStage(stage_gen->generate(node));
}
auto backend = node.lower_info()->backend();
// Generate Stage
- auto stage_gen = backend.stage_gen();
+ auto stage_gen = backend->stage_gen();
_builder.addStage(stage_gen->generate(node));
}
auto backend = node.lower_info()->backend();
// Generate Stage
- auto stage_gen = backend.stage_gen();
+ auto stage_gen = backend->stage_gen();
_builder.addStage(stage_gen->generate(node));
}
auto backend = node.lower_info()->backend();
// Generate Stage
- auto stage_gen = backend.stage_gen();
+ auto stage_gen = backend->stage_gen();
_builder.addStage(stage_gen->generate(node));
}
auto backend = node.lower_info()->backend();
// Generate Initializers
- auto init_gen = backend.initializer_gen();
+ auto init_gen = backend->initializer_gen();
_builder.addInitializer(weight_index, init_gen->generateWeight(node));
_builder.addInitializer(bias_index, init_gen->generateBias(node));
// Generate Stage
- auto stage_gen = backend.stage_gen();
+ auto stage_gen = backend->stage_gen();
_builder.addStage(stage_gen->generate(node));
}
auto backend = node.lower_info()->backend();
// Generate Stage
- auto stage_gen = backend.stage_gen();
+ auto stage_gen = backend->stage_gen();
_builder.addStage(stage_gen->generate(node));
}
auto backend = node.lower_info()->backend();
// Generate Stage
- auto stage_gen = backend.stage_gen();
+ auto stage_gen = backend->stage_gen();
_builder.addStage(stage_gen->generate(node));
}
namespace graph
{
+Graph::Graph(void) = default;
+
+Graph::~Graph(void) = default;
+
operand::Index Graph::addOperand(const operand::Shape &shape, const operand::TypeInfo &type)
{
return _operands.append(shape, type);
nnfw::make_unique<operand::LowerInfo>(operand::asShape4D(object.shape()));
});
- auto _backend_resolver = codegen::BackendResolver(_operands);
+ _backend_resolver = nnfw::make_unique<codegen::BackendResolver>(_operands);
_operations.iterate([&](const operation::Index &, operation::Node &node) {
- auto backend = _backend_resolver.getBackend(typeid(node));
+ auto backend = _backend_resolver->getBackend(typeid(node));
// Operation LowerInfo
node.lower_info(nnfw::make_unique<operation::LowerInfo>(backend));
for (auto operand : node.getInputs())
{
auto &&lower_info = operands_lower_info.at(operand);
- lower_info->addUseLayout(backend.config()->getOperandLayout());
+ lower_info->addUseLayout(backend->config()->getOperandLayout());
}
for (auto operand : node.getOutputs())
{
auto &&lower_info = operands_lower_info.at(operand);
- lower_info->addDefLayout(backend.config()->getOperandLayout());
+ lower_info->addDefLayout(backend->config()->getOperandLayout());
}
});
namespace neurun
{
+namespace codegen
+{
+class BackendResolver;
+} // namespace linear
+} // namespace neurun
+
+namespace neurun
+{
namespace graph
{
using PostDfsConstIterator = PostDfsIterator<true>;
public:
- Graph(void) = default;
+ Graph(void);
+ ~Graph(void);
// Graph Building
public:
operand::Set _operands;
operand::IndexSet _inputs;
operand::IndexSet _outputs;
+
+ // For LOWERED phase
+private:
+ std::unique_ptr<codegen::BackendResolver> _backend_resolver;
};
} // namespace graph
namespace operation
{
-LowerInfo::LowerInfo(const backend::Backend &backend) : _backend(backend)
+LowerInfo::LowerInfo(const backend::Backend *backend) : _backend(backend)
{
// DO NOTHING
}
class LowerInfo
{
public:
- LowerInfo(const backend::Backend &backend);
- const backend::Backend &backend() const { return _backend; }
+ LowerInfo(const backend::Backend *backend);
+ const backend::Backend *backend() const { return _backend; }
private:
- backend::Backend _backend;
+ const backend::Backend *_backend;
};
} // namespace operation
backend::TensorBuilderSet tensor_builders;
for (const auto op : _operations)
{
- const auto tensor_builder = op->lower_info()->backend().stage_gen()->tensor_builder();
+ const auto tensor_builder = op->lower_info()->backend()->stage_gen()->tensor_builder();
for (const auto &ind : op->getInputs())
{
tensor_builder->mark(ind);