Skip to content

Commit a18ab3f

Browse files
committed
[mlir][tosa] Stop folding pad into avg_pool2d
Keep explicit padding ahead of tosa.avg_pool2d to preserve semantics. Folding a pad into the op drops padded values from the average divisor. Change-Id: I229bbdc0a8ef5d4ff4c6942788614c55593ce30f
1 parent d10af9d commit a18ab3f

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -247,9 +247,8 @@ struct FoldPadToTensorOp : public OpRewritePattern<OpTy> {
247247

248248
void AvgPool2dOp::getCanonicalizationPatterns(RewritePatternSet &results,
249249
MLIRContext *context) {
250-
results.add<FoldPadToTensorOp<tosa::AvgPool2dOp,
251-
PoolPadFoldAdaptor<tosa::AvgPool2dOp>>>(
252-
context);
250+
(void)results;
251+
(void)context;
253252
}
254253

255254
void Conv2DOp::getCanonicalizationPatterns(RewritePatternSet &results,

mlir/test/Dialect/Tosa/canonicalize.mlir

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ func.func @argmax_nofold(%arg0: tensor<?x1xf32>) -> tensor<1xi32> {
99

1010
// -----
1111

12-
// CHECK-LABEL: @pad_wh_avg_pool2d_fold
13-
func.func @pad_wh_avg_pool2d_fold(%input: tensor<1x10x8x3xf32>) -> tensor<1x6x5x3xf32> {
14-
// CHECK-NOT: tosa.pad
12+
// CHECK-LABEL: @pad_wh_avg_pool2d_nofold
13+
func.func @pad_wh_avg_pool2d_nofold(%input: tensor<1x10x8x3xf32>) -> tensor<1x6x5x3xf32> {
14+
// CHECK: tosa.pad
1515
// CHECK: tosa.avg_pool2d
16-
// CHECK-SAME: pad = array<i64: 1, 1, 1, 1>
16+
// CHECK-SAME: pad = array<i64: 0, 1, 0, 1>
1717
%pad_shape = tosa.const_shape { values = dense<[0, 0, 1, 0, 1, 0, 0, 0]> : tensor<8xindex>} : () -> !tosa.shape<8>
1818
%pad_const = "tosa.const"() <{values = dense<0.0> : tensor<1xf32>}> : ()-> tensor<1xf32>
1919
%input_zp = "tosa.const"() <{values = dense<0.0> : tensor<1xf32>}> : ()-> tensor<1xf32>

0 commit comments

Comments
 (0)