From 78d9c15280ab9f2ad4f66d395370e60c2b41d701 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=EB=B0=95=EC=A2=85=ED=98=84/On-Device=20Lab=28SR=29/Staff?= =?utf8?q?=20Engineer/=EC=82=BC=EC=84=B1=EC=A0=84=EC=9E=90?= Date: Fri, 26 Jul 2019 14:36:37 +0900 Subject: [PATCH] [neurun] Generalize ExecutionObserver interface design (#5867) The current design declares "uploadExecTime" which is a bit specific to dedicated observer implementation. This commit revises ExecutionObserver to hook on the whole model execution, and ProfileObserver to invoke "uploadExecTime" when model execution ends. Signed-off-by: Jonghyun Park --- runtimes/neurun/core/include/exec/ExecutionObservers.h | 14 ++++++++++++-- runtimes/neurun/core/src/exec/DataflowExecutor.cc | 10 +++++++++- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/runtimes/neurun/core/include/exec/ExecutionObservers.h b/runtimes/neurun/core/include/exec/ExecutionObservers.h index 3ebe584..79006ed 100644 --- a/runtimes/neurun/core/include/exec/ExecutionObservers.h +++ b/runtimes/neurun/core/include/exec/ExecutionObservers.h @@ -30,9 +30,15 @@ namespace exec class IExecutionObserver { 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 uploadExecTime() = 0; + + /// @brief Invoked just after model (not individual operation) execution ends + virtual void handleEnd(IExecutor *) { return; } + virtual ~IExecutionObserver() = default; }; @@ -42,7 +48,11 @@ 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 uploadExecTime() override { _et->uploadOperationsExecTime(); } + + void handleEnd(IExecutor *) override { uploadExecTime(); } + +private: + void uploadExecTime() { _et->uploadOperationsExecTime(); } private: std::chrono::steady_clock::time_point _prev_time; diff --git a/runtimes/neurun/core/src/exec/DataflowExecutor.cc b/runtimes/neurun/core/src/exec/DataflowExecutor.cc index 5e87547..7f6b132 100644 --- a/runtimes/neurun/core/src/exec/DataflowExecutor.cc +++ b/runtimes/neurun/core/src/exec/DataflowExecutor.cc @@ -143,6 +143,14 @@ void DataflowExecutor::executeImpl() } assert(!_ready_jobs.empty()); // Cannot begin if there is no initial jobs bool is_profiling = util::getConfigBool(util::config::PROFILING_MODE); + if (is_profiling) + { + // Notifiy Execution Begin + for (auto &o : _observers) + { + o->handleBegin(this); + } + } while (!_ready_jobs.empty()) { auto job = std::move((_ready_jobs.begin())->second); @@ -163,7 +171,7 @@ void DataflowExecutor::executeImpl() { for (auto &o : _observers) { - o->uploadExecTime(); + o->handleEnd(this); } } // Reset input info for the next execution -- 2.7.4