anijain2305 commented on a change in pull request #6675:
URL: https://github.com/apache/incubator-tvm/pull/6675#discussion_r503645960



##########
File path: src/relay/qnn/op/requantize.cc
##########
@@ -155,17 +155,20 @@ Expr RequantizeLower(const Expr& input_tensor, const 
Expr& input_scale,
     if (!IsEqualScalar(input_scale, output_scale)) {
       int32_t fixed_point_multiplier, shift;
       std::tie(fixed_point_multiplier, shift) = 
GetFixedPointMultiplierShift(double_multiplier);
-
       const bool is_upward_rounding = (param->rounding == "UPWARD");
 
-      // When using upward rounding (i.e., x.5 rounded to x+1), leverage
-      // the FixedPointMultiply operator
-      scaled_int32_t =
-          (is_upward_rounding
-               ? FixedPointMultiply(scaled_int32_t, fixed_point_multiplier, 
shift)
-               : FixedPointMultiplyToNearest(scaled_int32_t, 
double_multiplier, input_shape));
+      if (is_upward_rounding && fixed_point_multiplier == (1 << 30)) {

Review comment:
       So, we use 'frexp' to represent a floating point numbers. It gives a 
float significant which is between [0.5, 1). For power of 2, it is always 0.5. 
We convert the float significand into a fixed point 32-bit integer, where 
decimal point is between the first and second bit. 0.5 in this representation = 
1 << 30

##########
File path: src/relay/qnn/op/requantize.cc
##########
@@ -155,17 +155,20 @@ Expr RequantizeLower(const Expr& input_tensor, const 
Expr& input_scale,
     if (!IsEqualScalar(input_scale, output_scale)) {
       int32_t fixed_point_multiplier, shift;
       std::tie(fixed_point_multiplier, shift) = 
GetFixedPointMultiplierShift(double_multiplier);
-
       const bool is_upward_rounding = (param->rounding == "UPWARD");
 
-      // When using upward rounding (i.e., x.5 rounded to x+1), leverage
-      // the FixedPointMultiply operator
-      scaled_int32_t =
-          (is_upward_rounding
-               ? FixedPointMultiply(scaled_int32_t, fixed_point_multiplier, 
shift)
-               : FixedPointMultiplyToNearest(scaled_int32_t, 
double_multiplier, input_shape));
+      if (is_upward_rounding && fixed_point_multiplier == (1 << 30)) {

Review comment:
       So, we use `frexp` to represent a floating point numbers. It gives a 
float significant which is between [0.5, 1). For power of 2, it is always 0.5. 
We convert the float significand into a fixed point 32-bit integer, where 
decimal point is between the first and second bit. 0.5 in this representation = 
1 << 30




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to