From 399b0ca78c9d91efa17cd9299a081020b58af600 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: Wed, 5 Sep 2018 13:07:33 +0900 Subject: [PATCH] [enco] Generate code for AvgPool2D op (#1340) This commit supports code generation on AvgPool2D op. 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 | 42 ++++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+) diff --git a/contrib/enco/core/src/ANN/IR/Operation.h b/contrib/enco/core/src/ANN/IR/Operation.h index 804f8bc..bf1f21b 100644 --- a/contrib/enco/core/src/ANN/IR/Operation.h +++ b/contrib/enco/core/src/ANN/IR/Operation.h @@ -16,6 +16,7 @@ public: { CONV_2D, MAX_POOL_2D, + AVG_POOL_2D, RELU }; diff --git a/contrib/enco/core/src/CppGen/Subnet.cpp b/contrib/enco/core/src/CppGen/Subnet.cpp index 5e52e36..084a102 100644 --- a/contrib/enco/core/src/CppGen/Subnet.cpp +++ b/contrib/enco/core/src/CppGen/Subnet.cpp @@ -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: diff --git a/contrib/enco/core/src/Transforms/Split.cpp b/contrib/enco/core/src/Transforms/Split.cpp index 94361ff..1e866fe 100644 --- a/contrib/enco/core/src/Transforms/Split.cpp +++ b/contrib/enco/core/src/Transforms/Split.cpp @@ -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(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 horizontal/vertical 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, avgpool->window()->horizontal()); + auto height = _binder->addOperand(); + _binder->setOperand(height, avgpool->window()->vertical()); + + // TODO Suport operation fusion + auto fuse = _binder->addOperand(); + _binder->setOperand(fuse, 0); + + auto ofm = _binder->addOperand(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"}; -- 2.7.4