From 0932e1dbdb971bfc8fcf9e7c8bfa34bfb206d4c0 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=EB=B0=95=EC=A2=85=ED=98=84/=EB=8F=99=EC=9E=91=EC=A0=9C?= =?utf8?q?=EC=96=B4Lab=28SR=29/Staff=20Engineer/=EC=82=BC=EC=84=B1?= =?utf8?q?=EC=A0=84=EC=9E=90?= Date: Fri, 15 Jun 2018 18:56:04 +0900 Subject: [PATCH] [Pure CL] Introduce Synchronization (#1693) * [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 * Enable sync when value is non-zero --- runtimes/pure_arm_compute/src/execution.cc | 10 ++++++ runtimes/pure_arm_compute/src/profiling.h | 52 ++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+) create mode 100644 runtimes/pure_arm_compute/src/profiling.h diff --git a/runtimes/pure_arm_compute/src/execution.cc b/runtimes/pure_arm_compute/src/execution.cc index 529b15f..2feb2cf 100644 --- a/runtimes/pure_arm_compute/src/execution.cc +++ b/runtimes/pure_arm_compute/src/execution.cc @@ -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 + #include // @@ -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 index 0000000..06d3ea1 --- /dev/null +++ b/runtimes/pure_arm_compute/src/profiling.h @@ -0,0 +1,52 @@ +#ifndef __PURE_ARM_COMPUTE_PROFILING_H__ +#define __PURE_ARM_COMPUTE_PROFILING_H__ + +#include + +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__ -- 2.7.4