33{
36 std::map<std::string, tensor::Shape> &shape_ctx = context->shape_ctx();
37 std::map<std::string, coco::Bag *> &bag_ctx = context->bag_ctx();
38
39 assert(layer.bottom().size() > 0);
40 assert(layer.top().size() == 1);
41
42
43
44
45 assert(!layer.has_concat_param());
46 const uint32_t concat_axis = 1;
47
48
49 std::vector<coco::FeatureObject *> input_objects;
50
51 for (const auto &input_name : layer.bottom())
52 {
54
55 auto input_bag = bag_ctx.at(input_name);
56 auto input_feature = module->entity()->object()->create<coco::FeatureObject>();
57
58 input_feature->bag(input_bag);
60
61 input_objects.emplace_back(input_feature);
62 }
63
65
66 assert(last_feature != nullptr);
67 assert(last_feature->
bag() !=
nullptr);
68
69
70
71
72
73
74
75
76
77
78
79
80 for (uint32_t n = 1; n < input_objects.size(); ++n)
81 {
82 auto const left_feature = last_feature;
83 auto const left_shape = left_feature->
layout()->
shape();
84
85 auto right_feature = input_objects.at(n);
86 auto right_shape = right_feature->layout()->shape();
87
88
89 assert(left_feature->layout()->batch() == 1);
90 assert(right_feature->layout()->batch() == 1);
91
92
93 assert(left_shape.height() == right_shape.height());
94 assert(left_shape.width() == right_shape.width());
95
96 const uint32_t
C = left_shape.depth() + right_shape.depth();
97 const uint32_t H = left_shape.height();
98 const uint32_t W = left_shape.width();
99
101
102 auto out_bag = module->entity()->bag()->create(num_elements(out_shape));
103 auto out_feature = module->entity()->object()->create<coco::FeatureObject>();
104
105 out_feature->bag(out_bag);
107
110
111 auto concat_f = module->entity()->op()->create<coco::ConcatF>();
112
114 concat_f->left(left_load);
115 concat_f->right(right_load);
116
118
119
120 blk->instr()->append(eval);
121
122
123 last_feature = out_feature;
124 }
125
126 assert(last_feature != nullptr);
127 assert(last_feature->
bag() !=
nullptr);
128
129
130 auto const out_name = layer.top(0);
132 auto const out_bag = last_feature->
bag();
133
134 bag_ctx[out_name] = out_bag;
135 shape_ctx[out_name] = out_shape;
136}
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.
coco::Op * pop(void)
Pop op from the internal stack.
A unit of (grouped) instructions.
static std::unique_ptr< BCHW > create(const nncc::core::ADT::feature::Shape &shape)
FeatureMap values (used in CNN)
const FeatureLayout * layout(void) const
Top-level element of coco IR which represents a neural network.
coco::Bag * bag(void) const
tensor::Shape as_tensor_shape(const ::caffe::BlobShape &blob_shape)
nncc::core::ADT::feature::Shape as_feature_shape(const nncc::core::ADT::tensor::Shape &)
virtual const FeatureShape & shape(void) const =0