ONE - On-device Neural Engine
Loading...
Searching...
No Matches
luci::ForceQuantParamPass Class Reference

Pass to write quantparam (scale, zerop) to the specified tensors. More...

#include <ForceQuantParamPass.h>

Collaboration diagram for luci::ForceQuantParamPass:

Public Types

using TensorVector = std::vector< std::string >
 
using ScaleVector = std::vector< float >
 
using ZPVector = std::vector< int64_t >
 

Public Member Functions

 ForceQuantParamPass (TensorVector &tensors, ScaleVector &scales, ZPVector &zerops)
 
virtual const char * name (void) const
 
bool run (loco::Graph *graph)
 Run the pass.
 
- Public Member Functions inherited from logo::Pass
virtual ~Pass ()=default
 

Detailed Description

Pass to write quantparam (scale, zerop) to the specified tensors.

Definition at line 30 of file ForceQuantParamPass.h.

Member Typedef Documentation

◆ ScaleVector

using luci::ForceQuantParamPass::ScaleVector = std::vector<float>

Definition at line 34 of file ForceQuantParamPass.h.

◆ TensorVector

using luci::ForceQuantParamPass::TensorVector = std::vector<std::string>

Definition at line 33 of file ForceQuantParamPass.h.

◆ ZPVector

using luci::ForceQuantParamPass::ZPVector = std::vector<int64_t>

Definition at line 35 of file ForceQuantParamPass.h.

Constructor & Destructor Documentation

◆ ForceQuantParamPass()

luci::ForceQuantParamPass::ForceQuantParamPass ( TensorVector tensors,
ScaleVector scales,
ZPVector zerops 
)
inline

Definition at line 38 of file ForceQuantParamPass.h.

39 : _tensors{tensors}, _scales{scales}, _zerops{zerops}
40 {
41 // DO NOTHING
42 }

Member Function Documentation

◆ name()

virtual const char * luci::ForceQuantParamPass::name ( void  ) const
inlinevirtual

Reimplemented from logo::Pass.

Definition at line 43 of file ForceQuantParamPass.h.

43{ return "luci::ForceQuantParamPass"; }

Referenced by run().

◆ run()

bool luci::ForceQuantParamPass::run ( loco::Graph graph)
virtual

Run the pass.

Returns
false if there was nothing changed

Implements logo::Pass.

Definition at line 41 of file ForceQuantParamPass.cpp.

42{
43 LOGGER(l);
44 INFO(l) << "ForceQuantParamPass Start" << std::endl;
45
46 for (auto node : loco::active_nodes(loco::output_nodes(g)))
47 {
48 auto const cnode = loco::must_cast<CircleNode *>(node);
49 auto const name = cnode->name();
50 auto target = std::find(_tensors.begin(), _tensors.end(), name);
51 if (target == _tensors.end())
52 continue;
53
54 auto index = target - _tensors.begin();
55 auto scale = _scales[index];
56 auto zp = _zerops[index];
57 set_qparam(cnode, scale, zp);
58
59 _tensors.erase(_tensors.begin() + index);
60 _scales.erase(_scales.begin() + index);
61 _zerops.erase(_zerops.begin() + index);
62 }
63
64 if (_tensors.size() > 0)
65 {
66 std::string msg;
67 for (auto const &t : _tensors)
68 msg += "Tensor does not exist: " + t + ".\n";
69 msg += "Please check tensor name.\n";
70 throw std::runtime_error(msg);
71 }
72
73 INFO(l) << "ForceQuantParamPass End" << std::endl;
74 return false; // one time run
75}
#define LOGGER(name)
Definition Log.h:65
#define INFO(name)
Definition Log.h:68
virtual const char * name(void) const
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
loco::GraphInputIndex index(const TFPlaceholder *node)
Definition TFNode.cpp:54
Option< std::string > target(optname("--target"), overview("select target language to emit for given architecture." "Valid values are '" NNC_TARGET_ARM_CPP "', '" NNC_TARGET_X86_CPP "', '" NNC_TARGET_ARM_GPU_CPP "', '" NNC_TARGET_INTERPRETER "'"), std::string(), optional(false), optvalues(NNC_TARGET_ARM_CPP "," NNC_TARGET_X86_CPP "," NNC_TARGET_ARM_GPU_CPP "," NNC_TARGET_INTERPRETER), nullptr, separators("="))
Definition Options.h:47

References loco::active_nodes(), INFO, LOGGER, name(), and loco::output_nodes().

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


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