ONE - On-device Neural Engine
Loading...
Searching...
No Matches
exo::FuseBiasAddPass Struct Referencefinal

Class to fuse TFLAdd or TFLSub into Bias input of the following ops: More...

#include <FuseBiasAddPass.h>

Collaboration diagram for exo::FuseBiasAddPass:

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
 

Detailed Description

Class to fuse TFLAdd or TFLSub into Bias input of the following ops:

  • TFLConv2D, TFLDepthwiseConv2D
  • TODO Consider to add FullyConnected, etc.

Case 1. Conv2D and TFLAdd

BEFORE:

              TFLConst A (a scalar or a tensor of shape [1] or [depth of TFLConv2D])
                   |

Foo – TFLConv2D – TFLAdd (or TFLSub) – Bar | TFLConst B –+ (bias)

AFTER: Foo --— TFLConv2D --— Bar | TFLConst A' –+ (bias)

TFLConst B (dead node)

TFLAdd (or TFLSub) (dead node)

Note
TFLSub, of which x() == TFLConv2D and y() == TFLConst, will be fused. If x() == TFLConst and y() == TFLConv2D, it won't be fused.

Definition at line 52 of file FuseBiasAddPass.h.

Member Function Documentation

◆ name()

const char * exo::FuseBiasAddPass::name ( void  ) const
inlinefinalvirtual

Reimplemented from logo::Pass.

Definition at line 54 of file FuseBiasAddPass.h.

54{ return "exo::FuseBiasAddPass"; }

◆ run()

bool exo::FuseBiasAddPass::run ( loco::Graph graph)
finalvirtual

Run the pass.

Returns
false if there was nothing changed

Implements logo::Pass.

Definition at line 339 of file FuseBiasAddPass.cpp.

340{
341 Collector collector;
342
343 for (auto node : loco::active_nodes(loco::output_nodes(g)))
344 {
345 if (node->dialect() == locoex::TFLDialect::get())
346 {
347 auto tfl_node = loco::must_cast<locoex::TFLNode *>(node);
348 tfl_node->accept(&collector);
349 }
350 }
351
352 Performer performer;
353
354 for (auto node : collector.candidates)
355 {
356 node->accept(&performer);
357 }
358
359 return collector.candidates.size() > 0;
360}
static loco::Dialect * get(void)
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

References locoex::TFLNode::accept(), loco::active_nodes(), locoex::TFLNode::dialect(), locoex::TFLDialect::get(), and loco::output_nodes().

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


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