ONE - On-device Neural Engine
Loading...
Searching...
No Matches
luci::FusePreActivationBatchNormPass Struct Referencefinal

Class to fuse batch normalization of pre-activation. More...

#include <FusePreActivationBatchNormPass.h>

Collaboration diagram for luci::FusePreActivationBatchNormPass:

Public Member Functions

const char * name (void) const final
 
bool run (loco::Graph *g) final
 Run the pass.
 
- Public Member Functions inherited from logo::Pass
virtual ~Pass ()=default
 

Data Fields

std::vector< luci::CircleMul * > _mul_list
 
std::vector< luci::CircleAdd * > _add_list
 
std::vector< luci::CircleSub * > _sub_list
 

Detailed Description

Class to fuse batch normalization of pre-activation.

Definition at line 29 of file FusePreActivationBatchNormPass.h.

Member Function Documentation

◆ name()

const char * luci::FusePreActivationBatchNormPass::name ( void  ) const
inlinefinalvirtual

Reimplemented from logo::Pass.

Definition at line 31 of file FusePreActivationBatchNormPass.h.

31{ return "luci::FusePreActivationBatchNormPass"; }

◆ run()

bool luci::FusePreActivationBatchNormPass::run ( loco::Graph graph)
finalvirtual

Run the pass.

Returns
false if there was nothing changed

Implements logo::Pass.

Definition at line 577 of file FusePreActivationBatchNormPass.cpp.

578{
579 LOGGER(l);
580 bool changed = false;
581
582 // Step 1. Swap MUL <-> ADD
583 for (auto node : loco::active_nodes(loco::output_nodes(g)))
584 {
585 auto add = dynamic_cast<luci::CircleAdd *>(node);
586 if (add == nullptr)
587 continue;
588
590 changed = true;
591 }
592
593 INFO(l) << "[FusePreActivationBatchNorm] Target pre-activations: " << _mul_list.size()
594 << std::endl;
595
596 // Valid pattern was not detected. Fast exit.
597 if (!changed)
598 return false;
599
600 // Step 2. Fuse MUL with the next CONV
601 for (auto const &mul : _mul_list)
602 {
603 if (fuse_mul_with_conv(mul))
604 INFO(l) << "[FusePreActivationBatchNorm] Fused MUL: " << mul->name() << std::endl;
605 }
606
607 // Step 3. Fuse ADD with the preceding CONV and insert SUB
608 for (auto const &add : _add_list)
609 {
611 INFO(l) << "[FusePreActivationBatchNorm] Fused ADD: " << add->name() << std::endl;
612 }
613
614 INFO(l) << "[FusePreActivationBatchNorm] " << _sub_list.size() << " SUB were added." << std::endl;
615
616 // Step 4. Fuse SUB to CONV (SUB -> ADD <- CONV pattern)
617 for (auto const &sub : _sub_list)
618 {
619 if (fuse_sub_with_conv(sub))
620 INFO(l) << "[FusePreActivationBatchNorm] Fused SUB: " << sub->name() << std::endl;
621 }
622
623 return changed;
624}
#define LOGGER(name)
Definition Log.h:65
#define INFO(name)
Definition Log.h:68
ADD in Circle.
Definition CircleAdd.h:34
std::set< loco::Node * > active_nodes(const std::vector< loco::Node * > &roots)
Enumerate all the nodes required to compute "roots".
std::vector< Node * > output_nodes(Graph *)
Definition Graph.cpp:101
void mul(const luci_interpreter::RuntimeShape &shape, const ArithmeticParams *params, const int16_t *input1_data, const int16_t *input2_data, int8_t *output_data)
bool fuse_add_with_conv(luci::CircleAdd *add, std::vector< luci::CircleSub * > &sub_list)
bool fuse_sub_with_conv(luci::CircleSub *sub)
bool swap_mul_add(luci::CircleAdd *add, std::vector< luci::CircleMul * > &mul_list, std::vector< luci::CircleAdd * > &add_list)
bool fuse_mul_with_conv(luci::CircleMul *mul)

References _add_list, _mul_list, _sub_list, loco::active_nodes(), luci::fuse_add_with_conv(), luci::fuse_mul_with_conv(), luci::fuse_sub_with_conv(), INFO, LOGGER, loco::output_nodes(), and luci::swap_mul_add().

Referenced by package.infer.session::inference().

Field Documentation

◆ _add_list

std::vector<luci::CircleAdd *> luci::FusePreActivationBatchNormPass::_add_list

Definition at line 36 of file FusePreActivationBatchNormPass.h.

Referenced by run().

◆ _mul_list

std::vector<luci::CircleMul *> luci::FusePreActivationBatchNormPass::_mul_list

Definition at line 35 of file FusePreActivationBatchNormPass.h.

Referenced by run().

◆ _sub_list

std::vector<luci::CircleSub *> luci::FusePreActivationBatchNormPass::_sub_list

Definition at line 37 of file FusePreActivationBatchNormPass.h.

Referenced by run().


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