[Pure CL] Introduce Synchronization (#1693)
author박종현/동작제어Lab(SR)/Staff Engineer/삼성전자 <jh1302.park@samsung.com>
Fri, 15 Jun 2018 09:56:04 +0000 (18:56 +0900)
committer이춘석/동작제어Lab(SR)/Staff Engineer/삼성전자 <chunseok.lee@samsung.com>
Fri, 15 Jun 2018 09:56:04 +0000 (18:56 +0900)
* [Pure CL] Introduce Synchronization

This commit introduces PURE_ARM_COMPUTE_SYNC_ENABLE option which synchronize
each operaation when it is turned on.

This option is neccessary for profiler.

Signed-off-by: Jonghyun Park <jh1302.park@samsung.com>
* Enable sync when value is non-zero

runtimes/pure_arm_compute/src/execution.cc
runtimes/pure_arm_compute/src/profiling.h [new file with mode: 0644]

index 529b15f..2feb2cf 100644 (file)
@@ -2,6 +2,7 @@
 
 #include "compilation.h"
 #include "execution.h"
+#include "profiling.h"
 
 #include "internal/VectorSource.h"
 #include "internal/MatrixSource.h"
@@ -17,6 +18,8 @@
 
 #include "util/feature/IndexIterator.h"
 
+#include <arm_compute/runtime/CL/CLScheduler.h>
+
 #include <cassert>
 
 //
@@ -441,6 +444,8 @@ int ANeuralNetworksExecution_setOutput(ANeuralNetworksExecution *execution, int3
 int ANeuralNetworksExecution_startCompute(ANeuralNetworksExecution *execution,
                                           ANeuralNetworksEvent **event)
 {
+  const bool sync = profiling::Context::get().sync().enabled();
+
   assert(execution != nullptr);
 
   const auto &plan = execution->plan();
@@ -459,6 +464,11 @@ int ANeuralNetworksExecution_startCompute(ANeuralNetworksExecution *execution,
   for (uint32_t n = 0; n < operations.size(); ++n)
   {
     operations.at(n).run();
+
+    if (sync)
+    {
+      arm_compute::CLScheduler::get().sync();
+    }
   }
 
   // Get output(s)
diff --git a/runtimes/pure_arm_compute/src/profiling.h b/runtimes/pure_arm_compute/src/profiling.h
new file mode 100644 (file)
index 0000000..06d3ea1
--- /dev/null
@@ -0,0 +1,52 @@
+#ifndef __PURE_ARM_COMPUTE_PROFILING_H__
+#define __PURE_ARM_COMPUTE_PROFILING_H__
+
+#include <iostream>
+
+namespace profiling
+{
+
+class Sync
+{
+public:
+  Sync() : _enabled{false}
+  {
+    auto env = std::getenv("PURE_ARM_COMPUTE_SYNC_ENABLE");
+
+    if (env && std::atoi(env) != 0)
+    {
+      _enabled = true;
+    }
+  }
+
+public:
+  bool enabled(void) const { return _enabled; }
+
+private:
+  bool _enabled;
+};
+
+} // namespace profiling
+
+namespace profiling
+{
+
+class Context
+{
+public:
+  const Sync &sync(void) const { return _sync; }
+
+private:
+  Sync _sync;
+
+public:
+  static const Context &get(void)
+  {
+    static Context ctx{};
+    return ctx;
+  }
+};
+
+} // namespace profiling
+
+#endif // __PURE_ARM_COMPUTE_PROFILING_H__