From: 박종현/동작제어Lab(SR)/Staff Engineer/삼성전자 Date: Wed, 5 Sep 2018 04:07:33 +0000 (+0900) Subject: [enco] Generate code for AvgPool2D op (#1340) X-Git-Tag: nncc_backup~1942 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=399b0ca78c9d91efa17cd9299a081020b58af600;p=platform%2Fcore%2Fml%2Fnnfw.git [enco] Generate code for AvgPool2D op (#1340) This commit supports code generation on AvgPool2D op. Signed-off-by: Jonghyun Park --- 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"};