From: Ivan Vagin/AI Tools Lab /SRR/Engineer/삼성전자 Date: Fri, 30 Aug 2019 01:39:28 +0000 (+0900) Subject: [neurun] Made scheduler to shuffle backends after all nodes are profiled (#7010) X-Git-Tag: accepted/tizen/unified/20190903.052428~39 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=43721c513ce8e33bf773756dc101d3c05d6a78cd;p=platform%2Fcore%2Fml%2Fnnfw.git [neurun] Made scheduler to shuffle backends after all nodes are profiled (#7010) [neurun] Made scheduler to shuffle backends after all nodes are already profiled Signed-off-by: Ivan Vagin --- diff --git a/runtimes/neurun/core/src/compiler/Scheduler.cc b/runtimes/neurun/core/src/compiler/Scheduler.cc index 3016fb6..0032a69 100644 --- a/runtimes/neurun/core/src/compiler/Scheduler.cc +++ b/runtimes/neurun/core/src/compiler/Scheduler.cc @@ -173,6 +173,19 @@ void Scheduler::scheduleShufflingBackends() } } +bool Scheduler::isNodeProfiled(const model::Operation &node) +{ + const bool quant = isQuant(*_graph, node); + const auto size = getOperationsFlattenedIOSize(*_graph, node); + for (const auto *backend : _all_backends) + { + const auto exec_time = _exec_time->getOperationExecTime(backend, node.getName(), quant, size); + if (exec_time == _exec_time->NOT_FOUND) + return false; + } + return true; +} + std::unique_ptr Scheduler::schedule(const graph::Graph &graph) { _graph = &graph; @@ -188,40 +201,16 @@ std::unique_ptr Scheduler::schedule(const graph::Grap const bool is_profiling = util::getConfigBool(util::config::PROFILING_MODE); if (is_profiling) { - bool profile_data_transfer = true; - const auto &node = _graph->operations().at(_rank_to_op.begin()->second); - const bool quant = isQuant(*_graph, node); - const auto size = getOperationsFlattenedIOSize(*_graph, node); - for (const auto *backend : _all_backends) - { - const auto exec_time = _exec_time->getOperationExecTime(backend, node.getName(), quant, size); - // if there is a record for a backend - if (exec_time == _exec_time->NOT_FOUND) - { - profile_data_transfer = false; - break; - } - } - // Check if profiling of data transfer is already done - for (uint32_t i = 0; i < _all_backends.size() && profile_data_transfer; ++i) - { - for (const auto *another_backend : _all_backends) - { - if (_all_backends[i] == another_backend) - { - continue; - } - const auto permute_time = - _exec_time->getPermuteTime(_all_backends[i], another_backend, quant, size); - // if permutation already was done - if (permute_time != _exec_time->NOT_FOUND) - { - profile_data_transfer = false; - break; - } - } - } - if (profile_data_transfer) + // Check if profiling info about all backend/node pairs already exists + bool all_nodes_are_profiled = true; + _graph->operations().iterate([&](const model::OperationIndex &, const model::Operation &op) { + if (all_nodes_are_profiled) + all_nodes_are_profiled = isNodeProfiled(op); + }); + + // If all nodes are already profiled - schedule backends in such order, so more profiling + // information about between-backends data transfer could be collected + if (all_nodes_are_profiled) { scheduleShufflingBackends(); VERBOSE(Scheduler::schedule) << "task scheduling finished" << std::endl; diff --git a/runtimes/neurun/core/src/compiler/Scheduler.h b/runtimes/neurun/core/src/compiler/Scheduler.h index 991dce4..a245171 100644 --- a/runtimes/neurun/core/src/compiler/Scheduler.h +++ b/runtimes/neurun/core/src/compiler/Scheduler.h @@ -76,6 +76,8 @@ public: std::shared_ptr> getIndexedRanks() { return _op_to_rank; } private: + bool isNodeProfiled(const model::Operation &); + void scheduleNode(const model::OperationIndex &); /** * @brief Get earliest starting time and execution time of an operation on a backend.