ONE - On-device Neural Engine
Loading...
Searching...
No Matches
Dump.cpp File Reference

Print coco IR produced from enco frontend. More...

#include "Dump.h"
#include <functional>
#include <iostream>

Go to the source code of this file.

Data Structures

struct  OpPrinter
 
struct  InstrPrinter
 

Functions

std::string tab (int n)
 
void dump (const coco::Op *op, int indent)
 
void dump (const coco::Instr *ins, int indent)
 
void dump (const coco::Block *B, int indent)
 
void dump (const coco::BlockList *L, int indent)
 
template<typename SetT , typename EntityF >
void dump (std::string header, SetT set, EntityF print_addr_f)
 
void dump (const coco::BagManager *l, int indent)
 
void dump (coco::FeatureObject *feature_ob)
 
void dump (coco::KernelObject *kernel_ob)
 
void dump (const coco::ObjectManager *l, int indent)
 
template<typename T >
void head (int indent)
 
template<>
void head< coco::Input > (int indent)
 
template<>
void head< coco::Output > (int indent)
 
template<typename PtrItemT >
void dump (const coco::PtrList< PtrItemT > *list, int indent)
 
void dump (const coco::Module *module)
 

Detailed Description

Print coco IR produced from enco frontend.

Note
Some object inherits multiple parents. For example, coco:Conv2D inherits coco::Consumer and more. Assume that op is an instance of coco::Conv2D. In this case, the printing results of the following may be different: 1) cout << op; // printing address of type coco::Conv2D 2) cout << reinterpret_cast<const coco::Object::Consumer *>(op); 3) cout << object->consumer(); // assume that this object->consumer() returns op 4) cout << dynamic_cast<const coco::Object::Consumer *>(op); 1) and 2) prints same address. 3) and 4) prints same address but different from 1) and 2). For details, refer to https://stackoverflow.com/questions/22256620/why-pointers-to-the-same-object-have-different-values For dumping, we will use 3), 4)

Definition in file Dump.cpp.

Function Documentation

◆ dump() [1/11]

void dump ( coco::FeatureObject feature_ob)

Definition at line 280 of file Dump.cpp.

281{
282 auto shape = feature_ob->shape();
283 std::cout << "kind: Feature, Shape [H/W/D=" << shape.height() << "," << shape.width() << ","
284 << shape.depth() << "]";
285}
const FeatureShape & shape(void) const
uint32_t height(void) const
Definition Shape.h:45

References nncc::core::ADT::feature::Shape::height(), and coco::FeatureObject::shape().

◆ dump() [2/11]

void dump ( coco::KernelObject kernel_ob)

Definition at line 287 of file Dump.cpp.

288{
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() << "]";
292}
const nncc::core::ADT::kernel::Shape & shape(void) const
uint32_t count(void) const
Definition Shape.h:44

References nncc::core::ADT::kernel::Shape::count(), and coco::KernelObject::shape().

◆ dump() [3/11]

void dump ( const coco::BagManager l,
int  indent 
)

Definition at line 228 of file Dump.cpp.

229{
230 std::cout << tab(indent) << "<Bag>:" << std::endl;
231
232 for (auto n = 0; n < l->size(); ++n)
233 {
234 auto bag = l->at(n);
235
236 std::cout << tab(indent + 1) << bag << ", ";
237
238 // print objects in bag->deps()
239 auto print_dep_object = [](coco::Dep *dep) { std::cout << dep->object(); };
240 dump("obj", bag->deps(), print_dep_object);
241 std::cout << ", ";
242
243 std::cout << "size: " << bag->size() << ", ";
244
245 if (bag->isInput())
246 std::cout << "input, ";
247 if (bag->isOutput())
248 std::cout << "output, ";
249 if ((!bag->isInput()) || (!bag->isOutput()))
250 std::cout << "const, ";
251
252 // print readers in bag->reads()
253 auto print_read_reader = [](coco::Read *read) {
254 if (coco::Op *op = dynamic_cast<coco::Op *>(read->reader()))
255 std::cout << "op: " << op;
256 else if (coco::Instr *instr = dynamic_cast<coco::Instr *>(read->reader()))
257 std::cout << "instr: " << instr;
258 else
259 std::cout << "x";
260 };
261 dump("reader", bag->reads(), print_read_reader);
262 std::cout << ", ";
263
264 // print updaters in bag->updates()
265 auto print_update_updater = [](coco::Update *update) {
266 if (coco::Op *op = dynamic_cast<coco::Op *>(update->updater()))
267 std::cout << "op: " << op;
268 else if (coco::Instr *instr = dynamic_cast<coco::Instr *>(update->updater()))
269 std::cout << "instr: " << instr;
270 else
271 std::cout << "x";
272 };
273 dump("updater", bag->updates(), print_update_updater);
274 std::cout << ", ";
275
276 std::cout << std::endl;
277 }
278}
A Dep represents the edge between a Bag and its dependent Object.
Definition Dep.h:33
Base interface on explicit computation steps in coco IR.
Definition Instr.h:57
A Read represents an edge between a Bag and its Reader.
Definition Read.h:29
A Update represents an edge between a Bag and its Updater.
Definition Update.h:29
std::string tab(int n)
Definition Dump.cpp:38
void dump(const coco::Op *op, int indent)
Definition Dump.cpp:177
FeatureShapeUpdater update(loco::FeatureShape &feature_shape)
luci::PartitionTable read(const std::string &path)
Reads and parse file and return PartitionTable.
Base interface on all supported NN operations.
Definition Op.h:45

References dump(), and tab().

◆ dump() [4/11]

void dump ( const coco::Block B,
int  indent 
)

Definition at line 192 of file Dump.cpp.

193{
194 std::cout << tab(indent) << "<Block> (index: " << B->index().value() << ")" << std::endl;
195 for (auto I = B->instr()->head(); I != nullptr; I = I->next())
196 {
197 dump(I, indent + 1);
198 }
199}
InstrList * instr(void)
Definition Block.h:65
const BlockIndex & index(void) const
Definition Block.h:69
uint32_t value(void) const
Definition BlockIndex.h:46
Child * head(void) const
Definition DLinkedList.h:48

References dump(), coco::DLinkedList< Child, Parent >::Head::head(), coco::Block::index(), coco::Block::instr(), tab(), and coco::BlockIndex::value().

◆ dump() [5/11]

void dump ( const coco::BlockList L,
int  indent 
)

Definition at line 201 of file Dump.cpp.

202{
203 for (auto B = L->head(); B != nullptr; B = B->next())
204 {
205 dump(B, indent);
206 }
207}

References dump(), and coco::DLinkedList< Child, Parent >::Head::head().

◆ dump() [6/11]

void dump ( const coco::Instr ins,
int  indent 
)

Definition at line 183 of file Dump.cpp.

184{
185 std::cout << tab(indent) << "<Inst>:" << std::endl;
186
187 static InstrPrinter prn(indent + 1);
188
189 ins->accept(prn);
190}
T accept(IVisitor< T > *v) const
Definition Instr.h:114

References coco::Instr::accept(), and tab().

◆ dump() [7/11]

void dump ( const coco::Module module)

Definition at line 362 of file Dump.cpp.

363{
364 std::cout << "<Module>" << std::endl;
365
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);
371}

References dump().

◆ dump() [8/11]

void dump ( const coco::ObjectManager l,
int  indent 
)

Definition at line 294 of file Dump.cpp.

295{
296 std::cout << tab(indent) << "<Object>:" << std::endl;
297 for (auto n = 0; n < l->size(); ++n)
298 {
299 auto obj = l->at(n);
300 std::cout << tab(indent + 1) << obj << ", bag: " << obj->bag() << ", ";
301
302 using ObDumpers = std::function<void(coco::Object * ob)>;
303
304 std::map<coco::Object::Kind, ObDumpers> ob_dumpers;
305
306 ob_dumpers[coco::Object::Kind::Feature] = [](coco::Object *ob) { dump(ob->asFeature()); };
307 ob_dumpers[coco::Object::Kind::Kernel] = [](coco::Object *ob) { dump(ob->asKernel()); };
308 ob_dumpers[coco::Object::Kind::Unknown] = [](coco::Object *ob) {
309 std::cout << "kind: Unknown";
310 };
311
312 ob_dumpers[obj->kind()](obj);
313
314 std::cout << ", producer: ";
315 auto def = obj->def();
316 if (def)
317 {
318 if (coco::Op *op = dynamic_cast<coco::Op *>(def->producer()))
319 std::cout << "op: " << op;
320 else if (coco::Instr *instr = dynamic_cast<coco::Instr *>(def->producer()))
321 std::cout << "instr: " << instr;
322 else
323 std::cout << "x";
324 }
325 else
326 std::cout << "x";
327 std::cout << ", ";
328
329 // print consumers in obj->uses()
330 auto print_consumer = [](coco::Use *use) {
331 if (coco::Op *op = dynamic_cast<coco::Op *>(use->consumer()))
332 std::cout << "op: " << op;
333 else if (coco::Instr *instr = dynamic_cast<coco::Instr *>(use->consumer()))
334 std::cout << "inst: " << instr;
335 else
336 std::cout << "x";
337 };
338 dump("comsumer", obj->uses(), print_consumer);
339 std::cout << std::endl;
340 }
341}
Base interface on all typed NN values.
Definition Object.h:38

References coco::Object::asFeature(), coco::Object::asKernel(), dump(), and tab().

◆ dump() [9/11]

void dump ( const coco::Op op,
int  indent 
)

Definition at line 177 of file Dump.cpp.

178{
179 OpPrinter prn(std::cout, indent);
180 op->accept(prn);
181}
T accept(IVisitor< T > *v) const
Definition Op.h:101

References coco::Op::accept().

Referenced by dump(), dump(), dump(), dump(), dump(), onert::dumper::dot::DotDumper::dump(), entry(), and operator<<().

◆ dump() [10/11]

template<typename PtrItemT >
void dump ( const coco::PtrList< PtrItemT > *  list,
int  indent 
)

Definition at line 349 of file Dump.cpp.

350{
351 head<PtrItemT>(indent);
352 for (int n = 0; n < list->size(); n++)
353 {
354 const PtrItemT *item = list->at(n);
355 if (n != 0)
356 std::cout << ", ";
357 std::cout << "bag " << item->bag() << ", name=" << item->name();
358 }
359 std::cout << std::endl;
360}
T * at(uint32_t n) const
Definition PtrList.h:43
uint32_t size(void) const
Definition PtrList.h:40

References coco::PtrList< T >::at(), and coco::PtrList< T >::size().

◆ dump() [11/11]

template<typename SetT , typename EntityF >
void dump ( std::string  header,
SetT  set,
EntityF  print_addr_f 
)

Definition at line 210 of file Dump.cpp.

211{
212 std::cout << header << ": [";
213 if (set->size() == 0)
214 std::cout << "x";
215 else
216 {
217 int idx = 0;
218 for (auto entity : *set)
219 {
220 if (idx++ != 0)
221 std::cout << ", ";
222 print_addr_f(entity);
223 }
224 }
225 std::cout << "]";
226}
void set(Dialect d)
Definition Knob.cpp:100

◆ head()

template<typename T >
void head ( int  indent)

◆ head< coco::Input >()

template<>
void head< coco::Input > ( int  indent)

Definition at line 345 of file Dump.cpp.

345{ std::cout << tab(indent) << "<Input>: "; }

References tab().

◆ head< coco::Output >()

template<>
void head< coco::Output > ( int  indent)

Definition at line 347 of file Dump.cpp.

347{ std::cout << tab(indent) << "<Output>: "; }

References tab().

◆ tab()