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 28 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 32 of file ManualScheduler.cc.

34 : _backends{backends}, _options{options}
35{
36}

Member Function Documentation

◆ schedule()

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

Implements onert::compiler::IScheduler.

Definition at line 38 of file ManualScheduler.cc.

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