Upload exec_time explicitely, not in destructor (#5511)
authorДилшоджон Умронхонович Пошшоев/AI Tools Lab /SRR/Engineer/삼성전자 <d.poshshoev@samsung.com>
Tue, 2 Jul 2019 01:41:59 +0000 (04:41 +0300)
committer오형석/On-Device Lab(SR)/Staff Engineer/삼성전자 <hseok82.oh@samsung.com>
Tue, 2 Jul 2019 01:41:59 +0000 (10:41 +0900)
Since exec time is updated just in case of turned on profiler, no need
to upload it in a destructor. Moreover, since graph::Graph is reusable,
in its next usages BackendResolver will be recreated without destructing
JSON/ExecTime/Graph, so Backend, that is pointed by
JSON::_measurements.first in the first call is destructed and
JSON::uploadOperationsExecTime will cause a segmentation error in
`printString(backend.first->config()->id(), stream);`

Signed-off-by: Poshshoev Dilshodzhon <d.poshshoev@samsung.com>
runtimes/neurun/core/include/backend/ExecTime.h
runtimes/neurun/core/include/backend/JSONExecTime.h
runtimes/neurun/core/include/exec/ExecutionObservers.h
runtimes/neurun/core/src/exec/DataflowExecutor.cc
runtimes/neurun/test/core/backend/ExecTime.test.cc

index 88829a9..4eaf49f 100644 (file)
@@ -90,6 +90,10 @@ public:
    * @return max value
    */
   static int64_t getMax() { return _MAX; }
+  /**
+   * @brief Update metrics file with new data.
+   */
+  void uploadOperationsExecTime() const { _json.uploadOperationsExecTime(); }
   static const int64_t NOT_FOUND = -1;
 
 private:
index f70b476..84505e1 100644 (file)
@@ -52,7 +52,10 @@ public:
     }
     loadOperationsExecTime();
   };
-  ~JSON() { uploadOperationsExecTime(); };
+  /**
+   * @brief Update _operations_exec_time_file with new data.
+   */
+  void uploadOperationsExecTime() const;
 
 private:
   ///@brief file containing measurements
@@ -85,10 +88,6 @@ private:
    * @brief Parse and load operations_exec_time from _operations_exec_time_file.
    */
   void loadOperationsExecTime();
-  /**
-   * @brief Update _operations_exec_time_file with new data.
-   */
-  void uploadOperationsExecTime() const;
 };
 
 } // namespace backend
index beede15..3ebe584 100644 (file)
@@ -32,6 +32,7 @@ class IExecutionObserver
 public:
   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;
   virtual ~IExecutionObserver() = default;
 };
 
@@ -41,6 +42,7 @@ 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 uploadExecTime() override { _et->uploadOperationsExecTime(); }
 
 private:
   std::chrono::steady_clock::time_point _prev_time;
index 1c0e0e3..9055d41 100644 (file)
@@ -159,7 +159,13 @@ void DataflowExecutor::executeImpl()
     _finished_jobs[job_index] = std::move(job);
   }
   assert(noWaitingJobs());
-
+  if (is_profiling)
+  {
+    for (auto &o : _observers)
+    {
+      o->uploadExecTime();
+    }
+  }
   // Reset input info for the next execution
   _input_info = _initial_input_info;
 }
index de8d2a3..09440e5 100644 (file)
@@ -57,6 +57,7 @@ TEST(ExecTime, roundtrip_ok)
     et.updateOperationExecTime(b, "op1", true, 100, 100);
     et.updateOperationExecTime(b, "op1", true, 200, 200);
     et.updateOperationExecTime(b, "op1", false, 100, 888);
+    et.uploadOperationsExecTime();
   }
   {
     ExecTime et(bs);
@@ -67,6 +68,7 @@ TEST(ExecTime, roundtrip_ok)
     ASSERT_EQ(time, 150);
     time = et.getOperationExecTime(b, "op1", false, 100);
     ASSERT_EQ(time, 888);
+    et.uploadOperationsExecTime();
   }
   // clean up
   remove("exec_time.json");
@@ -81,6 +83,7 @@ TEST(ExecTime, structure)
     ExecTime et(bs);
     et.updateOperationExecTime(b, "op1", true, 100, 100);
     et.updateOperationExecTime(b, "op1", true, 200, 200);
+    et.uploadOperationsExecTime();
   }
   {
     ExecTime et(bs);
@@ -89,6 +92,7 @@ TEST(ExecTime, structure)
     // Check interpolation
     time = et.getOperationExecTime(b, "op1", true, 200);
     ASSERT_EQ(time, 200);
+    et.uploadOperationsExecTime();
   }
   // clean up
   remove("exec_time.json");