[enco] Generate code for AvgPool2D op (#1340)
author박종현/동작제어Lab(SR)/Staff Engineer/삼성전자 <jh1302.park@samsung.com>
Wed, 5 Sep 2018 04:07:33 +0000 (13:07 +0900)
committerGitHub Enterprise <noreply-CODE@samsung.com>
Wed, 5 Sep 2018 04:07:33 +0000 (13:07 +0900)
This commit supports code generation on AvgPool2D op.

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 804f8bc..bf1f21b 100644 (file)
@@ -16,6 +16,7 @@ public:
   {
     CONV_2D,
     MAX_POOL_2D,
+    AVG_POOL_2D,
     RELU
   };
 
index 5e52e36..084a102 100644 (file)
@@ -215,6 +215,8 @@ private:
       return "ANEURALNETWORKS_CONV_2D";
     case ann::Operation::Code::MAX_POOL_2D:
       return "ANEURALNETWORKS_MAX_POOL_2D";
+    case ann::Operation::Code::AVG_POOL_2D:
+      return "ANEURALNETWORKS_AVERAGE_POOL_2D";
     case ann::Operation::Code::RELU:
       return "ANEURALNETWORKS_RELU";
     default:
index 94361ff..1e866fe 100644 (file)
@@ -65,6 +65,12 @@ Compatibility ANNGroupBuilder::kind(const coco::Instr *ins) const
       return true;
     }
 
+    bool visit(const coco::AvgPool2D *) override
+    {
+      // TODO Check data layout
+      return true;
+    }
+
     bool visit(const coco::ReLU *) override
     {
       // TODO Check data layout
@@ -281,6 +287,42 @@ public:
                             {ifm, left, right, top, bottom, hstride, vstride, width, height, fuse},
                             {ofm});
     }
+    else if (auto avgpool = unit->op()->asAvgPool2D())
+    {
+      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 horizontal/vertical 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, avgpool->window()->horizontal());
+      auto height = _binder->addOperand<int32_t>();
+      _binder->setOperand(height, avgpool->window()->vertical());
+
+      // 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::AVG_POOL_2D,
+                            {ifm, left, right, top, bottom, hstride, vstride, width, height, fuse},
+                            {ofm});
+    }
     else
     {
       throw std::runtime_error{"Not supported, yet"};