ONE - On-device Neural Engine
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
onert::compiler::ManualScheduler Class Reference

#include <ManualScheduler.h>

Collaboration diagram for onert::compiler::ManualScheduler:

Public Member Functions

 ManualScheduler (const std::vector< const backend::Backend * > &backends, const compiler::CompilerOptions &options)
 
std::unique_ptr< BackendResolverschedule (const ir::Graph &graph) override
 
- Public Member Functions inherited from onert::compiler::IScheduler
virtual ~IScheduler ()=default
 

Detailed Description

Definition at line 26 of file ManualScheduler.h.

Constructor & Destructor Documentation

◆ ManualScheduler()

onert::compiler::ManualScheduler::ManualScheduler ( const std::vector< const backend::Backend * > &  backends,
const compiler::CompilerOptions options 
)

Definition at line 30 of file ManualScheduler.cc.

32 : _backends{backends}, _options{options}
33{
34}

Member Function Documentation

◆ schedule()

std::unique_ptr< BackendResolver > onert::compiler::ManualScheduler::schedule ( const ir::Graph graph)
overridevirtual

Implements onert::compiler::IScheduler.

Definition at line 36 of file ManualScheduler.cc.

37{
38 const auto &manual_options = _options.manual_scheduler_options;
39 auto backend_resolver = std::make_unique<compiler::BackendResolver>();
40
41 // This fallback will be used in case that `backend_for_all` is unavailable
42 auto fallback = [&]() -> const backend::Backend * {
43 for (auto &&backend_id : _options.backend_list)
44 {
45 auto backend = resolveBackend(backend_id);
46 if (backend)
47 return backend;
48 }
49 return nullptr;
50 }();
51 if (fallback == nullptr)
52 throw std::runtime_error{"No loaded backends available."};
53
54 // 1. Backend for All operations
55 const backend::Backend *backend_all = resolveBackend(manual_options.backend_for_all, fallback);
56 VERBOSE(ManualScheduler) << "Default backend for all ops: " << backend_all->config()->id()
57 << std::endl;
58
59 graph.operations().iterate([&](const ir::OperationIndex &index, const ir::IOperation &) {
60 backend_resolver->setBackend(index, backend_all);
61 });
62
63 // 2. Backend per operation type
64 std::unordered_map<ir::OpCode, backend::Backend *> op_type_map;
65 for (const auto &[op_code, backend_name] : manual_options.opcode_to_backend)
66 {
67 op_type_map.emplace(op_code, BackendManager::get().get(backend_name));
68 }
69 // By default, Custom uses cpu backend
70 op_type_map[ir::OpCode::Custom] = BackendManager::get().get("cpu");
71
72 graph.operations().iterate([&](const ir::OperationIndex &index, const ir::IOperation &operation) {
73 auto itr = op_type_map.find(operation.opcode());
74 if (itr != op_type_map.end())
75 {
76 backend_resolver->setBackend(index, itr->second);
77 }
78 });
79
80 // 3. Backend per operation
81 for (const auto &[key, val] : manual_options.index_to_backend)
82 {
83 try
84 {
85 graph.operations().at(key); // Check if exist, or this will throw
86 backend_resolver->setBackend(key, BackendManager::get().get(val));
87 }
88 catch (...)
89 {
90 VERBOSE(ManualScheduler) << "Invalid value while OperationIndex to Backend mapping : @" << key
91 << " -> \"" << val << "\"" << std::endl;
92 }
93 }
94
95 // Dump final assignment
96 WHEN_LOG_ENABLED(backend_resolver->iterate(
97 [&](const ir::OperationIndex &index, const backend::Backend &backend) {
98 VERBOSE(ManualScheduler) << "backend for " << index << ": " << backend.config()->id()
99 << std::endl;
100 }));
101
102 return backend_resolver;
103}
static BackendManager & get()
#define VERBOSE(name, lv)
Definition Log.h:71
KnobTrait< K >::ValueType get(void)
::onert::util::Index< uint32_t, OperationIndexTag > OperationIndex
Definition Index.h:30
#define WHEN_LOG_ENABLED(METHOD)
Definition logging.h:73
ManualSchedulerOptions manual_scheduler_options

References onert::compiler::CompilerOptions::backend_list, onert::backend::Backend::config(), onert::compiler::BackendManager::get(), onert::compiler::CompilerOptions::manual_scheduler_options, onert::ir::IOperation::opcode(), VERBOSE, and WHEN_LOG_ENABLED.


The documentation for this class was generated from the following files: