ONE - On-device Neural Engine
Loading...
Searching...
No Matches
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 order will be used in case that manual backend mapping is unavailable
42 std::vector<const backend::Backend *> backend_order;
43 for (auto &&backend_id : _options.backend_list)
44 {
45 auto backend = resolveBackend(backend_id);
46 if (backend)
47 backend_order.push_back(backend);
48 }
49 if (backend_order.size() == 0)
50 throw std::runtime_error{"No loaded backends available."};
51
52 // 1. Backend per operation type
53 std::unordered_map<ir::OpCode, backend::Backend *> op_type_map;
54 for (const auto &[op_code, backend_name] : manual_options.opcode_to_backend)
55 {
56 op_type_map.emplace(op_code, BackendManager::get().get(backend_name));
57 }
58
59 graph.operations().iterate([&](const ir::OperationIndex &index, const ir::IOperation &operation) {
60 auto itr = op_type_map.find(operation.opcode());
61 if (itr != op_type_map.end())
62 {
63 backend_resolver->setBackend(index, itr->second);
64 }
65 });
66
67 // 2. Backend per operation index
68 for (const auto &[key, val] : manual_options.index_to_backend)
69 {
70 try
71 {
72 graph.operations().at(key); // Check if exist, or this will throw
73 backend_resolver->setBackend(key, BackendManager::get().get(val));
74 }
75 catch (...)
76 {
77 VERBOSE(ManualScheduler) << "Invalid value while OperationIndex to Backend mapping : @" << key
78 << " -> \"" << val << "\"" << std::endl;
79 }
80 }
81
82 // 3. Fallback - backend priority order
83 std::unordered_map<const backend::Backend *, std::unique_ptr<backend::ValidatorBase>> validators;
84 for (auto &&backend : backend_order)
85 {
86 // Skip train backend because it's not supporting validator
87 // TODO: Remove this condition when train backend supports validator
88 if (backend->config()->id() == "train")
89 continue;
90
91 validators.emplace(backend, backend->validator(graph));
92 }
93
94 graph.operations().iterate([&](const ir::OperationIndex &index, const ir::IOperation &op) {
95 if (!backend_resolver->hasBackend(index))
96 {
97 for (auto backend : backend_order)
98 {
99 // Use train backend if existed
100 // On training mode, we should use train backend only for all operations
101 // TODO: Remove this condition when train backend supports validator
102 if (backend->config()->id() == "train")
103 {
104 backend_resolver->setBackend(index, backend);
105 break;
106 }
107
108 if (validators[backend]->supported(op))
109 {
110 backend_resolver->setBackend(index, backend);
111 break;
112 }
113 }
114 if (!backend_resolver->hasBackend(index))
115 throw std::runtime_error{"No backend found for operation @" +
116 std::to_string(index.value())};
117 }
118 });
119
120 // Dump final assignment
121 WHEN_LOG_ENABLED(backend_resolver->iterate(
122 [&](const ir::OperationIndex &index, const backend::Backend &backend) {
123 VERBOSE(ManualScheduler) << "backend for " << index << ": " << backend.config()->id()
124 << std::endl;
125 }));
126
127 return backend_resolver;
128}
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:74
ManualSchedulerOptions manual_scheduler_options

References onert::compiler::CompilerOptions::backend_list, 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: