38std::string
tab(
int n) {
return std::string(n * 2,
' '); }
43 OpPrinter(std::ostream &os,
int indent) : _os(os), _indent(indent) {}
48 _os <<
tab(_indent) <<
"Load(" <<
dynamic_cast<const coco::Op *
>(op)
49 <<
", obj: " << op->
object() <<
")" << std::endl;
55 _os <<
tab(_indent) <<
"PadF" << std::endl;
64 _os <<
tab(_indent) <<
"Conv2D(" <<
dynamic_cast<const coco::Op *
>(op)
65 <<
", ker obj: " << op->
ker() <<
", padding [T/B/L/R=" << pad->
top() <<
"," << pad->
bottom()
66 <<
"," << pad->
left() <<
"," << pad->
right() <<
"]"
74 _os <<
tab(_indent) <<
"MaxPool2D" << std::endl;
80 _os <<
tab(_indent) <<
"AvgPool2D" << std::endl;
87 _os <<
tab(_indent) <<
"Add" << std::endl;
94 _os <<
tab(_indent) <<
"Mul" << std::endl;
100 _os <<
tab(_indent) <<
"ReLU" << std::endl;
106 _os <<
tab(_indent) <<
"ReLU6" << std::endl;
113 _os <<
tab(_indent) <<
"Sub" << std::endl;
120 _os <<
tab(_indent) <<
"ConcatF" << std::endl;
127 _os <<
tab(_indent) <<
"Div" << std::endl;
146 std::cout <<
tab(_indent) <<
"Eval (" <<
dynamic_cast<const coco::Instr *
>(ins) <<
")"
148 std::cout <<
tab(_indent + 1) <<
"out: " << ins->
out() << std::endl;
149 std::cout <<
tab(_indent + 1) <<
"<op>: " << std::endl;
159 std::cout <<
tab(_indent) <<
"Copy (" <<
dynamic_cast<const coco::Instr *
>(ins) <<
")"
161 std::cout <<
tab(_indent) <<
" from: " << ins->
from() << std::endl;
162 std::cout <<
tab(_indent) <<
" into: " << ins->
into() << std::endl;
167 std::cout <<
tab(_indent) <<
"Shuffle (" <<
dynamic_cast<const coco::Instr *
>(ins) <<
")"
169 std::cout <<
tab(_indent) <<
" from: " << ins->
from() << std::endl;
170 std::cout <<
tab(_indent) <<
" into: " << ins->
into() << std::endl;
185 std::cout <<
tab(indent) <<
"<Inst>:" << std::endl;
187 static InstrPrinter prn(indent + 1);
194 std::cout <<
tab(indent) <<
"<Block> (index: " << B->
index().
value() <<
")" << std::endl;
195 for (
auto I = B->
instr()->
head(); I !=
nullptr; I = I->next())
203 for (
auto B = L->
head(); B !=
nullptr; B = B->next())
209template <
typename SetT,
typename EntityF>
210void dump(std::string header, SetT set, EntityF print_addr_f)
212 std::cout << header <<
": [";
213 if (set->size() == 0)
218 for (
auto entity : *set)
222 print_addr_f(entity);
230 std::cout <<
tab(indent) <<
"<Bag>:" << std::endl;
232 for (
auto n = 0; n < l->size(); ++n)
236 std::cout <<
tab(indent + 1) << bag <<
", ";
239 auto print_dep_object = [](
coco::Dep *dep) { std::cout << dep->object(); };
240 dump(
"obj", bag->deps(), print_dep_object);
243 std::cout <<
"size: " << bag->size() <<
", ";
246 std::cout <<
"input, ";
248 std::cout <<
"output, ";
249 if ((!bag->isInput()) || (!bag->isOutput()))
250 std::cout <<
"const, ";
253 auto print_read_reader = [](
coco::Read *read) {
255 std::cout <<
"op: " << op;
257 std::cout <<
"instr: " << instr;
261 dump(
"reader", bag->reads(), print_read_reader);
267 std::cout <<
"op: " << op;
269 std::cout <<
"instr: " << instr;
273 dump(
"updater", bag->updates(), print_update_updater);
276 std::cout << std::endl;
282 auto shape = feature_ob->
shape();
283 std::cout <<
"kind: Feature, Shape [H/W/D=" << shape.
height() <<
"," << shape.width() <<
","
284 << shape.depth() <<
"]";
289 auto shape = kernel_ob->
shape();
290 std::cout <<
"kind: Kernel, Shape [N/H/W/D=" << shape.
count() <<
"," << shape.height() <<
","
291 << shape.width() <<
"," << shape.depth() <<
"]";
296 std::cout <<
tab(indent) <<
"<Object>:" << std::endl;
297 for (
auto n = 0; n < l->size(); ++n)
300 std::cout <<
tab(indent + 1) << obj <<
", bag: " << obj->bag() <<
", ";
302 using ObDumpers = std::function<void(
coco::Object * ob)>;
304 std::map<coco::Object::Kind, ObDumpers> ob_dumpers;
308 ob_dumpers[coco::Object::Kind::Unknown] = [](
coco::Object *ob) {
309 std::cout <<
"kind: Unknown";
312 ob_dumpers[obj->kind()](obj);
314 std::cout <<
", producer: ";
315 auto def = obj->def();
319 std::cout <<
"op: " << op;
321 std::cout <<
"instr: " << instr;
330 auto print_consumer = [](
coco::Use *use) {
332 std::cout <<
"op: " << op;
334 std::cout <<
"inst: " << instr;
338 dump(
"comsumer", obj->uses(), print_consumer);
339 std::cout << std::endl;
343template <
typename T>
void head(
int indent);
351 head<PtrItemT>(indent);
352 for (
int n = 0; n < list->
size(); n++)
354 const PtrItemT *item = list->
at(n);
357 std::cout <<
"bag " << item->bag() <<
", name=" << item->name();
359 std::cout << std::endl;
364 std::cout <<
"<Module>" << std::endl;
366 dump(module->block(), 1);
367 dump(module->input(), 1);
368 dump(module->output(), 1);
369 dump(module->entity()->bag(), 1);
370 dump(module->entity()->object(), 1);
A unit of (grouped) instructions.
const BlockIndex & index(void) const
uint32_t value(void) const
Concatenate two feature maps.
2D Convolution over 3D Feature Map with 4D kernel
KernelObject * ker(void) const
Op * arg(uint32_t n) const final
Return N-th argument.
Index-wise element transfer between two objects.
Object * from(void) const
Object * into(void) const
A Dep represents the edge between a Bag and its dependent Object.
Evaluate an Object from a given Op.
FeatureMap values (used in CNN)
const FeatureShape & shape(void) const
Base interface on explicit computation steps in coco IR.
T accept(IVisitor< T > *v) const
Convolution Kernel (in CNN) values.
const nncc::core::ADT::kernel::Shape & shape(void) const
Top-level element of coco IR which represents a neural network.
Element-wise multiplication.
Base interface on all typed NN values.
virtual KernelObject * asKernel(void)
virtual FeatureObject * asFeature(void)
uint32_t left(void) const
uint32_t right(void) const
uint32_t bottom(void) const
uint32_t size(void) const
Apply ReLU6 over elements.
Apply ReLU over elements.
A Read represents an edge between a Bag and its Reader.
Generic element transfer.
uint32_t vertical(void) const
uint32_t horizontal(void) const
Element-wise subtraction.
Op * arg(uint32_t n) const final
Return N-th argument.
A Update represents an edge between a Bag and its Updater.
uint32_t height(void) const
uint32_t count(void) const
void head< coco::Output >(int indent)
void dump(const coco::Op *op, int indent)
void head< coco::Input >(int indent)
void visit(const coco::Eval *ins) override
void visit(const coco::Copy *ins) override
void visit(const coco::Shuffle *ins) override
void visit(const coco::Add *op) override
void visit(const coco::AvgPool2D *op) override
void visit(const coco::Mul *op) override
void visit(const coco::PadF *op) override
void visit(const coco::Conv2D *op) override
void visit(const coco::MaxPool2D *op) override
void visit(const coco::ReLU6 *op) override
void visit(const coco::Sub *op) override
void visit(const coco::Load *op) override
OpPrinter(std::ostream &os, int indent)
void visit(const coco::ReLU *op) override
void visit(const coco::ConcatF *op) override
void visit(const coco::Div *op) override
Base interface on all supported NN operations.
T accept(IVisitor< T > *v) const