[neurun] Change param type of ExecutionObserver (#9209)
author이한종/On-Device Lab(SR)/Engineer/삼성전자 <hanjoung.lee@samsung.com>
Tue, 26 Nov 2019 05:46:13 +0000 (14:46 +0900)
committer이춘석/On-Device Lab(SR)/Staff Engineer/삼성전자 <chunseok.lee@samsung.com>
Tue, 26 Nov 2019 05:46:13 +0000 (14:46 +0900)
Let ExecutionObserver's handler functions accept `Subgraph` rather than
`Operation` since the execution unit is Subgraph.

Signed-off-by: Hanjoung Lee <hanjoung.lee@samsung.com>
runtime/neurun/core/include/exec/ExecutionObservers.h
runtime/neurun/core/src/exec/DataflowExecutor.cc
runtime/neurun/core/src/exec/ExecutionObservee.cc
runtime/neurun/core/src/exec/ExecutionObservee.h
runtime/neurun/core/src/exec/ExecutionObservers.cc
runtime/neurun/core/src/exec/LinearExecutor.cc

index c8af96c..9f066fc 100644 (file)
@@ -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<backend::ExecTime> 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:
index 7622e22..a5c0bde 100644 (file)
@@ -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);
   }
index 94e25bf..74cc982 100644 (file)
@@ -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);
   }
 }
 
index 9616b02..b081dc9 100644 (file)
@@ -41,9 +41,9 @@ public:
   void add(std::unique_ptr<IExecutionObserver> 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:
index 146c652..59e03bc 100644 (file)
@@ -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 *)
index d87ec40..0cafd1e 100644 (file)
@@ -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);
 }