Introduce Split operation into pureACL runtime (#2447)
author윤지영/동작제어Lab(SR)/Engineer/삼성전자 <jy910.yun@samsung.com>
Fri, 24 Aug 2018 02:24:49 +0000 (11:24 +0900)
committer박세희/동작제어Lab(SR)/Principal Engineer/삼성전자 <saehie.park@samsung.com>
Fri, 24 Aug 2018 02:24:49 +0000 (11:24 +0900)
* Introduce Split operation into pureACL runtime

This commit introduces Split operation into pureACL runtime.

Signed-off-by: Jiyoung Yun <jy910.yun@samsung.com>
* Remove num_split_index of Split operator

The `num_split_index` is always the same with the number of output.
So it can be omitted.

Signed-off-by: Jiyoung Yun <jy910.yun@samsung.com>
runtimes/pure_arm_compute/src/compilation.cc
runtimes/pure_arm_compute/src/internal/op/NodeVisitor.h
runtimes/pure_arm_compute/src/internal/op/Split.cc [new file with mode: 0644]
runtimes/pure_arm_compute/src/internal/op/Split.h [new file with mode: 0644]
runtimes/pure_arm_compute/src/model.cc

index 04c99e8..fa92809 100644 (file)
@@ -456,6 +456,7 @@ public:
   void visit(const ::internal::tflite::op::RNN::Node &node) override;
   void visit(const ::internal::tflite::op::LSTM::Node &node) override;
   void visit(const ::internal::tflite::op::Floor::Node &node) override;
+  void visit(const ::internal::tflite::op::Split::Node &node) override;
 
 private:
   const ::internal::tflite::operand::Set &_ctx;
@@ -3245,6 +3246,13 @@ void Planner::visit(const ::internal::tflite::op::Floor::Node &node)
   _builder.addStage(stage);
 }
 
+void Planner::visit(const ::internal::tflite::op::Split::Node &node)
+{
+  VERBOSE(Split) << "Configure Split operation" << std::endl;
+
+  throw std::runtime_error("Not supported, yet");
+}
+
 class AllocationContext final : public IAllocationContext
 {
 public:
index 9a523ef..a4ed37a 100644 (file)
@@ -30,6 +30,7 @@
 #include "internal/op/Rnn.h"
 #include "internal/op/Lstm.h"
 #include "internal/op/Floor.h"
+#include "internal/op/Split.h"
 
 namespace internal
 {
@@ -75,6 +76,7 @@ struct NodeVisitor
   virtual void visit(const RNN::Node &) = 0;
   virtual void visit(const LSTM::Node &) = 0;
   virtual void visit(const Floor::Node &) = 0;
+  virtual void visit(const Split::Node &) = 0;
 };
 
 } // namespace op
diff --git a/runtimes/pure_arm_compute/src/internal/op/Split.cc b/runtimes/pure_arm_compute/src/internal/op/Split.cc
new file mode 100644 (file)
index 0000000..9a91414
--- /dev/null
@@ -0,0 +1,53 @@
+#include "internal/op/Split.h"
+#include "internal/op/NodeVisitor.h"
+
+#include <cassert>
+
+namespace internal
+{
+namespace tflite
+{
+namespace op
+{
+namespace Split
+{
+
+void Node::accept(NodeVisitor &&v) const { v.visit(*this); }
+
+} // namespace Split
+} // namespace op
+} // namespace tflite
+} // namespace internal
+
+namespace internal
+{
+namespace tflite
+{
+namespace op
+{
+namespace Split
+{
+
+Param::Param(uint32_t inputCount, const uint32_t *inputs, uint32_t outputCount,
+             const uint32_t *outputs)
+{
+  assert(inputCount == 2);
+
+  // Each input should be interpreted as follows:
+  //  0 -> A 0-D int32 tensor, indicating the dimension along which to split.
+  //  1 -> An n-D tensor, specifying the tensor to be split.
+  axis_index = inputs[0];
+  ifm_index = inputs[1];
+
+  // Each output should be interpreted as follow:
+  //  [0, outputCount) -> An n-D tensor.
+  for (uint32_t n = 0; n < outputCount; ++n)
+  {
+    ofm_indexes.emplace_back(outputs[n]);
+  }
+}
+
+} // namespace Split
+} // namespace op
+} // namespace tflite
+} // namespace internal
diff --git a/runtimes/pure_arm_compute/src/internal/op/Split.h b/runtimes/pure_arm_compute/src/internal/op/Split.h
new file mode 100644 (file)
index 0000000..14f45b7
--- /dev/null
@@ -0,0 +1,55 @@
+#ifndef __INTERNAL_OP_SPLIT_H__
+#define __INTERNAL_OP_SPLIT_H__
+
+#include "internal/op/Node.h"
+
+#include <cstdint>
+#include <vector>
+
+namespace internal
+{
+namespace tflite
+{
+namespace op
+{
+namespace Split
+{
+
+struct Param
+{
+  int32_t axis_index;
+  int32_t ifm_index;
+
+  std::vector<int32_t> ofm_indexes;
+
+  Param() = default;
+  Param(uint32_t inputCount, const uint32_t *inputs, uint32_t outputCount, const uint32_t *outputs);
+};
+
+class Node final : public op::Node
+{
+public:
+  Node(const Param &param) : _param(param)
+  {
+    // DO NOTHING
+  }
+
+public:
+  virtual ~Node() = default;
+
+public:
+  const Param &param(void) const { return _param; }
+
+public:
+  void accept(NodeVisitor &&) const override;
+
+private:
+  const Param _param;
+};
+
+} // namespace Split
+} // namespace op
+} // namespace tflite
+} // namespace internal
+
+#endif // __INTERNAL_OP_SPLIT_H__
index f2d616c..84dad11 100644 (file)
@@ -564,6 +564,18 @@ int ANeuralNetworksModel_addOperationEx(ANeuralNetworksModel *model,
 
       break;
     }
+    case ANEURALNETWORKS_SPLIT_EX:
+    {
+      using internal::tflite::op::Split::Param;
+      using internal::tflite::op::Split::Node;
+
+      // Add 'operations'
+      auto &operations = model->deref().operations();
+
+      operations.emplace_back<Node>(Param{inputCount, inputs, outputCount, outputs});
+
+      break;
+    }
     default:
       throw std::runtime_error{"Not supported operation"};
   }