From 8f910f4e1f7028b5ccd3237ef72784134075fb0d Mon Sep 17 00:00:00 2001 From: =?utf8?q?=EB=B0=95=EC=A2=85=ED=98=84/=EB=8F=99=EC=9E=91=EC=A0=9C?= =?utf8?q?=EC=96=B4Lab=28SR=29/Staff=20Engineer/=EC=82=BC=EC=84=B1?= =?utf8?q?=EC=A0=84=EC=9E=90?= Date: Tue, 4 Sep 2018 14:00:49 +0900 Subject: [PATCH] [enco] Initial MaxPool2D codegen support (#1318) This commit implements codegen routines for MaxPool2D without padding/stride. Signed-off-by: Jonghyun Park --- contrib/enco/core/src/ANN/IR/Operation.h | 1 + contrib/enco/core/src/CppGen/Subnet.cpp | 2 ++ contrib/enco/core/src/Transforms/Split.cpp | 43 ++++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+) diff --git a/contrib/enco/core/src/ANN/IR/Operation.h b/contrib/enco/core/src/ANN/IR/Operation.h index bcae799..804f8bc 100644 --- a/contrib/enco/core/src/ANN/IR/Operation.h +++ b/contrib/enco/core/src/ANN/IR/Operation.h @@ -15,6 +15,7 @@ public: enum class Code { CONV_2D, + MAX_POOL_2D, RELU }; diff --git a/contrib/enco/core/src/CppGen/Subnet.cpp b/contrib/enco/core/src/CppGen/Subnet.cpp index 332ed67..5e52e36 100644 --- a/contrib/enco/core/src/CppGen/Subnet.cpp +++ b/contrib/enco/core/src/CppGen/Subnet.cpp @@ -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: diff --git a/contrib/enco/core/src/Transforms/Split.cpp b/contrib/enco/core/src/Transforms/Split.cpp index 2236e00..46d6317 100644 --- a/contrib/enco/core/src/Transforms/Split.cpp +++ b/contrib/enco/core/src/Transforms/Split.cpp @@ -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(unit->ifm()); + + // TODO Support padding + auto left = _binder->addOperand(); + _binder->setOperand(left, 0); + auto right = _binder->addOperand(); + _binder->setOperand(right, 0); + auto top = _binder->addOperand(); + _binder->setOperand(top, 0); + auto bottom = _binder->addOperand(); + _binder->setOperand(bottom, 0); + + // TODO Support stride + auto hstride = _binder->addOperand(); + _binder->setOperand(hstride, 1); + auto vstride = _binder->addOperand(); + _binder->setOperand(vstride, 1); + + // Set receptive field size + auto width = _binder->addOperand(); + _binder->setOperand(width, maxpool->window()->horizontal()); + auto height = _binder->addOperand(); + _binder->setOperand(height, maxpool->window()->vertical()); + + // Set fuse code + // TODO Suport operation fusion + auto fuse = _binder->addOperand(); + _binder->setOperand(fuse, 0); + + auto ofm = _binder->addOperand(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"}; -- 2.7.4