ONE - On-device Neural Engine
Loading...
Searching...
No Matches
onert::compiler::HEScheduler Class Reference

Class to schedule tasks. More...

#include <HEScheduler.h>

Collaboration diagram for onert::compiler::HEScheduler:

Public Member Functions

 HEScheduler (const std::vector< const backend::Backend * > &backends, const CompilerOptions &options)
 Construct a new Heterogeneous Execution Scheduler object.
 
std::unique_ptr< compiler::BackendResolverschedule (const ir::Graph &graph) final
 Task scheduling.
 
std::shared_ptr< ir::OperationIndexMap< int64_t > > getIndexedRanks ()
 

Detailed Description

Class to schedule tasks.

Definition at line 47 of file HEScheduler.h.

Constructor & Destructor Documentation

◆ HEScheduler()

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

Construct a new Heterogeneous Execution Scheduler object.

Parameters
[in]modelGraph model
[in]backend_resolverbackend resolver

Definition at line 55 of file HEScheduler.h.

56 : _is_supported{}, _backends_avail_time{}, _ops_eft{},
57 _op_to_rank{std::make_shared<ir::OperationIndexMap<int64_t>>()},
58 _is_profiling_mode{options.he_profiling_mode}, _is_linear_exec{options.executor == "Linear"},
59 _is_parallel_exec{options.executor == "Parallel"}
60 {
61 for (auto &&entry : backends)
62 {
63 if (entry->config()->id() == backend::builtin::Config::ID)
64 continue;
65 _all_backends.push_back(entry);
66 }
67 _backend_resolver = std::make_unique<compiler::BackendResolver>();
68 _exec_time = std::make_unique<exec::ExecTime>(_all_backends);
69
70 // Find cpu backend
71 auto cpu_backend_it =
72 std::find_if(_all_backends.begin(), _all_backends.end(), [](const backend::Backend *backend) {
73 return backend->config()->id() == "cpu";
74 });
75 if (cpu_backend_it == _all_backends.end())
76 throw std::runtime_error("HEScheduler could be used only if 'cpu' backend is available");
77 _cpu_backend = *cpu_backend_it;
78 }
static std::string ID
Definition Config.h:34
int entry(const int argc, char **argv)
Definition Driver.cpp:53

References entry(), and onert::backend::builtin::Config::ID.

Member Function Documentation

◆ getIndexedRanks()

std::shared_ptr< ir::OperationIndexMap< int64_t > > onert::compiler::HEScheduler::getIndexedRanks ( )
inline

Definition at line 88 of file HEScheduler.h.

88{ return _op_to_rank; }

◆ schedule()

std::unique_ptr< compiler::BackendResolver > onert::compiler::HEScheduler::schedule ( const ir::Graph graph)
finalvirtual

Task scheduling.

Note
The main idea is taken from HSIP algo: https://www.hindawi.com/journals/sp/2016/3676149/

Implements onert::compiler::IScheduler.

Definition at line 183 of file HEScheduler.cc.

184{
185 _graph = &graph;
186 VERBOSE(HEScheduler::schedule) << "task scheduling started" << std::endl;
187 // Make ranks and save in descending order
188 makeRank();
189
190 for (const auto *backend : _all_backends)
191 {
192 _backends_avail_time.emplace(backend, std::map<int64_t, int64_t>{{0, 0}});
193 }
194
195 if (_is_profiling_mode)
196 {
197 // Check if profiling info about all backend/node pairs already exists
198 bool all_nodes_are_profiled = true;
199 _graph->operations().iterate([&](const ir::OperationIndex &, const ir::IOperation &op) {
200 if (all_nodes_are_profiled)
201 all_nodes_are_profiled = isNodeProfiled(op);
202 });
203
204 // If all nodes are already profiled - schedule backends in such order, so more profiling
205 // information about between-backends data transfer could be collected
206 if (all_nodes_are_profiled)
207 {
208 scheduleShufflingBackends();
209 VERBOSE(HEScheduler::schedule) << "task scheduling finished" << std::endl;
210 return std::move(_backend_resolver);
211 }
212 }
213
215 graph.operations().iterate(
216 [&](const ir::OperationIndex &index, const ir::IOperation &) { visited[index] = false; });
217 // for each task select the backend with the smallest earliest finishing time(eft)
218 for (const auto &rank : _rank_to_op)
219 {
220 scheduleBranch(rank.second, visited);
221 }
222 VERBOSE(HEScheduler::schedule) << "task scheduling finished" << std::endl;
223 return std::move(_backend_resolver);
224}
std::unique_ptr< compiler::BackendResolver > schedule(const ir::Graph &graph) final
Task scheduling.
const Operations & operations() const override
Definition Graph.h:114
void iterate(const std::function< void(const Index &, const Object &)> &fn) const
Iterate over the container with given function.
#define VERBOSE(name, lv)
Definition Log.h:71
loco::GraphInputIndex index(const TFPlaceholder *node)
Definition TFNode.cpp:54
std::unordered_map< OperationIndex, T > OperationIndexMap

References onert::util::ObjectManager< Index, Object >::iterate(), onert::ir::Graph::operations(), schedule(), and VERBOSE.

Referenced by schedule().


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