[Pure ACL NN Runtime] Add Execution Placeholder (#526)
author박종현/동작제어Lab(SR)/Senior Engineer/삼성전자 <jh1302.park@samsung.com>
Tue, 10 Apr 2018 07:38:48 +0000 (16:38 +0900)
committer김정현/동작제어Lab(SR)/Senior Engineer/삼성전자 <jh0822.kim@samsung.com>
Tue, 10 Apr 2018 07:38:48 +0000 (16:38 +0900)
This commit partially implements functions related with ANeuralNetworksExecution
struct.

Signed-off-by: Jonghyun Park <jh1302.park@samsung.com>
tools/nnapi_bindings/bindings/pure_arm_compute/src/compilation.h
tools/nnapi_bindings/bindings/pure_arm_compute/src/execution.cc
tools/nnapi_bindings/bindings/pure_arm_compute/src/execution.h
tools/nnapi_bindings/bindings/pure_arm_compute/src/internal/arm_compute.cc [new file with mode: 0644]
tools/nnapi_bindings/bindings/pure_arm_compute/src/internal/arm_compute.h [new file with mode: 0644]

index f14f631..3f48a50 100644 (file)
@@ -2,21 +2,30 @@
 #define __COMPILATION_H__
 
 #include "internal/Model.h"
+#include "internal/arm_compute.h"
 
 struct ANeuralNetworksCompilation
 {
 public:
   ANeuralNetworksCompilation(const std::shared_ptr<const internal::tflite::Model> &model)
-    : _model{model}
+    : _model{model}, _output{new internal::arm_compute::Model}
   {
     // DO NOTHING
   }
 
 public:
   const internal::tflite::Model &model(void) const { return *_model; }
+  internal::arm_compute::Model &output(void) { return *_output; }
+
+public:
+  void publish(std::shared_ptr<const internal::arm_compute::Model> &output)
+  {
+    output = _output;
+  }
 
 private:
   std::shared_ptr<const internal::tflite::Model> _model;
+  std::shared_ptr<internal::arm_compute::Model> _output;
 };
 
 #endif
index d04244f..cae7015 100644 (file)
@@ -1,10 +1,19 @@
 #include <nnapi.h>
 
+#include "compilation.h"
 #include "execution.h"
 
+#include <cassert>
+
 ResultCode
 ANeuralNetworksExecution_create(ANeuralNetworksCompilation* compilation, ANeuralNetworksExecution** execution)
 {
+  std::shared_ptr<const ::internal::arm_compute::Model> model;
+
+  compilation->publish(model);
+
+  *execution = new ANeuralNetworksExecution{model};
+
   return ANEURALNETWORKS_NO_ERROR;
 }
 
@@ -27,6 +36,15 @@ ANeuralNetworksExecution_setOutput(ANeuralNetworksExecution* execution,
 ResultCode
 ANeuralNetworksExecution_startCompute(ANeuralNetworksExecution* execution, ANeuralNetworksEvent** event)
 {
+  assert(execution != nullptr);
+
+  const auto &operations = execution->model().operations();
+
+  for (uint32_t n = 0; n < operations.size(); ++n)
+  {
+    operations.at(n).run();
+  }
+
   return ANEURALNETWORKS_NO_ERROR;
 }
 
index 84d4e88..ecc6ff9 100644 (file)
@@ -1,8 +1,22 @@
 #ifndef __EXECUTION_H__
 #define __EXECUTION_H__
 
+#include "internal/arm_compute.h"
+
 struct ANeuralNetworksExecution
 {
+public:
+  ANeuralNetworksExecution(const std::shared_ptr<const internal::arm_compute::Model> &model)
+    : _model{model}
+  {
+    // DO NOTHING
+  }
+
+public:
+  const internal::arm_compute::Model &model(void) const { return *_model; }
+
+private:
+  std::shared_ptr<const internal::arm_compute::Model> _model;
 };
 
 #endif
diff --git a/tools/nnapi_bindings/bindings/pure_arm_compute/src/internal/arm_compute.cc b/tools/nnapi_bindings/bindings/pure_arm_compute/src/internal/arm_compute.cc
new file mode 100644 (file)
index 0000000..20c9da3
--- /dev/null
@@ -0,0 +1,22 @@
+#include "internal/arm_compute.h"
+
+#include <cassert>
+
+namespace internal
+{
+namespace arm_compute
+{
+namespace operand
+{
+
+Context &Context::set(const ::internal::tflite::operand::Index &id,
+                      const std::shared_ptr<::arm_compute::ICLTensor> &tensor)
+{
+  assert(_objects.find(id.asInt()) == _objects.end());
+
+  _objects[id.asInt()] = Object{tensor};
+}
+
+} // namespace operand
+} // namepsace arm_compute
+} // namespace internal
diff --git a/tools/nnapi_bindings/bindings/pure_arm_compute/src/internal/arm_compute.h b/tools/nnapi_bindings/bindings/pure_arm_compute/src/internal/arm_compute.h
new file mode 100644 (file)
index 0000000..8ce555c
--- /dev/null
@@ -0,0 +1,122 @@
+#ifndef __INTERNAL_ARM_COMPUTE_H__
+#define __INTERNAL_ARM_COMPUTE_H__
+
+#include <arm_compute/core/CL/ICLTensor.h>
+
+namespace internal
+{
+namespace arm_compute
+{
+namespace operand
+{
+
+class Object
+{
+public:
+  Object() = default;
+
+public:
+  Object(const std::shared_ptr<::arm_compute::ICLTensor> &tensor) : _tensor{tensor}
+  {
+    // DO NOTHING
+  }
+
+public:
+  ::arm_compute::ICLTensor *ptr(void) const { return _tensor.get(); }
+
+private:
+  std::shared_ptr<::arm_compute::ICLTensor> _tensor;
+};
+
+} // namespace operand
+} // namepsace arm_compute
+} // namespace internal
+
+#include "internal/Model.h"
+
+#include <map>
+
+namespace internal
+{
+namespace arm_compute
+{
+namespace operand
+{
+
+class Context
+{
+public:
+  Context &set(const ::internal::tflite::operand::Index &id,
+               const std::shared_ptr<::arm_compute::ICLTensor> &tensor);
+
+public:
+  const Object &at(const ::internal::tflite::operand::Index &) const;
+  Object &at(const ::internal::tflite::operand::Index &);
+
+private:
+  std::map<int, Object> _objects;
+};
+
+} // namespace operand
+} // namepsace arm_compute
+} // namespace internal
+
+#include <arm_compute/runtime/IFunction.h>
+
+namespace internal
+{
+namespace arm_compute
+{
+namespace op
+{
+
+class Sequence
+{
+public:
+  uint32_t size(void) const { return _functions.size(); }
+
+public:
+  Sequence &append(std::unique_ptr<::arm_compute::IFunction> &&func)
+  {
+    _functions.emplace_back(std::move(func));
+    return (*this);
+  }
+
+public:
+  ::arm_compute::IFunction &at(uint32_t n) const
+  {
+    return *(_functions.at(n));
+  }
+
+private:
+  std::vector<std::unique_ptr<::arm_compute::IFunction>> _functions;
+};
+
+} // namespace op
+} // namepsace arm_compute
+} // namespace internal
+
+namespace internal
+{
+namespace arm_compute
+{
+
+class Model
+{
+public:
+  operand::Context &operands(void) { return _operands; }
+  const operand::Context &operands(void) const { return _operands; }
+
+public:
+  op::Sequence &operations(void) { return _ops; }
+  const op::Sequence &operations(void) const { return _ops; }
+
+private:
+  operand::Context _operands;
+  op::Sequence _ops;
+};
+
+} // namepsace arm_compute
+} // namespace internal
+
+#endif // __INTERNAL_ARM_COMPUTE_H__