[Mlir-commits] [mlir] 8e7630e - [mlir][tosa] Fix tosa.resize for i48 accumulator
Rob Suderman
llvmlistbot at llvm.org
Wed Dec 7 11:28:24 PST 2022
Author: Rob Suderman
Date: 2022-12-07T11:27:33-08:00
New Revision: 8e7630ece1250bc40be78ba17ac5823c1d678f77
URL: https://github.com/llvm/llvm-project/commit/8e7630ece1250bc40be78ba17ac5823c1d678f77
DIFF: https://github.com/llvm/llvm-project/commit/8e7630ece1250bc40be78ba17ac5823c1d678f77.diff
LOG: [mlir][tosa] Fix tosa.resize for i48 accumulator
Implementation assumed a i32 accumulator. Fixed the implementation to
work with an i32 accumulator.
Reviewed By: NatashaKnk
Differential Revision: https://reviews.llvm.org/D139365
Added:
Modified:
mlir/lib/Conversion/TosaToLinalg/TosaToLinalg.cpp
mlir/test/Conversion/TosaToLinalg/tosa-to-linalg-resize.mlir
Removed:
################################################################################
diff --git a/mlir/lib/Conversion/TosaToLinalg/TosaToLinalg.cpp b/mlir/lib/Conversion/TosaToLinalg/TosaToLinalg.cpp
index 3c74da1e939d9..abe5f53374813 100644
--- a/mlir/lib/Conversion/TosaToLinalg/TosaToLinalg.cpp
+++ b/mlir/lib/Conversion/TosaToLinalg/TosaToLinalg.cpp
@@ -1681,13 +1681,24 @@ class GenericResizeConverter : public OpRewritePattern<tosa::ResizeOp> {
dy = rewriter.create<arith::ExtSIOp>(loc, resultElementTy, dy);
}
+ Value xScaleNExt = xScaleN;
+ Value yScaleNExt = yScaleN;
+
+ if (xScaleN.getType() != resultElementTy)
+ xScaleNExt =
+ rewriter.create<arith::ExtSIOp>(loc, resultElementTy, xScaleN);
+
+ if (yScaleN.getType() != resultElementTy)
+ yScaleNExt =
+ rewriter.create<arith::ExtSIOp>(loc, resultElementTy, yScaleN);
+
Value topAcc, bottomAcc;
if (imageW == 1) {
- topAcc = rewriter.create<arith::MulIOp>(loc, y0x0, xScaleN);
- bottomAcc = rewriter.create<arith::MulIOp>(loc, y1x0, xScaleN);
+ topAcc = rewriter.create<arith::MulIOp>(loc, y0x0, xScaleNExt);
+ bottomAcc = rewriter.create<arith::MulIOp>(loc, y1x0, xScaleNExt);
} else {
Value rightPart = dx;
- Value leftPart = rewriter.create<arith::SubIOp>(loc, xScaleN, dx);
+ Value leftPart = rewriter.create<arith::SubIOp>(loc, xScaleNExt, dx);
y0x0 = rewriter.create<arith::MulIOp>(loc, y0x0, leftPart);
y0x1 = rewriter.create<arith::MulIOp>(loc, y0x1, rightPart);
@@ -1700,10 +1711,10 @@ class GenericResizeConverter : public OpRewritePattern<tosa::ResizeOp> {
Value result;
if (imageH == 1) {
- result = rewriter.create<arith::MulIOp>(loc, topAcc, yScaleN);
+ result = rewriter.create<arith::MulIOp>(loc, topAcc, yScaleNExt);
} else {
Value bottomPart = dy;
- Value topPart = rewriter.create<arith::SubIOp>(loc, yScaleN, dy);
+ Value topPart = rewriter.create<arith::SubIOp>(loc, yScaleNExt, dy);
topAcc = rewriter.create<arith::MulIOp>(loc, topAcc, topPart);
bottomAcc =
rewriter.create<arith::MulIOp>(loc, bottomAcc, bottomPart);
diff --git a/mlir/test/Conversion/TosaToLinalg/tosa-to-linalg-resize.mlir b/mlir/test/Conversion/TosaToLinalg/tosa-to-linalg-resize.mlir
index f9bfb4d073135..3582b6f254217 100644
--- a/mlir/test/Conversion/TosaToLinalg/tosa-to-linalg-resize.mlir
+++ b/mlir/test/Conversion/TosaToLinalg/tosa-to-linalg-resize.mlir
@@ -484,3 +484,11 @@ func.func @resize_dyn(%input: tensor<?x2x2x1xi8>) -> () {
%output = "tosa.resize"(%input) { scale = [4, 2, 4, 2], offset = [-1, -1], border = [1, 1], mode = "BILINEAR" } : (tensor<?x2x2x1xi8>) -> (tensor<?x4x4x1xi32>)
return
}
+
+// -----
+
+// CHECK-LABEL: @resize_bilinear_int48
+func.func @resize_bilinear_int48(%arg0: tensor<1x19x19x1xi16>) {
+ %0 = "tosa.resize"(%arg0) {mode = "BILINEAR", scale = [16, 1, 16, 1], offset = [0, 0], border = [0, 0]} : (tensor<1x19x19x1xi16>) -> tensor<1x289x289x1xi48>
+ return
+}
More information about the Mlir-commits
mailing list