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

Class to fold Dequantize, which can be folded by constant inputs. More...

#include <FoldDequantizePass.h>

Collaboration diagram for luci::FoldDequantizePass:

Public Member Functions

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

Detailed Description

Class to fold Dequantize, which can be folded by constant inputs.

Definition at line 29 of file FoldDequantizePass.h.

Member Function Documentation

◆ name()

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

Reimplemented from logo::Pass.

Definition at line 31 of file FoldDequantizePass.h.

31{ return "luci::FOLD_DEQUANTIZE"; }

◆ run()

bool luci::FoldDequantizePass::run ( loco::Graph g)
finalvirtual

Folding pattern 1 - When input of Dequantize is foldable constant

[Before] quantized_const_input -------— Dequantize -------— Op — +– Op1_with_quant_input — +– Op2_with_quant_input —

[After] dequantized_const_input -----------------------------— Op —

quantized_const_input --— Op1_with_quant_input — +– Op2_with_quant_input —

Folding pattern 2 - When input of Dequantize uses quantized output value

[Before] quantized_const_input --— Gather --— Dequantize — Op — +– Op1_with_quant_input — +– Op2_with_quant_input —

[After] dequantized_const_input ---—Gather -----------------— Op —

quantized_const_input --— Op1_with_quant_input — +– Op2_with_quant_input —

Implements logo::Pass.

Definition at line 213 of file FoldDequantizePass.cpp.

214{
215 bool changed = false;
216
217 for (auto node : loco::active_nodes(loco::output_nodes(g)))
218 {
219 if (auto circle_dequant = dynamic_cast<luci::CircleDequantize *>(node))
220 {
221 if (auto const_input = dynamic_cast<luci::CircleConst *>(circle_dequant->input()))
222 {
223 // Pattern 1 - When input of Dequantize is foldable constant
224 if (is_foldable_const(const_input))
225 {
226 loco::replace(circle_dequant).with(dequantized_const_node(const_input));
227 changed = true;
228 }
229 }
230 }
231 else if (auto const_node = dynamic_cast<luci::CircleConst *>(node))
232 {
233 if (is_foldable_const(const_node))
234 {
235 for (auto const_node_user : loco::succs(const_node))
236 {
237 // If user is hybrid kernel supported operation, do not dequantize
238 if (is_hybrid_kernel_supported(const_node_user))
239 continue;
240
241 auto users = loco::succs(const_node_user);
242 if (users.size() > 1)
243 continue;
244
245 // Pattern 2 - When input of Dequantize uses quantized output value
246 if (auto dequant = dynamic_cast<luci::CircleDequantize *>(*users.begin()))
247 {
248 if (replace_const_node(const_node_user, const_node))
249 {
250 loco::replace(dequant).with(const_node_user);
251 luci::add_origin(loco::must_cast<luci::CircleNode *>(const_node_user),
252 luci::get_origin(dequant));
253 changed = true;
254 }
255 }
256 }
257 }
258 }
259 }
260
261 return changed;
262}
void with(Node *into) const
Definition Node.cpp:66
Class to build tensor data.
Definition CircleConst.h:35
DEQUANTIZE in Circle.
std::set< Node * > succs(const Node *node)
Enumerate all the successors of a given node.
Definition Node.cpp:46
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
Subst< SubstQualifier::Default > replace(Node *node)
Definition Node.cpp:82

References loco::active_nodes(), loco::output_nodes(), loco::replace(), loco::succs(), and loco::Subst< SubstQualifier::Default >::with().

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


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