From d7862f4e829337602e1ce6aaf7c19642fde13b2a 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: Thu, 11 Oct 2018 10:12:56 +0900 Subject: [PATCH] [enco] Introduce ANNAvgPool2DAppender (#1820) This commit extracts AvgPool2D Op generation code as ANNAvgPool2DAppender. Signed-off-by: Jonghyun Park --- contrib/enco/core/src/Transforms/Split.cpp | 98 ++++++++++++++++++++---------- 1 file changed, 66 insertions(+), 32 deletions(-) diff --git a/contrib/enco/core/src/Transforms/Split.cpp b/contrib/enco/core/src/Transforms/Split.cpp index 972e091..a430c01 100644 --- a/contrib/enco/core/src/Transforms/Split.cpp +++ b/contrib/enco/core/src/Transforms/Split.cpp @@ -360,6 +360,65 @@ private: coco::FeatureObject *_ofm; }; +class ANNAvgPool2DAppender final : public ANNOpAppender +{ +public: + void pad(const coco::Padding2D *pad) { _pad = *pad; } + void stride(const coco::Stride2D *stride) { _stride = *stride; } + void window(const coco::Window2D *window) { _window = *window; } + + void ifm(coco::FeatureObject *ifm) { _ifm = ifm; } + void ofm(coco::FeatureObject *ofm) { _ofm = ofm; } + +public: + void append(ANNBinder *binder) const override + { + auto ifm = binder->addOperand(_ifm); + + // Set padding + auto left = binder->addOperand(); + binder->setOperand(left, _pad.left()); + auto right = binder->addOperand(); + binder->setOperand(right, _pad.right()); + auto top = binder->addOperand(); + binder->setOperand(top, _pad.top()); + auto bottom = binder->addOperand(); + binder->setOperand(bottom, _pad.bottom()); + + // Set horizontal/vertical stride + auto hstride = binder->addOperand(); + binder->setOperand(hstride, _stride.horizontal()); + auto vstride = binder->addOperand(); + binder->setOperand(vstride, _stride.vertical()); + + // Set receptive field size + auto width = binder->addOperand(); + binder->setOperand(width, _window.width()); + auto height = binder->addOperand(); + binder->setOperand(height, _window.height()); + + // Set fuse code + // TODO Suport operation fusion + auto fuse = binder->addOperand(); + binder->setOperand(fuse, 0); + + auto ofm = binder->addOperand(_ofm); + + binder->addOperation(ann::Operation::Code::AVG_POOL_2D, + {ifm, left, right, top, bottom, hstride, vstride, width, height, fuse}, + {ofm}); + } + +private: + coco::Padding2D _pad; + coco::Stride2D _stride; + coco::Window2D _window; + +private: + coco::FeatureObject *_ifm; + coco::FeatureObject *_ofm; +}; + class ANNOpFunctionalAppender final : public ANNOpAppender { public: @@ -582,41 +641,16 @@ private: return nullptr; } - // TODO Rename "_binder" - return make_unique([unit, avgpool](ANNBinder *_binder) { - auto ifm = _binder->addOperand(unit->ifm()); + auto app = make_unique(); - auto left = _binder->addOperand(); - _binder->setOperand(left, avgpool->pad()->left()); - auto right = _binder->addOperand(); - _binder->setOperand(right, avgpool->pad()->right()); - auto top = _binder->addOperand(); - _binder->setOperand(top, avgpool->pad()->top()); - auto bottom = _binder->addOperand(); - _binder->setOperand(bottom, avgpool->pad()->bottom()); - - // Set horizontal/vertical stride - auto hstride = _binder->addOperand(); - _binder->setOperand(hstride, avgpool->stride()->horizontal()); - auto vstride = _binder->addOperand(); - _binder->setOperand(vstride, avgpool->stride()->vertical()); - - // Set receptive field size - auto width = _binder->addOperand(); - _binder->setOperand(width, avgpool->window()->width()); - auto height = _binder->addOperand(); - _binder->setOperand(height, avgpool->window()->height()); - - // TODO Suport operation fusion - auto fuse = _binder->addOperand(); - _binder->setOperand(fuse, 0); + app->pad(avgpool->pad()); + app->stride(avgpool->stride()); + app->window(avgpool->window()); - auto ofm = _binder->addOperand(unit->ofm()); + app->ifm(unit->ifm()); + app->ofm(unit->ofm()); - _binder->addOperation(ann::Operation::Code::AVG_POOL_2D, - {ifm, left, right, top, bottom, hstride, vstride, width, height, fuse}, - {ofm}); - }); + return std::move(app); } std::unique_ptr pad(const coco::UnitF *unit) -- 2.7.4