pureACl profiler keeps track of operator's index (#2412)
author이상규/동작제어Lab(SR)/Principal Engineer/삼성전자 <sg5.lee@samsung.com>
Wed, 22 Aug 2018 10:03:51 +0000 (19:03 +0900)
committer박세희/동작제어Lab(SR)/Principal Engineer/삼성전자 <saehie.park@samsung.com>
Wed, 22 Aug 2018 10:03:51 +0000 (19:03 +0900)
Some operators in model are expanded into multiple Steps.
To analyze the profile data, it need to keep track of operator index
to interpreter op's.

Now, we know where the ACL kernel is generated by seeing Step's _op_idx
member.

Related Issue: #2376

Signed-off-by: Sanggyu Lee <sg5.lee@samsung.com>
runtimes/pure_arm_compute/src/compilation.cc
runtimes/pure_arm_compute/src/execution.cc
runtimes/pure_arm_compute/src/internal/arm_compute.h

index f4c8413..789011f 100644 (file)
@@ -3271,6 +3271,16 @@ public:
     _plan.operations().at(_plan.operations().size() - 1).name() = name;
   }
 
+#ifdef TFLITE_PROFILING_ENABLED
+public:
+  int plan_op_size() const { return _plan.operations().size(); }
+  void addOpIndexToSteps(int from, int to, int op_idx)
+  {
+    for (int i = from; i < to; ++i)
+      _plan.operations().at(i).op_idx() = op_idx;
+  }
+#endif
+
 private:
   ::internal::arm_compute::Plan &_plan;
 };
@@ -3538,9 +3548,17 @@ void PlanBuilder::finalize(void) const
   AllocationContext allocation_context{_plan};
   ExecutionBuilder execution_builder{_plan};
 
-  for (const auto &stage : _stages)
+  for (int idx = 0; idx < _stages.size(); idx++)
   {
+    const auto &stage = _stages[idx];
+#ifdef TFLITE_PROFILING_ENABLED
+    int from = execution_builder.plan_op_size();
+#endif
     stage(allocation_context, execution_builder);
+#ifdef TFLITE_PROFILING_ENABLED
+    int to = execution_builder.plan_op_size();
+    execution_builder.addOpIndexToSteps(from, to, idx);
+#endif
   }
 
   // Allocate Tensor Memory
index a64b54a..90a93bc 100644 (file)
@@ -493,7 +493,7 @@ int ANeuralNetworksExecution_startCompute(ANeuralNetworksExecution *execution,
   for (uint32_t n = 0; n < operations.size(); ++n)
   {
     auto prof = profiling::Context::get().getProfiler();
-    SCOPED_OPERATOR_PROFILE(prof, n);
+    SCOPED_OPERATOR_PROFILE(prof, operations.at(n).op_idx());
     operations.at(n).run();
 
     if (sync)
index cacdfce..6fe8c80 100644 (file)
@@ -103,6 +103,13 @@ public:
 private:
   std::string _name;
   std::unique_ptr<::arm_compute::IFunction> _func;
+#ifdef TFLITE_PROFILING_ENABLED
+public:
+  int op_idx() const { return _op_idx; }
+  int &op_idx() { return _op_idx; }
+private:
+  int _op_idx;
+#endif
 };
 
 } // namespace op