ONE - On-device Neural Engine
Loading...
Searching...
No Matches
coco Namespace Reference

Namespaces

namespace  FeatureLayouts
 
namespace  KernelLayouts
 

Data Structures

class  Add
 Element-wise addition. More...
 
class  Arg
 Base class for NN model arguments (Input/Output) More...
 
class  AvgPool2D
 2D Average Pooling More...
 
class  Bag
 A collection of (abstracted) elements of the same type. More...
 
class  BagManager
 
class  BinaryOp
 Op with two arguments. More...
 
class  Block
 A unit of (grouped) instructions. More...
 
class  BlockIndex
 A BlockIndex denotes the index of a block in a block list. More...
 
class  BlockManager
 
class  ConcatF
 Concatenate two feature maps. More...
 
class  Conv2D
 2D Convolution over 3D Feature Map with 4D kernel More...
 
class  Copy
 Index-wise element transfer between two objects. More...
 
struct  Data
 Core coco entity for constant weights. More...
 
class  Def
 
class  Dep
 A Dep represents the edge between a Bag and its dependent Object. More...
 
class  Div
 Element-wise division. More...
 
struct  DLinkedList
 
class  ElemID
 
class  Entity
 A base class for IR entities. More...
 
class  EntityBuilder
 A base class for IR entity builders. More...
 
struct  EntityManager
 Meta (lifetime) manager interface. More...
 
class  Eval
 Evaluate an Object from a given Op. More...
 
struct  FeatureLayout
 A FeatureLayout connects each feature index to a Bag element. More...
 
class  FeatureObject
 FeatureMap values (used in CNN) More...
 
class  FeatureShape
 The shape of a feature map. More...
 
class  Input
 
class  InputManager
 
class  Instr
 Base interface on explicit computation steps in coco IR. More...
 
class  InstrIndex
 A InstrIndex denotes the index of an instruction in an instruction list. More...
 
class  InstrManager
 
struct  KernelLayout
 A KernelLayout connectes each kernel index to an element (in a bag) More...
 
class  KernelObject
 Convolution Kernel (in CNN) values. More...
 
class  Load
 Load an Object. More...
 
struct  Locatable
 Return the associated instruction if exists. More...
 
class  MaxPool2D
 2D Max Pooling More...
 
class  Module
 Top-level element of coco IR which represents a neural network. More...
 
class  Mul
 Element-wise multiplication. More...
 
class  Object
 Base interface on all typed NN values. More...
 
class  ObjectManager
 
struct  Op
 Base interface on all supported NN operations. More...
 
class  OpManager
 
class  Output
 
class  OutputManager
 
class  Padding2D
 
class  PadF
 Introduce padding area. More...
 
class  Part
 A Part represents the edge between a child Op and its parent Op. More...
 
struct  PlainWeightContext
 Non-quantized (plain) Weight Data Accessor. More...
 
class  PtrList
 
class  PtrManager
 
class  Read
 A Read represents an edge between a Bag and its Reader. More...
 
class  ReLU
 Apply ReLU over elements. More...
 
class  ReLU6
 Apply ReLU6 over elements. More...
 
class  Shuffle
 Generic element transfer. More...
 
class  Span
 A Span is a non-owing reference to a memory chunk. More...
 
class  Sqrt
 Apply Sqrt over elements. More...
 
class  Step
 A Step denotes the edge between Op and Instr. More...
 
class  Stride2D
 
class  Sub
 Element-wise subtraction. More...
 
class  UnaryOp
 Op with a single argument. More...
 
class  Update
 A Update represents an edge between a Bag and its Updater. More...
 
class  Use
 
class  Window2D
 

Typedefs

using BlockList = DLinkedList< Block, Module >::Head
 
using DepSet = std::set< Dep * >
 
using InputList = PtrList< Input >
 
using InstrList = coco::DLinkedList< Instr, Block >::Head
 
using ObjectSet = std::set< Object * >
 
using OutputList = PtrList< Output >
 
using ReadSet = std::set< Read * >
 
using UpdateSet = std::set< Update * >
 
using UseSet = std::set< Use * >
 

Functions

ObjectSet dependent_objects (const Bag *)
 Return a set of objects that depends on a given bag.
 
Bag::ReaderSet readers (const Bag *)
 Return a set of readers that reads a given bag.
 
Bag::UpdaterSet updaters (const Bag *)
 Return a set of updaters that updates a given bag.
 
bool operator== (const ElemID &lhs, const ElemID &rhs)
 
bool operator< (const ElemID &lhs, const ElemID &rhs)
 
template<typename T >
bool isa (const Instr *ins)
 Return true if a given instruction is of T type.
 
template<typename T >
T * safe_cast (Instr *ins)
 Cast as a derived instruction.
 
template<typename T >
bool isa (const Object *)
 Check whether a given object is of type T.
 
template<typename T >
T * cast (Object *)
 Cast a generic object as a specific one.
 
template<typename T >
T * safe_cast (Object *)
 Cast a generic object as a specific one.
 
Object::Producer * producer (const Object *)
 Return the producer of a given object if it exists.
 
Object::ConsumerSet consumers (const Object *)
 Return a set of consumers of a given object.
 
Oproot (Op *)
 Return the root Op from a given Op node.
 
template<>
bool isa< FeatureObject > (const Object *o)
 
template<>
bool isa< KernelObject > (const Object *o)
 
template<>
FeatureObjectcast (Object *o)
 
template<>
KernelObjectcast (Object *o)
 
template<>
FeatureObjectsafe_cast (Object *o)
 
template<>
KernelObjectsafe_cast (Object *o)
 

Typedef Documentation

◆ BlockList

using coco::BlockList = typedef DLinkedList<Block, Module>::Head

Definition at line 31 of file Block.h.

◆ DepSet

using coco::DepSet = typedef std::set<Dep *>

Definition at line 27 of file DepSet.h.

◆ InputList

using coco::InputList = typedef PtrList<Input>

Definition at line 27 of file InputList.h.

◆ InstrList

using coco::InstrList = typedef coco::DLinkedList<Instr, Block>::Head

Definition at line 38 of file Instr.h.

◆ ObjectSet

using coco::ObjectSet = typedef std::set<Object *>

Definition at line 27 of file ObjectSet.h.

◆ OutputList

using coco::OutputList = typedef PtrList<Output>

Definition at line 27 of file OutputList.h.

◆ ReadSet

using coco::ReadSet = typedef std::set<Read *>

Definition at line 27 of file ReadSet.h.

◆ UpdateSet

using coco::UpdateSet = typedef std::set<Update *>

Definition at line 27 of file UpdateSet.h.

◆ UseSet

using coco::UseSet = typedef std::set<Use *>

Definition at line 27 of file UseSet.h.

Function Documentation

◆ cast() [1/3]

template<typename T >
T * coco::cast ( Object )

Cast a generic object as a specific one.

"cast<T>(o)" accepts only a valid object pointer "o" that "isa<T>(o)" holds

  • Then, "cast<T>(o)" always returns a valid object pointer.

References cast().

Referenced by cast(), and cast().

◆ cast() [2/3]

template<>
FeatureObject * coco::cast ( Object o)

Definition at line 88 of file Object.cpp.

89{
90 assert(o != nullptr);
91 auto res = o->asFeature();
92 assert(res != nullptr);
93 return res;
94}
virtual FeatureObject * asFeature(void)
Definition Object.h:78

References coco::Object::asFeature(), and cast().

◆ cast() [3/3]

template<>
KernelObject * coco::cast ( Object o)

Definition at line 96 of file Object.cpp.

97{
98 assert(o != nullptr);
99 auto res = o->asKernel();
100 assert(res != nullptr);
101 return res;
102}
virtual KernelObject * asKernel(void)
Definition Object.h:81

References coco::Object::asKernel(), and cast().

◆ consumers()

Object::ConsumerSet coco::consumers ( const Object obj)

Return a set of consumers of a given object.

Definition at line 65 of file Object.cpp.

66{
67 Object::ConsumerSet res;
68
69 for (const auto &use : *(obj->uses()))
70 {
71 if (auto consumer = use->consumer())
72 {
73 res.insert(consumer);
74 }
75 }
76
77 return res;
78}

Referenced by readers().

◆ dependent_objects()

ObjectSet coco::dependent_objects ( const Bag b)

Return a set of objects that depends on a given bag.

Definition at line 87 of file Bag.cpp.

88{
89 ObjectSet res;
90
91 for (const auto &dep : *(b->deps()))
92 {
93 if (auto obj = dep->object())
94 {
95 res.insert(obj);
96 }
97 }
98
99 return res;
100}
std::set< Object * > ObjectSet
Definition ObjectSet.h:27

Referenced by readers(), and updaters().

◆ isa() [1/2]

template<typename T >
bool coco::isa ( const Instr ins)

Return true if a given instruction is of T type.

Note
"ins" cannot be a null pointer

Definition at line 141 of file Instr.h.

142{
143 assert(ins != nullptr);
144 return dynamic_cast<const T *>(ins) != nullptr;
145}

◆ isa() [2/2]

template<typename T >
bool coco::isa ( const Object )

Check whether a given object is of type T.

The example below shows how to use this "isa<T>" helper: auto obj = new FeatureObject{};

if (isa<FeatureObject>()) { std::cout << "FeatureObject" << std::endl; }

◆ isa< FeatureObject >()

template<>
bool coco::isa< FeatureObject > ( const Object o)

Casting Helpers

TODO Use Macro to reduce code duplication

Definition at line 85 of file Object.cpp.

85{ return o->asFeature() != nullptr; }

References coco::Object::asFeature().

◆ isa< KernelObject >()

template<>
bool coco::isa< KernelObject > ( const Object o)

Definition at line 86 of file Object.cpp.

86{ return o->asKernel() != nullptr; }

References coco::Object::asKernel().

◆ operator<()

bool coco::operator< ( const ElemID lhs,
const ElemID rhs 
)

Definition at line 23 of file ElemID.cpp.

23{ return lhs.value() < rhs.value(); }
uint32_t value(void) const
Definition ElemID.h:40

References operator<(), and coco::ElemID::value().

Referenced by operator<().

◆ operator==()

bool coco::operator== ( const ElemID lhs,
const ElemID rhs 
)

Definition at line 22 of file ElemID.cpp.

22{ return lhs.value() == rhs.value(); }

References coco::ElemID::value().

◆ producer()

Object::Producer * coco::producer ( const Object obj)

Return the producer of a given object if it exists.

Definition at line 55 of file Object.cpp.

56{
57 if (auto d = obj->def())
58 {
59 return d->producer();
60 }
61
62 return nullptr;
63}

References coco::Def::producer().

Referenced by enco::eliminate_dead_object(), enco::eliminate_indirect_copy(), enco::reduce_duplicated_object(), and updaters().

◆ readers()

Bag::ReaderSet coco::readers ( const Bag b)

Return a set of readers that reads a given bag.

Definition at line 102 of file Bag.cpp.

103{
104 Bag::ReaderSet res;
105
106 for (auto obj : dependent_objects(b))
107 {
108 for (auto consumer : consumers(obj))
109 {
110 // NOTE Object::Consumer inherits Bag::Reader
111 res.insert(consumer);
112 }
113 }
114
115 for (auto read : *b->reads())
116 {
117 auto reader = read->reader();
118 assert(reader != nullptr);
119 res.insert(reader);
120 }
121
122 return res;
123}
std::set< Reader * > ReaderSet
Definition Bag.h:62
ObjectSet dependent_objects(const Bag *)
Return a set of objects that depends on a given bag.
Definition Bag.cpp:87
Object::ConsumerSet consumers(const Object *)
Return a set of consumers of a given object.
Definition Object.cpp:65
luci::PartitionTable read(const std::string &path)
Reads and parse file and return PartitionTable.

References consumers(), and dependent_objects().

Referenced by enco::fold_constants(), enco::generate_bypass_shuffle(), enco::hoist_object(), and enco::readers().

◆ root()

Op * coco::root ( Op cur)

Return the root Op from a given Op node.

Note
root(op) == op holds for a root op

Definition at line 144 of file Op.cpp.

145{
146 while (cur->up())
147 {
148 cur = cur->up();
149 }
150 return cur;
151}
Op * up(void) const
Return a pointer to the parent Op.
Definition Op.cpp:52

References coco::Op::up().

◆ safe_cast() [1/4]

template<typename T >
T * coco::safe_cast ( Instr ins)

Cast as a derived instruction.

Note
"safe_cast<T>(ins)" returns a null pointer if "ins" is not of T type
"safe_cast<T>(ins)" returns a null pointer if "ins" is a null pointer

Definition at line 153 of file Instr.h.

154{
155 // NOTE dynamic_cast<T *>(nullptr) returns nullptr
156 return dynamic_cast<T *>(ins);
157}

◆ safe_cast() [2/4]

template<typename T >
T * coco::safe_cast ( Object )

Cast a generic object as a specific one.

Unlike "cast<T>", "safe_cast<T>" accepts any object pointer

  • "safe_cast<T>(nullptr)" returns "nullptr"
  • "safe_cast<T>(o)" returns "nullptr" if "isa<T>(o)" does not hold

◆ safe_cast() [3/4]

template<>
FeatureObject * coco::safe_cast ( Object o)

Definition at line 104 of file Object.cpp.

105{
106 // NOTE o may be nullptr
107 return (o == nullptr) ? nullptr : o->asFeature();
108}

References coco::Object::asFeature().

◆ safe_cast() [4/4]

template<>
KernelObject * coco::safe_cast ( Object o)

Definition at line 110 of file Object.cpp.

111{
112 // NOTE o may be nullptr
113 return (o == nullptr) ? nullptr : o->asKernel();
114}

References coco::Object::asKernel().

◆ updaters()

Bag::UpdaterSet coco::updaters ( const Bag b)

Return a set of updaters that updates a given bag.

Definition at line 125 of file Bag.cpp.

126{
127 Bag::UpdaterSet res;
128
129 for (auto obj : dependent_objects(b))
130 {
131 if (auto p = producer(obj))
132 {
133 res.insert(p);
134 }
135 }
136
137 for (auto update : *b->updates())
138 {
139 auto updater = update->updater();
140 assert(updater != nullptr);
141 res.insert(updater);
142 }
143
144 return res;
145}
std::set< Updater * > UpdaterSet
Definition Bag.h:55
Object::Producer * producer(const Object *)
Return the producer of a given object if it exists.
Definition Object.cpp:55
FeatureShapeUpdater update(loco::FeatureShape &feature_shape)

References dependent_objects(), and producer().

Referenced by enco::eliminate_dead_bag(), enco::generate_bypass_shuffle(), and enco::updaters().