From 7c8043602a766462586b46bbcb9bb523d0cb1f94 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=EC=9D=B4=ED=95=9C=EC=A2=85/On-Device=20Lab=28SR=29/Enginee?= =?utf8?q?r/=EC=82=BC=EC=84=B1=EC=A0=84=EC=9E=90?= Date: Tue, 26 Nov 2019 14:46:13 +0900 Subject: [PATCH] [neurun] Change param type of ExecutionObserver (#9209) Let ExecutionObserver's handler functions accept `Subgraph` rather than `Operation` since the execution unit is Subgraph. Signed-off-by: Hanjoung Lee --- runtime/neurun/core/include/exec/ExecutionObservers.h | 14 +++++++------- runtime/neurun/core/src/exec/DataflowExecutor.cc | 7 +++---- runtime/neurun/core/src/exec/ExecutionObservee.cc | 8 ++++---- runtime/neurun/core/src/exec/ExecutionObservee.h | 4 ++-- runtime/neurun/core/src/exec/ExecutionObservers.cc | 14 ++++++++------ runtime/neurun/core/src/exec/LinearExecutor.cc | 7 +++---- 6 files changed, 27 insertions(+), 27 deletions(-) diff --git a/runtime/neurun/core/include/exec/ExecutionObservers.h b/runtime/neurun/core/include/exec/ExecutionObservers.h index c8af96c..9f066fc 100644 --- a/runtime/neurun/core/include/exec/ExecutionObservers.h +++ b/runtime/neurun/core/include/exec/ExecutionObservers.h @@ -18,7 +18,7 @@ #define __NEURUN_EXEC_OBSREVERS_H__ #include "exec/IFunction.h" -#include "model/Operation.h" +#include "model/Subgraph.h" #include "backend/ExecTime.h" #include "util/ITimer.h" #include "IExecutor.h" @@ -35,8 +35,8 @@ public: /// @brief Invoked just before model (not individual operation) execution begins virtual void handleBegin(IExecutor *) { return; } - virtual void handleBegin(IExecutor *, const model::Operation *, const backend::Backend *) = 0; - virtual void handleEnd(IExecutor *, const model::Operation *, const backend::Backend *) = 0; + virtual void handleBegin(IExecutor *, const model::Subgraph *, const backend::Backend *) = 0; + virtual void handleEnd(IExecutor *, const model::Subgraph *, const backend::Backend *) = 0; /// @brief Invoked just after model (not individual operation) execution ends virtual void handleEnd(IExecutor *) { return; } @@ -48,8 +48,8 @@ class ProfileObserver : public IExecutionObserver { public: explicit ProfileObserver(std::shared_ptr et) : _et(std::move(et)) {} - void handleBegin(IExecutor *, const model::Operation *, const backend::Backend *) override; - void handleEnd(IExecutor *, const model::Operation *, const backend::Backend *) override; + void handleBegin(IExecutor *, const model::Subgraph *, const backend::Backend *) override; + void handleEnd(IExecutor *, const model::Subgraph *, const backend::Backend *) override; void handleEnd(IExecutor *) override { _et->uploadOperationsExecTime(); } @@ -64,8 +64,8 @@ public: ChromeTracingObserver(const std::string &filepath); ~ChromeTracingObserver(); void handleBegin(IExecutor *) override; - void handleBegin(IExecutor *, const model::Operation *, const backend::Backend *) override; - void handleEnd(IExecutor *, const model::Operation *, const backend::Backend *) override; + void handleBegin(IExecutor *, const model::Subgraph *, const backend::Backend *) override; + void handleEnd(IExecutor *, const model::Subgraph *, const backend::Backend *) override; void handleEnd(IExecutor *) override; private: diff --git a/runtime/neurun/core/src/exec/DataflowExecutor.cc b/runtime/neurun/core/src/exec/DataflowExecutor.cc index 7622e22..a5c0bde 100644 --- a/runtime/neurun/core/src/exec/DataflowExecutor.cc +++ b/runtime/neurun/core/src/exec/DataflowExecutor.cc @@ -154,18 +154,17 @@ void DataflowExecutor::executeImpl() VERBOSE(DataflowExecutor) << "Run job #" << job_index << std::endl; auto subgraph_index = _job_to_subgraph[job_index]; - // Workaround - assumes only one operation in a subgraph - auto op = _subgraphs->at(subgraph_index).operations().at(0).node; + auto subgraph = &_subgraphs->at(subgraph_index); const backend::Backend *backend = _lower_info->operation.at(subgraph_index)->backend(); - _subject.notifyJobBegin(this, op, backend); + _subject.notifyJobBegin(this, subgraph, backend); if (is_profiling) job->fn()->runSync(); else job->run(); - _subject.notifyJobEnd(this, op, backend); + _subject.notifyJobEnd(this, subgraph, backend); notify(job_index); _finished_jobs[job_index] = std::move(job); } diff --git a/runtime/neurun/core/src/exec/ExecutionObservee.cc b/runtime/neurun/core/src/exec/ExecutionObservee.cc index 94e25bf..74cc982 100644 --- a/runtime/neurun/core/src/exec/ExecutionObservee.cc +++ b/runtime/neurun/core/src/exec/ExecutionObservee.cc @@ -42,21 +42,21 @@ void ExecutionObservee::notifyModelEnd(IExecutor *executor) } } -void ExecutionObservee::notifyJobBegin(IExecutor *executor, const model::Operation *operation, +void ExecutionObservee::notifyJobBegin(IExecutor *executor, const model::Subgraph *subgraph, const backend::Backend *backend) { for (auto &o : _observers) { - o->handleBegin(executor, operation, backend); + o->handleBegin(executor, subgraph, backend); } } -void ExecutionObservee::notifyJobEnd(IExecutor *executor, const model::Operation *operation, +void ExecutionObservee::notifyJobEnd(IExecutor *executor, const model::Subgraph *subgraph, const backend::Backend *backend) { for (auto &o : _observers) { - o->handleEnd(executor, operation, backend); + o->handleEnd(executor, subgraph, backend); } } diff --git a/runtime/neurun/core/src/exec/ExecutionObservee.h b/runtime/neurun/core/src/exec/ExecutionObservee.h index 9616b02..b081dc9 100644 --- a/runtime/neurun/core/src/exec/ExecutionObservee.h +++ b/runtime/neurun/core/src/exec/ExecutionObservee.h @@ -41,9 +41,9 @@ public: void add(std::unique_ptr observer); void notifyModelBegin(IExecutor *executor); void notifyModelEnd(IExecutor *executor); - void notifyJobBegin(IExecutor *executor, const model::Operation *operation, + void notifyJobBegin(IExecutor *executor, const model::Subgraph *subgraph, const backend::Backend *backend); - void notifyJobEnd(IExecutor *executor, const model::Operation *operation, + void notifyJobEnd(IExecutor *executor, const model::Subgraph *subgraph, const backend::Backend *backend); private: diff --git a/runtime/neurun/core/src/exec/ExecutionObservers.cc b/runtime/neurun/core/src/exec/ExecutionObservers.cc index 146c652..59e03bc 100644 --- a/runtime/neurun/core/src/exec/ExecutionObservers.cc +++ b/runtime/neurun/core/src/exec/ExecutionObservers.cc @@ -26,7 +26,7 @@ namespace neurun namespace exec { -void ProfileObserver::handleBegin(neurun::exec::IExecutor *, const neurun::model::Operation *, +void ProfileObserver::handleBegin(neurun::exec::IExecutor *, const neurun::model::Subgraph *, const neurun::backend::Backend *backend) { _timer = backend->config()->timer(); @@ -35,12 +35,14 @@ void ProfileObserver::handleBegin(neurun::exec::IExecutor *, const neurun::model _timer->handleBegin(); } -void ProfileObserver::handleEnd(IExecutor *exec, const model::Operation *node, +void ProfileObserver::handleEnd(IExecutor *exec, const model::Subgraph *subgraph, const backend::Backend *backend) { _timer->handleEnd(); const auto timer_res = _timer->getTime(); + // NOTE This assumes there is just one operation in a subgraph + auto node = subgraph->operations().at(0).node; auto node_name = node->name(); VERBOSE(ProfileInfo) << "Time for " << node_name << " : " << timer_res << std::endl; @@ -84,16 +86,16 @@ void ChromeTracingObserver::handleBegin(IExecutor *) // TODO Record the run of the entire graph begin } -void ChromeTracingObserver::handleBegin(IExecutor *, const model::Operation *op, +void ChromeTracingObserver::handleBegin(IExecutor *, const model::Subgraph *subgraph, const backend::Backend *) { - _collector.onEvent(EventCollector::Event{EventCollector::Edge::BEGIN, op->name()}); + _collector.onEvent(EventCollector::Event{EventCollector::Edge::BEGIN, subgraph->name()}); } -void ChromeTracingObserver::handleEnd(IExecutor *, const model::Operation *op, +void ChromeTracingObserver::handleEnd(IExecutor *, const model::Subgraph *subgraph, const backend::Backend *) { - _collector.onEvent(EventCollector::Event{EventCollector::Edge::END, op->name()}); + _collector.onEvent(EventCollector::Event{EventCollector::Edge::END, subgraph->name()}); } void ChromeTracingObserver::handleEnd(IExecutor *) diff --git a/runtime/neurun/core/src/exec/LinearExecutor.cc b/runtime/neurun/core/src/exec/LinearExecutor.cc index d87ec40..0cafd1e 100644 --- a/runtime/neurun/core/src/exec/LinearExecutor.cc +++ b/runtime/neurun/core/src/exec/LinearExecutor.cc @@ -26,12 +26,11 @@ void LinearExecutor::executeImpl() _subject.notifyModelBegin(this); for (auto &&code : _code) { - // FIXME Assumes only one operation in a subgraph - const auto op = code.elem.subgraph->operations().at(0).node; + const auto subgraph = code.elem.subgraph; const auto backend = code.elem.lower_info->backend(); - _subject.notifyJobBegin(this, op, backend); + _subject.notifyJobBegin(this, subgraph, backend); code.fn->run(); - _subject.notifyJobEnd(this, op, backend); + _subject.notifyJobEnd(this, subgraph, backend); } _subject.notifyModelEnd(this); } -- 2.7.4