std::shared_ptr<IConfig> config() const override { return _config; }
- std::unique_ptr<BackendContext> newContext(const model::Operands &operands) const override
+ std::unique_ptr<BackendContext>
+ newContext(const model::Operands &operands,
+ const std::shared_ptr<custom::KernelRegistry> &) const override
{
auto tensor_builder = std::make_shared<TensorBuilder>(createMemoryManager());
- auto kernel_registry = std::make_shared<custom::KernelRegistry>();
return std::unique_ptr<BackendContext>{new BackendContext{
this, tensor_builder, std::make_shared<ConstantInitializer>(operands, tensor_builder),
std::make_shared<KernelGenerator>(operands, tensor_builder),
- std::make_shared<ShapeFixer>(operands, tensor_builder), kernel_registry}};
+ std::make_shared<ShapeFixer>(operands, tensor_builder)}};
}
private:
std::shared_ptr<IConfig> config() const override { return _config; }
- std::unique_ptr<BackendContext> newContext(const model::Operands &operands) const override
+ std::unique_ptr<BackendContext>
+ newContext(const model::Operands &operands,
+ const std::shared_ptr<custom::KernelRegistry> &) const override
{
auto tensor_builder = std::make_shared<TensorBuilder>(createMemoryManager());
- auto kernel_registry = std::make_shared<custom::KernelRegistry>();
return std::unique_ptr<BackendContext>{new BackendContext{
this, tensor_builder, std::make_shared<ConstantInitializer>(operands, tensor_builder),
std::make_shared<KernelGenerator>(operands, tensor_builder),
- std::make_shared<ShapeFixer>(operands, tensor_builder), kernel_registry}};
+ std::make_shared<ShapeFixer>(operands, tensor_builder)}};
}
private:
std::shared_ptr<IConfig> config() const override { return _config; }
- std::unique_ptr<BackendContext> newContext(const model::Operands &operands) const override
+ std::unique_ptr<BackendContext>
+ newContext(const model::Operands &operands,
+ const std::shared_ptr<custom::KernelRegistry> ®istry) const override
{
auto tensor_builder = std::make_shared<TensorBuilder>();
- auto kernel_registry = std::make_shared<custom::KernelRegistry>();
return std::unique_ptr<BackendContext>{new BackendContext{
this, tensor_builder, std::make_shared<ConstantInitializer>(operands, tensor_builder),
- std::make_shared<KernelGenerator>(operands, tensor_builder, kernel_registry),
- std::make_shared<ShapeFixer>(operands, tensor_builder), kernel_registry}};
+ std::make_shared<KernelGenerator>(operands, tensor_builder, registry),
+ std::make_shared<ShapeFixer>(operands, tensor_builder)}};
}
private:
std::shared_ptr<IConstantInitializer> constant_initializer;
std::shared_ptr<IKernelGenerator> kernel_gen;
std::shared_ptr<IShapeFixer> shape_fixer;
- std::shared_ptr<custom::KernelRegistry> _custom_kernel_registry;
};
class Backend
public:
virtual ~Backend() = default;
virtual std::shared_ptr<neurun::backend::IConfig> config() const = 0;
- virtual std::unique_ptr<BackendContext> newContext(const model::Operands &operands) const = 0;
+
+ virtual std::unique_ptr<BackendContext>
+ newContext(const model::Operands &operands,
+ const std::shared_ptr<custom::KernelRegistry> ®istry) const = 0;
};
} // namespace backend
namespace neurun
{
+namespace backend
+{
+namespace custom
+{
+class KernelRegistry;
+} // namespace neurun
+} // namespace backend
+} // namespace neurun
+
+namespace neurun
+{
namespace graph
{
private:
void initializeUseDef();
+ // Custom operations support
+public:
+ void bindKernelRegistry(const std::shared_ptr<backend::custom::KernelRegistry> ®istry)
+ {
+ _kernel_registry = registry;
+ }
+
+ const std::shared_ptr<backend::custom::KernelRegistry> &getKernelRegistry() const
+ {
+ return _kernel_registry;
+ }
+
+private:
+ std::shared_ptr<backend::custom::KernelRegistry> _kernel_registry;
+
// Accessors
public:
const model::OperandIndexSequence &getInputs() const { return _model->inputs; }
{
public:
BackendResolver(const model::Operands &operands,
- const std::vector<const backend::Backend *> &backends)
+ const std::vector<const backend::Backend *> &backends,
+ const std::shared_ptr<backend::custom::KernelRegistry> ®istry)
{
for (const auto backend : backends)
{
- _context_manager.emplace(backend, backend->newContext(operands));
+ _context_manager.emplace(backend, backend->newContext(operands, registry));
}
}
if (util::getConfigBool(util::config::USE_SCHEDULER))
{
auto scheduler =
- compiler::Scheduler(_graph->operands(), backend::BackendManager::instance().getAll());
+ compiler::Scheduler(_graph->operands(), backend::BackendManager::instance().getAll(),
+ _graph->getKernelRegistry());
br = scheduler.schedule(*_graph);
indexed_ranks = scheduler.getIndexedRanks();
}
std::unique_ptr<BackendResolver> ManualScheduler::schedule(const graph::Graph &graph)
{
auto backend_resolver = nnfw::cpp14::make_unique<compiler::BackendResolver>(
- graph.operands(), backend::BackendManager::instance().getAll());
+ graph.operands(), backend::BackendManager::instance().getAll(), graph.getKernelRegistry());
// 1. Backend for All operations
const auto backend_all_str = util::getConfigString(util::config::OP_BACKEND_ALLOPS);
* @param[in] model Graph model
* @param[in] backend_resolver backend resolver
*/
- Scheduler(const neurun::model::Operands &operands, std::vector<const backend::Backend *> backends)
+ Scheduler(const neurun::model::Operands &operands, std::vector<const backend::Backend *> backends,
+ const std::shared_ptr<backend::custom::KernelRegistry> ®istry)
: _is_supported{}, _backends_avail_time{}, _ops_eft{},
_op_to_rank{std::make_shared<model::OperationIndexMap<int64_t>>()},
_all_backends(std::move(backends))
{
_backend_resolver =
- nnfw::cpp14::make_unique<compiler::BackendResolver>(operands, _all_backends);
+ nnfw::cpp14::make_unique<compiler::BackendResolver>(operands, _all_backends, registry);
_exec_time = nnfw::cpp14::make_unique<backend::ExecTime>(_all_backends);
// Find cpu backend
{
return std::make_shared<MockConfig>();
}
- std::unique_ptr<BackendContext> newContext(const model::Operands &) const override
+ std::unique_ptr<BackendContext>
+ newContext(const model::Operands &,
+ const std::shared_ptr<backend::custom::KernelRegistry> &) const override
{
return nullptr;
}
struct MockBackendCPU : public Backend
{
std::shared_ptr<IConfig> config() const override { return std::make_shared<MockConfigCPU>(); }
- std::unique_ptr<BackendContext> newContext(const Operands &) const override
+ std::unique_ptr<BackendContext>
+ newContext(const Operands &,
+ const std::shared_ptr<backend::custom::KernelRegistry> &) const override
{
return std::unique_ptr<BackendContext>(
new BackendContext{this, nullptr, nullptr, nullptr, nullptr});
struct MockBackendGPU : public Backend
{
std::shared_ptr<IConfig> config() const override { return std::make_shared<MockConfigGPU>(); }
- std::unique_ptr<BackendContext> newContext(const Operands &) const override
+ std::unique_ptr<BackendContext>
+ newContext(const Operands &,
+ const std::shared_ptr<backend::custom::KernelRegistry> &) const override
{
return std::unique_ptr<BackendContext>(
new BackendContext{this, nullptr, nullptr, nullptr, nullptr});
struct MockBackendNPU : public Backend
{
std::shared_ptr<IConfig> config() const override { return std::make_shared<MockConfigNPU>(); }
- std::unique_ptr<BackendContext> newContext(const Operands &) const override
+ std::unique_ptr<BackendContext>
+ newContext(const Operands &,
+ const std::shared_ptr<backend::custom::KernelRegistry> &) const override
{
return std::unique_ptr<BackendContext>(
new BackendContext{this, nullptr, nullptr, nullptr, nullptr});
et.uploadOperationsExecTime();
// Test scheduler
- auto scheduler = compiler::Scheduler(graph->operands(), _mock_backends);
+ auto scheduler = compiler::Scheduler(graph->operands(), _mock_backends, nullptr);
const auto br = scheduler.schedule(*graph);
ASSERT_EQ(br->getBackend(add_op_idx)->config()->id(), "cpu");
ASSERT_EQ(br->getBackend(sub_op_idx)->config()->id(), "gpu");
setPermutationsExecutionTime(_mock_backends, OPERAND_SIZE, 1e5);
// Test scheduler
- auto scheduler = compiler::Scheduler(graph->operands(), _mock_backends);
+ auto scheduler = compiler::Scheduler(graph->operands(), _mock_backends, nullptr);
const auto br = scheduler.schedule(*graph);
ASSERT_EQ(br->getBackend(add_op_idx)->config()->id(), "cpu");
ASSERT_EQ(br->getBackend(sub_op_idx)->config()->id(), "cpu");
et.uploadOperationsExecTime();
// Test scheduler
- auto scheduler = compiler::Scheduler(graph->operands(), _mock_backends);
+ auto scheduler = compiler::Scheduler(graph->operands(), _mock_backends, nullptr);
const auto br = scheduler.schedule(*graph);
std::string branch1_expected_backend("npu"), branch2_expected_backend("npu");
et.uploadOperationsExecTime();
// Test scheduler
- auto scheduler = compiler::Scheduler(graph->operands(), _mock_backends);
+ auto scheduler = compiler::Scheduler(graph->operands(), _mock_backends, nullptr);
const auto br = scheduler.schedule(*graph);
ASSERT_EQ(br->getBackend(add_op_idx)->config()->id(), "npu");
ASSERT_EQ(br->getBackend(mul1_op_idx)->config()->id(), "npu");