ONE - On-device Neural Engine
Loading...
Searching...
No Matches
dalgona::PreOperatorHook Class Referencefinal

#include <PreOperatorHook.h>

Collaboration diagram for dalgona::PreOperatorHook:

Public Member Functions

 PreOperatorHook (py::object analysis, luci_interpreter::Interpreter *interpreter)
 
void visit (const luci::CircleNode *node)
 Default fallback.
 
void visit (const luci::CircleConv2D *node)
 
void visit (const luci::CircleDepthwiseConv2D *node)
 
void visit (const luci::CircleAdd *node)
 
void visit (const luci::CircleFullyConnected *node)
 
void visit (const luci::CircleTransposeConv *node)
 
void visit (const luci::CircleInstanceNorm *node)
 
void visit (const luci::CircleSplit *node)
 
- Public Member Functions inherited from luci::CircleNodeVisitor< void >
virtual ~CircleNodeVisitor ()=default
 
- Public Member Functions inherited from luci::CircleNodeVisitorBase< T >
virtual ~CircleNodeVisitorBase ()=default
 

Detailed Description

Definition at line 37 of file PreOperatorHook.h.

Constructor & Destructor Documentation

◆ PreOperatorHook()

dalgona::PreOperatorHook::PreOperatorHook ( py::object  analysis,
luci_interpreter::Interpreter interpreter 
)
inlineexplicit

Definition at line 57 of file PreOperatorHook.h.

58 : _analysis(analysis), _interpreter(interpreter)
59 {
60 // Do nothing
61 }

Member Function Documentation

◆ visit() [1/8]

void dalgona::PreOperatorHook::visit ( const luci::CircleAdd node)
inline

Definition at line 137 of file PreOperatorHook.h.

138 {
140
141 auto fused_act = node->fusedActivationFunction();
142
143 pySafeCall(hook,
144 node->name(), // name
145 inputs[0], // x
146 inputs[1], // y
147 toString(fused_act) // fused activation
148 );
149 }
void Add(const float *input1_data, const Dims< 4 > &input1_dims, const float *input2_data, const Dims< 4 > &input2_dims, float *output_data, const Dims< 4 > &output_dims)
Definition Add.float.cpp:28
#define PRE_OPERATOR_HOOK_PROLOGUE(OP_NAME)
const std::string toString(luci::CircleOpcode opcode)
void pySafeCall(py::object func, Args... args)
Definition Utils.h:29
NodeName name(void) const

References Add(), luci::CircleNodeMixin< CircleNodeTrait::FusedActFunc >::fusedActivationFunction(), luci::CircleNode::name(), PRE_OPERATOR_HOOK_PROLOGUE, dalgona::pySafeCall(), and dalgona::toString().

◆ visit() [2/8]

void dalgona::PreOperatorHook::visit ( const luci::CircleConv2D node)
inline

Definition at line 85 of file PreOperatorHook.h.

86 {
88
89 auto padding = node->padding();
90 auto stride = node->stride();
91 auto dilation = node->dilation();
92
93 auto py_stride = py::dict("w"_a = stride->w(), "h"_a = stride->h());
94 auto py_dilation = py::dict("w"_a = dilation->w(), "h"_a = dilation->h());
95
96 auto fused_act = node->fusedActivationFunction();
97
98 pySafeCall(hook,
99 node->name(), // name
100 inputs[0], // input
101 inputs[1], // filter
102 inputs[2], // bias
103 padding == luci::Padding::SAME ? "SAME" : "VALID", // padding
104 py_stride, // stride
105 py_dilation, // dilation
106 toString(fused_act) // fused activation
107 );
108 }
const Stride * stride(void) const
Padding padding() const
const Dilation * dilation(void) const

References luci::CircleConv2D::dilation(), luci::CircleNodeMixin< CircleNodeTrait::FusedActFunc >::fusedActivationFunction(), luci::CircleNode::name(), luci::CircleConv2D::padding(), PRE_OPERATOR_HOOK_PROLOGUE, dalgona::pySafeCall(), luci::SAME, luci::CircleConv2D::stride(), and dalgona::toString().

◆ visit() [3/8]

void dalgona::PreOperatorHook::visit ( const luci::CircleDepthwiseConv2D node)
inline

Definition at line 110 of file PreOperatorHook.h.

111 {
113
114 auto padding = node->padding();
115 auto stride = node->stride();
116 auto dilation = node->dilation();
117 auto depthMultiplier = node->depthMultiplier();
118
119 auto py_stride = py::dict("w"_a = stride->w(), "h"_a = stride->h());
120 auto py_dilation = py::dict("w"_a = dilation->w(), "h"_a = dilation->h());
121
122 auto fused_act = node->fusedActivationFunction();
123
124 pySafeCall(hook,
125 node->name(), // name
126 inputs[0], // input
127 inputs[1], // filter
128 inputs[2], // bias
129 padding == luci::Padding::SAME ? "SAME" : "VALID", // padding
130 py_stride, // stride
131 depthMultiplier, // depthMultiplier
132 py_dilation, // dilation
133 toString(fused_act) // fused activation
134 );
135 }
const Stride * stride(void) const
const Dilation * dilation(void) const

References luci::CircleDepthwiseConv2D::depthMultiplier(), DepthwiseConv2D, luci::CircleDepthwiseConv2D::dilation(), luci::CircleNodeMixin< CircleNodeTrait::FusedActFunc >::fusedActivationFunction(), luci::CircleNode::name(), luci::CircleDepthwiseConv2D::padding(), PRE_OPERATOR_HOOK_PROLOGUE, dalgona::pySafeCall(), luci::SAME, luci::CircleDepthwiseConv2D::stride(), and dalgona::toString().

◆ visit() [4/8]

void dalgona::PreOperatorHook::visit ( const luci::CircleFullyConnected node)
inline

Definition at line 151 of file PreOperatorHook.h.

152 {
154
155 auto fused_act = node->fusedActivationFunction();
156
157 pySafeCall(hook,
158 node->name(), // name
159 inputs[0], // input
160 inputs[1], // weights
161 inputs[2], // bias
162 toString(fused_act) // fused activation
163 );
164 }
void FullyConnected(const float *input_data, const Dims< 4 > &input_dims, const float *weights_data, const Dims< 4 > &weights_dims, const float *bias_data, const Dims< 4 > &bias_dims, float *output_data, const Dims< 4 > &output_dims)

References FullyConnected(), luci::CircleNodeMixin< CircleNodeTrait::FusedActFunc >::fusedActivationFunction(), luci::CircleNode::name(), PRE_OPERATOR_HOOK_PROLOGUE, dalgona::pySafeCall(), and dalgona::toString().

◆ visit() [5/8]

void dalgona::PreOperatorHook::visit ( const luci::CircleInstanceNorm node)
inline

Definition at line 186 of file PreOperatorHook.h.

187 {
188 PRE_OPERATOR_HOOK_PROLOGUE(InstanceNorm)
189
190 auto epsilon = node->epsilon();
191
192 auto fused_act = node->fusedActivationFunction();
193
194 pySafeCall(hook,
195 node->name(), // name
196 inputs[0], // input
197 inputs[1], // gamma
198 inputs[2], // beta
199 epsilon, // epsilon
200 toString(fused_act) // fused activation
201 );
202 }

References luci::CircleInstanceNorm::epsilon(), luci::CircleNodeMixin< CircleNodeTrait::FusedActFunc >::fusedActivationFunction(), PRE_OPERATOR_HOOK_PROLOGUE, dalgona::pySafeCall(), and dalgona::toString().

◆ visit() [6/8]

void dalgona::PreOperatorHook::visit ( const luci::CircleNode )
inlinevirtual

Default fallback.

Reimplemented from luci::CircleNodeVisitor< void >.

Definition at line 64 of file PreOperatorHook.h.

65 {
66 if (not py::hasattr(_analysis, "DefaultOpPre"))
67 return;
68
69 py::object hook = _analysis.attr("DefaultOpPre");
70 auto inputs = inputsPyArray(node, _interpreter);
71
72 py::list input_list;
73 for (uint32_t i = 0; i < inputs.size(); i++)
74 {
75 input_list.append(inputs[i]);
76 }
77
78 pySafeCall(hook,
79 node->name(), // name
80 toString(node->opcode()), // opcode
81 input_list // list of inputs
82 );
83 }
std::vector< py::dict > inputsPyArray(const luci::CircleNode *node, luci_interpreter::Interpreter *interpreter)
Definition Utils.cpp:109

References dalgona::inputsPyArray(), luci::CircleNode::name(), luci::CircleNode::opcode(), dalgona::pySafeCall(), and dalgona::toString().

◆ visit() [7/8]

void dalgona::PreOperatorHook::visit ( const luci::CircleSplit node)
inline

Definition at line 204 of file PreOperatorHook.h.

205 {
207
208 auto num_split = node->num_split();
209
210 pySafeCall(hook,
211 node->name(), // name
212 inputs[0], // split_dim
213 inputs[1], // input
214 num_split // num_split
215 );
216 }
int32_t num_split(void) const
Definition CircleSplit.h:42

References luci::CircleNode::name(), luci::CircleSplit::num_split(), PRE_OPERATOR_HOOK_PROLOGUE, and dalgona::pySafeCall().

◆ visit() [8/8]

void dalgona::PreOperatorHook::visit ( const luci::CircleTransposeConv node)
inline

Definition at line 166 of file PreOperatorHook.h.

167 {
168 PRE_OPERATOR_HOOK_PROLOGUE(TransposeConv)
169
170 auto padding = node->padding();
171 auto stride = node->stride();
172
173 auto py_stride = py::dict("w"_a = stride->w(), "h"_a = stride->h());
174
175 pySafeCall(hook,
176 node->name(), // name
177 inputs[2], // input
178 inputs[1], // filter
179 inputs[0], // output shape
180 inputs.size() == 4 ? inputs[3] : none(), // bias
181 padding == luci::Padding::SAME ? "SAME" : "VALID", // padding
182 py_stride // stride
183 );
184 }
const Stride * stride(void) const
const Padding & padding(void) const
py::object none()
Definition Utils.cpp:107

References luci::CircleNode::name(), dalgona::none(), luci::CircleTransposeConv::padding(), PRE_OPERATOR_HOOK_PROLOGUE, dalgona::pySafeCall(), luci::SAME, and luci::CircleTransposeConv::stride().


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