Skip to content

Commit b387d2c

Browse files
author
git apple-llvm automerger
committed
Merge commit 'e04f4cce85e0' from llvm.org/main into next
2 parents 9e574fd + e04f4cc commit b387d2c

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

mlir/include/mlir/Dialect/Tosa/Utils/QuantUtils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ namespace tosa {
2828

2929
/// From a scale value, computes multiplier and shift values
3030
/// for 16 or 32-bit scale widths.
31-
void computeMultiplierAndShift(double scale, int32_t &multiplier,
31+
bool computeMultiplierAndShift(double scale, int32_t &multiplier,
3232
int32_t &shift, int32_t scaleWidth);
3333

3434
//// Builds ConvOpQuantizationAttr from input and weight.

mlir/lib/Dialect/Tosa/Utils/QuantUtils.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,18 +92,25 @@ static void computeMultiplierAndShiftTosaScale32(double scale,
9292
}
9393

9494
/// Generates a quantized multiplier/shift from double.
95-
void mlir::tosa::computeMultiplierAndShift(double scale, int32_t &multiplier,
95+
bool mlir::tosa::computeMultiplierAndShift(double scale, int32_t &multiplier,
9696
int32_t &shift, int32_t scaleWidth) {
9797

9898
switch (scaleWidth) {
9999
case 16:
100100
computeMultiplierAndShiftTosaScale16(scale, multiplier, shift);
101-
return;
101+
102+
// In some cases computeMultiplierAndShiftTosaScale16 can return
103+
// a value less then 2, which is not valid in the TOSA spec.
104+
return (!(shift < 2));
102105
case 32:
103106
computeMultiplierAndShiftTosaScale32(scale, multiplier, shift);
104-
return;
107+
108+
// In some cases computeMultiplierAndShiftTosaScale32 can return
109+
// a value less then 2, which is not valid in the TOSA spec.
110+
return (!(shift < 2));
105111
default:
106112
assert(0 && "Unsupported Tosa quantized_scale regime specified!");
113+
return false;
107114
}
108115
}
109116

mlir/test/lib/Dialect/Tosa/TosaTestPasses.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,8 @@ ConvertTosaConv2DOp::matchAndRewrite(Operation *op,
163163
int32_t shift;
164164

165165
// Obtain the quantized scale = multiplier and shift.
166-
computeMultiplierAndShift(opTensorScale, multiplier, shift, 32);
166+
if (!computeMultiplierAndShift(opTensorScale, multiplier, shift, 32))
167+
return failure();
167168

168169
bool input_unsigned =
169170
newTosaConv2DOp.getResult().getType().isUnsignedInteger();

0 commit comments

Comments
 (0)