ONE - On-device Neural Engine
|
Typedefs | |
using | SessionID = uint32_t |
using | GlobalOffset = uint32_t |
Functions | |
void | subst (coco::Object *from, coco::Object *into) |
Substitute all the USE occurrences of an object with another object. | |
std::vector< coco::Instr * > | instr_sequence (coco::Module *m) |
Return instructions in execution order. | |
coco::FeatureShape | output_shape (coco::Conv2D *conv2D) |
bool | validate_output_shape (Code *code) |
bool | validate (Code *code) |
SessionID | make_session (coco::Module *m, coco::Data *d) |
SessionID | session (const coco::Module *m) |
SessionID | session (const coco::Data *d) |
coco::Module * | module (const SessionID &sess) |
coco::Data * | data (const SessionID &sess) |
Code * | code (const SessionID &sess) |
template<typename It > | |
void | concat (std::ostream &os, const std::string &sep, It beg, It end) |
template<typename It > | |
std::string | concat (const std::string &sep, It beg, It end) |
void | lower_avgpool (enco::Code *) |
Rewrite NN API-incompatible average pooling. | |
void | lower_concat (enco::Code *code) |
Lower eval(Concat(...)) as a sequence of shuffle instructions. | |
void | fold_constants (enco::Code *) |
Evaluate "constant" expressions at compile time. | |
void | lower_copy (enco::Code *code) |
Lower copy(...) instruction into shuffle(...) | |
void | convert_data_layout (enco::Code *code) |
Insert data reordering if necessary. | |
void | eliminate_dead_bag (enco::Code *code) |
Eliminate dead bags. | |
void | eliminate_dead_object (enco::Code *code) |
Eliminate dead objects in IR. | |
void | duplicate_inout_bag (enco::Code *code) |
Eliminate in/out bags by duplication. | |
void | reduce_duplicated_object (enco::Code *code) |
Reduce duplicated feature objects as its dominating feature object. | |
void | eliminate_free_instr (coco::Module *mod) |
Eliminate free instructions. | |
void | eliminate_free_op (coco::Module *mod) |
Eliminate free op. | |
void | generate_global_data (std::ostream &, enco::Code *) |
Generate 'Global' weight array. | |
void | reduce_identical_object (enco::Code *code) |
Reduce identically copied objects as its original object. | |
void | eliminate_indirect_copy (enco::Code *code) |
Convert all the indirect copies as a direct copy. | |
void | select_intrinsic (enco::Code *) |
Select Intricsic (API) to be used. | |
void | generate_bypass_shuffle (enco::Code *code) |
Add a bypass Shuffle if two continued Shuffles map same from-into. | |
void | hoist_object (enco::Code *code) |
Update the base bag of each object if possible. | |
void | split_into_phases (enco::Code *code) |
Split instructions into a set of phases. | |
std::set< coco::Block * > | readers (const coco::Bag *bag) |
Returns the set of blocks that reads a given bag. | |
std::set< coco::Block * > | updaters (const coco::Bag *bag) |
Return the set of blocks that updates a given bag. | |
using enco::GlobalOffset = typedef uint32_t |
Definition at line 27 of file GlobalDataGeneration.h.
using enco::SessionID = typedef uint32_t |
Definition at line 54 of file Session.cpp.
Referenced by convert_data_layout(), duplicate_inout_bag(), eliminate_dead_bag(), eliminate_dead_object(), eliminate_indirect_copy(), fold_constants(), generate_bypass_shuffle(), generate_global_data(), hoist_object(), lower_avgpool(), lower_concat(), lower_copy(), reduce_duplicated_object(), reduce_identical_object(), enco::AvgPoolLoweringPass::run(), enco::ConcatLoweringPass::run(), enco::ConstantFoldingPass::run(), enco::CopyLoweringPass::run(), enco::DataLayoutConversionPass::run(), enco::DeadBagEliminationPass::run(), enco::DeadObjectEliminationPass::run(), enco::BagDuplicationPass::run(), enco::DuplicatedObjectReductionPass::run(), enco::FeatureUnificationPass::run(), enco::FreeInstrEliminationPass::run(), enco::FreeOpEliminationPass::run(), enco::IdenticalObjectReductionPass::run(), enco::IndirectCopyEliminationPass::run(), enco::IntrinsicSelectionPass::run(), enco::BypassGenerationPass::run(), enco::PhaseConstructionPass::run(), select_intrinsic(), split_into_phases(), and validate().
std::string enco::concat | ( | const std::string & | sep, |
It | beg, | ||
It | end | ||
) |
Definition at line 48 of file String.h.
References concat().
void enco::concat | ( | std::ostream & | os, |
const std::string & | sep, | ||
It | beg, | ||
It | end | ||
) |
void enco::convert_data_layout | ( | enco::Code * | code | ) |
Insert data reordering if necessary.
Definition at line 377 of file DataLayoutConversion.cpp.
References code().
Referenced by enco::DataLayoutConversionPass::run().
coco::Data * enco::data | ( | const SessionID & | sess | ) |
Definition at line 52 of file Session.cpp.
void enco::duplicate_inout_bag | ( | enco::Code * | code | ) |
Eliminate in/out bags by duplication.
Definition at line 129 of file Duplicate.cpp.
References code().
Referenced by enco::BagDuplicationPass::run().
void enco::eliminate_dead_bag | ( | enco::Code * | code | ) |
Eliminate dead bags.
A bag is referred to as dead if it is neither input nor output, and has no read. If a bag is dead, it is unnecessary to updates its values as these values are never used.
"eliminate_dead_bag" removes all the dead bags and its updaters from IR.
Definition at line 50 of file DeadBagElimination.cpp.
References code(), m, enco::Code::module(), and coco::updaters().
Referenced by enco::DeadBagEliminationPass::run().
void enco::eliminate_dead_object | ( | enco::Code * | code | ) |
Eliminate dead objects in IR.
An object whose backing bag is unused is referred to as a dead object.
Dead Object Elimination (DOE) eliminates such dead objects along with their producer.
Definition at line 57 of file DeadObjectElimination.cpp.
References code(), m, enco::Code::module(), and coco::producer().
Referenced by enco::DeadObjectEliminationPass::run().
void enco::eliminate_free_instr | ( | coco::Module * | mod | ) |
Eliminate free instructions.
An instruction is referred to as "free" if it is not bound to any "block"
Definition at line 57 of file FreeInstrElimination.cpp.
References m.
Referenced by enco::FreeInstrEliminationPass::run().
void enco::eliminate_free_op | ( | coco::Module * | mod | ) |
Eliminate free op.
An op is referred to as "free" if it is not bound to any "instruction"
Definition at line 51 of file FreeOpElimination.cpp.
References m.
Referenced by enco::FreeOpEliminationPass::run().
void enco::eliminate_indirect_copy | ( | enco::Code * | code | ) |
Convert all the indirect copies as a direct copy.
BEFORE <<<
obj_0 = ... obj_1 = ... obj_2 = ...
copy(from: obj_0, into: obj_1) copy(from: obj_1, into: obj_2)
AFTER <<<
obj_0 = ... obj_1 = ... obj_2 = ...
copy(from: obj_0, into: obj_1) copy(from: obj_0, into: obj_2)
Definition at line 55 of file IndirectCopyElimination.cpp.
References code(), m, enco::Code::module(), and coco::producer().
Referenced by enco::IndirectCopyEliminationPass::run().
void enco::fold_constants | ( | enco::Code * | code | ) |
Evaluate "constant" expressions at compile time.
Definition at line 419 of file ConstantFolding.cpp.
References code(), and coco::readers().
Referenced by enco::ConstantFoldingPass::run().
void enco::generate_bypass_shuffle | ( | enco::Code * | code | ) |
Add a bypass Shuffle if two continued Shuffles map same from-into.
bag_1 = Bag(size: N) bag_2 = Bag(size: N) bag_3 = Bag(size: N)
BEFORE <<<
Shuffle(from: bag_1, into: bag_2, [0 -> 0]) Shuffle(from: bag_2, into: bag_3, [0 -> 0])
Let's refer to the former shuffle as Shuffle 1 and the latter one as Shuffle 2. We can replace Shuffle 2 with new Shuffle 3 as follows when Shuffle 1 and Shuffle 2 map to the same position.
AFTER <<<
Shuffle(from: bag_1, into: bag_2, [0 -> 0]) <- Shuffle 1 Shuffle(from: bag_1, into: bag_3, [0 -> 0]) <- Shuffle 3
Note that Shuffle 1 can be eliminated when bag_2 is not used
Definition at line 25 of file Optimizations.cpp.
References coco::PtrManager< T >::at(), coco::EntityManager::bag(), code(), coco::Module::entity(), coco::Shuffle::from(), m, enco::Code::module(), coco::readers(), size, and coco::updaters().
Referenced by enco::BypassGenerationPass::run().
void enco::generate_global_data | ( | std::ostream & | , |
enco::Code * | |||
) |
Generate 'Global' weight array.
NOTE Succeeding passes can access offsets via "GlobalData"
Definition at line 109 of file GlobalDataGeneration.cpp.
References code(), enco::SubnetManager::context(), enco::Code::data(), info, m, enco::Code::module(), and size.
void enco::hoist_object | ( | enco::Code * | code | ) |
Update the base bag of each object if possible.
— Case 1 — Let us consider the following code:
bag_1 = Bag(size: 4) bag_2 = Bag(size: 1)
obj_1 = ... at bag_1 obj_2 = ... at bag_2
... Shuffle(from: bag_1, into: bag_2, [0 -> 0]) <- shuffle ...
Note that the content of bag_2 after shuffle is identical to a part of bag_1, so the following code is identical to the above code
bag_1 = Bag(size: 4) bag_2 = Bag(size: 1)
obj_1 = ... at bag_1 obj_2 = ... at bag_1
... Shuffle(from: bag_1, into: bag_2, [0 -> 0]) ...
— Case 2 — Let us consider the following code:
bag_1 = Bag(size: 4) bag_2 = Bag(size: 1) bag_3 = Bag(size: 1)
obj_1 = ... at bag_2 obj_2 = ... at bag_3
Shuffle(from: bag_1, into: bag_2, [0 -> 0]) <- shuffle_1 Shuffle(from: bag_1, into: bag_3, [0 -> 0]) <- shuffle_2
Note that the content of bag_3 after shuffle_2 is identical to that of bag_2 after shuffle_1, so the following code is identical to the above one:
bag_1 = Bag(size: 4) bag_2 = Bag(size: 1) bag_3 = Bag(size: 1)
obj_1 = ... at bag_2 obj_2 = ... at bag_2 <- HERE
Shuffle(from: bag_1, into: bag_2, [0 -> 0]) <- shuffle_1 Shuffle(from: bag_1, into: bag_3, [0 -> 0]) <- shuffle_2
"hoist_object" optimization rewrites the former code as the latter one.
NOTE "hoist_object" DOES NOT change any instruction. It just updates the base bag of objects of interest.
Definition at line 175 of file Optimizations.cpp.
References coco::Shuffle::asShuffle(), coco::Shuffle::at(), code(), coco::Shuffle::from(), coco::Shuffle::into(), m, enco::Code::module(), coco::DLinkedList< Child, Parent >::Node::parent(), coco::readers(), coco::Bag::replaceAllDepsWith(), and size.
std::vector< coco::Instr * > enco::instr_sequence | ( | coco::Module * | m | ) |
Return instructions in execution order.
Definition at line 50 of file IRUtils.cpp.
References m.
Referenced by reduce_identical_object().
void enco::lower_avgpool | ( | enco::Code * | code | ) |
Rewrite NN API-incompatible average pooling.
Definition at line 223 of file AvgPoolLowering.cpp.
References code().
Referenced by enco::AvgPoolLoweringPass::run().
void enco::lower_concat | ( | enco::Code * | code | ) |
Lower eval(Concat(...)) as a sequence of shuffle instructions.
Definition at line 101 of file ConcatLowering.cpp.
References nncc::core::ADT::tensor::Index::at(), code(), m, enco::Code::module(), and nncc::core::ADT::tensor::IndexEnumerator::valid().
Referenced by enco::ConcatLoweringPass::run().
void enco::lower_copy | ( | enco::Code * | code | ) |
Lower copy(...) instruction into shuffle(...)
Definition at line 28 of file CopyLowering.cpp.
References coco::PtrManager< T >::at(), code(), coco::Module::entity(), coco::Shuffle::from(), coco::EntityManager::instr(), m, enco::Code::module(), and size.
Referenced by enco::CopyLoweringPass::run().
SessionID enco::make_session | ( | coco::Module * | m, |
coco::Data * | d | ||
) |
coco::Module * enco::module | ( | const SessionID & | sess | ) |
Definition at line 51 of file Session.cpp.
Referenced by validate_output_shape().
coco::FeatureShape enco::output_shape | ( | coco::Conv2D * | conv2D | ) |
Definition at line 24 of file IRValidator.cpp.
References coco::Conv2D::arg(), coco::Conv2D::ker(), coco::Padding2D::left(), coco::Conv2D::pad(), and coco::Conv2D::stride().
std::set< coco::Block * > enco::readers | ( | const coco::Bag * | bag | ) |
Returns the set of blocks that reads a given bag.
Definition at line 22 of file Usage.cpp.
References coco::readers().
void enco::reduce_duplicated_object | ( | enco::Code * | code | ) |
Reduce duplicated feature objects as its dominating feature object.
BEFORE <<<
obj_0 = Feature(layout: ???) at ... obj_1 = Feature(layout: BHWC) at ... obj_2 = Feature(layout: BHWC) at ...
copy(from: obj_0, into: obj_1) copy(from: obj_0, into: obj_2)
... Use(obj_1) Use(obj_2) ...
AFTER <<<
obj_0 = Feature(layout: ???) at ... obj_1 = Feature(layout: BHWC) at ... obj_2 = Feature(layout: BHWC) at ...
copy(from: obj_0, into: obj_1) copy(from: obj_0, into: obj_2)
... Use(obj_1) Use(obj_1) <– CHANGED ...
NOTE Given a set of feature objects, a feature object referred to as a dominating feature object if its producer proceeds the producer of every feature object in the given set
Definition at line 81 of file DuplicatedObjectReduction.cpp.
References code(), m, enco::Code::module(), coco::producer(), and subst().
Referenced by enco::DuplicatedObjectReductionPass::run().
void enco::reduce_identical_object | ( | enco::Code * | code | ) |
Reduce identically copied objects as its original object.
BEFORE <<<
bag_0 = Bag(size: N) bag_1 = Bag(size: N)
obj_0 = Feature(layout: BHWC) at bag_0 obj_1 = Feature(layout: BHWC) at bag_1
copy(from: obj_0, into: obj_1) ... Use(obj_0) Use(obj_1) ...
AFTER <<<
bag_0 = Bag(size: N) bag_1 = Bag(size: N)
obj_0 = Feature(layout: BHWC) at bag_0 obj_1 = Feature(layout: BHWC) at bag_1
copy(from: obj_0, into: obj_1) ... Use(obj_0) Use(obj_0) <- obj_1 is replaced ...
Definition at line 25 of file IdenticalObjectReduction.cpp.
References code(), instr_sequence(), m, enco::Code::module(), subst(), and coco::FeatureLayouts::BHWC::uid().
Referenced by enco::IdenticalObjectReductionPass::run().
void enco::select_intrinsic | ( | enco::Code * | ) |
Select Intricsic (API) to be used.
This pass is analogue of "Instruction Selection" pass. This "Intrisic Selection" pass will replace a general coco IR instruction into a backend-specific coco (extended) IR instruction.
Definition at line 77 of file IntrinsicSelection.cpp.
References code(), m, and enco::Code::module().
Referenced by enco::IntrinsicSelectionPass::run().
SessionID enco::session | ( | const coco::Data * | d | ) |
Definition at line 49 of file Session.cpp.
SessionID enco::session | ( | const coco::Module * | m | ) |
void enco::split_into_phases | ( | enco::Code * | code | ) |
Split instructions into a set of phases.
Definition at line 1227 of file Split.cpp.
References code().
Referenced by enco::PhaseConstructionPass::run().
void enco::subst | ( | coco::Object * | from, |
coco::Object * | into | ||
) |
Substitute all the USE occurrences of an object with another object.
Replace all the "USE" of 'from' with 'into'.
from | Object to be replaced |
into | Object to be used instead NOTE This maybe used when something like – 'from' will be removed so we need to replace object Consumers that use 'from' to 'into' EXAMPLE { subst(child, bigone); m->entity()->object()->destroy(child); } This code will change all the Consumers that use 'child' to 'bigone' and destroy the 'child' object. |
NOTE subst(from, into) WILL NOT update 'DEF'
Definition at line 38 of file IRUtils.cpp.
References coco::Object::uses().
Referenced by reduce_duplicated_object(), and reduce_identical_object().
std::set< coco::Block * > enco::updaters | ( | const coco::Bag * | bag | ) |
Return the set of blocks that updates a given bag.
Definition at line 40 of file Usage.cpp.
References coco::updaters().
bool enco::validate | ( | Code * | code | ) |
Definition at line 83 of file IRValidator.cpp.
References code(), validate(), and validate_output_shape().
Referenced by validate().
bool enco::validate_output_shape | ( | Code * | code | ) |
Definition at line 51 of file IRValidator.cpp.
References coco::Module::block(), coco::DLinkedList< Child, Parent >::Head::head(), module(), and output_shape.
Referenced by validate().