* [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
#include "compilation.h"
#include "execution.h"
+#include "profiling.h"
#include "internal/VectorSource.h"
#include "internal/MatrixSource.h"
#include "util/feature/IndexIterator.h"
+#include <arm_compute/runtime/CL/CLScheduler.h>
+
#include <cassert>
//
int ANeuralNetworksExecution_startCompute(ANeuralNetworksExecution *execution,
ANeuralNetworksEvent **event)
{
+ const bool sync = profiling::Context::get().sync().enabled();
+
assert(execution != nullptr);
const auto &plan = execution->plan();
for (uint32_t n = 0; n < operations.size(); ++n)
{
operations.at(n).run();
+
+ if (sync)
+ {
+ arm_compute::CLScheduler::get().sync();
+ }
}
// Get output(s)
--- /dev/null
+#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__