} // namespace
+namespace
+{
+
+class PadInstrBuilder final
+{
+public:
+ PadInstrBuilder(const coco::Padding2D *pad) : _pad{pad}
+ {
+ // DO NOTHING
+ }
+
+public:
+ coco::Instr *build(coco::FeatureObject *ifm_obj, coco::FeatureObject *ofm_obj) const
+ {
+ assert(ifm_obj->module() == ofm_obj->module());
+ auto m = ifm_obj->module();
+ assert(m != nullptr);
+
+ auto pad_op = m->entity()->op()->create<coco::PadF>();
+
+ pad_op->pad()->top(_pad->top());
+ pad_op->pad()->bottom(_pad->bottom());
+ pad_op->pad()->left(_pad->left());
+ pad_op->pad()->right(_pad->right());
+
+ auto pad_instr = m->entity()->instr()->create<coco::UnitF>();
+
+ pad_instr->ifm(ifm_obj);
+ pad_instr->ofm(ofm_obj);
+ pad_instr->op(pad_op);
+
+ return pad_instr;
+ }
+
+private:
+ const coco::Padding2D *_pad;
+};
+
+PadInstrBuilder pad_instr_builder(const coco::Padding2D *pad) { return PadInstrBuilder{pad}; }
+
+} // namespace
+
namespace enco
{
pad_obj->bag(pad_bag);
pad_obj->layout(coco::FeatureLayouts::BHWC::create(pad_shape));
- auto pad_op = m->entity()->op()->create<coco::PadF>();
-
- pad_op->pad()->top(avgpool->pad()->top());
- pad_op->pad()->bottom(avgpool->pad()->bottom());
- pad_op->pad()->left(avgpool->pad()->left());
- pad_op->pad()->right(avgpool->pad()->right());
-
- auto pad_instr = m->entity()->instr()->create<coco::UnitF>();
-
- pad_instr->ifm(ifm_obj);
- pad_instr->ofm(pad_obj);
- pad_instr->op(pad_op);
+ auto pad_instr = pad_instr_builder(avgpool->pad()).build(ifm_obj, pad_obj);
// Insert PadF before AvgPool2D
pad_instr->insertBefore(unit);