Skip to content

Commit 1c9b6e2

Browse files
authored
Merge pull request #201 from Xilinx/release_rai_1_2
Release rai 1 2
2 parents fb1143c + f951d24 commit 1c9b6e2

File tree

2 files changed

+39
-4
lines changed

2 files changed

+39
-4
lines changed

mlir/lib/Dialect/Tosa/IR/TosaCanonicalizations.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,12 @@ struct SqrtReciprocalOptimization : public OpRewritePattern<tosa::PowOp> {
9999
// An improvement for the future would be to generate a tile operator here instead
100100
if (inputType != outputType)
101101
return rewriter.notifyMatchFailure(op, "input type and output type are different, tiling is not supported for this canonicalization");
102-
103-
rewriter.replaceOpWithNewOp<tosa::RsqrtOp>(user, outputType, op.getInput1());
104102

103+
auto rsqrtOp = rewriter.create<tosa::RsqrtOp>(
104+
rewriter.getFusedLoc({op.getLoc(), user->getLoc()}), outputType,
105+
op.getInput1());
106+
rewriter.replaceOp(user, rsqrtOp);
107+
105108
return success();
106109
}
107110
};

mlir/test/Dialect/Tosa/canonicalize_with_debuginfo.mlir

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: mlir-opt -mlir-print-debuginfo -canonicalize="test-convergence" %s | FileCheck %s
1+
// RUN: mlir-opt -split-input-file -mlir-print-debuginfo -canonicalize="test-convergence" %s | FileCheck %s
22

33
// CHECK-LABEL: @clamp_twice_is_single_clamp
44
func.func @clamp_twice_is_single_clamp(%arg0: tensor<4xi8>) -> tensor<4xi8> {
@@ -11,4 +11,36 @@ func.func @clamp_twice_is_single_clamp(%arg0: tensor<4xi8>) -> tensor<4xi8> {
1111
return %1 : tensor<4xi8>
1212
}
1313
#loc0 = loc("Clamp_A")
14-
#loc1 = loc("Clamp_B")
14+
#loc1 = loc("Clamp_B")
15+
16+
// -----
17+
18+
// CHECK-LABEL: @canonicalize_optimize_sqrt_reciprocal
19+
func.func @canonicalize_optimize_sqrt_reciprocal_with_debinfo(%arg0: tensor<1x5x1x1xf32>) -> tensor<1x5x1x1xf32> {
20+
// CHECK: %[[RSQRT:.*]] = tosa.rsqrt %arg{{.*}} : (tensor<1x5x1x1xf32>) -> tensor<1x5x1x1xf32> loc([[LOC:.*]])
21+
// CHECK-DAG: #[[A:.*]] = loc("Pow_A")
22+
// CHECK-DAG: #[[B:.*]] = loc("Reciprocal_B")
23+
// CHECK-DAG: [[LOC]] = loc(fused[#[[A]], #[[B]]])
24+
%0 = "tosa.const"() <{value = dense<5.000000e-01> : tensor<1x1x1x1xf32>}> : () -> tensor<1x1x1x1xf32>
25+
%1 = tosa.pow %arg0, %0 : (tensor<1x5x1x1xf32>, tensor<1x1x1x1xf32>) -> tensor<1x5x1x1xf32> loc(#loc0)
26+
%2 = tosa.reciprocal %1 : (tensor<1x5x1x1xf32>) -> tensor<1x5x1x1xf32> loc(#loc1)
27+
return %2 : tensor<1x5x1x1xf32>
28+
}
29+
#loc0 = loc("Pow_A")
30+
#loc1 = loc("Reciprocal_B")
31+
32+
// -----
33+
34+
// CHECK-LABEL: @canonicalize_optimize_sqrt_reciprocal
35+
func.func @canonicalize_optimize_sqrt_reciprocal_bf16(%arg0: tensor<1x5x1x1xbf16>) -> tensor<1x5x1x1xbf16> {
36+
// CHECK: %[[RSQRT:.*]] = tosa.rsqrt %arg{{.*}} : (tensor<1x5x1x1xbf16>) -> tensor<1x5x1x1xbf16> loc([[LOC:.*]])
37+
// CHECK-DAG: #[[A:.*]] = loc("Pow_B")
38+
// CHECK-DAG: #[[B:.*]] = loc("Reciprocal_C")
39+
// CHECK-DAG: [[LOC]] = loc(fused[#[[A]], #[[B]]])
40+
%0 = "tosa.const"() <{value = dense<5.000000e-01> : tensor<1x1x1x1xbf16>}> : () -> tensor<1x1x1x1xbf16>
41+
%1 = tosa.pow %arg0, %0 : (tensor<1x5x1x1xbf16>, tensor<1x1x1x1xbf16>) -> tensor<1x5x1x1xbf16> loc(#loc0)
42+
%2 = tosa.reciprocal %1 : (tensor<1x5x1x1xbf16>) -> tensor<1x5x1x1xbf16> loc(#loc1)
43+
return %2 : tensor<1x5x1x1xbf16>
44+
}
45+
#loc0 = loc("Pow_B")
46+
#loc1 = loc("Reciprocal_C")

0 commit comments

Comments
 (0)