[Mlir-commits] [mlir] [TOSA] Usage of 32bit integer for 'index to float' in rfft2d (PR #75098)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Thu Dec 14 03:54:38 PST 2023


github-actions[bot] wrote:

<!--LLVM CODE FORMAT COMMENT: {clang-format}-->


:warning: C/C++ code formatter, clang-format found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
git-clang-format --diff 8592241e29e29f0e7e407e0989489c6e70c91c42 f055337dff55826eec4d7cbaaa4727f427cca603 -- mlir/lib/Conversion/TosaToLinalg/TosaToLinalg.cpp
``````````

</details>

<details>
<summary>
View the diff from clang-format here.
</summary>

``````````diff
diff --git a/mlir/lib/Conversion/TosaToLinalg/TosaToLinalg.cpp b/mlir/lib/Conversion/TosaToLinalg/TosaToLinalg.cpp
index 0ba5bca359..f224641a3a 100644
--- a/mlir/lib/Conversion/TosaToLinalg/TosaToLinalg.cpp
+++ b/mlir/lib/Conversion/TosaToLinalg/TosaToLinalg.cpp
@@ -2410,9 +2410,9 @@ for_each(0 <= n < N, 0 <= oy < H, 0 <= ox < W) {
     in_out_t sum_real = 0.0;
     in_out_t sum_imag = 0.0;
     for_each(0 <= iy < H, 0 <= ix < W) {
-        in_out_t val_real = tensor_read<in_out_t>(input_real, [N,H,W], [n,iy,ix]);
-        in_out_t val_imag = tensor_read<in_out_t>(input_imag, [N,H,W], [n,iy,ix]);
-        float_t a = sign_val * 2 * pi() * ((iy * oy) / H + (ix * ox) / W);
+        in_out_t val_real = tensor_read<in_out_t>(input_real, [N,H,W],
+[n,iy,ix]); in_out_t val_imag = tensor_read<in_out_t>(input_imag, [N,H,W],
+[n,iy,ix]); float_t a = sign_val * 2 * pi() * ((iy * oy) / H + (ix * ox) / W);
         sum_real += val_real * cos(a) + val_imag * sin(a);
         sum_imag += -val_real * sin(a) + val_imag * cos(a);
     }
@@ -2495,8 +2495,7 @@ struct FFT2dConverter final : public OpRewritePattern<FFT2dOp> {
                                 PatternRewriter &rewriter) const override {
     if (!llvm::all_of(fft2d->getOperandTypes(), isRankedTensor) ||
         !llvm::all_of(fft2d->getResultTypes(), isRankedTensor)) {
-      return rewriter.notifyMatchFailure(fft2d,
-                                         "only supports ranked tensors");
+      return rewriter.notifyMatchFailure(fft2d, "only supports ranked tensors");
     }
 
     auto loc = fft2d.getLoc();
@@ -2506,18 +2505,25 @@ struct FFT2dConverter final : public OpRewritePattern<FFT2dOp> {
 
     float sign_val = 1.0;
     if (inverse) {
-        sign_val = -1.0;
+      sign_val = -1.0;
     }
 
-    auto real_el_ty = input_real.getType().cast<ShapedType>().getElementType().cast<FloatType>();
-    auto imag_el_ty = input_imag.getType().cast<ShapedType>().getElementType().cast<FloatType>();
+    auto real_el_ty = input_real.getType()
+                          .cast<ShapedType>()
+                          .getElementType()
+                          .cast<FloatType>();
+    auto imag_el_ty = input_imag.getType()
+                          .cast<ShapedType>()
+                          .getElementType()
+                          .cast<FloatType>();
 
     assert(real_el_ty == imag_el_ty);
 
     // Compute the output type and set of dynamic sizes
     llvm::SmallVector<Value> dynamicSizes;
 
-    auto outputType = RankedTensorType::get(cast<ShapedType>(input_real.getType()).getShape(), real_el_ty);
+    auto outputType = RankedTensorType::get(
+        cast<ShapedType>(input_real.getType()).getShape(), real_el_ty);
 
     // Iterator types for the linalg.generic implementation
     llvm::SmallVector<utils::IteratorType, 5> iteratorTypes = {
@@ -2558,38 +2564,36 @@ struct FFT2dConverter final : public OpRewritePattern<FFT2dOp> {
       auto iy = createLinalgIndex(builder, loc, real_el_ty, 3);
       auto ix = createLinalgIndex(builder, loc, real_el_ty, 4);
       /*float_t a = sign_val * 2 * pi() * ((iy * oy) / H + (ix * ox) / W);*/
-                    // angle = 2 * pi() * ((iy * oy) / H + (ix * ox) / W)
+      // angle = 2 * pi() * ((iy * oy) / H + (ix * ox) / W)
       auto iyXoy = builder.create<arith::MulFOp>(loc, iy, oy);
       auto ixXox = builder.create<arith::MulFOp>(loc, ix, ox);
       auto yComponent = builder.create<arith::DivFOp>(loc, iyXoy, constH);
       auto xComponent = builder.create<arith::DivFOp>(loc, ixXox, constW);
       auto sumXY = builder.create<arith::AddFOp>(loc, yComponent, xComponent);
       auto angle = builder.create<arith::MulFOp>(loc, twoPi, sumXY);
-      if( inverse.getValue() ) {
-          angle = builder.create<arith::MulFOp>(loc, angle, rewriter.create<arith::ConstantOp>(loc, rewriter.getFloatAttr(real_el_ty, -1.0)));
+      if (inverse.getValue()) {
+        angle = builder.create<arith::MulFOp>(
+            loc, angle,
+            rewriter.create<arith::ConstantOp>(
+                loc, rewriter.getFloatAttr(real_el_ty, -1.0)));
       }
-/*
-      sum_real += val_real * cos(a) + val_imag * sin(a);
-      sum_imag += -val_real * sin(a) + val_imag * cos(a);
-*/
+      /*
+            sum_real += val_real * cos(a) + val_imag * sin(a);
+            sum_imag += -val_real * sin(a) + val_imag * cos(a);
+      */
       // realComponent = valReal * cos(angle)
       // imagComponent = valReal * sin(angle)
       auto cosAngle = builder.create<math::CosOp>(loc, angle);
       auto sinAngle = builder.create<math::SinOp>(loc, angle);
 
-      auto rcos =
-          builder.create<arith::MulFOp>(loc, valReal, cosAngle);
-      auto rsin =
-          builder.create<arith::MulFOp>(loc, valImag, sinAngle);
+      auto rcos = builder.create<arith::MulFOp>(loc, valReal, cosAngle);
+      auto rsin = builder.create<arith::MulFOp>(loc, valImag, sinAngle);
       auto realComponent = builder.create<arith::AddFOp>(loc, rcos, rsin);
 
-      auto icos =
-          builder.create<arith::MulFOp>(loc, valImag, cosAngle);
-      auto isin =
-          builder.create<arith::MulFOp>(loc, valReal, sinAngle);
+      auto icos = builder.create<arith::MulFOp>(loc, valImag, cosAngle);
+      auto isin = builder.create<arith::MulFOp>(loc, valReal, sinAngle);
 
-      auto imagComponent =
-          builder.create<arith::SubFOp>(loc, icos, isin);
+      auto imagComponent = builder.create<arith::SubFOp>(loc, icos, isin);
 
       // outReal = sumReal + realComponent
       // outImag = sumImag - imagComponent

``````````

</details>


https://github.com/llvm/llvm-project/pull/75098


More information about the Mlir-commits mailing list