[llvm-branch-commits] [mlir] [mlir][transform] Drop redundant padding_dimensions spec from pad_tiling_interface (PR #145257)
https://github.com/nicolasvasilache updated
https://github.com/llvm/llvm-project/pull/145257
>From 2f1558ae8c1c90a6091dbc821fd5438f5136b8ae Mon Sep 17 00:00:00 2001
From: Nicolas Vasilache
Date: Wed, 18 Jun 2025 19:14:31 +0200
Subject: [PATCH 1/2] [mlir][transform] Plumb a simplified form of AffineMin
folding into transform.pad-tiling-interface
This revision introduces a simple variant of AffineMin folding in
makeComposedFoldedAffineApply
and makes use of it in transform.pad-tiling-interface.
Since this version explicitly call ValueBoundsInterface, it may be too
expensive and is
only activate behind a flag.
It results in better foldings when mixing tiling and padding, including with
dynamic shapes.
This should be further composed with #145068 to provide full simplification and
address
the remaining TODO in the test.
---
.../mlir/Dialect/Affine/IR/AffineOps.h| 18 ++-
.../mlir/Interfaces/ValueBoundsOpInterface.h | 2 +-
mlir/lib/Dialect/Affine/IR/AffineOps.cpp | 134 ++
.../Linalg/Transforms/PadTilingInterface.cpp | 5 +-
.../lib/Interfaces/ValueBoundsOpInterface.cpp | 2 +-
...m-op-pad-tiling-interface-multiple-of.mlir | 131 +
6 files changed, 251 insertions(+), 41 deletions(-)
diff --git a/mlir/include/mlir/Dialect/Affine/IR/AffineOps.h
b/mlir/include/mlir/Dialect/Affine/IR/AffineOps.h
index 6fdb72c370e6d..2091faa6b0b02 100644
--- a/mlir/include/mlir/Dialect/Affine/IR/AffineOps.h
+++ b/mlir/include/mlir/Dialect/Affine/IR/AffineOps.h
@@ -410,9 +410,11 @@ void canonicalizeSetAndOperands(IntegerSet *set,
/// other AffineApplyOps supplying those operands. The operands of the
resulting
/// AffineApplyOp do not change the length of AffineApplyOp chains.
AffineApplyOp makeComposedAffineApply(OpBuilder &b, Location loc, AffineMap
map,
- ArrayRef operands);
+ ArrayRef operands,
+ bool composeAffineMin = false);
AffineApplyOp makeComposedAffineApply(OpBuilder &b, Location loc, AffineExpr e,
- ArrayRef operands);
+ ArrayRef operands,
+ bool composeAffineMin = false);
/// Constructs an AffineApplyOp that applies `map` to `operands` after
composing
/// the map with the maps of any other AffineApplyOp supplying the operands,
@@ -421,16 +423,19 @@ AffineApplyOp makeComposedAffineApply(OpBuilder &b,
Location loc, AffineExpr e,
/// map.
OpFoldResult makeComposedFoldedAffineApply(OpBuilder &b, Location loc,
AffineMap map,
- ArrayRef operands);
+ ArrayRef operands,
+ bool composeAffineMin = false);
/// Variant of `makeComposedFoldedAffineApply` that applies to an expression.
OpFoldResult makeComposedFoldedAffineApply(OpBuilder &b, Location loc,
AffineExpr expr,
- ArrayRef operands);
+ ArrayRef operands,
+ bool composeAffineMin = false);
/// Variant of `makeComposedFoldedAffineApply` suitable for multi-result maps.
/// Note that this may create as many affine.apply operations as the map has
/// results given that affine.apply must be single-result.
SmallVector makeComposedFoldedMultiResultAffineApply(
-OpBuilder &b, Location loc, AffineMap map, ArrayRef
operands);
+OpBuilder &b, Location loc, AffineMap map, ArrayRef operands,
+bool composeAffineMin = false);
/// Returns an AffineMinOp obtained by composing `map` and `operands` with
/// AffineApplyOps supplying those operands.
@@ -459,7 +464,8 @@ OpFoldResult makeComposedFoldedAffineMax(OpBuilder &b,
Location loc,
/// terminal symbol, i.e., a symbol defined at the top level or a
block/function
/// argument.
void fullyComposeAffineMapAndOperands(AffineMap *map,
- SmallVectorImpl *operands);
+ SmallVectorImpl *operands,
+ bool composeAffineMin = false);
} // namespace affine
} // namespace mlir
diff --git a/mlir/include/mlir/Interfaces/ValueBoundsOpInterface.h
b/mlir/include/mlir/Interfaces/ValueBoundsOpInterface.h
index 337314143c80c..523df173093fa 100644
--- a/mlir/include/mlir/Interfaces/ValueBoundsOpInterface.h
+++ b/mlir/include/mlir/Interfaces/ValueBoundsOpInterface.h
@@ -135,7 +135,7 @@ class ValueBoundsConstraintSet
/// Construct a variable for a map and its operands.
Variable(AffineMap map, ArrayRef mapOperands);
-Variable(AffineMap map, ArrayRef mapOperands);
+Variable(AffineMap map, ValueRange mapOperands);
MLIRContext *getContext() const { return map.getContext();
[llvm-branch-commits] [mlir] [mlir][transform] Drop redundant padding_dimensions spec from pad_tiling_interface (PR #145257)
https://github.com/Groverkss approved this pull request. https://github.com/llvm/llvm-project/pull/145257 ___ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [mlir] [mlir][transform] Drop redundant padding_dimensions spec from pad_tiling_interface (PR #145257)
Groverkss wrote: Rebase needed, but otherwise LGTM https://github.com/llvm/llvm-project/pull/145257 ___ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [mlir] [mlir][transform] Drop redundant padding_dimensions spec from pad_tiling_interface (PR #145257)
llvmbot wrote:
@llvm/pr-subscribers-mlir
Author: Nicolas Vasilache (nicolasvasilache)
Changes
This revision aligns padding specification in pad_tiling_interface to that of
tiling specification.
Dimensions that should be skipped are specified by "padding by 0".
Trailing dimensions that are ignored are automatically completed to "pad to 0".
---
Full diff: https://github.com/llvm/llvm-project/pull/145257.diff
5 Files Affected:
- (modified)
mlir/include/mlir/Dialect/Linalg/TransformOps/LinalgTransformOps.td (+17-8)
- (modified) mlir/lib/Dialect/Linalg/TransformOps/LinalgTransformOps.cpp
(+1-20)
- (modified) mlir/lib/Dialect/Linalg/Transforms/PadTilingInterface.cpp (+21-24)
- (modified)
mlir/test/Dialect/Linalg/transform-op-pad-tiling-interface-multiple-of.mlir
(+11-17)
- (modified) mlir/test/Dialect/Linalg/transform-op-pad-tiling-interface.mlir
(+4-8)
``diff
diff --git
a/mlir/include/mlir/Dialect/Linalg/TransformOps/LinalgTransformOps.td
b/mlir/include/mlir/Dialect/Linalg/TransformOps/LinalgTransformOps.td
index cf3f2b70580da..c5650470fdc8d 100644
--- a/mlir/include/mlir/Dialect/Linalg/TransformOps/LinalgTransformOps.td
+++ b/mlir/include/mlir/Dialect/Linalg/TransformOps/LinalgTransformOps.td
@@ -1195,17 +1195,29 @@ def PadTilingInterfaceOp : Op {
let description = [{
-Pads the operations pointed to by the target handle using the options
-provided as operation attributes. The operation returns a handle to the
-padded operation and to the padding operation ("tensor.pad").
+Pads the **iteration domain** of the operations pointed to by the target
+handle using the options provided as operation attributes. Padding the
+iteration domain induces a padding of the operands that is consistent
+across the op semantics and, unlike for simple elementwise ops, may not be
+trivially deducible or specifiable on operands only (e.g. convolutions).
+
+The specification of `padding_sizes` follows that of `tile_sizes` during
+tiling: the value "0" on a particular iterator encode "no padding". Like in
+the case of tiling, an automatic completion by 0 to the operation rank
+occurs.
+
+This transformation returns a handle to the padded operation and to the
+padding operation ("tensor.pad").
TODO: in the future this should be moved out of a specific Linalg
implementation file and into a more general "Structured" file.
Return modes
-This operation ignores non-Linalg ops and drops them in the return.
-In the future, this operation will support all TilingInterfaceOps.
+This operation ignores non-IndexingMapOpInterface ops and drops them in the
+return. In the future, this operation will support all TilingInterfaceOps
+for which the contract between iteration domain and operands can be
+reified.
This operation may produce a definite failure if the padding fails for any
reason.
@@ -1219,7 +1231,6 @@ def PadTilingInterfaceOp : Op:$padding_values,
- DefaultValuedAttr:$padding_dimensions,
Variadic:$padding_sizes,
DefaultValuedOptionalAttr:
$static_padding_sizes,
@@ -1245,11 +1256,9 @@ def PadTilingInterfaceOp : Op":$paddingDimensions,
CArg<"ArrayRef", "{}">:$staticPaddingSizes,
CArg<"bool", "false">:$padToMultipleOf)>,
OpBuilder<(ins "Value":$target,
- "ArrayRef":$paddingDimensions,
"ArrayRef":$mixedPadPaddingSizes,
CArg<"bool", "false">:$usePrescribedTensorShapes)>
];
diff --git a/mlir/lib/Dialect/Linalg/TransformOps/LinalgTransformOps.cpp
b/mlir/lib/Dialect/Linalg/TransformOps/LinalgTransformOps.cpp
index 5d55adbf46f36..d9a0ba02f4fe4 100644
--- a/mlir/lib/Dialect/Linalg/TransformOps/LinalgTransformOps.cpp
+++ b/mlir/lib/Dialect/Linalg/TransformOps/LinalgTransformOps.cpp
@@ -2163,7 +2163,6 @@ LogicalResult transform::PadOp::verify() {
void transform::PadTilingInterfaceOp::build(OpBuilder &b,
OperationState &result,
Value target,
-ArrayRef
paddingDimensions,
ArrayRef paddingSizes,
bool padToMultipleOf) {
auto resultType = transform::AnyOpType::get(b.getContext());
@@ -2172,7 +2171,6 @@ void transform::PadTilingInterfaceOp::build(OpBuilder &b,
/*types=*/TypeRange{resultType, resultType},
/*target=*/target,
/*paddingValues=*/ArrayAttr(), // let inference handle this
- /*paddingDimensions=*/b.getI64ArrayAttr(paddingDimensions),
/*paddingSizes=*/ValueRange{},
/*paddingSizes=*/
(paddingSizes.empty() ? DenseI64ArrayAttr()
@@ -2183,7 +2181,6 @@ void transform::PadTilingInterfaceOp::build(OpBuilder &b,
