Skip to content

Commit fc0e5ac

Browse files
[DispatchCreation] Skip Pad decomposition within dispatches. (iree-org#20373)
If a pad is already in a dispatch it shouldn't be decomposed. That is effectively user assertion to not decompose the pad. Signed-off-by: MaheshRavishankar <mahesh.ravishankar@gmail.com>
1 parent 3971291 commit fc0e5ac

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

compiler/src/iree/compiler/DispatchCreation/TensorPadToTensorInsertSlice.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
//===----------------------------------------------------------------------===//
1212

1313
#include "iree/compiler/Dialect/Encoding/IR/EncodingOps.h"
14+
#include "iree/compiler/Dialect/Flow/Transforms/RegionOpUtils.h"
1415
#include "iree/compiler/DispatchCreation/Passes.h"
1516
#include "mlir/Dialect/Affine/IR/AffineOps.h"
1617
#include "mlir/Dialect/Arith/IR/Arith.h"
@@ -41,6 +42,9 @@ struct TensorPadOpConversion : public OpRewritePattern<tensor::PadOp> {
4142

4243
LogicalResult matchAndRewrite(tensor::PadOp padTensorOp,
4344
PatternRewriter &rewriter) const override {
45+
if (!IREE::Flow::isNonNullAndOutsideDispatch(padTensorOp)) {
46+
return failure();
47+
}
4448
// Check that the region is just a yield operation which is returning a
4549
// scalar that is not one of the arguments of the linalg operation.
4650
Region &region = padTensorOp.getRegion();

compiler/src/iree/compiler/DispatchCreation/test/tensor_pad_to_tensor_insert_slice.mlir

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ util.func public @_main(%arg0: tensor<1x33x33x480xf32>, %arg1: tensor<3x3x480x1x
7777
// CHECK-NOT: tensor.pad
7878
// SKIP: tensor.pad
7979

80-
// ----
80+
// -----
8181

8282
#encoding = #iree_encoding.testing_encoding<>
8383
util.func public @dispatch_dispatch_0_generic_512x1024_f32(
@@ -105,3 +105,24 @@ util.func public @dispatch_dispatch_0_generic_512x1024_f32(
105105
// CHECK: %[[PAD:.+]] = tensor.pad %[[LOAD]] low
106106
// CHECK: %[[ENCODE:.+]] = iree_encoding.set_encoding %[[PAD]] : tensor<?x?xf32> -> tensor<?x?xf32, #[[ENCODING]]>
107107
// CHECK: flow.dispatch.tensor.store %[[ENCODE]],
108+
109+
// -----
110+
111+
// Do not break up pad within dispatches.
112+
113+
util.func @pad_within_dispatch(%arg0 : tensor<500x1000xf32>) -> tensor<512x1024xf32> {
114+
%cst = arith.constant 0.0 : f32
115+
%0 = flow.dispatch.region -> (tensor<512x1024xf32>) {
116+
%1 = tensor.pad %arg0 low [0, 0] high[12, 24] {
117+
^bb0(%arg1 : index, %arg2 : index):
118+
tensor.yield %cst : f32
119+
} : tensor<500x1000xf32> to tensor<512x1024xf32>
120+
flow.return %1 : tensor<512x1024xf32>
121+
}
122+
util.return %0 : tensor<512x1024xf32>
123+
}
124+
// CHECK-LABEL: func public @pad_within_dispatch
125+
// CHECK: %[[DISPATCH:.+]] = flow.dispatch.region
126+
// CHECK: %[[PAD:.+]] = tensor.pad
127+
// CHECK: flow.return %[[PAD]]
128+
// CHECK: return %[[DISPATCH]]

0 commit comments

Comments
 (0)