From 497a157ab7d373ef1d09dee2d2e12bdb11f1eaf0 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: Mon, 3 Sep 2018 14:47:02 +0900 Subject: [PATCH] [enco.caffe] Build IR from ReLU layer (#1292) This commit implements the initial implementation of IR builder for ReLU layer. Signed-off-by: Jonghyun Park --- contrib/enco/frontend/caffe/src/Frontend.cpp | 45 ++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/contrib/enco/frontend/caffe/src/Frontend.cpp b/contrib/enco/frontend/caffe/src/Frontend.cpp index 886b995..6d10069 100644 --- a/contrib/enco/frontend/caffe/src/Frontend.cpp +++ b/contrib/enco/frontend/caffe/src/Frontend.cpp @@ -225,6 +225,51 @@ enco::Bundle Frontend::load(void) const bag_ctx[ofm_name] = ofm_bag; shape_ctx[ofm_name] = ofm_shape; } + else if (layer.type() == "ReLU") + { + assert(layer.bottom().size() == 1); + assert(layer.top().size() == 1); + + // PReLU is not supported, yet + // TODO Support PReLU + assert(!layer.has_relu_param()); + + // NOTE The current implementation treats ReLU as Feature op + // TODO Support ReLU over general tensor + const auto ifm_name = layer.bottom(0); + const auto ifm_shape = shape_ctx.at(ifm_name); + auto ifm_bag = bag_ctx.at(ifm_name); + auto ifm_obj = m->entity()->object()->create(morph::caffe::as_feature_shape(ifm_shape)); + + ifm_obj->bag(ifm_bag); + ifm_obj->reorder(); + + const auto ofm_name = layer.top(0); + const auto ofm_shape = ifm_shape; + auto ofm_bag = m->entity()->bag()->create(num_elements(ofm_shape)); + auto ofm_obj = m->entity()->object()->create(morph::caffe::as_feature_shape(ofm_shape)); + + ofm_obj->bag(ofm_bag); + ofm_obj->reorder(); + + // Create a ReLU op + auto op = m->entity()->op()->create(); + + // Create a UnitF instruction + // TODO Use UnitT later + auto ins = m->entity()->instr()->create(); + + ins->ifm(ifm_obj); + ins->ofm(ofm_obj); + ins->op(op); + + // Append the instruction to the block + blk->instr()->append(ins); + + // Update bag and shape context + bag_ctx[ofm_name] = ofm_bag; + shape_ctx[ofm_name] = ofm_shape; + } else { throw std::runtime_error{"Not supported: " + layer.type()}; -- 2.7.4