Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
T
tic
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wenyuanbo
tic
Commits
1bc83853
Commit
1bc83853
authored
Sep 01, 2019
by
Animesh Jain
Committed by
Wuwei Lin
Sep 01, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[QNN] Requantize - Optimize lowering for some corner cases. (#3864)
parent
dee52466
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
10 additions
and
2 deletions
+10
-2
src/relay/qnn/op/requantize.cc
+9
-2
tests/python/relay/test_qnn_requantize.py
+1
-0
No files found.
src/relay/qnn/op/requantize.cc
View file @
1bc83853
...
...
@@ -129,6 +129,9 @@ Expr RequantizeLower(const Expr& input_tensor, const RequantizeAttrs* param,
tensor
=
Subtract
(
tensor
,
input_zp
);
}
// If the input and output scales are same, we can skip the fixed point multiplication.
auto
scaled_int64_t
=
tensor
;
if
(
param
->
input_scale
!=
param
->
output_scale
)
{
// 3) Multiply the integer multiplier
if
(
left_shift
!=
0
)
{
tensor
=
Multiply
(
tensor
,
MakeConstantScalar
(
hp_dtype
,
1
<<
left_shift
));
...
...
@@ -166,11 +169,15 @@ Expr RequantizeLower(const Expr& input_tensor, const RequantizeAttrs* param,
tensor
=
Add
(
tensor
,
round_scalar
);
// 5) Simply right shift the result to get the final output.
auto
scaled_int64_t
=
RightShift
(
tensor
,
MakeConstantScalar
(
hp_dtype
,
total_right_shift
));
scaled_int64_t
=
RightShift
(
tensor
,
MakeConstantScalar
(
hp_dtype
,
total_right_shift
));
}
// 6) Add the output zero point.
auto
shifted_int64_t
=
scaled_int64_t
;
if
(
param
->
output_zero_point
!=
0
)
{
auto
output_zp
=
MakeConstantScalar
(
hp_dtype
,
param
->
output_zero_point
);
auto
shifted_int64_t
=
Add
(
output_zp
,
scaled_int64_t
);
shifted_int64_t
=
Add
(
output_zp
,
scaled_int64_t
);
}
// 7) Clip to the out_dtype min/max.
auto
q_min
=
GetQmin
(
out_dtype
);
...
...
tests/python/relay/test_qnn_requantize.py
View file @
1bc83853
...
...
@@ -64,6 +64,7 @@ def test_requantize():
input_scale
=
0.5
,
output_scale
=
0.5
,
rounding
=
rounding
)
assert
'right_shift'
not
in
mod
.
astext
()
verify
(
mod
,
(
golden_data
,
golden_output
))
def
downscale_test
():
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment