34{
37 std::map<std::string, tensor::Shape> &shape_ctx = context->shape_ctx();
38 std::map<std::string, coco::Bag *> &bag_ctx = context->bag_ctx();
39
41
42 assert(layer.bottom().size() > 1);
43 assert(layer.top().size() == 1);
44
45 assert(layer.has_eltwise_param());
46 const auto ¶m = layer.eltwise_param();
47
48 using ::caffe::EltwiseParameter_EltwiseOp;
49 using ::caffe::EltwiseParameter_EltwiseOp_SUM;
50 using ::caffe::EltwiseParameter_EltwiseOp_PROD;
51
53 using ReducerRegistry = std::map<EltwiseParameter_EltwiseOp, Reducer>;
54
55 ReducerRegistry registry;
56
57
59 if (lhs == nullptr)
60 {
61 assert(rhs != nullptr);
62 return rhs;
63 }
64
65 assert(lhs != nullptr && rhs != nullptr);
66 assert(lhs->module() == rhs->module());
67 assert(lhs->module() != nullptr);
68
69 auto m = lhs->module();
71 };
72
74 if (lhs == nullptr)
75 {
76 assert(rhs != nullptr);
77 return rhs;
78 }
79
80 assert(lhs != nullptr && rhs != nullptr);
81 assert(lhs->
module() == rhs->module());
82 assert(lhs->
module() !=
nullptr);
83
86 };
87
88
89 assert(!param.coeff().size());
90
91
92 auto reduce = registry.at(param.operation());
93
95
96 for (const auto &ifm_name : layer.bottom())
97 {
98 auto ifm_shape = shape_ctx.at(ifm_name);
99
100
101 auto ifm_bag = bag_ctx.at(ifm_name);
102 auto ifm_obj = module->entity()->object()->create<coco::FeatureObject>();
103
104 ifm_obj->bag(ifm_bag);
106
108
109 op = reduce(op, load);
110 }
111
112 assert(op != nullptr);
113
114 const auto ofm_name = layer.top(0);
115 const auto ofm_shape = shape_ctx.at(layer.bottom(0));
116
117 auto ofm_bag = module->entity()->bag()->create(num_elements(ofm_shape));
118 auto ofm_obj = module->entity()->object()->create<coco::FeatureObject>();
119
120 ofm_obj->bag(ofm_bag);
122
123
125
126
127 blk->instr()->append(eval);
128
129
130 bag_ctx[ofm_name] = ofm_bag;
131 shape_ctx[ofm_name] = ofm_shape;
132}
OpBuilder op_builder(coco::Module *m)
InstrBuilder instr_builder(coco::Module *m)
coco::Eval * eval(coco::Object *out, coco::Op *op) const
Create "Eval" instruction with a given "Object" and "Op".
OpBuilder & load(coco::Object *obj)
Create "Load" op and push it onto the internal stack.
OpBuilder & mul(void)
Create "Mul" op and push it onto the internal stack.
OpBuilder & push(coco::Op *op)
Push op onto the internal stack.
coco::Op * pop(void)
Pop op from the internal stack.
OpBuilder & add(void)
Create "Add" op and push it onto the internal stack.
A unit of (grouped) instructions.
Module * module(void) const
Top-level element of coco IR which represents a neural network.
nncc::core::ADT::feature::Shape as_feature_shape(const nncc::core::ADT::tensor::Shape &)
TensorSignatures load(const char *info_path)
Function to create TensorSignatures defined in info file.
Base interface on all supported NN operations.