35{
38 std::map<std::string, tensor::Shape> &shape_ctx = context->shape_ctx();
39 std::map<std::string, coco::Bag *> &bag_ctx = context->bag_ctx();
40
41 assert(layer.bottom().size() == 1);
42 assert(layer.top().size() == 1);
43
44 assert(layer.has_pooling_param());
45 const auto ¶m = layer.pooling_param();
46
48 {
49 const auto ifm_name = layer.bottom(0);
50 const auto ifm_shape = shape_ctx.at(ifm_name);
52 }
53
54
55 const auto ifm_name = layer.bottom(0);
56 const auto ifm_shape = shape_ctx.at(ifm_name);
57 auto ifm_bag = bag_ctx.at(ifm_name);
58 auto ifm_obj = module->entity()->object()->create<coco::FeatureObject>();
59
60 ifm_obj->bag(ifm_bag);
62
63
64 const auto ofm_name = layer.top(0);
65 const auto ofm_shape = spec.ofm_shape();
66 auto ofm_bag = module->entity()->bag()->create(num_elements(ofm_shape));
67 auto ofm_obj = module->entity()->object()->create<coco::FeatureObject>();
68
69 ofm_obj->bag(ofm_bag);
71
73
74 std::map<PoolingMethod, PoolingOpBuilder> builders;
75
76
79
80 auto op = module->entity()->op()->create<coco::MaxPool2D>();
81
83
84 op->window()->height(spec.window_height());
85 op->window()->width(spec.window_width());
86
87 op->stride()->vertical(spec.vertical_stride());
88 op->stride()->horizontal(spec.horizontal_stride());
89
90 op->pad()->top(spec.vertical_pad());
91 op->pad()->bottom(spec.vertical_pad());
92 op->pad()->left(spec.horizontal_pad());
93 op->pad()->right(spec.horizontal_pad());
94
95 return op;
96 };
97
98
101
102 auto op = module->entity()->op()->create<coco::AvgPool2D>();
103
105
106
108
109 op->window()->height(spec.window_height());
110 op->window()->width(spec.window_width());
111
112 op->stride()->vertical(spec.vertical_stride());
113 op->stride()->horizontal(spec.horizontal_stride());
114
115 op->pad()->top(spec.vertical_pad());
116 op->pad()->bottom(spec.vertical_pad());
117 op->pad()->left(spec.horizontal_pad());
118 op->pad()->right(spec.horizontal_pad());
119
120 return op;
121 };
122
123
124 auto builder = builders.at(spec.method());
125 auto op = builder(module, spec);
126
127
129
130
131 blk->instr()->append(ins);
132
133
134 bag_ctx[ofm_name] = ofm_bag;
135 shape_ctx[ofm_name] = ofm_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.
const nncc::core::ADT::tensor::Shape & ifm_shape(void) const
A unit of (grouped) instructions.
static std::unique_ptr< BCHW > create(const nncc::core::ADT::feature::Shape &shape)
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.
virtual Op * arg(uint32_t n) const =0
Return N-th argument.