ONE - On-device Neural Engine
Loading...
Searching...
No Matches
moco::ConstantFoldAdd Class Reference

Constant folder for Const + Add -> Const. More...

#include <ConstantFoldAdd.h>

Collaboration diagram for moco::ConstantFoldAdd:

Public Member Functions

const char * name (void) const final
 
bool run (loco::Graph *graph) override
 
- Public Member Functions inherited from logo::Pass
virtual ~Pass ()=default
 

Detailed Description

Constant folder for Const + Add -> Const.

Definition at line 30 of file ConstantFoldAdd.h.

Member Function Documentation

◆ name()

const char * moco::ConstantFoldAdd::name ( void  ) const
inlinefinalvirtual

Reimplemented from logo::Pass.

Definition at line 33 of file ConstantFoldAdd.h.

33{ return "ConstantFoldAdd"; }

◆ run()

bool moco::ConstantFoldAdd::run ( loco::Graph graph)
overridevirtual
Note
This will Replace TFAdd with TFConst when inputs are TFConst
  Before
            A --- TFAdd --- C
            B --/
  After
            A --- TFAdd
            B --/
                  TFConst ---------- C
  Where
            A,B : inputs of TFAdd
            C : a node that uses TFAdd as an input
            TFAdd is disconnected from C
            Nodes are drawn multiple times to simplify the diagram

Implements logo::Pass.

Definition at line 101 of file ConstantFoldAdd.cpp.

102{
103 bool changed = false;
104 for (auto node : loco::active_nodes(loco::output_nodes(graph)))
105 {
106 if (auto add_node = as<moco::TFAdd>(node))
107 {
108 if (constantfold_add(add_node))
109 changed = true;
110 }
111 }
112
113 return changed;
114}
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 loco::active_nodes(), and loco::output_nodes().

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


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