[enco] Initial MaxPool2D codegen support (#1318)
author박종현/동작제어Lab(SR)/Staff Engineer/삼성전자 <jh1302.park@samsung.com>
Tue, 4 Sep 2018 05:00:49 +0000 (14:00 +0900)
committerGitHub Enterprise <noreply-CODE@samsung.com>
Tue, 4 Sep 2018 05:00:49 +0000 (14:00 +0900)
This commit implements codegen routines for MaxPool2D without
padding/stride.

Signed-off-by: Jonghyun Park <jh1302.park@samsung.com>
contrib/enco/core/src/ANN/IR/Operation.h
contrib/enco/core/src/CppGen/Subnet.cpp
contrib/enco/core/src/Transforms/Split.cpp

index bcae799..804f8bc 100644 (file)
@@ -15,6 +15,7 @@ public:
   enum class Code
   {
     CONV_2D,
+    MAX_POOL_2D,
     RELU
   };
 
index 332ed67..5e52e36 100644 (file)
@@ -213,6 +213,8 @@ private:
     {
     case ann::Operation::Code::CONV_2D:
       return "ANEURALNETWORKS_CONV_2D";
+    case ann::Operation::Code::MAX_POOL_2D:
+      return "ANEURALNETWORKS_MAX_POOL_2D";
     case ann::Operation::Code::RELU:
       return "ANEURALNETWORKS_RELU";
     default:
index 2236e00..46d6317 100644 (file)
@@ -59,6 +59,12 @@ Compatibility ANNGroupBuilder::kind(const coco::Instr *ins) const
       return true;
     }
 
+    bool visit(const coco::MaxPool2D *) override
+    {
+      // TODO Check data layout
+      return true;
+    }
+
     bool visit(const coco::ReLU *) override
     {
       // TODO Check data layout
@@ -238,6 +244,43 @@ public:
 
       _binder->addOperation(ann::Operation::Code::RELU, {ifm}, {ofm});
     }
+    else if (auto maxpool = unit->op()->asMaxPool2D())
+    {
+      auto ifm = _binder->addOperand<float>(unit->ifm());
+
+      // TODO Support padding
+      auto left = _binder->addOperand<int32_t>();
+      _binder->setOperand(left, 0);
+      auto right = _binder->addOperand<int32_t>();
+      _binder->setOperand(right, 0);
+      auto top = _binder->addOperand<int32_t>();
+      _binder->setOperand(top, 0);
+      auto bottom = _binder->addOperand<int32_t>();
+      _binder->setOperand(bottom, 0);
+
+      // TODO Support stride
+      auto hstride = _binder->addOperand<int32_t>();
+      _binder->setOperand(hstride, 1);
+      auto vstride = _binder->addOperand<int32_t>();
+      _binder->setOperand(vstride, 1);
+
+      // Set receptive field size
+      auto width = _binder->addOperand<int32_t>();
+      _binder->setOperand(width, maxpool->window()->horizontal());
+      auto height = _binder->addOperand<int32_t>();
+      _binder->setOperand(height, maxpool->window()->vertical());
+
+      // Set fuse code
+      // TODO Suport operation fusion
+      auto fuse = _binder->addOperand<int32_t>();
+      _binder->setOperand(fuse, 0);
+
+      auto ofm = _binder->addOperand<float>(unit->ofm());
+
+      _binder->addOperation(ann::Operation::Code::MAX_POOL_2D,
+                            {ifm, left, right, top, bottom, hstride, vstride, width, height, fuse},
+                            {ofm});
+    }
     else
     {
       throw std::runtime_error{"Not supported, yet"};