OpBuilder op_builder(coco::Module *m) { return OpBuilder{m}; }
OpBuilder op_builder(const std::unique_ptr<coco::Module> &m) { return op_builder(m.get()); }
+class InstrBuilder
+{
+public:
+ InstrBuilder(coco::Module *module) : _module{module}
+ {
+ // NOTE _module SHOULD be valid
+ assert(_module != nullptr);
+ }
+
+public:
+ /**
+ * @brief Create "Eval" instruction with a given "Object" and "Op"
+ *
+ * @note "eval(out, op)" will create "%out <- Eval(op)" instruction
+ */
+ coco::Eval *eval(coco::Object *out, coco::Op *op) const
+ {
+ auto ins = _module->entity()->instr()->create<coco::Eval>();
+ ins->op(op);
+ ins->out(out);
+ return ins;
+ }
+
+private:
+ coco::Module *_module;
+};
+
+using ModuleHandle = std::unique_ptr<coco::Module>;
+
+InstrBuilder instr_builder(coco::Module *m) { return InstrBuilder{m}; }
+InstrBuilder instr_builder(const ModuleHandle &m) { return instr_builder(m.get()); }
+
} // namespace
Frontend::Frontend() : _prototxt{new ::caffe::NetParameter}, _caffemodel{new ::caffe::NetParameter}
op->arg(load);
// Create an Eval instruction
- auto ins = m->entity()->instr()->create<coco::Eval>();
-
- ins->out(ofm_obj);
- ins->op(op);
+ auto ins = instr_builder(m).eval(ofm_obj, op);
// Append the instruction to the block
blk->instr()->append(ins);
auto bias_add = op_builder(m).load(bias_obj).load(ofm_obj).add().pop();
// Create Instr
- auto bias_add_ins = m->entity()->instr()->create<coco::Eval>();
-
- bias_add_ins->out(added_obj);
- bias_add_ins->op(bias_add);
+ auto bias_add_ins = instr_builder(m).eval(added_obj, bias_add);
// Append the instruction
blk->instr()->append(bias_add_ins);
auto op = builder(m.get(), spec);
// Create a UnitF instruction
- auto ins = m->entity()->instr()->create<coco::Eval>();
-
- ins->out(ofm_obj);
- ins->op(op);
+ auto ins = instr_builder(m).eval(ofm_obj, op);
// Append the instruction to the block
blk->instr()->append(ins);
op->arg(load);
// Create a Eval instruction
- auto ins = m->entity()->instr()->create<coco::Eval>();
-
- ins->out(ofm_obj);
- ins->op(op);
+ auto ins = instr_builder(m).eval(ofm_obj, op);
// Append the instruction to the block
blk->instr()->append(ins);
ofm_obj->layout(BCHW::create(morph::caffe::as_feature_shape(ofm_shape)));
// Create "Eval" instruction
- auto eval = m->entity()->instr()->create<coco::Eval>();
-
- eval->op(op);
- eval->out(ofm_obj);
+ auto eval = instr_builder(m).eval(ofm_obj, op);
// Append the instruction to the block
blk->instr()->append(eval);