ONE - On-device Neural Engine
Loading...
Searching...
No Matches
coco::Bag Class Referencefinal

A collection of (abstracted) elements of the same type. More...

#include <Bag.h>

Collaboration diagram for coco::Bag:

Data Structures

struct  Reader
 
struct  Updater
 

Public Types

using UpdaterSet = std::set< Updater * >
 
using ReaderSet = std::set< Reader * >
 

Public Member Functions

 Bag (uint32_t size)
 
 ~Bag ()
 
uint32_t size (void) const
 
bool isInput (void) const
 
bool isOutput (void) const
 
const DepSetdeps (void) const
 Return the set of Dep links that point to this bag.
 
const ReadSetreads (void) const
 Return the set of Read links that point to this bag.
 
const UpdateSetupdates (void) const
 Return the set of Update links that point to this bag.
 
Inputinput (void) const
 Return a valid pointer if this bag is marked as an input of the model.
 
Outputoutput (void) const
 Return a valid pointer if this bag is marked as an output of the model.
 
void replaceWith (Bag *b)
 Replace all the occurence of a bag (except those in Input/Output) with another bag.
 
void replaceAllDepsWith (Bag *)
 Replace all the occurence of a bag in Object with another bag.
 
- Public Member Functions inherited from coco::Entity
virtual ~Entity ()=default
 
Modulemodule (void) const
 

Friends

class Dep
 
class Read
 
class Update
 
class Input
 
class Output
 

Detailed Description

A collection of (abstracted) elements of the same type.

When there are N elements in a bag, we refer to N as the size of this bag, and every element in a bag has a unique numeric ID whose range is [0, N).

NOTE 'Bag' is not a container (such as std::vector). 'Bag' just assures that there are N elements. It does not state about its value.

NOTE coco IR treats Bag as virtual memory allocation

Definition at line 47 of file Bag.h.

Member Typedef Documentation

◆ ReaderSet

using coco::Bag::ReaderSet = std::set<Reader *>

Definition at line 62 of file Bag.h.

◆ UpdaterSet

using coco::Bag::UpdaterSet = std::set<Updater *>

Definition at line 55 of file Bag.h.

Constructor & Destructor Documentation

◆ Bag()

coco::Bag::Bag ( uint32_t  size)
explicit

Definition at line 28 of file Bag.cpp.

28 : _size{size}
29{
30 // DO NOTHING
31}
uint32_t size(void) const
Definition Bag.cpp:41

◆ ~Bag()

coco::Bag::~Bag ( )

Definition at line 33 of file Bag.cpp.

34{
35 // All the references over a bag SHOULD be dropped before its destruction
36 assert(deps()->size() == 0);
37 assert(reads()->size() == 0);
38 assert(updates()->size() == 0);
39}
const UpdateSet * updates(void) const
Return the set of Update links that point to this bag.
Definition Bag.cpp:48
const ReadSet * reads(void) const
Return the set of Read links that point to this bag.
Definition Bag.cpp:47
const DepSet * deps(void) const
Return the set of Dep links that point to this bag.
Definition Bag.cpp:46

References deps(), reads(), size(), and updates().

Member Function Documentation

◆ deps()

const DepSet * coco::Bag::deps ( void  ) const

Return the set of Dep links that point to this bag.

Definition at line 46 of file Bag.cpp.

46{ return &_deps; }

Referenced by coco::Dep::bag(), replaceAllDepsWith(), replaceWith(), and ~Bag().

◆ input()

Input * coco::Bag::input ( void  ) const
inline

Return a valid pointer if this bag is marked as an input of the model.

Definition at line 94 of file Bag.h.

94{ return _input; }

◆ isInput()

bool coco::Bag::isInput ( void  ) const

Definition at line 43 of file Bag.cpp.

43{ return _input != nullptr; }

Referenced by replaceWith().

◆ isOutput()

bool coco::Bag::isOutput ( void  ) const

Definition at line 44 of file Bag.cpp.

44{ return _output != nullptr; }

Referenced by replaceWith().

◆ output()

Output * coco::Bag::output ( void  ) const
inline

Return a valid pointer if this bag is marked as an output of the model.

Definition at line 96 of file Bag.h.

96{ return _output; }

◆ reads()

const ReadSet * coco::Bag::reads ( void  ) const

Return the set of Read links that point to this bag.

Definition at line 47 of file Bag.cpp.

47{ return &_reads; }

Referenced by replaceWith(), and ~Bag().

◆ replaceAllDepsWith()

void coco::Bag::replaceAllDepsWith ( Bag b)

Replace all the occurence of a bag in Object with another bag.

NOTE Unlike replaceWith(b), replaceAllDepsWith(b) has no restriction

Definition at line 76 of file Bag.cpp.

77{
78 // Replace all the occurence inside Dep
79 while (!(deps()->empty()))
80 {
81 auto dep = *(deps()->begin());
82 assert(dep->bag() == this);
83 dep->bag(b);
84 }
85}

References deps().

Referenced by enco::hoist_object(), and replaceWith().

◆ replaceWith()

void coco::Bag::replaceWith ( Bag b)

Replace all the occurence of a bag (except those in Input/Output) with another bag.

NOTE reaplceWith(b) works correctly only when b is neither Input nor Output

Definition at line 50 of file Bag.cpp.

51{
52 assert(!isInput() && !isOutput());
53
55 // Replace all the occurence inside Read
56 while (!(reads()->empty()))
57 {
58 auto read = *(reads()->begin());
59 assert(read->bag() == this);
60 read->bag(b);
61 }
62
63 // Replace all the occurence insider Update
64 while (!(updates()->empty()))
65 {
66 auto update = *(updates()->begin());
67 assert(update->bag() == this);
68 update->bag(b);
69 }
70
71 assert(deps()->empty());
72 assert(reads()->empty());
73 assert(updates()->empty());
74}
bool isOutput(void) const
Definition Bag.cpp:44
bool isInput(void) const
Definition Bag.cpp:43
void replaceAllDepsWith(Bag *)
Replace all the occurence of a bag in Object with another bag.
Definition Bag.cpp:76
FeatureShapeUpdater update(loco::FeatureShape &feature_shape)
luci::PartitionTable read(const std::string &path)
Reads and parse file and return PartitionTable.

References deps(), isInput(), isOutput(), reads(), replaceAllDepsWith(), and updates().

◆ size()

uint32_t coco::Bag::size ( void  ) const

Definition at line 41 of file Bag.cpp.

41{ return _size; }

Referenced by enco::SubnetBlockCompiler::compile(), and ~Bag().

◆ updates()

const UpdateSet * coco::Bag::updates ( void  ) const

Return the set of Update links that point to this bag.

Definition at line 48 of file Bag.cpp.

48{ return &_updates; }

Referenced by replaceWith(), and ~Bag().

Friends And Related Symbol Documentation

◆ Dep

friend class Dep
friend

Definition at line 65 of file Bag.h.

◆ Input

friend class Input
friend

Definition at line 68 of file Bag.h.

◆ Output

friend class Output
friend

Definition at line 69 of file Bag.h.

◆ Read

friend class Read
friend

Definition at line 66 of file Bag.h.

◆ Update

friend class Update
friend

Definition at line 67 of file Bag.h.


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