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

#include <OpManager.h>

Collaboration diagram for coco::OpManager:

Public Member Functions

 OpManager (Module *m=nullptr)
 
 ~OpManager ()
 
template<typename T >
T * create (void)
 
void destroy (Op *)
 Destroy (= deallocate) a Op instance.
 
void destroy_all (Op *)
 Destroy a Op tree.
 
- Public Member Functions inherited from coco::PtrManager< Op >
uint32_t size (void) const
 Return the number of managed objects.
 
Opat (uint32_t n) const
 
- Public Member Functions inherited from coco::EntityBuilder
virtual ~EntityBuilder ()=default
 

Additional Inherited Members

- Protected Member Functions inherited from coco::PtrManager< Op >
U * take (std::unique_ptr< U > &&o)
 
std::unique_ptr< Oprelease (Op *ptr)
 
- Protected Member Functions inherited from coco::EntityBuilder
Modulemodule (void) const
 
void module (Module *m)
 
void modulize (Entity *entity) const
 

Detailed Description

Definition at line 34 of file OpManager.h.

Constructor & Destructor Documentation

◆ OpManager()

coco::OpManager::OpManager ( Module m = nullptr)
inline

Definition at line 37 of file OpManager.h.

37{ module(m); }
Module * module(void) const

References m, and coco::EntityBuilder::module().

◆ ~OpManager()

coco::OpManager::~OpManager ( )

Definition at line 29 of file OpManager.cpp.

30{
31 std::set<coco::Op *> roots;
32
33 for (uint32_t n = 0; n < size(); ++n)
34 {
35 auto op = at(n);
36
37 if (op->up() != nullptr)
38 {
39 continue;
40 }
41
42 roots.insert(op);
43 }
44
45 for (const auto &op : roots)
46 {
47 destroy_all(op);
48 }
49}
void destroy_all(Op *)
Destroy a Op tree.
Definition OpManager.cpp:70
uint32_t size(void) const
Return the number of managed objects.
Definition PtrManager.h:32
Op * at(uint32_t n) const
Definition PtrManager.h:35

References coco::PtrManager< Op >::at(), destroy_all(), and coco::PtrManager< Op >::size().

Member Function Documentation

◆ create()

template<typename T >
T * coco::OpManager::create ( void  )

Referenced by OpBuilder::load().

◆ destroy()

void coco::OpManager::destroy ( Op op)

Destroy (= deallocate) a Op instance.

NOTE destroy(op) WILL NOT update op->parent(). Client SHOULD detach op before destroy(op) call

Definition at line 64 of file OpManager.cpp.

65{
66 assert(op->parent() == nullptr);
67 release(op);
68}
std::unique_ptr< Op > release(Op *ptr)
Definition PtrManager.h:46

References coco::Op::parent(), and coco::PtrManager< Op >::release().

Referenced by destroy_all().

◆ destroy_all()

void coco::OpManager::destroy_all ( Op op)

Destroy a Op tree.

@require op->parent() == nullptr && op->up() == nullptr

Definition at line 70 of file OpManager.cpp.

71{
72 assert(op->parent() == nullptr);
73 assert(op->up() == nullptr);
74
75 std::queue<coco::Op *> q;
76
77 q.emplace(op);
78
79 while (q.size() > 0)
80 {
81 auto cur = q.front();
82 q.pop();
83
84 // Insert child op nodes
85 for (uint32_t n = 0; n < cur->arity(); ++n)
86 {
87 if (auto child = cur->arg(n))
88 {
89 q.emplace(child);
90 }
91 }
92
93 // Destroy the current op node
94 destroy(cur);
95 }
96}
void destroy(Op *)
Destroy (= deallocate) a Op instance.
Definition OpManager.cpp:64

References destroy(), coco::Op::parent(), and coco::Op::up().

Referenced by ~OpManager().


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