ONE - On-device Neural Engine
Loading...
Searching...
No Matches
coco::Op Struct Referenceabstract

Base interface on all supported NN operations. More...

#include <Op.h>

Collaboration diagram for coco::Op:

Data Structures

struct  IMutator
 Op mutator interface. More...
 
struct  IVisitor
 Op visitor interface. More...
 
struct  Mutator
 
struct  Visitor
 

Public Member Functions

virtual ~Op ()
 
virtual uint32_t arity (void) const =0
 Return the number of arguments (# of child Ops)
 
virtual Oparg (uint32_t n) const =0
 Return N-th argument.
 
virtual std::set< Object * > uses (void) const =0
 Return a set of object(s) used during execution.
 
template<typename T >
accept (IVisitor< T > *v) const
 
template<typename T >
accept (IVisitor< T > &v) const
 
template<typename T >
accept (IVisitor< T > &&v) const
 
void accept (IMutator *m)
 
void accept (IMutator &m)
 
void accept (IMutator &&m)
 
Instrparent (void) const
 
Opup (void) const
 Return a pointer to the parent Op.
 
- Public Member Functions inherited from coco::Entity
virtual ~Entity ()=default
 
Modulemodule (void) const
 

Friends

class Step
 
class Part
 

Detailed Description

Base interface on all supported NN operations.

Definition at line 44 of file Op.h.

Constructor & Destructor Documentation

◆ ~Op()

coco::Op::~Op ( )
virtual

Definition at line 25 of file Op.cpp.

26{
27 // NOTE Op SHOULD NOT be referred by an instruction to be destructed
28 assert(_step == nullptr);
29}

Member Function Documentation

◆ accept() [1/6]

void coco::Op::accept ( IMutator &&  m)
inline

Definition at line 155 of file Op.h.

155{ return accept(&m); }
T accept(IVisitor< T > *v) const
Definition Op.h:101

References accept(), and m.

Referenced by accept().

◆ accept() [2/6]

void coco::Op::accept ( IMutator m)
inline

Definition at line 154 of file Op.h.

154{ return accept(&m); }

References accept(), and m.

Referenced by accept().

◆ accept() [3/6]

void coco::Op::accept ( IMutator m)
inline

Definition at line 142 of file Op.h.

143 {
144#define OP(Name) \
145 if (auto op = as##Name()) \
146 { \
147 return m->mutate(op); \
148 }
149#include "coco/IR/Op.lst"
150#undef OP
151 throw std::runtime_error{"unreachable"};
152 }

◆ accept() [4/6]

template<typename T >
T coco::Op::accept ( IVisitor< T > &&  v) const
inline

Definition at line 114 of file Op.h.

114{ return accept(&v); }

References accept().

Referenced by accept().

◆ accept() [5/6]

template<typename T >
T coco::Op::accept ( IVisitor< T > &  v) const
inline

Definition at line 113 of file Op.h.

113{ return accept(&v); }

References accept().

Referenced by accept().

◆ accept() [6/6]

template<typename T >
T coco::Op::accept ( IVisitor< T > *  v) const
inline

Definition at line 101 of file Op.h.

102 {
103#define OP(Name) \
104 if (auto op = as##Name()) \
105 { \
106 return v->visit(op); \
107 }
108#include "coco/IR/Op.lst"
109#undef OP
110 throw std::runtime_error{"unreachable"};
111 }

Referenced by dump(), OpPrinter::visit(), OpPrinter::visit(), OpPrinter::visit(), OpPrinter::visit(), OpPrinter::visit(), InstrPrinter::visit(), OpPrinter::visit(), OpPrinter::visit(), OpPrinter::visit(), OpPrinter::visit(), OpPrinter::visit(), and OpPrinter::visit().

◆ arg()

virtual Op * coco::Op::arg ( uint32_t  n) const
pure virtual

Return N-th argument.

Note
The behavior of arg(n) is defined only when n < artiy()

Implemented in coco::UnaryOp, coco::BinaryOp, coco::Load, and coco::Conv2D.

Referenced by caffeimport::BatchNormBuilder::build(), caffeimport::ConvolutionBuilder::build(), caffeimport::PoolingBuilder::build(), and caffeimport::ReLUBuilder::build().

◆ arity()

virtual uint32_t coco::Op::arity ( void  ) const
pure virtual

Return the number of arguments (# of child Ops)

Implemented in coco::UnaryOp, coco::BinaryOp, coco::Load, and coco::Conv2D.

◆ parent()

Instr * coco::Op::parent ( void  ) const

Definition at line 31 of file Op.cpp.

32{
33 // Get the parent instruction specified by _step for root nodes
34 if (_step)
35 {
36 // Op SHOULD BE a root node
37 assert(_part == nullptr);
38 assert(_step->instr() != nullptr);
39 return _step->instr();
40 }
41
42 // Get the parent instruction of its parent Op for non-root nodes
43 if (_part)
44 {
45 assert(_part->parent() != nullptr);
46 return _part->parent()->parent();
47 }
48
49 return nullptr;
50}
Op * parent(void) const
Definition Part.h:44
Instr * instr(void) const
Definition Step.h:45
Instr * parent(void) const
Definition Op.cpp:31

References coco::Step::instr(), parent(), and coco::Part::parent().

Referenced by coco::OpManager::destroy(), coco::OpManager::destroy_all(), coco::Load::loc(), coco::Conv2D::loc(), and parent().

◆ up()

Op * coco::Op::up ( void  ) const

Return a pointer to the parent Op.

Definition at line 52 of file Op.cpp.

53{
54 if (_part)
55 {
56 assert(_part->parent() != nullptr);
57 return _part->parent();
58 }
59 return nullptr;
60}

References coco::Part::parent().

Referenced by coco::OpManager::destroy_all(), and coco::root().

◆ uses()

virtual std::set< Object * > coco::Op::uses ( void  ) const
pure virtual

Return a set of object(s) used during execution.

NOTE There is no 'def' method as Op is not allowed to define a new object

Implemented in coco::UnaryOp, coco::BinaryOp, coco::Load, and coco::Conv2D.

Friends And Related Symbol Documentation

◆ Part

friend class Part
friend

Definition at line 47 of file Op.h.

◆ Step

friend class Step
friend

Definition at line 46 of file Op.h.


The documentation for this struct was generated from the following files: