diff --git a/integration_tests/models/8x8/test_sub/1.sh b/integration_tests/models/8x8/test_sub/1.sh new file mode 100755 index 000000000..4a264cea1 --- /dev/null +++ b/integration_tests/models/8x8/test_sub/1.sh @@ -0,0 +1,6 @@ +cp $1 /tmp/ +xcore-opt /tmp/$1 --lce-translate-tfl --mlir-print-ir-after-all -o /tmp/1.tflite >/tmp/1.mlir 2>&1 +cat /tmp/1.mlir | grep -v Tensor > /tmp/2.mlir +sed -i -e 's/tfl.add/tfl.sub/g' /tmp/2.mlir +xcore-opt --mlir-io --lce-translate-tfl /tmp/2.mlir -o /tmp/t.tflite +cp /tmp/t.tflite $1 diff --git a/integration_tests/models/8x8/test_sub/test_sub_0.tflite b/integration_tests/models/8x8/test_sub/test_sub_0.tflite new file mode 100644 index 000000000..3a3ed2e5c Binary files /dev/null and b/integration_tests/models/8x8/test_sub/test_sub_0.tflite differ diff --git a/integration_tests/models/8x8/test_sub/test_sub_1.tflite b/integration_tests/models/8x8/test_sub/test_sub_1.tflite new file mode 100644 index 000000000..933426f7a Binary files /dev/null and b/integration_tests/models/8x8/test_sub/test_sub_1.tflite differ diff --git a/integration_tests/models/8x8/test_sub/test_sub_10.tflite b/integration_tests/models/8x8/test_sub/test_sub_10.tflite new file mode 100644 index 000000000..c602e8ee8 Binary files /dev/null and b/integration_tests/models/8x8/test_sub/test_sub_10.tflite differ diff --git a/integration_tests/models/8x8/test_sub/test_sub_11.tflite b/integration_tests/models/8x8/test_sub/test_sub_11.tflite new file mode 100644 index 000000000..bd73d3a34 Binary files /dev/null and b/integration_tests/models/8x8/test_sub/test_sub_11.tflite differ diff --git a/integration_tests/models/8x8/test_sub/test_sub_12.tflite b/integration_tests/models/8x8/test_sub/test_sub_12.tflite new file mode 100644 index 000000000..1c983b9f0 Binary files /dev/null and b/integration_tests/models/8x8/test_sub/test_sub_12.tflite differ diff --git a/integration_tests/models/8x8/test_sub/test_sub_13.tflite b/integration_tests/models/8x8/test_sub/test_sub_13.tflite new file mode 100644 index 000000000..c388b3ce0 Binary files /dev/null and b/integration_tests/models/8x8/test_sub/test_sub_13.tflite differ diff --git a/integration_tests/models/8x8/test_sub/test_sub_14.tflite b/integration_tests/models/8x8/test_sub/test_sub_14.tflite new file mode 100644 index 000000000..70caf0c7f Binary files /dev/null and b/integration_tests/models/8x8/test_sub/test_sub_14.tflite differ diff --git a/integration_tests/models/8x8/test_sub/test_sub_15.tflite b/integration_tests/models/8x8/test_sub/test_sub_15.tflite new file mode 100644 index 000000000..9750f9b06 Binary files /dev/null and b/integration_tests/models/8x8/test_sub/test_sub_15.tflite differ diff --git a/integration_tests/models/8x8/test_sub/test_sub_16.tflite b/integration_tests/models/8x8/test_sub/test_sub_16.tflite new file mode 100644 index 000000000..81a1e3ceb Binary files /dev/null and b/integration_tests/models/8x8/test_sub/test_sub_16.tflite differ diff --git a/integration_tests/models/8x8/test_sub/test_sub_17.tflite b/integration_tests/models/8x8/test_sub/test_sub_17.tflite new file mode 100644 index 000000000..3a3493806 Binary files /dev/null and b/integration_tests/models/8x8/test_sub/test_sub_17.tflite differ diff --git a/integration_tests/models/8x8/test_sub/test_sub_18.tflite b/integration_tests/models/8x8/test_sub/test_sub_18.tflite new file mode 100644 index 000000000..8ec012fbf Binary files /dev/null and b/integration_tests/models/8x8/test_sub/test_sub_18.tflite differ diff --git a/integration_tests/models/8x8/test_sub/test_sub_19.tflite b/integration_tests/models/8x8/test_sub/test_sub_19.tflite new file mode 100644 index 000000000..5cde7b1e5 Binary files /dev/null and b/integration_tests/models/8x8/test_sub/test_sub_19.tflite differ diff --git a/integration_tests/models/8x8/test_sub/test_sub_2.tflite b/integration_tests/models/8x8/test_sub/test_sub_2.tflite new file mode 100644 index 000000000..578db1d86 Binary files /dev/null and b/integration_tests/models/8x8/test_sub/test_sub_2.tflite differ diff --git a/integration_tests/models/8x8/test_sub/test_sub_3.tflite b/integration_tests/models/8x8/test_sub/test_sub_3.tflite new file mode 100644 index 000000000..725acfdd7 Binary files /dev/null and b/integration_tests/models/8x8/test_sub/test_sub_3.tflite differ diff --git a/integration_tests/models/8x8/test_sub/test_sub_4.tflite b/integration_tests/models/8x8/test_sub/test_sub_4.tflite new file mode 100644 index 000000000..7bf123c24 Binary files /dev/null and b/integration_tests/models/8x8/test_sub/test_sub_4.tflite differ diff --git a/integration_tests/models/8x8/test_sub/test_sub_41.tflite b/integration_tests/models/8x8/test_sub/test_sub_41.tflite new file mode 100644 index 000000000..bf1466c48 Binary files /dev/null and b/integration_tests/models/8x8/test_sub/test_sub_41.tflite differ diff --git a/integration_tests/models/8x8/test_sub/test_sub_42.tflite b/integration_tests/models/8x8/test_sub/test_sub_42.tflite new file mode 100644 index 000000000..c8fdf4a0b Binary files /dev/null and b/integration_tests/models/8x8/test_sub/test_sub_42.tflite differ diff --git a/integration_tests/models/8x8/test_sub/test_sub_43.tflite b/integration_tests/models/8x8/test_sub/test_sub_43.tflite new file mode 100644 index 000000000..937fe3022 Binary files /dev/null and b/integration_tests/models/8x8/test_sub/test_sub_43.tflite differ diff --git a/integration_tests/models/8x8/test_sub/test_sub_44.tflite b/integration_tests/models/8x8/test_sub/test_sub_44.tflite new file mode 100644 index 000000000..70feb7854 Binary files /dev/null and b/integration_tests/models/8x8/test_sub/test_sub_44.tflite differ diff --git a/integration_tests/models/8x8/test_sub/test_sub_45.tflite b/integration_tests/models/8x8/test_sub/test_sub_45.tflite new file mode 100644 index 000000000..ad4b49749 Binary files /dev/null and b/integration_tests/models/8x8/test_sub/test_sub_45.tflite differ diff --git a/integration_tests/models/8x8/test_sub/test_sub_46.tflite b/integration_tests/models/8x8/test_sub/test_sub_46.tflite new file mode 100644 index 000000000..f41c031dd Binary files /dev/null and b/integration_tests/models/8x8/test_sub/test_sub_46.tflite differ diff --git a/integration_tests/models/8x8/test_sub/test_sub_47.tflite b/integration_tests/models/8x8/test_sub/test_sub_47.tflite new file mode 100644 index 000000000..8efac2d57 Binary files /dev/null and b/integration_tests/models/8x8/test_sub/test_sub_47.tflite differ diff --git a/integration_tests/models/8x8/test_sub/test_sub_5.tflite b/integration_tests/models/8x8/test_sub/test_sub_5.tflite new file mode 100644 index 000000000..ca3e769c4 Binary files /dev/null and b/integration_tests/models/8x8/test_sub/test_sub_5.tflite differ diff --git a/integration_tests/models/8x8/test_sub/test_sub_6.tflite b/integration_tests/models/8x8/test_sub/test_sub_6.tflite new file mode 100644 index 000000000..ddd3ced2c Binary files /dev/null and b/integration_tests/models/8x8/test_sub/test_sub_6.tflite differ diff --git a/integration_tests/models/8x8/test_sub/test_sub_7.tflite b/integration_tests/models/8x8/test_sub/test_sub_7.tflite new file mode 100644 index 000000000..3332f8c48 Binary files /dev/null and b/integration_tests/models/8x8/test_sub/test_sub_7.tflite differ diff --git a/integration_tests/models/8x8/test_sub/test_sub_8.tflite b/integration_tests/models/8x8/test_sub/test_sub_8.tflite new file mode 100644 index 000000000..397d94544 Binary files /dev/null and b/integration_tests/models/8x8/test_sub/test_sub_8.tflite differ diff --git a/integration_tests/models/8x8/test_sub/test_sub_9.tflite b/integration_tests/models/8x8/test_sub/test_sub_9.tflite new file mode 100644 index 000000000..89143cff6 Binary files /dev/null and b/integration_tests/models/8x8/test_sub/test_sub_9.tflite differ diff --git a/integration_tests/models/8x8/test_sub/test_sub_dual_output.tflite b/integration_tests/models/8x8/test_sub/test_sub_dual_output.tflite new file mode 100644 index 000000000..cf3bea545 Binary files /dev/null and b/integration_tests/models/8x8/test_sub/test_sub_dual_output.tflite differ diff --git a/xformer/Transforms/ReplaceAddSub.cpp b/xformer/Transforms/ReplaceAddSub.cpp index 7d0335463..b7bf738c6 100644 --- a/xformer/Transforms/ReplaceAddSub.cpp +++ b/xformer/Transforms/ReplaceAddSub.cpp @@ -39,7 +39,7 @@ LogicalResult replaceAddorSub(T addOp, PatternRewriter &rewriter, auto lhsZeroPoint = lhsQType.getZeroPoint(); auto rhsQType = utils::getQType(addOp.getRhs()); - auto rhsScale = negateForSub ? -rhsQType.getScale() : rhsQType.getScale(); + auto rhsScale = rhsQType.getScale(); auto rhsZeroPoint = rhsQType.getZeroPoint(); auto outputQType = utils::getQType(addOp.getOutput()); @@ -55,6 +55,9 @@ LogicalResult replaceAddorSub(T addOp, PatternRewriter &rewriter, // We want the max shift to be 14 bits int shift = int(floor(log2(pow(2, 14) / maxR))); + // For doing subtraction with add op + rhsRatio = negateForSub? -rhsRatio: rhsRatio; + // Multipliers are converted to fixed-point int m1 = round(lhsRatio * pow(2, shift)); int m2 = round(rhsRatio * pow(2, shift));